     1                                  ; ****************************************************************************
     2                                  ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 05/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                                  
   128                                  [BITS 16]       ; We need 16-bit intructions for Real mode
   129                                  
   130                                  [ORG 0] 
   131                                  	; 12/11/2014
   132                                  	; Save boot drive number (that is default root drive)
   133 00000000 8816[BAB8]              	mov	[boot_drv], dl ; physical drv number
   134                                  
   135                                  	; Determine installed memory
   136                                  	; 31/10/2014
   137                                  	;
   138 00000004 B801E8                  	mov	ax, 0E801h ; Get memory size 
   139 00000007 CD15                    	int	15h	   ; for large configurations
   140 00000009 7308                    	jnc	short chk_ms
   141 0000000B B488                    	mov	ah, 88h    ; Get extended memory size 
   142 0000000D CD15                    	int	15h
   143                                  	;	   
   144                                  	;mov	al, 17h	; Extended memory (1K blocks) low byte
   145                                  	;out	70h, al ; select CMOS register
   146                                  	;in	al, 71h ; read data (1 byte)
   147                                  	;mov	cl, al
   148                                  	;mov	al, 18h ; Extended memory (1K blocks) high byte
   149                                  	;out	70h, al ; select CMOS register
   150                                  	;in	al, 71h ; read data (1 byte)
   151                                  	;mov	ch, al
   152                                   	;      
   153 0000000F 89C1                    	mov	cx, ax
   154 00000011 31D2                    	xor	dx, dx
   155                                  chk_ms:
   156 00000013 890E[44BB]              	mov	[mem_1m_1k], cx
   157 00000017 8916[46BB]              	mov	[mem_16m_64k], dx
   158                                  	; 05/11/2014
   159                                  	;and	dx, dx
   160                                  	;jz	short L2
   161 0000001B 81F90004                        cmp     cx, 1024
   162 0000001F 7315                    	jnb	short L0
   163                                  		 ; insufficient memory_error	
   164                                  		 ; Minimum 2 MB memory is needed... 
   165                                  	; 05/11/2014
   166                                  	; (real mode error printing)
   167 00000021 FB                      	sti
   168 00000022 BE[D3B9]                	mov	si, msg_out_of_memory
   169 00000025 BB0700                  	mov	bx, 7
   170 00000028 B40E                    	mov	ah, 0Eh	; write tty
   171                                  oom_1:
   172 0000002A AC                      	lodsb
   173 0000002B 08C0                    	or	al, al
   174 0000002D 7404                    	jz	short oom_2
   175 0000002F CD10                    	int	10h
   176 00000031 EBF7                    	jmp	short oom_1
   177                                  oom_2:
   178 00000033 F4                              hlt
   179 00000034 EBFD                    	jmp	short oom_2
   180                                  
   181                                  L0:
   182                                  %include 'diskinit.s' ; 07/03/2015
   183                              <1> ; ****************************************************************************
   184                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskinit.s
   185                              <1> ; ----------------------------------------------------------------------------
   186                              <1> ; Last Update: 04/02/2016
   187                              <1> ; ----------------------------------------------------------------------------
   188                              <1> ; Beginning: 24/01/2016
   189                              <1> ; ----------------------------------------------------------------------------
   190                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
   191                              <1> ; ----------------------------------------------------------------------------
   192                              <1> ; Turkish Rational DOS
   193                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
   194                              <1> ;
   195                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
   196                              <1> ; diskinit.inc (10/07/2015)
   197                              <1> ;
   198                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
   199                              <1> ; ****************************************************************************
   200                              <1> 
   201                              <1> ; Retro UNIX 386 v1 Kernel - DISKINIT.INC
   202                              <1> ; Last Modification: 10/07/2015
   203                              <1> 
   204                              <1> ; DISK I/O SYSTEM INITIALIZATION - Erdogan Tan (Retro UNIX 386 v1 project)
   205                              <1> 
   206                              <1> ; ///////// DISK I/O SYSTEM STRUCTURE INITIALIZATION ///////////////
   207                              <1> 
   208                              <1> 	; 10/12/2014 - 02/02/2015 - dsectrm2.s
   209                              <1> ;L0:
   210                              <1> 	; 12/11/2014 (Retro UNIX 386 v1 - beginning)
   211                              <1> 	; Detecting disk drives... (by help of ROM-BIOS)
   212 00000036 BA7F00              <1> 	mov	dx, 7Fh
   213                              <1> L1:	
   214 00000039 FEC2                <1> 	inc	dl
   215 0000003B B441                <1> 	mov	ah, 41h ; Check extensions present
   216                              <1> 			; Phoenix EDD v1.1 - EDD v3
   217 0000003D BBAA55              <1> 	mov	bx, 55AAh
   218 00000040 CD13                <1> 	int 	13h
   219 00000042 721A                <1> 	jc	short L2
   220                              <1> 
   221 00000044 81FB55AA            <1> 	cmp	bx, 0AA55h
   222 00000048 7514                <1> 	jne	short L2
   223 0000004A FE06[BDB8]          <1> 	inc	byte [hdc]	; count of hard disks (EDD present)
   224 0000004E 8816[BCB8]          <1>         mov     [last_drv], dl  ; last hard disk number
   225 00000052 BB[40B8]            <1> 	mov	bx, hd0_type - 80h
   226 00000055 01D3                <1> 	add	bx, dx	 
   227 00000057 880F                <1> 	mov	[bx], cl ; Interface support bit map in CX
   228                              <1> 			 ; Bit 0 - 1, Fixed disk access subset ready
   229                              <1> 			 ; Bit 1 - 1, Drv locking and ejecting ready
   230                              <1> 			 ; Bit 2 - 1, Enhanced Disk Drive Support
   231                              <1>                          ;            (EDD) ready (DPTE ready)
   232                              <1> 			 ; Bit 3 - 1, 64bit extensions are present
   233                              <1>                          ;            (EDD-3)
   234                              <1> 			 ; Bit 4 to 15 - 0, Reserved
   235 00000059 80FA83              <1> 	cmp	dl, 83h	 ; drive number < 83h
   236 0000005C 72DB                <1> 	jb	short L1
   237                              <1> L2:
   238                              <1> 	; 23/11/2014
   239                              <1> 	; 19/11/2014
   240 0000005E 30D2                <1> 	xor	dl, dl  ; 0
   241                              <1> 	; 04/02/2016 (esi -> si)
   242 00000060 BE[BEB8]            <1> 	mov	si, fd0_type
   243                              <1> L3:
   244                              <1> 	; 14/01/2015
   245 00000063 8816[BBB8]          <1> 	mov	[drv], dl
   246                              <1> 	;
   247 00000067 B408                <1> 	mov 	ah, 08h ; Return drive parameters
   248 00000069 CD13                <1> 	int	13h	
   249 0000006B 7210                <1> 	jc	short L4
   250                              <1> 		; BL = drive type (for floppy drives)
   251                              <1> 		; DL = number of floppy drives
   252                              <1> 		;		
   253                              <1> 		; ES:DI = Address of DPT from BIOS
   254                              <1> 		;
   255 0000006D 881C                <1> 	mov	[si], bl ;  Drive type
   256                              <1> 			; 4 = 1.44 MB, 80 track, 3 1/2"
   257                              <1> 	; 14/01/2015
   258 0000006F E8A202              <1> 	call	set_disk_parms
   259                              <1> 	; 10/12/2014
   260 00000072 81FE[BEB8]          <1> 	cmp	si, fd0_type
   261 00000076 7705                <1> 	ja	short L4
   262 00000078 46                  <1> 	inc	si ; fd1_type
   263 00000079 B201                <1> 	mov	dl, 1
   264 0000007B EBE6                <1> 	jmp	short L3
   265                              <1> L4:
   266                              <1> 	; Older BIOS (INT 13h, AH = 48h is not available)
   267 0000007D B27F                <1> 	mov	dl, 7Fh
   268                              <1> 	; 24/12/2014 (Temporary)
   269 0000007F 803E[BDB8]00        <1> 	cmp	byte [hdc], 0 ; EDD present or not ?	
   270 00000084 0F879000            <1>         ja      L10       ; yes, all fixed disk operations
   271                              <1> 			  ; will be performed according to
   272                              <1> 			  ; present EDD specification
   273                              <1> L6:
   274 00000088 FEC2                <1> 	inc 	dl
   275 0000008A 8816[BBB8]          <1>         mov     [drv], dl
   276 0000008E 8816[BCB8]          <1>         mov     [last_drv], dl ; 14/01/2015
   277 00000092 B408                <1> 	mov 	ah, 08h ; Return drive parameters
   278 00000094 CD13                <1> 	int	13h	; (conventional function)
   279 00000096 0F828201            <1>         jc      L13	; fixed disk drive not ready
   280 0000009A 8816[BDB8]          <1>         mov     [hdc], dl ; number of drives
   281                              <1> 	;; 14/01/2013
   282                              <1> 	;;push	cx
   283 0000009E E87302              <1> 	call	set_disk_parms
   284                              <1> 	;;pop	cx
   285                              <1> 	;
   286                              <1> 	;;and	cl, 3Fh	 ; sectors per track (bits 0-6)
   287 000000A1 8A16[BBB8]          <1>         mov     dl, [drv]
   288 000000A5 BB0401              <1> 	mov	bx, 65*4 ; hd0 parameters table (INT 41h)	
   289 000000A8 80FA80              <1> 	cmp	dl, 80h
   290 000000AB 7603                <1> 	jna	short L7
   291 000000AD 83C314              <1> 	add	bx, 5*4	 ; hd1 parameters table (INT 46h)
   292                              <1> L7:	
   293 000000B0 31C0                <1> 	xor	ax, ax
   294 000000B2 8ED8                <1> 	mov	ds, ax
   295 000000B4 8B37                <1>         mov     si, [bx]
   296 000000B6 8B4702              <1>         mov     ax, [bx+2] 
   297 000000B9 8ED8                <1> 	mov	ds, ax
   298 000000BB 3A4C0E              <1>         cmp     cl, [si+FDPT_SPT] ; sectors per track 
   299 000000BE 0F855601            <1>         jne     L12 ; invalid FDPT
   300 000000C2 BF0000              <1> 	mov	di, HD0_DPT
   301 000000C5 80FA80              <1> 	cmp	dl, 80h
   302 000000C8 7603                <1> 	jna	short L8
   303 000000CA BF2000              <1> 	mov	di, HD1_DPT 
   304                              <1> L8:
   305                              <1> 	; 30/12/2014
   306 000000CD B80090              <1> 	mov	ax, DPT_SEGM
   307 000000D0 8EC0                <1> 	mov	es, ax
   308                              <1> 	; 24/12/2014
   309 000000D2 B90800              <1> 	mov	cx, 8
   310 000000D5 F3A5                <1> 	rep	movsw  ; copy 16 bytes to the kernel's DPT location
   311 000000D7 8CC8                <1> 	mov	ax, cs
   312 000000D9 8ED8                <1> 	mov	ds, ax
   313                              <1> 	; 02/02/2015
   314 000000DB 8A0E[BBB8]          <1>         mov     cl, [drv]
   315 000000DF 88CB                <1> 	mov	bl, cl
   316 000000E1 B8F001              <1> 	mov	ax, 1F0h
   317 000000E4 80E301              <1> 	and	bl, 1
   318 000000E7 7406                <1> 	jz	short L9
   319 000000E9 C0E304              <1> 	shl	bl, 4
   320 000000EC 2D8000              <1> 	sub	ax, 1F0h-170h
   321                              <1> L9:
   322 000000EF AB                  <1> 	stosw	; I/O PORT Base Address (1F0h, 170h)
   323 000000F0 050602              <1> 	add	ax, 206h
   324 000000F3 AB                  <1> 	stosw	; CONTROL PORT Address (3F6h, 376h)	
   325 000000F4 88D8                <1> 	mov	al, bl
   326 000000F6 04A0                <1> 	add	al, 0A0h
   327 000000F8 AA                  <1> 	stosb	; Device/Head Register upper nibble
   328                              <1> 	;
   329 000000F9 FE06[BBB8]          <1> 	inc	byte [drv]
   330 000000FD BB[40B8]            <1> 	mov	bx, hd0_type - 80h
   331 00000100 01CB                <1> 	add	bx, cx
   332 00000102 800F80              <1>         or      byte [bx], 80h  ; present sign (when lower nibble is 0)
   333 00000105 A0[BDB8]            <1> 	mov	al, [hdc]
   334 00000108 FEC8                <1> 	dec	al
   335 0000010A 0F840E01            <1>         jz      L13
   336 0000010E 80FA80              <1> 	cmp	dl, 80h
   337 00000111 0F8673FF            <1>         jna     L6
   338 00000115 E90401              <1>         jmp     L13
   339                              <1> L10:
   340 00000118 FEC2                <1> 	inc 	dl
   341                              <1> 	; 25/12/2014
   342 0000011A 8816[BBB8]          <1> 	mov	[drv], dl
   343 0000011E B408                <1> 	mov 	ah, 08h ; Return drive parameters
   344 00000120 CD13                <1> 	int	13h	; (conventional function)
   345 00000122 0F82F600            <1>         jc      L13
   346                              <1> 	; 14/01/2015
   347 00000126 8A16[BBB8]          <1> 	mov	dl, [drv]
   348 0000012A 52                  <1> 	push	dx
   349 0000012B 51                  <1> 	push	cx
   350 0000012C E8E501              <1> 	call	set_disk_parms
   351 0000012F 59                  <1> 	pop	cx
   352 00000130 5A                  <1> 	pop	dx
   353                              <1> 	; 04/02/2016 (esi -> si)
   354 00000131 BE[18DB]            <1> 	mov	si, _end ; 30 byte temporary buffer address 	
   355                              <1> 			 ; at the '_end' of kernel.
   356 00000134 C7041E00            <1> 	mov	word [si], 30
   357 00000138 B448                <1> 	mov	ah, 48h	 ; Get drive parameters (EDD function)
   358 0000013A CD13                <1> 	int	13h
   359 0000013C 0F82DC00            <1>         jc      L13
   360                              <1> 	; 04/02/2016 (ebx -> bx)
   361                              <1> 	; 14/01/2015
   362 00000140 29DB                <1> 	sub	bx, bx
   363 00000142 88D3                <1> 	mov	bl, dl
   364 00000144 80EB80              <1> 	sub	bl, 80h
   365 00000147 81C3[C0B8]          <1> 	add	bx, hd0_type
   366 0000014B 8A07                <1> 	mov 	al, [bx]
   367 0000014D 0C80                <1> 	or	al, 80h
   368 0000014F 8807                <1> 	mov 	[bx], al	
   369 00000151 81EB[BEB8]          <1> 	sub	bx, hd0_type - 2 ; 15/01/2015
   370 00000155 81C3[0AB9]          <1> 	add	bx, drv.status
   371 00000159 8807                <1> 	mov	[bx], al
   372                              <1> 	; 04/02/2016 (eax -> ax)
   373 0000015B 8B4410              <1> 	mov	ax, [si+16]
   374 0000015E 854412              <1> 	test	ax, [si+18]
   375 00000161 7412                <1> 	jz	short L10_A0h 
   376                              <1> 			; 'CHS only' disks on EDD system 
   377                              <1> 			;  are reported with ZERO disk size
   378 00000163 81EB[0AB9]          <1> 	sub	bx, drv.status
   379 00000167 C1E302              <1> 	shl	bx, 2
   380 0000016A 81C3[EEB8]          <1> 	add	bx, drv.size ; disk size (in sectors)
   381 0000016E 8907                <1> 	mov	[bx], ax
   382 00000170 8B4412              <1> 	mov	ax, [si+18]
   383 00000173 8907                <1> 	mov	[bx], ax
   384                              <1> 
   385                              <1> L10_A0h: ; Jump here to fix a ZERO (LBA) disk size problem 
   386                              <1> 	 ; for CHS disks (28/02/2015)
   387                              <1> 	; 30/12/2014
   388 00000175 BF0000              <1> 	mov	di, HD0_DPT
   389 00000178 88D0                <1> 	mov	al, dl
   390 0000017A 83E003              <1> 	and 	ax, 3
   391 0000017D C0E005              <1> 	shl	al, 5 ; *32
   392 00000180 01C7                <1> 	add 	di, ax
   393 00000182 B80090              <1> 	mov	ax, DPT_SEGM
   394 00000185 8EC0                <1> 	mov	es, ax
   395                              <1> 	;
   396 00000187 88E8                <1> 	mov	al, ch	; max. cylinder number (bits 0-7)
   397 00000189 88CC                <1> 	mov	ah, cl	
   398 0000018B C0EC06              <1> 	shr	ah, 6	; max. cylinder number (bits 8-9)
   399 0000018E 40                  <1>  	inc	ax	; logical cylinders (limit 1024)
   400 0000018F AB                  <1> 	stosw		
   401 00000190 88F0                <1> 	mov	al, dh	; max. head number
   402 00000192 FEC0                <1> 	inc	al
   403 00000194 AA                  <1> 	stosb		; logical heads (limits 256)
   404 00000195 B0A0                <1> 	mov	al, 0A0h ; Indicates translated table
   405 00000197 AA                  <1> 	stosb
   406 00000198 8A440C              <1> 	mov	al, [si+12]
   407 0000019B AA                  <1> 	stosb		 ; physical sectors per track
   408 0000019C 31C0                <1>  	xor	ax, ax
   409                              <1> 	;dec	ax	 ; 02/01/2015 
   410 0000019E AB                  <1> 	stosw		 ; precompensation (obsolete)
   411                              <1> 	;xor	al, al	 ; 02/01/2015	
   412 0000019F AA                  <1> 	stosb		 ; reserved
   413 000001A0 B008                <1> 	mov	al, 8	 ; drive control byte
   414                              <1> 		         ; (do not disable retries, 
   415                              <1> 			 ; more than 8 heads)
   416 000001A2 AA                  <1> 	stosb
   417 000001A3 8B4404              <1> 	mov	ax, [si+4]
   418 000001A6 AB                  <1> 	stosw		 ; physical number of cylinders	
   419                              <1> 	;push	ax	 ; 02/01/2015
   420 000001A7 8A4408              <1> 	mov	al, [si+8]
   421 000001AA AA                  <1> 	stosb		 ; physical num. of heads (limit 16)
   422 000001AB 29C0                <1> 	sub 	ax, ax
   423                              <1> 	;pop	ax	 ; 02/01/2015	
   424 000001AD AB                  <1> 	stosw		 ; landing zone (obsolete)
   425 000001AE 88C8                <1> 	mov	al, cl	 ; logical sectors per track (limit 63)
   426 000001B0 243F                <1> 	and 	al, 3Fh	
   427 000001B2 AA                  <1> 	stosb
   428                              <1> 	;sub	al, al	 ; checksum
   429                              <1> 	;stosb
   430                              <1> 	;
   431 000001B3 83C61A              <1> 	add	si, 26   ; (BIOS) DPTE address pointer
   432 000001B6 AD                  <1> 	lodsw
   433 000001B7 50                  <1> 	push	ax	 ; (BIOS) DPTE offset
   434 000001B8 AD                  <1> 	lodsw
   435 000001B9 50                  <1> 	push	ax	 ; (BIOS) DPTE segment
   436                              <1> 	;
   437                              <1> 	; checksum calculation
   438 000001BA 89FE                <1> 	mov	si, di
   439 000001BC 06                  <1> 	push	es
   440 000001BD 1F                  <1> 	pop	ds
   441                              <1> 	;mov	cx, 16
   442 000001BE B90F00              <1> 	mov 	cx, 15
   443 000001C1 29CE                <1> 	sub	si, cx
   444 000001C3 30E4                <1> 	xor	ah, ah
   445                              <1> 	;del	cl
   446                              <1> L11:		
   447 000001C5 AC                  <1> 	lodsb
   448 000001C6 00C4                <1> 	add	ah, al
   449 000001C8 E2FB                <1> 	loop	L11
   450                              <1> 	;
   451 000001CA 88E0                <1> 	mov	al, ah
   452 000001CC F6D8                <1> 	neg	al	; -x+x = 0
   453 000001CE AA                  <1> 	stosb		; put checksum in byte 15 of the tbl
   454                              <1> 	;
   455 000001CF 1F                  <1> 	pop	ds	; (BIOS) DPTE segment
   456 000001D0 5E                  <1> 	pop	si	; (BIOS) DPTE offset	
   457                              <1> 	;
   458                              <1> 	; 23/02/2015
   459 000001D1 57                  <1> 	push	di
   460                              <1> 	; ES:DI points to DPTE (FDPTE) location
   461                              <1> 	;mov	cx, 8
   462 000001D2 B108                <1> 	mov	cl, 8
   463 000001D4 F3A5                <1> 	rep	movsw	
   464                              <1> 	;
   465                              <1> 	; 23/02/2015
   466                              <1> 	; (P)ATA drive and LBA validation
   467                              <1> 	; (invalidating SATA drives and setting
   468                              <1> 	; CHS type I/O for old type fixed disks)
   469 000001D6 5B                  <1> 	pop	bx
   470 000001D7 8CC8                <1> 	mov	ax, cs
   471 000001D9 8ED8                <1> 	mov	ds, ax
   472 000001DB 268B07              <1> 	mov	ax, [es:bx]
   473 000001DE 3DF001              <1> 	cmp	ax, 1F0h
   474 000001E1 7418                <1> 	je	short L11a
   475 000001E3 3D7001              <1> 	cmp	ax, 170h
   476 000001E6 7413                <1> 	je	short L11a
   477                              <1> 	; invalidation 
   478                              <1> 	; (because base port address is not 1F0h or 170h)
   479 000001E8 30FF                <1> 	xor	bh, bh
   480 000001EA 88D3                <1> 	mov	bl, dl
   481 000001EC 80EB80              <1> 	sub	bl, 80h
   482 000001EF C687[C0B8]00        <1> 	mov	byte [bx+hd0_type], 0 ; not a valid disk drive !		
   483 000001F4 808F[0CB9]F0        <1>         or      byte [bx+drv.status+2], 0F0h ; (failure sign)
   484 000001F9 EB14                <1> 	jmp	short L11b
   485                              <1> L11a:	
   486                              <1> 	; LBA validation
   487 000001FB 268A4704            <1> 	mov	al, [es:bx+4] ; Head register upper nibble
   488 000001FF A840                <1> 	test	al, 40h ; LBA bit (bit 6)
   489 00000201 750C                <1> 	jnz	short L11b ; LBA type I/O is OK! (E0h or F0h)
   490                              <1> 	; force CHS type I/O for this drive (A0h or B0h)
   491 00000203 28FF                <1> 	sub	bh, bh
   492 00000205 88D3                <1> 	mov	bl, dl
   493 00000207 80EB80              <1> 	sub	bl, 80h ; 26/02/2015
   494 0000020A 80A7[0CB9]FE        <1>         and     byte [bx+drv.status+2], 0FEh ; clear bit 0
   495                              <1> 				; bit 0 = LBA ready bit
   496                              <1> 	; 'diskio' procedure will check this bit !
   497                              <1> L11b:
   498 0000020F 3A16[BCB8]          <1> 	cmp	dl, [last_drv] ; 25/12/2014
   499 00000213 7307                <1>         jnb     short L13
   500 00000215 E900FF              <1>         jmp     L10
   501                              <1> L12:
   502                              <1> 	; Restore data registers
   503 00000218 8CC8                <1> 	mov	ax, cs
   504 0000021A 8ED8                <1> 	mov	ds, ax	
   505                              <1> L13:
   506                              <1> 	; 13/12/2014
   507 0000021C 0E                  <1> 	push	cs
   508 0000021D 07                  <1> 	pop	es
   509                              <1> L14:
   510 0000021E B411                <1> 	mov 	ah, 11h
   511 00000220 CD16                <1> 	int 	16h
   512 00000222 7406                <1> 	jz 	short L15 ; no keys in keyboard buffer
   513 00000224 B010                <1> 	mov	al, 10h
   514 00000226 CD16                <1> 	int 	16h
   515 00000228 EBF4                <1> 	jmp 	short L14
   516                              <1> L15:
   517                              <1> ; //////
   518                              <1> 	; 24/11/2014
   519                              <1> 	; 19/11/2014
   520                              <1> 	; 14/11/2014
   521                              <1> 	; Temporary code for disk searching code check
   522                              <1> 	;
   523                              <1> 	; This code will show existing (usable) drives and also
   524                              <1> 	; will show EDD interface support status for hard disks		
   525                              <1> 	; (If status bit 7 is 1, Identify Device info is ready,
   526                              <1> 	; no need to get it again in protected mode...) 
   527                              <1> 	;	
   528                              <1> 	; 13/11/2014
   529 0000022A BB0700              <1> 	mov	bx, 7
   530 0000022D B40E                <1> 	mov	ah, 0Eh
   531 0000022F A0[BEB8]            <1> 	mov	al, [fd0_type]
   532 00000232 20C0                <1> 	and	al, al
   533 00000234 743D                <1> 	jz	short L15a
   534 00000236 88C2                <1> 	mov	dl, al
   535 00000238 B046                <1> 	mov	al, 'F'
   536 0000023A CD10                <1> 	int 	10h
   537 0000023C B044                <1> 	mov	al, 'D'
   538 0000023E CD10                <1> 	int 	10h
   539 00000240 B030                <1> 	mov	al, '0'
   540 00000242 CD10                <1> 	int 	10h
   541 00000244 B020                <1> 	mov	al, ' '
   542 00000246 CD10                <1> 	int	10h
   543 00000248 E8B200              <1> 	call	L15c
   544 0000024B B020                <1> 	mov	al, ' '
   545 0000024D CD10                <1> 	int	10h
   546                              <1> 	;
   547 0000024F A0[BFB8]            <1> 	mov	al, [fd1_type]
   548 00000252 20C0                <1> 	and	al, al
   549 00000254 741D                <1> 	jz	short L15a
   550 00000256 88C2                <1> 	mov	dl, al
   551 00000258 B046                <1> 	mov	al, 'F'
   552 0000025A CD10                <1> 	int 	10h
   553 0000025C B044                <1> 	mov	al, 'D'
   554 0000025E CD10                <1> 	int 	10h
   555 00000260 B031                <1> 	mov	al, '1'
   556 00000262 CD10                <1> 	int 	10h
   557 00000264 B020                <1> 	mov	al, ' '
   558 00000266 CD10                <1> 	int	10h
   559 00000268 E89200              <1> 	call	L15c
   560 0000026B B020                <1> 	mov	al, ' '
   561 0000026D CD10                <1> 	int	10h
   562 0000026F B020                <1> 	mov	al, ' '
   563 00000271 CD10                <1> 	int	10h
   564                              <1> L15a:
   565 00000273 A0[C0B8]            <1> 	mov	al, [hd0_type]
   566 00000276 20C0                <1> 	and	al, al
   567 00000278 7479                <1> 	jz	short L15b
   568 0000027A 88C2                <1> 	mov	dl, al
   569 0000027C B048                <1> 	mov	al, 'H'
   570 0000027E CD10                <1> 	int 	10h
   571 00000280 B044                <1> 	mov	al, 'D'
   572 00000282 CD10                <1> 	int 	10h
   573 00000284 B030                <1> 	mov	al, '0'
   574 00000286 CD10                <1> 	int 	10h
   575 00000288 B020                <1> 	mov	al, ' '
   576 0000028A CD10                <1> 	int 	10h
   577 0000028C E86E00              <1> 	call	L15c
   578 0000028F B020                <1> 	mov	al, ' '
   579 00000291 CD10                <1> 	int	10h
   580                              <1> 	;
   581 00000293 A0[C1B8]            <1> 	mov	al, [hd1_type]
   582 00000296 20C0                <1> 	and	al, al
   583 00000298 7459                <1> 	jz	short L15b
   584 0000029A 88C2                <1> 	mov	dl, al
   585 0000029C B048                <1> 	mov	al, 'H'
   586 0000029E CD10                <1> 	int 	10h
   587 000002A0 B044                <1> 	mov	al, 'D'
   588 000002A2 CD10                <1> 	int 	10h
   589 000002A4 B031                <1> 	mov	al, '1'
   590 000002A6 CD10                <1> 	int 	10h
   591 000002A8 B020                <1> 	mov	al, ' '
   592 000002AA CD10                <1> 	int 	10h
   593 000002AC E84E00              <1> 	call	L15c
   594 000002AF B020                <1> 	mov	al, ' '
   595 000002B1 CD10                <1> 	int	10h
   596                              <1> 	;
   597 000002B3 A0[C2B8]            <1> 	mov	al, [hd2_type]
   598 000002B6 20C0                <1> 	and	al, al
   599 000002B8 7439                <1> 	jz	short L15b
   600 000002BA 88C2                <1> 	mov	dl, al
   601 000002BC B048                <1> 	mov	al, 'H'
   602 000002BE CD10                <1> 	int 	10h
   603 000002C0 B044                <1> 	mov	al, 'D'
   604 000002C2 CD10                <1> 	int 	10h
   605 000002C4 B032                <1> 	mov	al, '2'
   606 000002C6 CD10                <1> 	int 	10h
   607 000002C8 B020                <1> 	mov	al, ' '
   608 000002CA CD10                <1> 	int 	10h
   609 000002CC E82E00              <1> 	call	L15c
   610 000002CF B020                <1> 	mov	al, ' '
   611 000002D1 CD10                <1> 	int	10h
   612                              <1> 	;
   613 000002D3 A0[C3B8]            <1> 	mov	al, [hd3_type]
   614 000002D6 20C0                <1> 	and	al, al
   615 000002D8 7419                <1> 	jz	short L15b
   616 000002DA 88C2                <1> 	mov	dl, al
   617 000002DC B048                <1> 	mov	al, 'H'
   618 000002DE CD10                <1> 	int 	10h
   619 000002E0 B044                <1> 	mov	al, 'D'
   620 000002E2 CD10                <1> 	int 	10h
   621 000002E4 B033                <1> 	mov	al, '3'
   622 000002E6 CD10                <1> 	int 	10h
   623 000002E8 B020                <1> 	mov	al, ' '
   624 000002EA CD10                <1> 	int 	10h
   625 000002EC E80E00              <1> 	call	L15c
   626 000002EF B020                <1> 	mov	al, ' '
   627 000002F1 CD10                <1> 	int	10h
   628                              <1> 	;
   629                              <1> L15b:
   630 000002F3 B00D                <1> 	mov	al, 0Dh
   631 000002F5 CD10                <1> 	int 	10h	
   632 000002F7 B00A                <1> 	mov	al, 0Ah
   633 000002F9 CD10                <1> 	int 	10h
   634                              <1> 	;;xor	ah, ah
   635                              <1> 	;;int 	16h	
   636                              <1> 	;
   637 000002FB EB77                <1>         jmp     L16  ; jmp short L16
   638                              <1>         ;
   639                              <1> L15c:
   640 000002FD 88D6                <1> 	mov	dh, dl
   641 000002FF C0EE04              <1> 	shr	dh, 4
   642 00000302 80C630              <1> 	add	dh, 30h
   643 00000305 80E20F              <1> 	and	dl, 15
   644 00000308 80C230              <1> 	add	dl, 30h
   645 0000030B 88F0                <1> 	mov	al, dh
   646 0000030D CD10                <1> 	int	10h
   647 0000030F 88D0                <1> 	mov	al, dl
   648 00000311 CD10                <1> 	int	10h
   649 00000313 C3                  <1> 	retn
   650                              <1> 	;
   651                              <1> 	; end of temporary code for disk searching code check
   652                              <1> 
   653                              <1> ; //////
   654                              <1> 
   655                              <1> set_disk_parms:
   656                              <1> 	; 04/02/2016 (ebx -> bx)
   657                              <1> 	; 10/07/2015
   658                              <1> 	; 14/01/2015
   659                              <1> 	;push	bx
   660 00000314 28FF                <1> 	sub	bh, bh
   661 00000316 8A1E[BBB8]          <1> 	mov	bl, [drv]
   662 0000031A 80FB80              <1> 	cmp	bl, 80h
   663 0000031D 7203                <1> 	jb	short sdp0
   664 0000031F 80EB7E              <1> 	sub	bl, 7Eh
   665                              <1> sdp0:	
   666 00000322 81C3[0AB9]          <1> 	add	bx, drv.status
   667 00000326 C60780              <1>   	mov	byte [bx], 80h ; 'Present' flag
   668                              <1> 	;
   669 00000329 88E8                <1> 	mov	al, ch ; last cylinder (bits 0-7)
   670 0000032B 88CC                <1> 	mov	ah, cl ; 
   671 0000032D C0EC06              <1> 	shr	ah, 6  ; last cylinder (bits 8-9)
   672 00000330 81EB[0AB9]          <1> 	sub	bx, drv.status
   673 00000334 D0E3                <1> 	shl	bl, 1
   674 00000336 81C3[C4B8]          <1> 	add	bx, drv.cylinders
   675 0000033A 40                  <1> 	inc	ax  ; convert max. cyl number to cyl count		
   676 0000033B 8907                <1> 	mov	[bx], ax
   677 0000033D 50                  <1> 	push	ax ; ** cylinders
   678 0000033E 81EB[C4B8]          <1> 	sub	bx, drv.cylinders
   679 00000342 81C3[D2B8]          <1> 	add	bx, drv.heads
   680 00000346 30E4                <1> 	xor	ah, ah
   681 00000348 88F0                <1> 	mov	al, dh ; heads
   682 0000034A 40                  <1> 	inc	ax
   683 0000034B 8907                <1> 	mov	[bx], ax
   684 0000034D 81EB[D2B8]          <1>         sub     bx, drv.heads
   685 00000351 81C3[E0B8]          <1>         add     bx, drv.spt
   686 00000355 30ED                <1> 	xor	ch, ch
   687 00000357 80E13F              <1> 	and	cl, 3Fh	; sectors (bits 0-6)
   688 0000035A 890F                <1> 	mov	[bx], cx
   689 0000035C 81EB[E0B8]          <1>         sub     bx, drv.spt
   690 00000360 D1E3                <1> 	shl	bx, 1
   691 00000362 81C3[EEB8]          <1> 	add	bx, drv.size ; disk size (in sectors)
   692                              <1> 	; LBA size = cylinders * heads * secpertrack
   693 00000366 F7E1                <1> 	mul	cx 
   694 00000368 89C2                <1> 	mov	dx, ax	; heads*spt					
   695 0000036A 58                  <1> 	pop	ax ; ** cylinders
   696 0000036B 48                  <1> 	dec	ax ; 1 cylinder reserved (!?)
   697 0000036C F7E2                <1> 	mul	dx ; cylinders * (heads*spt)		
   698 0000036E 8907                <1> 	mov	[bx], ax
   699 00000370 895702              <1> 	mov	[bx+2], dx
   700                              <1> 	;
   701                              <1> 	;pop	bx
   702 00000373 C3                  <1> 	retn
   703                              <1> 
   704                              <1> ;align 2
   705                              <1> 
   706                              <1> ;cylinders :  dw 0, 0, 0, 0, 0, 0
   707                              <1> ;heads	  :  dw 0, 0, 0, 0, 0, 0
   708                              <1> ;spt	  :  dw 0, 0, 0, 0, 0, 0
   709                              <1> ;disk_size :  dd 0, 0, 0, 0, 0, 0
   710                              <1> 
   711                              <1> ;last_drv:
   712                              <1> ;	db  0
   713                              <1> ;drv_status:
   714                              <1> ;	db  0,0,0,0,0,0
   715                              <1> ;	db 0
   716                              <1> 
   717                              <1> 
   718                              <1> ; End Of DISK I/O SYSTEM STRUCTURE INITIALIZATION /// 06/02/2015
   719                              <1> 
   720                              <1> L16:
   721                                  
   722                                  	; 10/11/2014
   723 00000374 FA                           	cli	; Disable interrupts (clear interrupt flag)
   724                                  		; Reset Interrupt MASK Registers (Master&Slave)
   725                                  	;mov	al, 0FFh	; mask off all interrupts
   726                                  	;out	21h, al		; on master PIC (8259)
   727                                  	;jmp 	$+2  ; (delay)
   728                                  	;out	0A1h, al	; on slave PIC (8259)
   729                                  	;
   730                                  	; Disable NMI 
   731 00000375 B080                    	mov   	al, 80h 
   732 00000377 E670                    	out   	70h, al		; set bit 7 to 1 for disabling NMI
   733                                  	;23/02/2015
   734 00000379 90                      	nop			;
   735                                  	;in	al, 71h		; read in 71h just after writing out to 70h
   736                                  				; for preventing unknown state (!?)
   737                                  	;
   738                                   	; 20/08/2014
   739                                  	; Moving the kernel 64 KB back (to physical address 0)
   740                                  	; DS = CS = 1000h
   741                                  	; 05/11/2014
   742 0000037A 31C0                    	xor	ax, ax
   743 0000037C 8EC0                    	mov	es, ax ; ES = 0
   744                                  	;
   745 0000037E B90040                  	mov	cx, (KEND - KLOAD)/4
   746 00000381 31F6                    	xor	si, si
   747 00000383 31FF                    	xor	di, di
   748 00000385 F366A5                  	rep	movsd
   749                                  	;
   750 00000388 06                      	push	es ; 0
   751 00000389 68[8D03]                	push	L17
   752 0000038C CB                      	retf
   753                                  	;
   754                                  L17:
   755                                  	; Turn off the floppy drive motor
   756 0000038D BAF203                          mov     dx, 3F2h
   757 00000390 EE                              out     dx, al ; 0 ; 31/12/2013
   758                                  
   759                                  	; Enable access to memory above one megabyte
   760                                  L18:
   761 00000391 E464                    	in	al, 64h
   762 00000393 A802                    	test	al, 2
   763 00000395 75FA                            jnz     short L18
   764 00000397 B0D1                    	mov	al, 0D1h	; Write output port
   765 00000399 E664                    	out	64h, al
   766                                  L19:
   767 0000039B E464                    	in	al, 64h
   768 0000039D A802                    	test	al, 2
   769 0000039F 75FA                            jnz     short L19
   770 000003A1 B0DF                    	mov	al, 0DFh	; Enable A20 line
   771 000003A3 E660                    	out	60h, al
   772                                  ;L20:
   773                                  	;
   774                                  	; Load global descriptor table register
   775                                  
   776                                          ;mov     ax, cs
   777                                          ;mov     ds, ax
   778                                  
   779 000003A5 2E0F0116[D0B5]                  lgdt    [cs:gdtd]
   780                                  
   781 000003AB 0F20C0                          mov     eax, cr0
   782                                  	; or 	eax, 1
   783 000003AE 40                      	inc     ax
   784 000003AF 0F22C0                  	mov     cr0, eax
   785                                  
   786                                  	; Jump to 32 bit code
   787                                  	
   788 000003B2 66                      	db 66h 			; Prefix for 32-bit
   789 000003B3 EA                      	db 0EAh 		; Opcode for far jump
   790 000003B4 [BA030000]              	dd StartPM 		; Offset to start, 32-bit
   791                                  				; (1000h:StartPM = StartPM + 10000h)
   792 000003B8 0800                    	dw KCODE		; This is the selector for CODE32_DESCRIPTOR,
   793                                  				; assuming that StartPM resides in code32
   794                                  
   795                                  [BITS 32] 
   796                                  
   797                                  StartPM:
   798                                  	; Kernel Base Address = 0 ; 30/12/2013
   799 000003BA 66B81000                	mov ax, KDATA           ; Save data segment identifier
   800 000003BE 8ED8                            mov ds, ax              ; Move a valid data segment into DS register
   801 000003C0 8EC0                           	mov es, ax              ; Move data segment into ES register
   802 000003C2 8EE0                           	mov fs, ax              ; Move data segment into FS register
   803 000003C4 8EE8                          	mov gs, ax              ; Move data segment into GS register
   804 000003C6 8ED0                            mov ss, ax              ; Move data segment into SS register
   805 000003C8 BC00000900                      mov esp, 90000h         ; Move the stack pointer to 090000h
   806                                  
   807                                  clear_bss: ; Clear uninitialized data area
   808                                  	; 11/03/2015
   809 000003CD 31C0                    	xor  eax, eax ; 0
   810 000003CF B9E6070000              	mov  ecx, (bss_end - bss_start)/4
   811                                  	;shr  ecx, 2 ; bss section is already aligned for double words
   812 000003D4 BF[80BB0000]            	mov  edi, bss_start	
   813 000003D9 F3AB                    	rep  stosd  		
   814                                  
   815                                  memory_init:
   816                                  	; Initialize memory allocation table and page tables
   817                                  	; 16/11/2014
   818                                  	; 15/11/2014
   819                                  	; 07/11/2014
   820                                  	; 06/11/2014
   821                                  	; 05/11/2014
   822                                  	; 04/11/2014
   823                                  	; 31/10/2014 (Retro UNIX 386 v1 - Beginning) 
   824                                  	;
   825                                  ;	xor	eax, eax
   826                                  ;	xor 	ecx, ecx
   827 000003DB B108                    	mov	cl, 8
   828 000003DD BF00001000              	mov	edi, MEM_ALLOC_TBL	
   829 000003E2 F3AB                    	rep	stosd		   ; clear Memory Allocation Table
   830                                  				   ; for the first 1 MB memory
   831                                  	;
   832 000003E4 668B0D[44BB0000]        	mov	cx, [mem_1m_1k]	   ; Number of contiguous KB between
   833                                  				   ; 1 and 16 MB, max. 3C00h = 15 MB.
   834 000003EB 66C1E902                	shr	cx, 2		   ; convert 1 KB count to 4 KB count
   835 000003EF 890D[F0BD0000]          	mov	[free_pages], ecx
   836 000003F5 668B15[46BB0000]        	mov	dx, [mem_16m_64k]  ; Number of contiguous 64 KB blocks
   837                                  				   ; between 16 MB and 4 GB.	
   838 000003FC 6609D2                  	or	dx, dx
   839 000003FF 7413                    	jz	short mi_0
   840                                  	;
   841 00000401 6689D0                  	mov	ax, dx
   842 00000404 C1E004                  	shl	eax, 4		   ; 64 KB -> 4 KB (page count)
   843 00000407 0105[F0BD0000]          	add	[free_pages], eax
   844 0000040D 0500100000              	add	eax, 4096	   ; 16 MB = 4096 pages
   845 00000412 EB07                    	jmp	short mi_1
   846                                  mi_0:
   847 00000414 6689C8                  	mov	ax, cx
   848 00000417 66050001                	add	ax, 256		   ; add 256 pages for the first 1 MB		 
   849                                  mi_1:
   850 0000041B A3[ECBD0000]            	mov	[memory_size], eax ; Total available memory in pages
   851                                  				   ; 1 alloc. tbl. bit = 1 memory page
   852                                  				   ; 32 allocation bits = 32 mem. pages   
   853                                  	;
   854 00000420 05FF7F0000              	add	eax, 32767	   ; 32768 memory pages per 1 M.A.T. page 	
   855 00000425 C1E80F                  	shr	eax, 15		   ; ((32768 * x) + y) pages (y < 32768)
   856                                  				   ;  --> x + 1 M.A.T. pages, if y > 0
   857                                  				   ;  --> x M.A.T. pages, if y = 0
   858 00000428 66A3[00BE0000]          	mov	[mat_size], ax	   ; Memory Alloc. Table Size in pages		
   859 0000042E C1E00C                  	shl	eax, 12		   ; 1 M.A.T. page = 4096 bytes
   860                                  	;			   ; Max. 32 M.A.T. pages (4 GB memory)
   861 00000431 89C3                    	mov	ebx, eax	   ; M.A.T. size in bytes
   862                                  	; Set/Calculate Kernel's Page Directory Address
   863 00000433 81C300001000            	add	ebx, MEM_ALLOC_TBL
   864 00000439 891D[E8BD0000]          	mov	[k_page_dir], ebx  ; Kernel's Page Directory address
   865                                  				   ; just after the last M.A.T. page
   866                                  	;
   867 0000043F 83E804                  	sub	eax, 4		   ; convert M.A.T. size to offset value
   868 00000442 A3[F8BD0000]            	mov	[last_page], eax   ; last page ofset in the M.A.T.
   869                                  	;			   ; (allocation status search must be 
   870                                  				   ; stopped after here)	
   871 00000447 31C0                    	xor	eax, eax
   872 00000449 48                      	dec	eax		   ; FFFFFFFFh (set all bits to 1)	
   873 0000044A 6651                    	push	cx
   874 0000044C C1E905                  	shr	ecx, 5		   ; convert 1 - 16 MB page count to 
   875                                  				   ; count of 32 allocation bits
   876 0000044F F3AB                    	rep	stosd
   877 00000451 6659                    	pop	cx
   878 00000453 40                      	inc	eax		   ; 0	
   879 00000454 80E11F                  	and	cl, 31		   ; remain bits
   880 00000457 7412                    	jz	short mi_4
   881 00000459 8907                    	mov	[edi], eax	   ; reset	
   882                                  mi_2:
   883 0000045B 0FAB07                  	bts	[edi], eax	   ; 06/11/2014		
   884 0000045E FEC9                    	dec	cl
   885 00000460 7404                    	jz	short mi_3
   886 00000462 FEC0                    	inc	al
   887 00000464 EBF5                    	jmp	short mi_2
   888                                  mi_3:
   889 00000466 28C0                    	sub	al, al	   	   ; 0
   890 00000468 83C704                  	add	edi, 4		   ; 15/11/2014
   891                                  mi_4:
   892 0000046B 6609D2                  	or	dx, dx		  ; check 16M to 4G memory space	
   893 0000046E 7421                    	jz	short mi_6	  ; max. 16 MB memory, no more...
   894                                  	;	
   895 00000470 B900021000              	mov	ecx, MEM_ALLOC_TBL + 512 ; End of first 16 MB memory
   896                                  	;	
   897 00000475 29F9                    	sub	ecx, edi	  ; displacement (to end of 16 MB)
   898 00000477 7406                    	jz	short mi_5	  ; jump if EDI points to 
   899                                  				  ;         end of first 16 MB	
   900 00000479 D1E9                    	shr	ecx, 1		  ; convert to dword count
   901 0000047B D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   902 0000047D F3AB                    	rep 	stosd		  ; reset all bits for reserved pages
   903                                  				  ; (memory hole under 16 MB)
   904                                  mi_5:
   905 0000047F 6689D1                  	mov	cx, dx		  ; count of 64 KB memory blocks
   906 00000482 D1E9                    	shr	ecx, 1		  ; 1 alloc. dword per 128 KB memory
   907 00000484 9C                      	pushf			  ; 16/11/2014		
   908 00000485 48                      	dec	eax		  ; FFFFFFFFh (set all bits to 1)
   909 00000486 F3AB                    	rep	stosd
   910 00000488 40                      	inc	eax		  ; 0
   911 00000489 9D                      	popf			  ; 16/11/2014
   912 0000048A 7305                    	jnc	short mi_6
   913 0000048C 6648                    	dec	ax		  ; eax = 0000FFFFh
   914 0000048E AB                      	stosd
   915 0000048F 6640                    	inc	ax		  ; 0		
   916                                  mi_6:
   917 00000491 39DF                    	cmp	edi, ebx	  ; check if EDI points to 	
   918 00000493 730A                    	jnb	short mi_7	  ; end of memory allocation table
   919                                  	;			  ; (>= MEM_ALLOC_TBL + 4906) 
   920 00000495 89D9                    	mov	ecx, ebx	  ; end of memory allocation table
   921 00000497 29F9                    	sub	ecx, edi	  ; convert displacement/offset
   922 00000499 D1E9                    	shr	ecx, 1		  ; to dword count 	 		
   923 0000049B D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   924 0000049D F3AB                    	rep 	stosd		  ; reset all remain M.A.T. bits
   925                                  mi_7:
   926                                  	; Reset M.A.T. bits in M.A.T. (allocate M.A.T. pages)
   927 0000049F BA00001000              	mov	edx, MEM_ALLOC_TBL
   928                                  	;sub	ebx, edx	  ; Mem. Alloc. Tbl. size in bytes
   929                                  	;shr	ebx, 12		  ; Mem. Alloc. Tbl. size in pages	
   930 000004A4 668B0D[00BE0000]        	mov	cx, [mat_size]	  ; Mem. Alloc. Tbl. size in pages
   931 000004AB 89D7                    	mov	edi, edx
   932 000004AD C1EF0F                  	shr	edi, 15		  ; convert M.A.T. address to
   933                                  				  ; byte offset in M.A.T.
   934                                  				  ; (1 M.A.T. byte points to 
   935                                  				  ;	      32768 bytes)
   936                                  				  ; Note: MEM_ALLOC_TBL address 
   937                                  				  ; must be aligned on 128 KB 
   938                                  				  ; boundary!
   939 000004B0 01D7                    	add	edi, edx	  ; points to M.A.T.'s itself	
   940                                  	; eax = 0
   941 000004B2 290D[F0BD0000]          	sub	[free_pages], ecx ; 07/11/2014
   942                                  mi_8:
   943 000004B8 0FB307                  	btr	[edi], eax	  ; clear bit 0 to bit x (1 to 31)
   944                                  	;dec	bl
   945 000004BB FEC9                    	dec	cl
   946 000004BD 7404                    	jz	short mi_9
   947 000004BF FEC0                    	inc	al
   948 000004C1 EBF5                    	jmp	short mi_8
   949                                  mi_9:
   950                                  	;
   951                                  	; Reset Kernel's Page Dir. and Page Table bits in M.A.T.
   952                                  	;		(allocate pages for system page tables)
   953                                  
   954                                  	; edx = MEM_ALLOC_TBL
   955 000004C3 8B0D[ECBD0000]          	mov	ecx, [memory_size] ; memory size in pages (PTEs)
   956 000004C9 81C1FF030000            	add	ecx, 1023	 ; round up (1024 PTEs per table)	 	
   957 000004CF C1E90A                  	shr	ecx, 10		 ; convert memory page count to 
   958                                  				 ; page table count (PDE count)
   959                                  	;
   960 000004D2 51                      	push	ecx		 ; (**) PDE count (<= 1024)
   961                                  	;
   962 000004D3 41                      	inc	ecx		 ; +1 for kernel page directory	
   963                                  	;
   964 000004D4 290D[F0BD0000]          	sub	[free_pages], ecx ; 07/11/2014
   965                                  	;
   966 000004DA 8B35[E8BD0000]          	mov	esi, [k_page_dir] ; Kernel's Page Directory address
   967 000004E0 C1EE0C                  	shr	esi, 12		 ; convert to page number
   968                                  mi_10:
   969 000004E3 89F0                    	mov	eax, esi	 ; allocation bit offset		 
   970 000004E5 89C3                    	mov	ebx, eax
   971 000004E7 C1EB03                  	shr	ebx, 3		 ; convert to alloc. byte offset
   972 000004EA 80E3FC                  	and	bl,  0FCh	 ; clear bit 0 and bit 1
   973                                  				 ;   to align on dword boundary
   974 000004ED 83E01F                  	and	eax, 31		 ; set allocation bit position 
   975                                  				 ;  (bit 0 to bit 31)
   976                                  	;
   977 000004F0 01D3                    	add	ebx, edx	 ; offset in M.A.T. + M.A.T. address 
   978                                  	;
   979 000004F2 0FB303                  	btr 	[ebx], eax	 ; reset relevant bit (0 to 31)
   980                                  	;
   981 000004F5 46                      	inc	esi		 ; next page table
   982 000004F6 E2EB                    	loop	mi_10		 ; allocate next kernel page table 
   983                                  				 ; (ecx = page table count + 1)		
   984                                  	;
   985 000004F8 59                      	pop	ecx		 ; (**) PDE count (= pg. tbl. count)
   986                                  	;
   987                                  	; Initialize Kernel Page Directory and Kernel Page Tables
   988                                  	;
   989                                  	; Initialize Kernel's Page Directory
   990 000004F9 8B3D[E8BD0000]          	mov	edi, [k_page_dir]
   991 000004FF 89F8                    	mov	eax, edi
   992 00000501 0C03                    	or	al, PDE_A_PRESENT + PDE_A_WRITE
   993                                  		     	      ; supervisor + read&write + present
   994 00000503 89CA                    	mov	edx, ecx 	; (**) PDE count (= pg. tbl. count)	
   995                                  mi_11:
   996 00000505 0500100000              	add	eax, 4096	; Add page size (PGSZ)
   997                                  			        ; EAX points to next page table
   998 0000050A AB                      	stosd
   999 0000050B E2F8                    	loop	mi_11
  1000 0000050D 29C0                    	sub	eax, eax	; Empty PDE
  1001 0000050F 66B90004                	mov	cx, 1024	; Entry count (PGSZ/4)
  1002 00000513 29D1                    	sub	ecx, edx
  1003 00000515 7402                    	jz	short mi_12
  1004 00000517 F3AB                    	rep	stosd 		; clear remain (empty) PDEs
  1005                                  	;
  1006                                  	; Initialization of Kernel's Page Directory is OK, here.
  1007                                  mi_12:
  1008                                  	; Initialize Kernel's Page Tables
  1009                                  	;
  1010                                  	; (EDI points to address of page table 0)
  1011                                  	; eax = 0
  1012 00000519 8B0D[ECBD0000]          	mov	ecx, [memory_size] ; memory size in pages
  1013 0000051F 89CA                    	mov	edx, ecx	; (***)
  1014 00000521 B003                    	mov	al, PTE_A_PRESENT + PTE_A_WRITE
  1015                                  			     ; supervisor + read&write + present 	
  1016                                  mi_13:
  1017 00000523 AB                      	stosd
  1018 00000524 0500100000              	add	eax, 4096	
  1019 00000529 E2F8                    	loop	mi_13	
  1020 0000052B 6681E2FF03              	and	dx, 1023	; (***)
  1021 00000530 740B                    	jz	short mi_14
  1022 00000532 66B90004                	mov	cx, 1024	
  1023 00000536 6629D1                  	sub	cx, dx		; from dx (<= 1023) to 1024
  1024 00000539 31C0                    	xor	eax, eax
  1025 0000053B F3AB                    	rep	stosd		; clear remain (empty) PTEs 
  1026                                  				; of the last page table
  1027                                  mi_14:
  1028                                  	;  Initialization of Kernel's Page Tables is OK, here.
  1029                                  	;
  1030 0000053D 89F8                    	mov	eax, edi	; end of the last page table page
  1031                                  			        ; (beginging of user space pages)
  1032 0000053F C1E80F                  	shr	eax, 15		; convert to M.A.T. byte offset
  1033 00000542 24FC                    	and	al, 0FCh	; clear bit 0 and bit 1 for
  1034                                  				; aligning on dword boundary	
  1035                                  	 
  1036 00000544 A3[FCBD0000]            	mov	[first_page], eax
  1037 00000549 A3[F4BD0000]            	mov	[next_page], eax ; The first free page pointer
  1038                                  				 ; for user programs
  1039                                  				 ; (Offset in Mem. Alloc. Tbl.)	
  1040                                  	;
  1041                                  	; Linear/FLAT (1 to 1) memory paging for the kernel is OK, here.
  1042                                  	;
  1043                                  	
  1044                                  	; Enable paging
  1045                                  	;
  1046 0000054E A1[E8BD0000]                    mov     eax, [k_page_dir]
  1047 00000553 0F22D8                  	mov	cr3, eax
  1048 00000556 0F20C0                  	mov	eax, cr0
  1049 00000559 0D00000080              	or	eax, 80000000h	; set paging bit (bit 31)
  1050 0000055E 0F22C0                  	mov	cr0, eax
  1051                                          ;jmp    KCODE:StartPMP
  1052                                  
  1053 00000561 EA                      	db 0EAh 		; Opcode for far jump
  1054 00000562 [68050000]                      dd StartPMP		; 32 bit offset
  1055 00000566 0800                    	dw KCODE		; kernel code segment descriptor
  1056                                  
  1057                                  
  1058                                  StartPMP:
  1059                                  	; 06/11//2014
  1060                                  	; Clear video page 0
  1061                                  	;
  1062                                  	; Temporary Code
  1063                                  	;
  1064 00000568 B9E8030000              	mov	ecx, 80*25/2
  1065 0000056D BF00800B00              	mov	edi, 0B8000h
  1066                                  	; 30/01/2016
  1067                                  	;xor	eax, eax	; black background, black fore color
  1068 00000572 B800070007              	mov	eax, 07000700h  ; black background, light gray fore color
  1069 00000577 F3AB                    	rep	stosd
  1070                                  	
  1071                                  	; 19/08/2014
  1072                                  	; Kernel Base Address = 0
  1073                                  	; It is mapped to (physically) 0 in the page table.
  1074                                  	; So, here is exactly 'StartPMP' address.
  1075                                  
  1076                                   	; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
  1077 00000579 BE[48BB0000]            	mov	esi, starting_msg
  1078                                  	;; 14/08/2015 (kernel version message will appear
  1079                                  	;;	       when protected mode and paging is enabled)
  1080 0000057E BF00800B00              	mov	edi, 0B8000h ; 27/08/2014
  1081 00000583 B40A                    	mov	ah, 0Ah ; Black background, light green forecolor
  1082                                  	; 20/08/2014
  1083 00000585 E87D010000              	call	printk
  1084                                  
  1085                                  	; 'UNIX v7/x86' source code by Robert Nordier (1999)
  1086                                  	; // Set IRQ offsets
  1087                                  	;
  1088                                  	;  Linux (v0.12) source code by Linus Torvalds (1991)
  1089                                  	;
  1090                                  					;; ICW1
  1091 0000058A B011                    	mov	al, 11h			; Initialization sequence
  1092 0000058C E620                    	out	20h, al			; 	8259A-1
  1093                                  	; jmp 	$+2
  1094 0000058E E6A0                    	out	0A0h, al		; 	8259A-2
  1095                                  					;; ICW2
  1096 00000590 B020                    	mov	al, 20h			; Start of hardware ints (20h)
  1097 00000592 E621                    	out	21h, al			;	for 8259A-1
  1098                                  	; jmp 	$+2
  1099 00000594 B028                    	mov	al, 28h			; Start of hardware ints (28h)
  1100 00000596 E6A1                    	out	0A1h, al		; 	for 8259A-2
  1101                                  					;
  1102 00000598 B004                    	mov	al, 04h			;; ICW3
  1103 0000059A E621                    	out	21h, al			; 	IRQ2 of 8259A-1 (master)
  1104                                  	; jmp 	$+2
  1105 0000059C B002                    	mov	al, 02h			; 	is 8259A-2 (slave)
  1106 0000059E E6A1                    	out	0A1h, al		;
  1107                                  					;; ICW4
  1108 000005A0 B001                    	mov	al, 01h	 		;
  1109 000005A2 E621                    	out	21h, al			; 	8086 mode, normal EOI	
  1110                                  	; jmp 	$+2
  1111 000005A4 E6A1                    	out	0A1h, al		;	for both chips.
  1112                                  
  1113                                  	;mov	al, 0FFh	; mask off all interrupts for now
  1114                                  	;out	21h, al
  1115                                  	;; jmp 	$+2
  1116                                  	;out	0A1h, al
  1117                                  
  1118                                  	; 02/04/2015
  1119                                  	; 26/03/2015 System call (INT 30h) modification
  1120                                  	;  DPL = 3 (Interrupt service routine can be called from user mode)			
  1121                                  	;
  1122                                  	;; Linux (v0.12) source code by Linus Torvalds (1991)
  1123                                  	;  setup_idt:
  1124                                  	;
  1125                                          ;; 16/02/2015
  1126                                  	;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
  1127                                  	; 21/08/2014 (timer_int)
  1128 000005A6 BE[DCB50000]            	mov	esi, ilist
  1129 000005AB 8D3D[80BB0000]          	lea	edi, [idt]
  1130                                  	; 26/03/2015
  1131 000005B1 B930000000              	mov	ecx, 48		; 48 hardware interrupts (INT 0 to INT 2Fh)
  1132                                  	; 02/04/2015
  1133 000005B6 BB00000800              	mov	ebx,  80000h
  1134                                  rp_sidt1:
  1135 000005BB AD                      	lodsd
  1136 000005BC 89C2                    	mov	edx, eax
  1137 000005BE 66BA008E                	mov	dx, 8E00h
  1138 000005C2 6689C3                  	mov	bx, ax
  1139 000005C5 89D8                    	mov	eax, ebx	; /* selector = 0x0008 = cs */
  1140                                         			        ; /* interrupt gate - dpl=0, present */
  1141 000005C7 AB                      	stosd	; selector & offset bits 0-15 	
  1142 000005C8 89D0                    	mov	eax, edx
  1143 000005CA AB                      	stosd	; attributes & offset bits 16-23
  1144 000005CB E2EE                    	loop	rp_sidt1
  1145 000005CD B110                    	mov	cl, 16        ; 16 software interrupts (INT 30h to INT 3Fh)
  1146                                  rp_sidt2:
  1147 000005CF AD                      	lodsd
  1148 000005D0 21C0                    	and	eax, eax
  1149 000005D2 7413                    	jz	short rp_sidt3
  1150 000005D4 89C2                    	mov	edx, eax
  1151 000005D6 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
  1152 000005DA 6689C3                  	mov	bx, ax
  1153 000005DD 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
  1154 000005DF AB                      	stosd
  1155 000005E0 89D0                    	mov	eax, edx
  1156 000005E2 AB                      	stosd
  1157 000005E3 E2EA                    	loop	rp_sidt2
  1158 000005E5 EB16                    	jmp	short sidt_OK
  1159                                  rp_sidt3:
  1160 000005E7 B8[310A0000]            	mov	eax, ignore_int
  1161 000005EC 89C2                    	mov	edx, eax
  1162 000005EE 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
  1163 000005F2 6689C3                  	mov	bx, ax
  1164 000005F5 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
  1165                                  rp_sidt4:
  1166 000005F7 AB                      	stosd
  1167 000005F8 92                      	xchg	eax, edx
  1168 000005F9 AB                      	stosd
  1169 000005FA 92                      	xchg	edx, eax
  1170 000005FB E2FA                    	loop	rp_sidt4
  1171                                  sidt_OK: 
  1172 000005FD 0F011D[D6B50000]        	lidt 	[idtd]
  1173                                  	;
  1174                                  	; TSS descriptor setup ; 24/03/2015
  1175 00000604 B8[80BD0000]            	mov	eax, task_state_segment
  1176 00000609 66A3[CAB50000]          	mov	[gdt_tss0], ax
  1177 0000060F C1C010                  	rol	eax, 16
  1178 00000612 A2[CCB50000]            	mov	[gdt_tss1], al
  1179 00000617 8825[CFB50000]          	mov	[gdt_tss2], ah
  1180 0000061D 66C705[E6BD0000]68-     	mov	word [tss.IOPB], tss_end - task_state_segment
  1181 00000625 00                 
  1182                                  		; 
  1183                                  		; IO Map Base address (When this address points
  1184                                  		; to end of the TSS, CPU does not use IO port 
  1185                                  		; permission bit map for RING 3 IO permissions, 
  1186                                  		; access to any IO ports in ring 3 will be forbidden.)
  1187                                   		;
  1188                                  	;mov	[tss.esp0], esp ; TSS offset 4
  1189                                  	;mov	word [tss.ss0], KDATA ; TSS offset 8 (SS)
  1190 00000626 66B82800                   	mov	ax, TSS  ; It is needed when an interrupt 
  1191                                  			 ; occurs (or a system call -software INT- is requested)
  1192                                  			 ; while cpu running in ring 3 (in user mode).				
  1193                                  			 ; (Kernel stack pointer and segment will be loaded
  1194                                  			 ; from offset 4 and 8 of the TSS, by the CPU.)	 
  1195 0000062A 0F00D8                  	ltr	ax  ; Load task register
  1196                                  	;
  1197                                  esp0_set0:
  1198                                  	; 30/07/2015
  1199 0000062D 8B0D[ECBD0000]          	mov 	ecx, [memory_size] ; memory size in pages
  1200 00000633 C1E10C                  	shl 	ecx, 12 ; convert page count to byte count
  1201 00000636 81F900004000            	cmp	ecx, CORE ; beginning of user's memory space (400000h)
  1202                                  			  ; (kernel mode virtual address)
  1203 0000063C 7605                    	jna	short esp0_set1
  1204                                  	;
  1205                                  	; If available memory > CORE (end of the 1st 4 MB)
  1206                                  	; set stack pointer to CORE
  1207                                  	;(Because, PDE 0 is reserved for kernel space in user's page directory)
  1208                                  	;(PDE 0 points to page table of the 1st 4 MB virtual address space)
  1209 0000063E B900004000              	mov	ecx, CORE
  1210                                  esp0_set1:
  1211 00000643 89CC                    	mov	esp, ecx ; top of kernel stack (**tss.esp0**)
  1212                                  esp0_set_ok:
  1213                                  	; 30/07/2015 (**tss.esp0**) 
  1214 00000645 8925[84BD0000]          	mov	[tss.esp0], esp
  1215 0000064B 66C705[88BD0000]10-             mov     word [tss.ss0], KDATA
  1216 00000653 00                 
  1217                                  	; 14/08/2015
  1218                                  	; 10/11/2014 (Retro UNIX 386 v1 - Erdogan Tan)
  1219                                  	;
  1220                                  	;cli	; Disable interrupts (for CPU)
  1221                                  	;    (CPU will not handle hardware interrupts, except NMI!)
  1222                                  	;
  1223 00000654 30C0                    	xor	al, al		; Enable all hardware interrupts!
  1224 00000656 E621                    	out	21h, al		; (IBM PC-AT compatibility)
  1225 00000658 EB00                    	jmp 	$+2		; (All conventional PC-AT hardware
  1226 0000065A E6A1                    	out	0A1h, al	;  interrupts will be in use.)	
  1227                                  				; (Even if related hardware component
  1228                                  				;  does not exist!)
  1229                                  	; Enable NMI 
  1230 0000065C B07F                    	mov	al, 7Fh		; Clear bit 7 to enable NMI (again)
  1231 0000065E E670                    	out  	70h, al
  1232                                  	; 23/02/2015
  1233 00000660 90                      	nop
  1234 00000661 E471                    	in	al, 71h		; read in 71h just after writing out to 70h
  1235                                  				; for preventing unknown state (!?)
  1236                                  	;
  1237                                  	; Only a NMI can occur here... (Before a 'STI' instruction)
  1238                                  	;
  1239                                  	; 02/09/2014
  1240 00000663 6631DB                  	xor	bx, bx
  1241 00000666 66BA0002                	mov	dx, 0200h	; Row 2, column 0  ; 07/03/2015
  1242 0000066A E8DC110000              	call	_set_cpos	; 24/01/2016
  1243                                  	;
  1244                                  	; 06/11/2014
  1245 0000066F E8BD120000              	call	memory_info
  1246                                  	; 14/08/2015
  1247                                  	;call getch ; 28/02/2015
  1248                                  drv_init:
  1249 00000674 FB                      	sti	; Enable Interrupts 
  1250                                  	; 06/02/2015
  1251 00000675 8B15[C0B80000]          	mov	edx, [hd0_type] ; hd0, hd1, hd2, hd3
  1252 0000067B 668B1D[BEB80000]        	mov	bx, [fd0_type] ; fd0, fd1
  1253                                  	; 22/02/2015
  1254 00000682 6621DB                  	and	bx, bx
  1255 00000685 751B                    	jnz	short di1
  1256                                  	;
  1257 00000687 09D2                    	or 	edx, edx
  1258 00000689 7529                    	jnz	short di2
  1259                                  	;
  1260                                  setup_error:
  1261 0000068B BE[0FBA0000]            	mov 	esi, setup_error_msg
  1262                                  psem:	
  1263 00000690 AC                      	lodsb
  1264 00000691 08C0                    	or	al, al
  1265                                  	;jz	short haltx ; 22/02/2015
  1266 00000693 7426                    	jz	short di3
  1267 00000695 56                      	push	esi
  1268 00000696 31DB                    	xor	ebx, ebx ; 0
  1269                                  			; Video page 0 (bl=0)
  1270 00000698 B407                    	mov	ah, 07h ; Black background, 
  1271                                  			; light gray forecolor
  1272 0000069A E818110000              	call	WRITE_TTY
  1273 0000069F 5E                      	pop	esi
  1274 000006A0 EBEE                    	jmp	short psem
  1275                                  
  1276                                  di1:
  1277                                  	; supress 'jmp short T6'
  1278                                  	;  (activate fdc motor control code)
  1279 000006A2 66C705[88070000]90-     	mov	word [T5], 9090h ; nop
  1280 000006AA 90                 
  1281                                  	;
  1282                                  	;mov	ax, int_0Eh	; IRQ 6 handler
  1283                                  	;mov	di, 0Eh*4	; IRQ 6 vector
  1284                                  	;stosw
  1285                                  	;mov 	ax, cs
  1286                                  	;stosw
  1287                                  	;; 16/02/2015
  1288                                          ;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
  1289                                  	;
  1290 000006AB E8DF210000              	CALL	DSKETTE_SETUP	; Initialize Floppy Disks
  1291                                  	;
  1292 000006B0 09D2                    	or	edx, edx
  1293 000006B2 7407                            jz      short di3
  1294                                  di2:
  1295 000006B4 E81B220000              	call   	DISK_SETUP	; Initialize Fixed Disks
  1296 000006B9 72D0                            jc      short setup_error
  1297                                  di3:
  1298 000006BB E845120000              	call	setup_rtc_int	; 22/05/2015 (dsectrpm.s)
  1299                                  	;
  1300 000006C0 E82DAE0000              	call	display_disks ; 07/03/2015  (Temporary)
  1301                                  ;haltx:
  1302                                  	; 14/08/2015
  1303                                  	;call	getch ; 22/02/2015
  1304                                  	;sti	; Enable interrupts (for CPU)
  1305                                  ;	; 29/01/2016
  1306                                  ;	sub	ah, ah ;  read time count
  1307                                  ;	call	int1Ah
  1308                                  ;	mov	edx, ecx ; 18.2 * seconds
  1309                                  ;md_info_msg_wait1:
  1310                                  ;	; 29/01/2016
  1311                                  ;	mov	ah, 1
  1312                                  ;	call	int16h
  1313                                  ;	jz	short md_info_msg_wait2
  1314                                  ;	xor	ah, ah ; 0
  1315                                  ;       call    int16h
  1316                                  ;	jmp 	short md_info_msg_ok
  1317                                  ;md_info_msg_wait2:
  1318                                  ;	sub	ah, ah  ; read time count
  1319                                  ;	call	int1Ah
  1320                                  ;	cmp	edx, ecx ; ; 18.2 * seconds
  1321                                  ;	jna	short md_info_msg_wait3
  1322                                  ;	xchg 	edx, ecx	
  1323                                  ;md_info_msg_wait3:
  1324                                  ;	sub	ecx, edx
  1325                                  ;	cmp	ecx, 127 ; 7 seconds (18.2 * 7)
  1326                                  ;	jb	short md_info_msg_wait1		
  1327                                  ;md_info_msg_ok:
  1328                                  	; 30/06/2015
  1329 000006C5 E818370000              	call	sys_init
  1330                                  	;
  1331                                  	;jmp 	cpu_reset ; 22/02/2015
  1332                                  hang:  
  1333                                  	; 23/02/2015
  1334                                  	;sti			; Enable interrupts
  1335 000006CA F4                      	hlt
  1336                                  	;
  1337                                  	;nop
  1338                                  	;; 03/12/2014
  1339                                  	;; 28/08/2014
  1340                                  	;mov	ah, 11h
  1341                                  	;call	getc
  1342                                  	;jz      _c8
  1343                                  	;
  1344                                  	; 23/02/2015
  1345                                  	; 06/02/2015
  1346                                  	; 07/09/2014
  1347 000006CB 31DB                    	xor	ebx, ebx
  1348 000006CD 8A1D[18BE0000]          	mov	bl, [ptty]	; active_page
  1349 000006D3 89DE                    	mov	esi, ebx
  1350 000006D5 66D1E6                  	shl 	si, 1
  1351 000006D8 81C6[1ABE0000]          	add	esi, ttychr
  1352 000006DE 668B06                  	mov	ax, [esi]
  1353 000006E1 6621C0                  	and	ax, ax
  1354                                  	;jz	short _c8
  1355 000006E4 74E4                    	jz	short hang
  1356 000006E6 66C7060000              	mov	word [esi], 0
  1357 000006EB 80FB03                  	cmp	bl, 3		; Video page 3
  1358                                  	;jb	short _c8
  1359 000006EE 72DA                    	jb	short hang
  1360                                  	;	
  1361                                  	; 02/09/2014
  1362 000006F0 B40E                    	mov	ah, 0Eh		; Yellow character 
  1363                                  				; on black background
  1364                                  	; 07/09/2014
  1365                                  nxtl:
  1366 000006F2 6653                    	push	bx
  1367                                  	;
  1368                                  	;xor	bx, bx		; bl = 0 (video page 0)
  1369                                  				; bh = 0 (video mode)
  1370                                  				; Retro UNIX 386 v1 - Video Mode 0
  1371                                  				; (PC/AT Video Mode 3 - 80x25 Alpha.)
  1372 000006F4 6650                    	push	ax
  1373 000006F6 E8BC100000              	call 	WRITE_TTY
  1374 000006FB 6658                    	pop	ax
  1375 000006FD 665B                    	pop	bx ; 07/09/2014
  1376 000006FF 3C0D                    	cmp	al, 0Dh		; carriage return (enter)
  1377                                  	;jne	short _c8
  1378 00000701 75C7                    	jne	short hang
  1379 00000703 B00A                    	mov	al, 0Ah		; next line
  1380 00000705 EBEB                    	jmp	short nxtl
  1381                                  	
  1382                                  ;_c8:
  1383                                  ;	; 25/08/2014
  1384                                  ;	cli				; Disable interrupts
  1385                                  ;	mov	al, [scounter + 1]
  1386                                  ;	and	al, al
  1387                                  ;	jnz	hang
  1388                                  ;	call	rtc_p
  1389                                  ;	jmp     hang
  1390                                  
  1391                                  
  1392                                  	; 27/08/2014
  1393                                  	; 20/08/2014
  1394                                  printk:
  1395                                          ;mov    edi, [scr_row]
  1396                                  pkl:
  1397 00000707 AC                      	lodsb
  1398 00000708 08C0                    	or 	al, al
  1399 0000070A 7404                    	jz	short pkr
  1400 0000070C 66AB                    	stosw
  1401 0000070E EBF7                    	jmp	short pkl
  1402                                  pkr:
  1403 00000710 C3                      	retn
  1404                                  
  1405                                  ; 25/07/2015
  1406                                  ; 14/05/2015 (multi tasking -time sharing- 'clock', x_timer)
  1407                                  ; 17/02/2015
  1408                                  ; 06/02/2015 (unix386.s)
  1409                                  ; 11/12/2014 - 22/12/2014 (dsectrm2.s) 
  1410                                  ;
  1411                                  ; IBM PC-XT Model 286 Source Code - BIOS2.ASM (06/10/85)
  1412                                  ;
  1413                                  ;-- HARDWARE INT  08 H - ( IRQ LEVEL 0 ) ---------------------------------------
  1414                                  ;	THIS ROUTINE HANDLES THE TIMER INTERRUPT FROM FROM CHANNEL 0 OF        :
  1415                                  ;	THE 8254 TIMER.  INPUT FREQUENCY IS 1.19318 MHZ AND THE DIVISOR        :
  1416                                  ;	IS 65536, RESULTING IN APPROXIMATELY 18.2 INTERRUPTS EVERY SECOND.     :
  1417                                  ;									       :
  1418                                  ;	THE INTERRUPT HANDLER MAINTAINS A COUNT (40:6C) OF INTERRUPTS SINCE    :
  1419                                  ;	POWER ON TIME, WHICH MAY BE USED TO ESTABLISH TIME OF DAY.	       :
  1420                                  ;	THE INTERRUPT HANDLER ALSO DECREMENTS THE MOTOR CONTROL COUNT (40:40)  :
  1421                                  ;	OF THE DISKETTE, AND WHEN IT EXPIRES, WILL TURN OFF THE 	       :
  1422                                  ;	DISKETTE MOTOR(s), AND RESET THE MOTOR RUNNING FLAGS.		       :
  1423                                  ;	THE INTERRUPT HANDLER WILL ALSO INVOKE A USER ROUTINE THROUGH	       :
  1424                                  ;	INTERRUPT 1CH AT EVERY TIME TICK.  THE USER MUST CODE A 	       :
  1425                                  ;	ROUTINE AND PLACE THE CORRECT ADDRESS IN THE VECTOR TABLE.	       :
  1426                                  ;-------------------------------------------------------------------------------
  1427                                  ;
  1428                                  
  1429                                  timer_int:	; IRQ 0
  1430                                  ;int_08h:	; Timer
  1431                                  	; 14/10/2015
  1432                                  	; Here, we are simulating system call entry (for task switch)
  1433                                  	; (If multitasking is enabled, 
  1434                                  	; 'clock' procedure may jump to 'sysrelease')
  1435 00000711 1E                      	push	ds
  1436 00000712 06                      	push	es
  1437 00000713 0FA0                    	push	fs
  1438 00000715 0FA8                    	push	gs
  1439 00000717 60                      	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
  1440 00000718 66B91000                	mov     cx, KDATA
  1441 0000071C 8ED9                            mov     ds, cx
  1442 0000071E 8EC1                            mov     es, cx
  1443 00000720 8EE1                            mov     fs, cx
  1444 00000722 8EE9                            mov     gs, cx
  1445                                  	;
  1446 00000724 0F20D9                  	mov	ecx, cr3
  1447 00000727 890D[C6070000]          	mov	[cr3reg], ecx ; save current cr3 register value/content
  1448                                  	;
  1449 0000072D 3B0D[E8BD0000]          	cmp 	ecx, [k_page_dir]
  1450 00000733 741F                    	je	short T3
  1451                                  	;
  1452                                  	; timer interrupt has been occurred while OS is in user mode
  1453 00000735 A3[40CE0000]            	mov 	[u.r0], eax
  1454 0000073A 89E1                    	mov	ecx, esp
  1455 0000073C 83C130                  	add	ecx, ESPACE ; 4 * 12 (stack frame)	
  1456 0000073F 890D[38CE0000]          	mov	[u.sp], ecx ; kernel stack pointer at the start of interrupt
  1457 00000745 8925[3CCE0000]          	mov	[u.usp], esp ; kernel stack points to user's registers   
  1458                                  	;
  1459 0000074B 8B0D[E8BD0000]          	mov	ecx, [k_page_dir]
  1460 00000751 0F22D9                  	mov	cr3, ecx
  1461                                  T3:
  1462 00000754 FB                      	sti				; INTERRUPTS BACK ON
  1463 00000755 66FF05[6CBE0000]        	INC	word [TIMER_LOW]	; INCREMENT TIME
  1464 0000075C 7507                    	JNZ	short T4		; GO TO TEST_DAY
  1465 0000075E 66FF05[6EBE0000]        	INC	word [TIMER_HIGH]	; INCREMENT HIGH WORD OF TIME
  1466                                  T4:					; TEST_DAY
  1467 00000765 66833D[6EBE0000]18      	CMP	word [TIMER_HIGH],018H	; TEST FOR COUNT EQUALING 24 HOURS
  1468 0000076D 7519                    	JNZ	short T5		; GO TO DISKETTE_CTL
  1469 0000076F 66813D[6CBE0000]B0-     	CMP	word [TIMER_LOW],0B0H
  1470 00000777 00                 
  1471 00000778 750E                    	JNZ	short T5		; GO TO DISKETTE_CTL
  1472                                  
  1473                                  ;-----	TIMER HAS GONE 24 HOURS
  1474                                  	;;SUB	AX,AX
  1475                                  	;MOV	[TIMER_HIGH],AX
  1476                                  	;MOV	[TIMER_LOW],AX
  1477 0000077A 29C0                    	sub	eax, eax
  1478 0000077C A3[6CBE0000]            	mov	[TIMER_LH], eax
  1479                                  	;	
  1480 00000781 C605[70BE0000]01        	MOV	byte [TIMER_OFL],1
  1481                                  
  1482                                  ;-----	TEST FOR DISKETTE TIME OUT
  1483                                  
  1484                                  T5:
  1485                                  	; 23/12/2014
  1486 00000788 EB1D                    	jmp	short T6		; will be replaced with nop, nop
  1487                                  					; (9090h) if a floppy disk
  1488                                  					; is detected.
  1489                                  	;mov	al,[CS:MOTOR_COUNT]
  1490 0000078A A0[73BE0000]            	mov	al, [MOTOR_COUNT]
  1491 0000078F FEC8                    	dec	al
  1492                                  	;mov	[CS:MOTOR_COUNT], al	; DECREMENT DISKETTE MOTOR CONTROL
  1493 00000791 A2[73BE0000]            	mov	[MOTOR_COUNT], al
  1494                                  	;mov	[ORG_MOTOR_COUNT], al
  1495 00000796 750F                    	JNZ	short T6		; RETURN IF COUNT NOT OUT
  1496 00000798 B0F0                    	mov 	al,0F0h
  1497                                  	;AND	[CS:MOTOR_STATUS],al 	; TURN OFF MOTOR RUNNING BITS
  1498 0000079A 2005[72BE0000]          	and	[MOTOR_STATUS], al
  1499                                  	;and	[ORG_MOTOR_STATUS], al
  1500 000007A0 B00C                    	MOV	AL,0CH			; bit 3 = enable IRQ & DMA, 
  1501                                  					; bit 2 = enable controller
  1502                                  					;	1 = normal operation
  1503                                  					;	0 = reset	
  1504                                  					; bit 0, 1 = drive select
  1505                                  					; bit 4-7 = motor running bits 
  1506 000007A2 66BAF203                	MOV	DX,03F2H		; FDC CTL PORT
  1507 000007A6 EE                      	OUT	DX,AL			; TURN OFF THE MOTOR
  1508                                  T6:	
  1509                                  	;inc	word [CS:wait_count]	; 22/12/2014 (byte -> word)
  1510                                  					; TIMER TICK INTERRUPT
  1511                                  	;;inc	word [wait_count] ;;27/02/2015
  1512                                  	;INT	1CH			; TRANSFER CONTROL TO A USER ROUTINE
  1513                                  	;;;;cli
  1514                                  	;call 	u_timer			; TRANSFER CONTROL TO A USER ROUTINE
  1515 000007A7 FF15[C2070000]          	call	[x_timer] ; 14/05/2015
  1516                                  T7:
  1517                                  	; 14/10/2015
  1518 000007AD B020                    	MOV	AL,EOI			; GET END OF INTERRUPT MASK
  1519 000007AF FA                      	CLI				; DISABLE INTERRUPTS TILL STACK CLEARED
  1520 000007B0 E620                    	OUT	INTA00,AL		; END OF INTERRUPT TO 8259 - 1	
  1521                                  	;
  1522 000007B2 A1[C6070000]            	mov 	eax, [cr3reg] 		; previous value/content of cr3 register
  1523 000007B7 0F22D8                   	mov	cr3, eax  ; restore cr3 register content
  1524                                  	;
  1525 000007BA 61                      	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
  1526                                  	;
  1527 000007BB 0FA9                    	pop	gs
  1528 000007BD 0FA1                    	pop	fs
  1529 000007BF 07                      	pop	es
  1530 000007C0 1F                      	pop	ds
  1531 000007C1 CF                      	iretd	; return from interrupt
  1532                                  
  1533                                  
  1534                                  ; ////////////////
  1535                                  
  1536                                  ; 14/05/2015 - Multi tasking 'clock' procedure (sys emt)
  1537                                  x_timer:
  1538 000007C2 [CA070000]              	dd 	u_timer			; 14/05/2015
  1539                                  	;dd	clock
  1540                                  
  1541                                  ; 14/10/2015
  1542 000007C6 00000000                cr3reg: dd 0
  1543                                  
  1544                                  	; 06/02/2015
  1545                                  	; 07/09/2014
  1546                                  	; 21/08/2014
  1547                                  u_timer:
  1548                                  ;timer_int:	; IRQ 0
  1549                                  	; 06/02/2015
  1550                                  	;push	eax
  1551                                  	;push	edx
  1552                                  	;push	ecx
  1553                                  	;push	ebx
  1554                                  	;push	ds
  1555                                  	;push	es
  1556                                  	;mov	eax, KDATA
  1557                                  	;mov	ds, ax
  1558                                  	;mov	es, ax
  1559 000007CA FF05[2EBE0000]          	inc	dword [tcount]
  1560 000007D0 BB[5DB90000]            	mov	ebx, tcountstr + 4
  1561 000007D5 66A1[2EBE0000]          	mov	ax, [tcount]
  1562 000007DB B90A000000              	mov	ecx, 10
  1563                                  rp_divtcnt:
  1564 000007E0 31D2                    	xor	edx, edx
  1565 000007E2 F7F1                    	div	ecx
  1566 000007E4 80C230                  	add	dl, 30h
  1567 000007E7 8813                    	mov	[ebx], dl
  1568 000007E9 6609C0                  	or	ax, ax
  1569 000007EC 7403                    	jz	short print_lzero
  1570 000007EE 4B                      	dec	ebx
  1571 000007EF EBEF                    	jmp	short rp_divtcnt
  1572                                  print_lzero:
  1573 000007F1 81FB[59B90000]          	cmp	ebx, tcountstr
  1574 000007F7 7606                    	jna	short print_tcount
  1575 000007F9 4B                      	dec	ebx
  1576 000007FA C60330                   	mov	byte [ebx], 30h
  1577 000007FD EBF2                    	jmp	short print_lzero
  1578                                  print_tcount:
  1579 000007FF 56                      	push	esi
  1580 00000800 57                      	push	edi
  1581 00000801 BE[35B90000]            	mov	esi, timer_msg ; Timer interrupt message
  1582                                  	; 07/09/2014
  1583 00000806 66BB0100                	mov	bx, 1		; Video page 1
  1584                                  ptmsg:
  1585 0000080A AC                      	lodsb
  1586 0000080B 08C0                    	or	al, al
  1587 0000080D 740F                    	jz	short ptmsg_ok
  1588 0000080F 56                      	push	esi
  1589 00000810 6653                    	push	bx
  1590 00000812 B42F                            mov     ah,  2Fh ; Green background, white forecolor
  1591 00000814 E89E0F0000              	call 	WRITE_TTY
  1592 00000819 665B                    	pop	bx
  1593 0000081B 5E                      	pop	esi
  1594 0000081C EBEC                    	jmp	short ptmsg
  1595                                  	;; 27/08/2014
  1596                                  	;mov     edi, 0B8000h + 0A0h ; Row 1
  1597                                  	;call	printk
  1598                                  	;
  1599                                  ptmsg_ok:
  1600                                  	; 07/09/2014
  1601 0000081E 6631D2                  	xor	dx, dx		; column 0, row 0
  1602 00000821 E825100000              	call	_set_cpos	; set cursor position to 0,0 
  1603                                  	; 23/02/2015
  1604                                  	; 25/08/2014
  1605                                  	;mov	ebx, scounter		; (seconds counter)
  1606                                  	;dec	byte [ebx+1]		; (for reading real time clock)
  1607                                  ;	dec	byte [scounter+1]
  1608                                  ;;	jns	short timer_eoi		; 0 -> 0FFh ?
  1609                                  ;	jns	short u_timer_retn
  1610                                  	; 26/02/2015
  1611                                  ;	call	rtc_p
  1612                                  ;	mov	ebx, scounter		; (seconds counter)
  1613                                  ;	mov	byte [ebx+1], 18	; (18.2 timer ticks per second)
  1614                                  ;	dec 	byte [ebx]		; 19+18+18+18+18 (5)	
  1615                                  ;	jnz	short timer_eoi		; (109 timer ticks in 5 seconds)
  1616                                  ;	jnz	short u_timer_retn ; 06/02/2015
  1617                                  ;	mov	byte [ebx], 5
  1618                                  ;	inc	byte [ebx+1] ; 19
  1619                                  ;;timer_eoi:
  1620                                  ;;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1621                                  ;;	out	20h, al	; 8259 PORT
  1622                                  	;
  1623                                  ;u_timer_retn:  ; 06/02/2015
  1624 00000826 5F                      	pop	edi
  1625 00000827 5E                      	pop	esi
  1626                                  	;pop	es
  1627                                  	;pop	ds
  1628                                  	;pop	ebx
  1629                                  	;pop	ecx
  1630                                  	;pop	edx
  1631                                  	;pop	eax
  1632                                  	;iret
  1633 00000828 C3                      	retn	; 06/02/2015
  1634                                  
  1635                                  	; 28/08/2014
  1636                                  irq0:
  1637 00000829 6A00                            push 	dword 0
  1638 0000082B EB48                    	jmp	short which_irq
  1639                                  irq1:
  1640 0000082D 6A01                            push 	dword 1
  1641 0000082F EB44                    	jmp	short which_irq
  1642                                  irq2:
  1643 00000831 6A02                            push 	dword 2
  1644 00000833 EB40                    	jmp	short which_irq
  1645                                  irq3:
  1646                                  	; 20/11/2015
  1647                                  	; 24/10/2015
  1648 00000835 2EFF15[79AE0000]        	call	dword [cs:com2_irq3]
  1649 0000083C 6A03                    	push 	dword 3
  1650 0000083E EB35                    	jmp	short which_irq
  1651                                  irq4:
  1652                                  	; 20/11/2015
  1653                                  	; 24/10/2015
  1654 00000840 2EFF15[75AE0000]        	call	dword [cs:com1_irq4]
  1655 00000847 6A04                            push 	dword 4
  1656 00000849 EB2A                    	jmp	short which_irq
  1657                                  irq5:
  1658 0000084B 6A05                            push 	dword 5
  1659 0000084D EB26                    	jmp	short which_irq
  1660                                  irq6:
  1661 0000084F 6A06                            push 	dword 6
  1662 00000851 EB22                    	jmp	short which_irq
  1663                                  irq7:
  1664 00000853 6A07                            push 	dword 7
  1665 00000855 EB1E                    	jmp	short which_irq
  1666                                  irq8:
  1667 00000857 6A08                            push 	dword 8
  1668 00000859 EB1A                    	jmp	short which_irq
  1669                                  irq9:
  1670 0000085B 6A09                            push 	dword 9
  1671 0000085D EB16                    	jmp	short which_irq
  1672                                  irq10:
  1673 0000085F 6A0A                            push 	dword 10
  1674 00000861 EB12                    	jmp	short which_irq
  1675                                  irq11:
  1676 00000863 6A0B                            push 	dword 11
  1677 00000865 EB0E                    	jmp	short which_irq
  1678                                  irq12:
  1679 00000867 6A0C                            push 	dword 12
  1680 00000869 EB0A                    	jmp	short which_irq
  1681                                  irq13:
  1682 0000086B 6A0D                            push 	dword 13
  1683 0000086D EB06                    	jmp	short which_irq
  1684                                  irq14:
  1685 0000086F 6A0E                            push 	dword 14
  1686 00000871 EB02                    	jmp	short which_irq
  1687                                  irq15:
  1688 00000873 6A0F                            push 	dword 15
  1689                                  	;jmp	short which_irq
  1690                                  
  1691                                  	; 19/10/2015
  1692                                  	; 29/08/2014
  1693                                  	; 21/08/2014
  1694                                  which_irq:
  1695 00000875 870424                  	xchg	eax, [esp]  ; 28/08/2014
  1696 00000878 53                      	push	ebx
  1697 00000879 56                      	push	esi
  1698 0000087A 57                      	push	edi
  1699 0000087B 1E                      	push 	ds
  1700 0000087C 06                      	push 	es
  1701                                  	;
  1702 0000087D 88C3                    	mov	bl, al
  1703                                  	;
  1704 0000087F B810000000              	mov	eax, KDATA
  1705 00000884 8ED8                    	mov	ds, ax
  1706 00000886 8EC0                    	mov	es, ax
  1707                                  	; 19/10/2015
  1708 00000888 FC                      	cld
  1709                                          ; 27/08/2014
  1710 00000889 8105[18B90000]A000-             add     dword [scr_row], 0A0h
  1711 00000891 0000               
  1712                                  	;
  1713 00000893 B417                    	mov	ah, 17h	; blue (1) background, 
  1714                                  			; light gray (7) forecolor
  1715 00000895 8B3D[18B90000]                  mov     edi, [scr_row]
  1716 0000089B B049                    	mov	al, 'I'
  1717 0000089D 66AB                    	stosw
  1718 0000089F B052                    	mov	al, 'R'
  1719 000008A1 66AB                    	stosw
  1720 000008A3 B051                    	mov	al, 'Q'
  1721 000008A5 66AB                    	stosw
  1722 000008A7 B020                    	mov	al, ' '
  1723 000008A9 66AB                    	stosw
  1724 000008AB 88D8                    	mov	al, bl
  1725 000008AD 3C0A                    	cmp	al, 10
  1726 000008AF 7208                    	jb	short iix
  1727 000008B1 B031                    	mov	al, '1'
  1728 000008B3 66AB                    	stosw
  1729 000008B5 88D8                    	mov	al, bl
  1730 000008B7 2C0A                    	sub	al, 10
  1731                                  iix:
  1732 000008B9 0430                    	add	al, '0'
  1733 000008BB 66AB                    	stosw
  1734 000008BD B020                    	mov	al, ' '
  1735 000008BF 66AB                    	stosw
  1736 000008C1 B021                    	mov	al, '!'
  1737 000008C3 66AB                    	stosw
  1738 000008C5 B020                    	mov	al, ' '
  1739 000008C7 66AB                    	stosw
  1740                                  	; 23/02/2015
  1741 000008C9 80FB07                  	cmp	bl, 7 ; check for IRQ 8 to IRQ 15 
  1742 000008CC 0F868D010000            	jna	iiret
  1743 000008D2 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  1744 000008D4 E6A0                    	out	0A0h, al ; the 2nd 8259
  1745 000008D6 E984010000              	jmp     iiret
  1746                                  	;
  1747                                  	; 22/08/2014
  1748                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1749                                  	;out	20h, al	; 8259 PORT
  1750                                  	;
  1751                                  	;pop	es
  1752                                  	;pop	ds
  1753                                  	;pop	edi
  1754                                  	;pop	esi
  1755                                  	;pop	ebx
  1756                                  	;pop 	eax
  1757                                  	;iret
  1758                                  
  1759                                  	; 02/04/2015
  1760                                  	; 25/08/2014
  1761                                  exc0:
  1762 000008DB 6A00                            push 	dword 0
  1763 000008DD E990000000                      jmp     cpu_except
  1764                                  exc1:
  1765 000008E2 6A01                            push 	dword 1
  1766 000008E4 E989000000                      jmp     cpu_except
  1767                                  exc2:
  1768 000008E9 6A02                            push 	dword 2
  1769 000008EB E982000000                      jmp     cpu_except
  1770                                  exc3:
  1771 000008F0 6A03                            push 	dword 3
  1772 000008F2 EB7E                            jmp     cpu_except
  1773                                  exc4:
  1774 000008F4 6A04                            push 	dword 4
  1775 000008F6 EB7A                            jmp     cpu_except
  1776                                  exc5:
  1777 000008F8 6A05                            push 	dword 5
  1778 000008FA EB76                            jmp     cpu_except
  1779                                  exc6:
  1780 000008FC 6A06                            push 	dword 6
  1781 000008FE EB72                            jmp     cpu_except
  1782                                  exc7:
  1783 00000900 6A07                            push 	dword 7
  1784 00000902 EB6E                            jmp     cpu_except
  1785                                  exc8:
  1786                                  	; [esp] = Error code
  1787 00000904 6A08                            push 	dword 8
  1788 00000906 EB5C                            jmp     cpu_except_en
  1789                                  exc9:
  1790 00000908 6A09                            push 	dword 9
  1791 0000090A EB66                            jmp     cpu_except
  1792                                  exc10:
  1793                                  	; [esp] = Error code
  1794 0000090C 6A0A                            push 	dword 10
  1795 0000090E EB54                            jmp     cpu_except_en
  1796                                  exc11:
  1797                                  	; [esp] = Error code
  1798 00000910 6A0B                            push 	dword 11
  1799 00000912 EB50                            jmp     cpu_except_en
  1800                                  exc12:
  1801                                  	; [esp] = Error code
  1802 00000914 6A0C                            push 	dword 12
  1803 00000916 EB4C                            jmp     cpu_except_en
  1804                                  exc13:
  1805                                  	; [esp] = Error code
  1806 00000918 6A0D                            push 	dword 13
  1807 0000091A EB48                            jmp     cpu_except_en
  1808                                  exc14:
  1809                                  	; [esp] = Error code
  1810 0000091C 6A0E                            push 	dword 14
  1811 0000091E EB44                    	jmp	short cpu_except_en
  1812                                  exc15:
  1813 00000920 6A0F                            push 	dword 15
  1814 00000922 EB4E                            jmp     cpu_except
  1815                                  exc16:
  1816 00000924 6A10                            push 	dword 16
  1817 00000926 EB4A                            jmp     cpu_except
  1818                                  exc17:
  1819                                  	; [esp] = Error code
  1820 00000928 6A11                            push 	dword 17
  1821 0000092A EB38                    	jmp	short cpu_except_en
  1822                                  exc18:
  1823 0000092C 6A12                            push 	dword 18
  1824 0000092E EB42                    	jmp	short cpu_except
  1825                                  exc19:
  1826 00000930 6A13                            push 	dword 19
  1827 00000932 EB3E                    	jmp	short cpu_except
  1828                                  exc20:
  1829 00000934 6A14                            push 	dword 20
  1830 00000936 EB3A                    	jmp	short cpu_except
  1831                                  exc21:
  1832 00000938 6A15                            push 	dword 21
  1833 0000093A EB36                    	jmp	short cpu_except
  1834                                  exc22:
  1835 0000093C 6A16                            push 	dword 22
  1836 0000093E EB32                    	jmp	short cpu_except
  1837                                  exc23:
  1838 00000940 6A17                            push 	dword 23
  1839 00000942 EB2E                    	jmp	short cpu_except
  1840                                  exc24:
  1841 00000944 6A18                            push 	dword 24
  1842 00000946 EB2A                    	jmp	short cpu_except
  1843                                  exc25:
  1844 00000948 6A19                            push 	dword 25
  1845 0000094A EB26                    	jmp	short cpu_except
  1846                                  exc26:
  1847 0000094C 6A1A                            push 	dword 26
  1848 0000094E EB22                    	jmp	short cpu_except
  1849                                  exc27:
  1850 00000950 6A1B                            push 	dword 27
  1851 00000952 EB1E                    	jmp	short cpu_except
  1852                                  exc28:
  1853 00000954 6A1C                            push 	dword 28
  1854 00000956 EB1A                    	jmp	short cpu_except
  1855                                  exc29:
  1856 00000958 6A1D                            push 	dword 29
  1857 0000095A EB16                    	jmp	short cpu_except
  1858                                  exc30:
  1859 0000095C 6A1E                            push 	dword 30
  1860 0000095E EB04                    	jmp	short cpu_except_en
  1861                                  exc31:
  1862 00000960 6A1F                            push 	dword 31
  1863 00000962 EB0E                            jmp     short cpu_except
  1864                                  
  1865                                  	; 19/10/2015
  1866                                  	; 19/09/2015
  1867                                  	; 01/09/2015
  1868                                  	; 28/08/2015
  1869                                  	; 28/08/2014
  1870                                  cpu_except_en:
  1871 00000964 87442404                	xchg	eax, [esp+4] ; Error code
  1872 00000968 36A3[0CDB0000]          	mov	[ss:error_code], eax
  1873 0000096E 58                      	pop	eax  ; Exception number
  1874 0000096F 870424                  	xchg	eax, [esp]
  1875                                  		; eax = eax before exception
  1876                                  		; [esp] -> exception number
  1877                                  		; [esp+4] -> EIP to return
  1878                                  	; 19/10/2015
  1879                                  	; 19/09/2015
  1880                                  	; 01/09/2015
  1881                                  	; 28/08/2015
  1882                                  	; 29/08/2014
  1883                                  	; 28/08/2014
  1884                                  	; 25/08/2014
  1885                                  	; 21/08/2014
  1886                                  cpu_except:	; CPU Exceptions
  1887 00000972 FC                      	cld
  1888 00000973 870424                  	xchg	eax, [esp] 
  1889                                  		; eax = Exception number
  1890                                  		; [esp] = eax (before exception)	
  1891 00000976 53                      	push	ebx
  1892 00000977 56                      	push	esi
  1893 00000978 57                      	push	edi
  1894 00000979 1E                      	push 	ds
  1895 0000097A 06                      	push 	es
  1896                                  	; 28/08/2015
  1897 0000097B 66BB1000                	mov	bx, KDATA
  1898 0000097F 8EDB                    	mov	ds, bx
  1899 00000981 8EC3                    	mov	es, bx
  1900 00000983 0F20DB                  	mov	ebx, cr3
  1901 00000986 53                      	push	ebx ; (*) page directory
  1902                                  	; 19/10/2015
  1903 00000987 FC                      	cld
  1904                                  	; 25/03/2015
  1905 00000988 8B1D[E8BD0000]          	mov	ebx, [k_page_dir]
  1906 0000098E 0F22DB                  	mov	cr3, ebx
  1907                                  	; 28/08/2015
  1908 00000991 83F80E                  	cmp	eax, 0Eh ; 14, PAGE FAULT	
  1909 00000994 7512                    	jne	short cpu_except_nfp
  1910 00000996 E83E2A0000              	call	page_fault_handler
  1911 0000099B 21C0                    	and 	eax, eax
  1912 0000099D 0F84B8000000                    jz	iiretp ; 01/09/2015
  1913 000009A3 B80E000000              	mov	eax, 0Eh ; 14
  1914                                  cpu_except_nfp:
  1915                                  	; 02/04/2015
  1916 000009A8 BB[CA060000]            	mov	ebx, hang
  1917 000009AD 875C241C                	xchg	ebx, [esp+28]
  1918                                  		; EIP (points to instruction which faults)
  1919                                  	  	; New EIP (hang)
  1920 000009B1 891D[10DB0000]          	mov	[FaultOffset], ebx
  1921 000009B7 C744242008000000        	mov	dword [esp+32], KCODE ; kernel's code segment
  1922 000009BF 814C242400020000        	or	dword [esp+36], 200h ; enable interrupts (set IF)
  1923                                  	;
  1924 000009C7 88C4                    	mov	ah, al
  1925 000009C9 240F                    	and	al, 0Fh
  1926 000009CB 3C09                    	cmp	al, 9
  1927 000009CD 7602                    	jna	short h1ok
  1928 000009CF 0407                    	add	al, 'A'-':'
  1929                                  h1ok:
  1930 000009D1 D0EC                    	shr	ah, 1
  1931 000009D3 D0EC                    	shr	ah, 1
  1932 000009D5 D0EC                    	shr	ah, 1
  1933 000009D7 D0EC                    	shr	ah, 1
  1934 000009D9 80FC09                  	cmp	ah, 9
  1935 000009DC 7603                    	jna	short h2ok
  1936 000009DE 80C407                  	add	ah, 'A'-':'
  1937                                  h2ok:	
  1938 000009E1 86E0                    	xchg 	ah, al	
  1939 000009E3 66053030                	add	ax, '00'
  1940 000009E7 66A3[70B90000]          	mov	[excnstr], ax
  1941                                  	;
  1942                                  	; 29/08/2014
  1943 000009ED A1[10DB0000]            	mov	eax, [FaultOffset]
  1944 000009F2 51                      	push	ecx
  1945 000009F3 52                      	push	edx
  1946 000009F4 89E3                    	mov	ebx, esp
  1947                                  	; 28/08/2015
  1948 000009F6 B910000000              	mov	ecx, 16	  ; divisor value to convert binary number
  1949                                  			  ; to hexadecimal string
  1950                                  	;mov	ecx, 10	    ; divisor to convert	
  1951                                  			    ; binary number to decimal string
  1952                                  b2d1:
  1953 000009FB 31D2                    	xor	edx, edx
  1954 000009FD F7F1                    	div	ecx
  1955 000009FF 6652                    	push	dx
  1956 00000A01 39C8                    	cmp	eax, ecx
  1957 00000A03 73F6                    	jnb	short b2d1
  1958 00000A05 BF[7BB90000]            	mov	edi, EIPstr ; EIP value
  1959                                  			    ; points to instruction which faults	
  1960                                  	; 28/08/2015
  1961 00000A0A 89C2                    	mov	edx, eax
  1962                                  b2d2:
  1963                                  	;add	al, '0'
  1964 00000A0C 8A82[F9190000]          	mov	al, [edx+hexchrs]
  1965 00000A12 AA                      	stosb		    ; write hexadecimal digit to its place	
  1966 00000A13 39E3                    	cmp	ebx, esp
  1967 00000A15 7606                    	jna	short b2d3
  1968 00000A17 6658                    	pop	ax
  1969 00000A19 88C2                    	mov	dl, al
  1970 00000A1B EBEF                    	jmp	short b2d2
  1971                                  b2d3:
  1972 00000A1D B068                    	mov 	al, 'h' ; 28/08/2015
  1973 00000A1F AA                      	stosb
  1974 00000A20 B020                    	mov	al, 20h	    ; space
  1975 00000A22 AA                      	stosb
  1976 00000A23 30C0                    	xor	al, al	    ; to do it an ASCIIZ string	
  1977 00000A25 AA                      	stosb
  1978                                  	;
  1979 00000A26 5A                      	pop	edx
  1980 00000A27 59                      	pop	ecx
  1981                                  	;
  1982 00000A28 B44F                    	mov	ah, 4Fh	; red (4) background, 
  1983                                  			; white (F) forecolor
  1984 00000A2A BE[60B90000]            	mov	esi, exc_msg ; message offset
  1985                                  	;
  1986 00000A2F EB11                    	jmp	short piemsg
  1987                                  	;
  1988                                          ;add    dword [scr_row], 0A0h
  1989                                          ;mov    edi, [scr_row]
  1990                                          ;
  1991                                  	;call 	printk
  1992                                  	;
  1993                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  1994                                  	;out	20h, al	; 8259 PORT
  1995                                  	;
  1996                                  	;pop	es
  1997                                  	;pop	ds
  1998                                  	;pop	edi
  1999                                  	;pop	esi
  2000                                  	;pop 	eax
  2001                                  	;iret
  2002                                  	
  2003                                  	; 28/08/2015
  2004                                  	; 23/02/2015
  2005                                  	; 20/08/2014
  2006                                  ignore_int:
  2007 00000A31 50                      	push	eax
  2008 00000A32 53                      	push	ebx ; 23/02/2015
  2009 00000A33 56                      	push	esi
  2010 00000A34 57                      	push	edi
  2011 00000A35 1E                      	push 	ds
  2012 00000A36 06                      	push 	es
  2013                                  	; 28/08/2015
  2014 00000A37 0F20D8                  	mov	eax, cr3
  2015 00000A3A 50                      	push	eax ; (*) page directory
  2016                                  	;
  2017 00000A3B B467                    	mov	ah, 67h	; brown (6) background, 
  2018                                  			; light gray (7) forecolor
  2019 00000A3D BE[20B90000]            	mov	esi, int_msg ; message offset
  2020                                  piemsg:
  2021                                          ; 27/08/2014
  2022 00000A42 8105[18B90000]A000-             add     dword [scr_row], 0A0h
  2023 00000A4A 0000               
  2024 00000A4C 8B3D[18B90000]                  mov     edi, [scr_row]
  2025                                          ;
  2026 00000A52 E8B0FCFFFF              	call 	printk
  2027                                  	;
  2028                                  	; 23/02/2015
  2029 00000A57 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  2030 00000A59 E6A0                    	out	0A0h, al ; the 2nd 8259
  2031                                  iiretp: ; 01/09/2015
  2032                                  	; 28/08/2015
  2033 00000A5B 58                      	pop	eax ; (*) page directory
  2034 00000A5C 0F22D8                  	mov	cr3, eax
  2035                                  	;
  2036                                  iiret:
  2037                                  	; 22/08/2014
  2038 00000A5F B020                    	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  2039 00000A61 E620                    	out	20h, al	; 8259 PORT
  2040                                  	;
  2041 00000A63 07                      	pop	es
  2042 00000A64 1F                      	pop	ds
  2043 00000A65 5F                      	pop	edi
  2044 00000A66 5E                      	pop	esi
  2045 00000A67 5B                      	pop	ebx ; 29/08/2014
  2046 00000A68 58                      	pop 	eax
  2047 00000A69 CF                      	iretd
  2048                                  
  2049                                  	; 26/02/2015
  2050                                  	; 07/09/2014
  2051                                  	; 25/08/2014
  2052                                  rtc_int:       ; Real Time Clock Interrupt (IRQ 8)
  2053                                  	; 22/08/2014
  2054 00000A6A 50                      	push	eax
  2055 00000A6B 53                      	push	ebx ; 29/08/2014
  2056 00000A6C 56                      	push	esi
  2057 00000A6D 57                      	push	edi
  2058 00000A6E 1E                      	push 	ds
  2059 00000A6F 06                      	push 	es
  2060                                  	;
  2061 00000A70 B810000000              	mov	eax, KDATA
  2062 00000A75 8ED8                    	mov	ds, ax
  2063 00000A77 8EC0                    	mov	es, ax
  2064                                  	;
  2065                                  	; 25/08/2014
  2066 00000A79 E884000000              	call	rtc_p
  2067                                  	;
  2068                                  	; 22/02/2015 - dsectpm.s
  2069                                  	; [ source: http://wiki.osdev.org/RTC ]
  2070                                  	; read status register C to complete procedure
  2071                                  	;(it is needed to get a next IRQ 8) 
  2072 00000A7E B00C                    	mov	al, 0Ch ; 
  2073 00000A80 E670                    	out	70h, al ; select register C
  2074 00000A82 90                      	nop
  2075 00000A83 E471                    	in	al, 71h ; just throw away contents
  2076                                  	; 22/02/2015
  2077 00000A85 B020                    	MOV	AL,EOI		; END OF INTERRUPT
  2078 00000A87 E6A0                    	OUT	INTB00,AL	; FOR CONTROLLER #2
  2079                                  	;
  2080 00000A89 EBD4                    	jmp	short iiret	
  2081                                  
  2082                                  	; 22/08/2014
  2083                                  	; IBM PC/AT BIOS source code ----- 10/06/85 (bios.asm)
  2084                                  	; (INT 1Ah)
  2085                                  	;; Linux (v0.12) source code (main.c) by Linus Torvalds (1991)
  2086                                  time_of_day:
  2087 00000A8B E803330000              	call	UPD_IPR			; WAIT TILL UPDATE NOT IN PROGRESS
  2088 00000A90 726F                            jc      short rtc_retn 
  2089 00000A92 B000                    	mov	al, CMOS_SECONDS
  2090 00000A94 E815330000              	call	CMOS_READ
  2091 00000A99 A2[5EBE0000]            	mov	[time_seconds], al 
  2092 00000A9E B002                    	mov	al, CMOS_MINUTES
  2093 00000AA0 E809330000              	call	CMOS_READ
  2094 00000AA5 A2[5FBE0000]            	mov	[time_minutes], al 
  2095 00000AAA B004                    	mov	al, CMOS_HOURS
  2096 00000AAC E8FD320000              	call	CMOS_READ
  2097 00000AB1 A2[60BE0000]                    mov     [time_hours], al
  2098 00000AB6 B006                    	mov	al, CMOS_DAY_WEEK 
  2099 00000AB8 E8F1320000              	call	CMOS_READ
  2100 00000ABD A2[61BE0000]            	mov	[date_wday], al
  2101 00000AC2 B007                     	mov	al, CMOS_DAY_MONTH
  2102 00000AC4 E8E5320000              	call	CMOS_READ
  2103 00000AC9 A2[62BE0000]            	mov	[date_day], al
  2104 00000ACE B008                    	mov	al, CMOS_MONTH
  2105 00000AD0 E8D9320000              	call	CMOS_READ
  2106 00000AD5 A2[63BE0000]            	mov	[date_month], al
  2107 00000ADA B009                    	mov	al, CMOS_YEAR
  2108 00000ADC E8CD320000              	call	CMOS_READ
  2109 00000AE1 A2[64BE0000]            	mov	[date_year], al
  2110 00000AE6 B032                    	mov	al, CMOS_CENTURY
  2111 00000AE8 E8C1320000              	call	CMOS_READ
  2112 00000AED A2[65BE0000]            	mov	[date_century], al
  2113                                  	;
  2114 00000AF2 B000                    	mov	al, CMOS_SECONDS
  2115 00000AF4 E8B5320000              	call 	CMOS_READ
  2116 00000AF9 3A05[5EBE0000]          	cmp	al, [time_seconds]
  2117 00000AFF 758A                    	jne	short time_of_day
  2118                                  
  2119                                  rtc_retn:
  2120 00000B01 C3                      	retn
  2121                                  
  2122                                  rtc_p:	
  2123                                  	; 07/09/2014
  2124                                  	; 29/08/2014
  2125                                  	; 27/08/2014
  2126                                  	; 25/08/2014
  2127                                   	; Print Real Time Clock content
  2128                                  	;
  2129                                  	;
  2130 00000B02 E884FFFFFF              	call	time_of_day
  2131 00000B07 72F8                    	jc	short rtc_retn
  2132                                  	;
  2133 00000B09 3A05[D2B90000]          	cmp	al, [ptime_seconds]
  2134 00000B0F 74F0                            je      short rtc_retn ; 29/08/2014
  2135                                  	;
  2136 00000B11 A2[D2B90000]            	mov	[ptime_seconds], al
  2137                                  	;
  2138 00000B16 A0[65BE0000]            	mov	al, [date_century]
  2139 00000B1B E8BE000000              	call	bcd_to_ascii
  2140 00000B20 66A3[9FB90000]          	mov	[datestr+6], ax
  2141 00000B26 A0[64BE0000]            	mov	al, [date_year]
  2142 00000B2B E8AE000000              	call	bcd_to_ascii
  2143 00000B30 66A3[A1B90000]          	mov	[datestr+8], ax
  2144 00000B36 A0[63BE0000]            	mov	al, [date_month]
  2145 00000B3B E89E000000              	call	bcd_to_ascii
  2146 00000B40 66A3[9CB90000]          	mov	[datestr+3], ax
  2147 00000B46 A0[62BE0000]            	mov	al, [date_day]
  2148 00000B4B E88E000000              	call	bcd_to_ascii
  2149 00000B50 66A3[99B90000]          	mov	[datestr], ax
  2150                                  	;
  2151 00000B56 0FB61D[61BE0000]        	movzx	ebx, byte [date_wday]
  2152 00000B5D C0E302                  	shl 	bl, 2
  2153 00000B60 81C3[B2B90000]          	add	ebx, daytmp
  2154 00000B66 8B03                    	mov	eax, [ebx]
  2155 00000B68 A3[A4B90000]            	mov	[daystr], eax
  2156                                  	;
  2157 00000B6D A0[60BE0000]            	mov	al, [time_hours]
  2158 00000B72 E867000000              	call	bcd_to_ascii
  2159 00000B77 66A3[A8B90000]          	mov	[timestr], ax
  2160 00000B7D A0[5FBE0000]            	mov	al, [time_minutes]
  2161 00000B82 E857000000              	call	bcd_to_ascii
  2162 00000B87 66A3[ABB90000]          	mov	[timestr+3], ax
  2163 00000B8D A0[5EBE0000]            	mov	al, [time_seconds]
  2164 00000B92 E847000000              	call	bcd_to_ascii
  2165 00000B97 66A3[AEB90000]          	mov	[timestr+6], ax
  2166                                  	;		
  2167 00000B9D BE[87B90000]            	mov	esi, rtc_msg ; message offset
  2168                                  	; 23/02/2015
  2169 00000BA2 52                      	push	edx
  2170 00000BA3 51                      	push	ecx
  2171                                  	; 07/09/2014
  2172 00000BA4 66BB0200                	mov	bx, 2		; Video page 2
  2173                                  prtmsg:
  2174 00000BA8 AC                      	lodsb
  2175 00000BA9 08C0                    	or	al, al
  2176 00000BAB 740F                    	jz	short prtmsg_ok
  2177 00000BAD 56                      	push	esi
  2178 00000BAE 6653                    	push	bx
  2179 00000BB0 B43F                            mov	ah, 3Fh	; cyan (6) background, 
  2180                                  			; white (F) forecolor
  2181 00000BB2 E8000C0000              	call 	WRITE_TTY
  2182 00000BB7 665B                    	pop	bx
  2183 00000BB9 5E                      	pop	esi
  2184 00000BBA EBEC                    	jmp	short prtmsg
  2185                                  	;
  2186                                  	;mov	edi, 0B8000h+0A0h+0A0h ; Row 2
  2187                                  	;call	printk
  2188                                  prtmsg_ok:
  2189                                  	; 07/09/2014
  2190 00000BBC 6631D2                  	xor	dx, dx		; column 0, row 0
  2191 00000BBF E8870C0000              	call	_set_cpos	; set curspor position to 0,0 
  2192                                  	; 23/02/2015
  2193 00000BC4 59                      	pop	ecx
  2194 00000BC5 5A                      	pop	edx
  2195 00000BC6 C3                      	retn
  2196                                  
  2197                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  2198                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  2199                                  default_irq7:
  2200 00000BC7 6650                    	push	ax
  2201 00000BC9 B00B                    	mov	al, 0Bh  ; In-Service register
  2202 00000BCB E620                    	out	20h, al
  2203 00000BCD EB00                            jmp short $+2
  2204 00000BCF EB00                    	jmp short $+2
  2205 00000BD1 E420                    	in	al, 20h
  2206 00000BD3 2480                    	and 	al, 80h ; bit 7 (is it real IRQ 7 or fake?)
  2207 00000BD5 7404                            jz      short irq7_iret ; Fake (spurious) IRQ, do not send EOI 
  2208 00000BD7 B020                            mov     al, 20h ; EOI
  2209 00000BD9 E620                    	out	20h, al 
  2210                                  irq7_iret:
  2211 00000BDB 6658                    	pop	ax
  2212 00000BDD CF                      	iretd
  2213                                  	
  2214                                  bcd_to_ascii:
  2215                                  	; 25/08/2014
  2216                                  	; INPUT ->
  2217                                  	;	al = Packed BCD number
  2218                                  	; OUTPUT ->
  2219                                  	;	ax  = ASCII word/number
  2220                                  	;
  2221                                  	; Erdogan Tan - 1998 (proc_hex) - TRDOS.ASM (2004-2011)
  2222                                  	;
  2223 00000BDE D410                    	db 0D4h,10h                     ; Undocumented inst. AAM
  2224                                  					; AH = AL / 10h
  2225                                  					; AL = AL MOD 10h
  2226 00000BE0 660D3030                	or ax,'00'                      ; Make it ASCII based
  2227                                  
  2228 00000BE4 86E0                            xchg ah, al 
  2229                                  	
  2230 00000BE6 C3                      	retn	
  2231                                  	
  2232                                  
  2233                                  %include 'keyboard.s' ; 07/03/2015
  2234                              <1> ; ****************************************************************************
  2235                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - keyboard.s
  2236                              <1> ; ----------------------------------------------------------------------------
  2237                              <1> ; Last Update: 29/01/2016
  2238                              <1> ; ----------------------------------------------------------------------------
  2239                              <1> ; Beginning: 17/01/2016
  2240                              <1> ; ----------------------------------------------------------------------------
  2241                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
  2242                              <1> ; ----------------------------------------------------------------------------
  2243                              <1> ; Turkish Rational DOS
  2244                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
  2245                              <1> ;
  2246                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
  2247                              <1> ; keyboard.inc (17/10/2015)
  2248                              <1> ;
  2249                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
  2250                              <1> ; ****************************************************************************
  2251                              <1> 
  2252                              <1> ; Retro UNIX 386 v1 Kernel - KEYBOARD.INC
  2253                              <1> ; Last Modification: 17/10/2015
  2254                              <1> ;		    (Keyboard Data is in 'KYBDATA.INC')	
  2255                              <1> ;
  2256                              <1> ; ///////// KEYBOARD FUNCTIONS (PROCEDURES) ///////////////
  2257                              <1> 
  2258                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
  2259                              <1> 
  2260                              <1> ; 03/12/2014
  2261                              <1> ; 26/08/2014
  2262                              <1> ; KEYBOARD I/O
  2263                              <1> ; (INT_16h - Retro UNIX 8086 v1 - U9.ASM, 30/06/2014)
  2264                              <1> 
  2265                              <1> ;NOTE: 'k0' to 'k7' are name of OPMASK registers.
  2266                              <1> ;	(The reason of using '_k' labels!!!) (27/08/2014)    
  2267                              <1> ;NOTE: 'NOT' keyword is '~' unary operator in NASM.
  2268                              <1> ;	('NOT LC_HC' --> '~LC_HC') (bit reversing operator)
  2269                              <1> 
  2270                              <1> int16h:	; 30/06/2015
  2271                              <1> ;getc:
  2272 00000BE7 9C                  <1> 	pushfd	; 28/08/2014
  2273 00000BE8 0E                  <1> 	push 	cs
  2274 00000BE9 E801000000          <1> 	call 	KEYBOARD_IO_1 ; getc_int
  2275 00000BEE C3                  <1> 	retn	
  2276                              <1> 
  2277                              <1> getc_int:
  2278                              <1> 	; 28/02/2015
  2279                              <1> 	; 03/12/2014 (derivation from pc-xt-286 bios source code -1986-, 
  2280                              <1> 	;	      instead of pc-at bios - 1985-)
  2281                              <1> 	; 28/08/2014 (_k1d)
  2282                              <1> 	; 30/06/2014
  2283                              <1> 	; 03/03/2014
  2284                              <1> 	; 28/02/2014
  2285                              <1> 	; Derived from "KEYBOARD_IO_1" procedure of IBM "pc-xt-286" 
  2286                              <1> 	; rombios source code (21/04/1986)
  2287                              <1> 	;	 'keybd.asm', INT 16H, KEYBOARD_IO
  2288                              <1> 	;
  2289                              <1> 	; KYBD --- 03/06/86  KEYBOARD BIOS
  2290                              <1> 	;
  2291                              <1> 	;--- INT 16 H -----------------------------------------------------------------
  2292                              <1> 	; KEYBOARD I/O								      :
  2293                              <1> 	;	THESE ROUTINES PROVIDE READ KEYBOARD SUPPORT			      :
  2294                              <1> 	; INPUT									      :
  2295                              <1> 	;	(AH)= 00H  READ THE NEXT ASCII CHARACTER ENTERED FROM THE KEYBOARD,   :
  2296                              <1> 	;		   RETURN THE RESULT IN (AL), SCAN CODE IN (AH).              :
  2297                              <1> 	;		   THIS IS THE COMPATIBLE READ INTERFACE, EQUIVALENT TO THE   :
  2298                              <1> 	;                  STANDARD PC OR PCAT KEYBOARD				      :	
  2299                              <1> 	;-----------------------------------------------------------------------------:
  2300                              <1> 	;	(AH)= 01H  SET THE ZERO FLAG TO INDICATE IF AN ASCII CHARACTER IS     :
  2301                              <1> 	;		   AVAILABLE TO BE READ FROM THE KEYBOARD BUFFER.	      :
  2302                              <1> 	;		   (ZF)= 1 -- NO CODE AVAILABLE			              :
  2303                              <1> 	;		   (ZF)= 0 -- CODE IS AVAILABLE  (AX)= CHARACTER              :
  2304                              <1> 	;		   IF (ZF)= 0, THE NEXT CHARACTER IN THE BUFFER TO BE READ IS :
  2305                              <1> 	;		   IN (AX), AND THE ENTRY REMAINS IN THE BUFFER.              :
  2306                              <1> 	;		   THIS WILL RETURN ONLY PC/PCAT KEYBOARD COMPATIBLE CODES    :
  2307                              <1> 	;-----------------------------------------------------------------------------:	
  2308                              <1> 	;	(AH)= 02H  RETURN THE CURRENT SHIFT STATUS IN AL REGISTER             :
  2309                              <1> 	;		   THE BIT SETTINGS FOR THIS CODE ARE INDICATED IN THE        :
  2310                              <1> 	;		   EQUATES FOR @KB_FLAG		                              :
  2311                              <1> 	;-----------------------------------------------------------------------------:	
  2312                              <1> 	;	(AH)= 03H  SET TYPAMATIC RATE AND DELAY                               :
  2313                              <1> 	;	      (AL) = 05H                                                      :
  2314                              <1> 	;	      (BL) = TYPAMATIC RATE (BITS 5 - 7 MUST BE RESET TO 0)           :
  2315                              <1> 	;		       							      :
  2316                              <1> 	;                     REGISTER     RATE      REGISTER     RATE                :
  2317                              <1> 	;                      VALUE     SELECTED     VALUE     SELECTED              :
  2318                              <1> 	;                     --------------------------------------------            :
  2319                              <1> 	;			00H        30.0        10H        7.5                 :
  2320                              <1> 	;			01H        26.7        11H        6.7                 :
  2321                              <1> 	;			02H        24.0        12H        6.0                 :
  2322                              <1> 	;			03H        21.8        13H        5.5                 :
  2323                              <1> 	;			04H        20.0        14H        5.0                 :
  2324                              <1> 	;			05H        18.5        15H        4.6                 :
  2325                              <1> 	;			06H        17.1        16H        4.3                 :
  2326                              <1> 	;			07H        16.0        17H        4.0                 :
  2327                              <1> 	;			08H        15.0        18H        3.7                 :
  2328                              <1> 	;			09H        13.3        19H        3.3                 :
  2329                              <1> 	;			0AH        12.0        1AH        3.0                 :
  2330                              <1> 	;			0BH        10.9        1BH        2.7                 :
  2331                              <1>         ;			0CH        10.0        1CH        2.5                 :
  2332                              <1> 	;			0DH         9.2        1DH        2.3                 :
  2333                              <1> 	;			0EH         8.6        1EH        2.1                 :
  2334                              <1> 	;			0FH         8.0        1FH        2.0                 :
  2335                              <1> 	;									      :
  2336                              <1> 	;	      (BH) = TYPAMATIC DELAY  (BITS 2 - 7 MUST BE RESET TO 0)         :
  2337                              <1> 	;		       							      :
  2338                              <1> 	;                     REGISTER     DELAY                                      :
  2339                              <1> 	;                      VALUE       VALUE                                      :
  2340                              <1> 	;                     ------------------                                      :
  2341                              <1> 	;			00H        250 ms                                     :
  2342                              <1> 	;			01H        500 ms                                     :
  2343                              <1> 	;			02H        750 ms                                     :
  2344                              <1> 	;			03H       1000 ms                                     :
  2345                              <1> 	;-----------------------------------------------------------------------------:
  2346                              <1> 	;	(AH)= 05H  PLACE ASCII CHARACTER/SCAN CODE COMBINATION IN KEYBOARD    :
  2347                              <1> 	;		   BUFFER AS IF STRUCK FROM KEYBOARD                          :
  2348                              <1> 	;		   ENTRY:  (CL) = ASCII CHARACTER		              :
  2349                              <1> 	;		           (CH) = SCAN CODE                                   :
  2350                              <1> 	;		   EXIT:   (AH) = 00H = SUCCESSFUL OPERATION                  :
  2351                              <1> 	;		           (AL) = 01H = UNSUCCESSFUL - BUFFER FULL            :
  2352                              <1> 	;		   FLAGS:  CARRY IF ERROR                                     :
  2353                              <1> 	;-----------------------------------------------------------------------------:		
  2354                              <1> 	;	(AH)= 10H  EXTENDED READ INTERFACE FOR THE ENHANCED KEYBOARD,         :
  2355                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=0                            :
  2356                              <1> 	;-----------------------------------------------------------------------------:
  2357                              <1> 	;	(AH)= 11H  EXTENDED ASCII STATUS FOR THE ENHANCED KEYBOARD,           :
  2358                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=1                            :
  2359                              <1> 	;-----------------------------------------------------------------------------:	
  2360                              <1> 	;	(AH)= 12H  RETURN THE EXTENDED SHIFT STATUS IN AX REGISTER            :
  2361                              <1> 	;		   AL = BITS FROM KB_FLAG, AH = BITS FOR LEFT AND RIGHT       :
  2362                              <1> 	;		   CTL AND ALT KEYS FROM KB_FLAG_1 AND KB_FLAG_3              :
  2363                              <1> 	; OUTPUT					                              :
  2364                              <1> 	;	AS NOTED ABOVE, ONLY (AX) AND FLAGS CHANGED	                      :
  2365                              <1> 	;	ALL REGISTERS RETAINED		                                      :
  2366                              <1> 	;------------------------------------------------------------------------------
  2367                              <1> 
  2368                              <1> KEYBOARD_IO_1:	
  2369 00000BEF FB                  <1> 	sti				; INTERRUPTS BACK ON
  2370 00000BF0 1E                  <1> 	push	ds			; SAVE CURRENT DS
  2371 00000BF1 53                  <1> 	push	ebx			; SAVE BX TEMPORARILY
  2372                              <1> 	;push	ecx			; SAVE CX TEMPORARILY
  2373 00000BF2 66BB1000            <1>         mov     bx, KDATA 
  2374 00000BF6 8EDB                <1> 	mov	ds, bx			; PUT SEGMENT VALUE OF DATA AREA INTO DS
  2375 00000BF8 08E4                <1> 	or	ah, ah			; CHECK FOR (AH)= 00H
  2376 00000BFA 7439                <1> 	jz	short _K1		; ASCII_READ
  2377 00000BFC FECC                <1> 	dec	ah                      ; CHECK FOR (AH)= 01H
  2378 00000BFE 7452                <1>         jz      short _K2               ; ASCII_STATUS
  2379 00000C00 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 02H
  2380 00000C02 0F8485000000        <1>         jz      _K3                     ; SHIFT STATUS
  2381 00000C08 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 03H	
  2382 00000C0A 0F8484000000        <1>         jz      _K300                   ; SET TYPAMATIC RATE/DELAY
  2383 00000C10 80EC02              <1> 	sub	ah, 2			; CHECK FOR (AH)= 05H	
  2384 00000C13 0F84A1000000        <1>         jz      _K500                   ; KEYBOARD WRITE         
  2385                              <1> _KIO1:	
  2386 00000C19 80EC0B              <1> 	sub	ah, 11			; AH =  10H
  2387 00000C1C 740B                <1> 	jz	short _K1E		; EXTENDED ASCII READ
  2388 00000C1E FECC                <1> 	dec	ah			; CHECK FOR (AH)= 11H
  2389 00000C20 7421                <1> 	jz	short _K2E		; EXTENDED_ASCII_STATUS
  2390 00000C22 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 12H
  2391 00000C24 7449                <1> 	jz	short _K3E		; EXTENDED_SHIFT_STATUS
  2392                              <1> _KIO_EXIT:
  2393                              <1> 	;pop	ecx			; RECOVER REGISTER
  2394 00000C26 5B                  <1> 	pop	ebx			; RECOVER REGISTER
  2395 00000C27 1F                  <1> 	pop	ds			; RECOVER SEGMENT
  2396 00000C28 CF                  <1> 	iretd				; INVALID COMMAND, EXIT
  2397                              <1> 
  2398                              <1> 	;-----	ASCII CHARACTER
  2399                              <1> _K1E:	
  2400 00000C29 E8B9000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER (EXTENDED)
  2401 00000C2E E82E010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
  2402 00000C33 EBF1                <1> 	jmp	short _KIO_EXIT         ; GIVE IT TO THE CALLER
  2403                              <1> _K1:	
  2404 00000C35 E8AD000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER
  2405 00000C3A E82D010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
  2406 00000C3F 72F4                <1> 	jc	short _K1		; CARRY SET MEANS TROW CODE AWAY
  2407                              <1> _K1A:
  2408 00000C41 EBE3                <1> 	jmp	short _KIO_EXIT         ; RETURN TO CALLER
  2409                              <1> 
  2410                              <1> 	;-----	ASCII STATUS
  2411                              <1> _K2E:	
  2412 00000C43 E8EA000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER (EXTENDED)
  2413 00000C48 7420                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
  2414 00000C4A 9C                  <1> 	pushf				; SAVE ZF FROM TEST
  2415 00000C4B E811010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
  2416 00000C50 EB17                <1> 	jmp	short _K2A	        ; GIVE IT TO THE CALLER
  2417                              <1> _K2:	
  2418 00000C52 E8DB000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER
  2419 00000C57 7411                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
  2420 00000C59 9C                  <1> 	pushf				; SAVE ZF FROM TEST
  2421 00000C5A E80D010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
  2422 00000C5F 7308                <1> 	jnc	short _K2A	        ; CARRY CLEAR MEANS PASS VALID CODE
  2423 00000C61 9D                  <1> 	popf				; INVALID CODE FOR THIS TYPE OF CALL
  2424 00000C62 E880000000          <1> 	call	_K1S			; THROW THE CHARACTER AWAY
  2425 00000C67 EBE9                <1> 	jmp	short _K2		; GO LOOK FOR NEXT CHAR, IF ANY
  2426                              <1> _K2A:
  2427 00000C69 9D                  <1> 	popf				; RESTORE ZF FROM TEST
  2428                              <1> _K2B:
  2429                              <1> 	;pop	ecx			; RECOVER REGISTER
  2430 00000C6A 5B                  <1> 	pop	ebx			; RECOVER REGISTER
  2431 00000C6B 1F                  <1> 	pop	ds			; RECOVER SEGMENT
  2432 00000C6C CA0400              <1> 	retf	4			; THROW AWAY (e)FLAGS
  2433                              <1> 
  2434                              <1> 	;-----	SHIFT STATUS
  2435                              <1> _K3E:                                   ; GET THE EXTENDED SHIFT STATUS FLAGS
  2436 00000C6F 8A25[E2B70000]      <1> 	mov	ah, [KB_FLAG_1]		; GET SYSTEM SHIFT KEY STATUS
  2437 00000C75 80E404              <1> 	and	ah, SYS_SHIFT		; MASK ALL BUT SYS KEY BIT
  2438                              <1> 	;mov	cl, 5			; SHIFT THEW SYSTEMKEY BIT OVER TO
  2439                              <1> 	;shl	ah, cl			; BIT 7 POSITION
  2440 00000C78 C0E405              <1>         shl	ah, 5
  2441 00000C7B A0[E2B70000]        <1> 	mov	al, [KB_FLAG_1]		; GET SYSTEM SHIFT STATES BACK
  2442 00000C80 2473                <1> 	and	al, 01110011b		; ELIMINATE SYS SHIFT, HOLD_STATE AND INS_SHIFT
  2443 00000C82 08C4                <1> 	or	ah, al                  ; MERGE REMAINING BITS INTO AH
  2444 00000C84 A0[E4B70000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT CTL AND ALT
  2445 00000C89 240C                <1> 	and	al, 00001100b		; ELIMINATE LC_E0 AND LC_E1
  2446 00000C8B 08C4                <1> 	or	ah, al			; OR THE SHIFT FLAGS TOGETHER
  2447                              <1> _K3:
  2448 00000C8D A0[E1B70000]        <1> 	mov	al, [KB_FLAG]		; GET THE SHIFT STATUS FLAGS
  2449 00000C92 EB92                <1> 	jmp	short _KIO_EXIT		; RETURN TO CALLER
  2450                              <1> 
  2451                              <1> 	;-----	SET TYPAMATIC RATE AND DELAY
  2452                              <1> _K300:
  2453 00000C94 3C05                <1> 	cmp	al, 5			; CORRECT FUNCTION CALL?
  2454 00000C96 758E                <1> 	jne	short _KIO_EXIT		; NO, RETURN
  2455 00000C98 F6C3E0              <1>      	test	bl, 0E0h		; TEST FOR OUT-OF-RANGE RATE
  2456 00000C9B 7589                <1> 	jnz	short _KIO_EXIT		; RETURN IF SO
  2457 00000C9D F6C7FC              <1> 	test	BH, 0FCh		; TEST FOR OUT-OF-RANGE DELAY
  2458 00000CA0 7584                <1> 	jnz	short _KIO_EXIT		; RETURN IF SO
  2459 00000CA2 B0F3                <1> 	mov	al, KB_TYPA_RD		; COMMAND FOR TYPAMATIC RATE/DELAY		
  2460 00000CA4 E8DA060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
  2461                              <1> 	;mov	cx, 5			; SHIFT COUNT
  2462                              <1> 	;shl	bh, cl			; SHIFT DELAY OVER
  2463 00000CA9 C0E705              <1> 	shl	bh, 5
  2464 00000CAC 88D8                <1> 	mov	al, bl			; PUT IN RATE
  2465 00000CAE 08F8                <1> 	or	al, bh			; AND DELAY
  2466 00000CB0 E8CE060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
  2467 00000CB5 E96CFFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER
  2468                              <1> 
  2469                              <1> 	;-----	WRITE TO KEYBOARD BUFFER
  2470                              <1> _K500:
  2471 00000CBA 56                  <1> 	push	esi			; SAVE SI (esi)
  2472 00000CBB FA                  <1> 	cli				; 
  2473 00000CBC 8B1D[F2B70000]      <1>      	mov	ebx, [BUFFER_TAIL]	; GET THE 'IN TO' POINTER TO THE BUFFER
  2474 00000CC2 89DE                <1> 	mov	esi, ebx		; SAVE A COPY IN CASE BUFFER NOT FULL
  2475 00000CC4 E8D3000000          <1> 	call	_K4			; BUMP THE POINTER TO SEE IF BUFFER IS FULL
  2476 00000CC9 3B1D[EEB70000]      <1> 	cmp	ebx, [BUFFER_HEAD]	; WILL THE BUFFER OVERRUN IF WE STORE THIS?
  2477 00000CCF 740D                <1> 	je	short _K502		; YES - INFORM CALLER OF ERROR		
  2478 00000CD1 66890E              <1> 	mov	[esi], cx		; NO - PUT ASCII/SCAN CODE INTO BUFFER	
  2479 00000CD4 891D[F2B70000]      <1> 	mov	[BUFFER_TAIL], ebx	; ADJUST 'IN TO' POINTER TO REFLECT CHANGE
  2480 00000CDA 28C0                <1> 	sub	al, al			; TELL CALLER THAT OPERATION WAS SUCCESSFUL
  2481 00000CDC EB02                <1> 	jmp	short _K504		; SUB INSTRUCTION ALSO RESETS CARRY FLAG
  2482                              <1> _K502:
  2483 00000CDE B001                <1> 	mov	al, 01h			; BUFFER FULL INDICATION
  2484                              <1> _K504:
  2485 00000CE0 FB                  <1> 	sti				
  2486 00000CE1 5E                  <1> 	pop	esi			; RECOVER SI (esi)
  2487 00000CE2 E93FFFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER WITH STATUS IN AL
  2488                              <1> 
  2489                              <1> 	;-----	READ THE KEY TO FIGURE OUT WHAT TO DO -----
  2490                              <1> _K1S:
  2491 00000CE7 FA                  <1> 	cli	; 03/12/2014
  2492 00000CE8 8B1D[EEB70000]      <1>         mov     ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
  2493 00000CEE 3B1D[F2B70000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
  2494                              <1> 	;jne	short _K1U		; IF ANYTHING IN BUFFER SKIP INTERRUPT
  2495 00000CF4 750F                <1> 	jne	short _k1x ; 03/12/2014
  2496                              <1> 	;
  2497                              <1> 	; 03/12/2014
  2498                              <1> 	; 28/08/2014
  2499                              <1> 	; PERFORM OTHER FUNCTION ?? here !
  2500                              <1> 	;; MOV	AX, 9002h		; MOVE IN WAIT CODE & TYPE
  2501                              <1> 	;; INT 	15H			; PERFORM OTHER FUNCTION
  2502                              <1> _K1T:                                   ; ASCII READ
  2503 00000CF6 FB                  <1> 	sti				; INTERRUPTS BACK ON DURING LOOP
  2504 00000CF7 90                  <1> 	nop				; ALLOW AN INTERRUPT TO OCCUR
  2505                              <1> _K1U:	
  2506 00000CF8 FA                  <1> 	cli				; INTERRUPTS BACK OFF
  2507 00000CF9 8B1D[EEB70000]      <1>         mov    	ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
  2508 00000CFF 3B1D[F2B70000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
  2509                              <1> _k1x:
  2510 00000D05 53                  <1> 	push	ebx			; SAVE ADDRESS		
  2511 00000D06 9C                  <1> 	pushf				; SAVE FLAGS
  2512 00000D07 E82F070000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
  2513 00000D0C 8A1D[E3B70000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
  2514 00000D12 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
  2515 00000D14 80E307              <1> 	and	bl, 07h	; KB_LEDS	; ISOLATE INDICATOR BITS
  2516 00000D17 7406                <1> 	jz	short _K1V		; IF NO CHANGE BYPASS UPDATE
  2517 00000D19 E8C9060000          <1> 	call	SND_LED1
  2518 00000D1E FA                  <1> 	cli				; DISABLE INTERRUPTS
  2519                              <1> _K1V:
  2520 00000D1F 9D                  <1> 	popf				; RESTORE FLAGS
  2521 00000D20 5B                  <1> 	pop	ebx			; RESTORE ADDRESS
  2522 00000D21 74D3                <1>         je      short _K1T              ; LOOP UNTIL SOMETHING IN BUFFER
  2523                              <1> 	;
  2524 00000D23 668B03              <1> 	mov	ax, [ebx] 		; GET SCAN CODE AND ASCII CODE
  2525 00000D26 E871000000          <1>         call    _K4                     ; MOVE POINTER TO NEXT POSITION
  2526 00000D2B 891D[EEB70000]      <1>         mov     [BUFFER_HEAD], ebx      ; STORE VALUE IN VARIABLE
  2527 00000D31 C3                  <1> 	retn				; RETURN
  2528                              <1> 
  2529                              <1> 	;-----	READ THE KEY TO SEE IF ONE IS PRESENT -----
  2530                              <1> _K2S:
  2531 00000D32 FA                  <1> 	cli				; INTERRUPTS OFF
  2532 00000D33 8B1D[EEB70000]      <1>         mov     ebx, [BUFFER_HEAD]      ; GET HEAD POINTER
  2533 00000D39 3B1D[F2B70000]      <1>         cmp     ebx, [BUFFER_TAIL]      ; IF EQUAL (Z=1) THEN NOTHING THERE
  2534 00000D3F 668B03              <1> 	mov	ax, [ebx]
  2535 00000D42 9C                  <1> 	pushf				; SAVE FLAGS
  2536 00000D43 6650                <1> 	push	ax			; SAVE CODE
  2537 00000D45 E8F1060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
  2538 00000D4A 8A1D[E3B70000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
  2539 00000D50 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
  2540 00000D52 80E307              <1> 	and	bl, 07h ; KB_LEDS	; ISOLATE INDICATOR BITS
  2541 00000D55 7405                <1> 	jz	short _K2T		; IF NO CHANGE BYPASS UPDATE
  2542 00000D57 E874060000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
  2543                              <1> _K2T:
  2544 00000D5C 6658                <1> 	pop	ax			; RESTORE CODE
  2545 00000D5E 9D                  <1> 	popf				; RESTORE FLAGS
  2546 00000D5F FB                  <1> 	sti				; INTERRUPTS BACK ON
  2547 00000D60 C3                  <1> 	retn				; RETURN
  2548                              <1> 
  2549                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR EXTENDED CALLS -----
  2550                              <1> _KIO_E_XLAT:
  2551 00000D61 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
  2552 00000D63 7506                <1> 	jne	short _KIO_E_RET	; NO, PASS IT ON
  2553 00000D65 08E4                <1>         or 	ah, ah			; AH = 0 IS SPECIAL CASE
  2554 00000D67 7402                <1>         jz	short _KIO_E_RET        ; PASS THIS ON UNCHANGED
  2555 00000D69 30C0                <1> 	xor	al, al			; OTHERWISE SET AL = 0
  2556                              <1> _KIO_E_RET:				
  2557 00000D6B C3                  <1> 	retn				; GO BACK
  2558                              <1> 
  2559                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR STANDARD CALLS -----
  2560                              <1> _KIO_S_XLAT:
  2561 00000D6C 80FCE0              <1> 	cmp	ah, 0E0h		; IS IT KEYPAD ENTER OR / ?
  2562 00000D6F 750F                <1> 	jne	short _KIO_S2		; NO, CONTINUE
  2563 00000D71 3C0D                <1> 	cmp	al, 0Dh			; KEYPAD ENTER CODE?
  2564 00000D73 7408                <1>         je	short _KIO_S1		; YES, MASSAGE A BIT
  2565 00000D75 3C0A                <1> 	cmp	al, 0Ah			; CTRL KEYPAD ENTER CODE?
  2566 00000D77 7404                <1>         je	short _KIO_S1		; YES, MASSAGE THE SAME
  2567 00000D79 B435                <1> 	mov	ah, 35h			; NO, MUST BE KEYPAD /
  2568                              <1> _kio_ret: ; 03/12/2014
  2569 00000D7B F8                  <1> 	clc
  2570 00000D7C C3                  <1> 	retn
  2571                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
  2572                              <1> _KIO_S1:				
  2573 00000D7D B41C                <1> 	mov	ah, 1Ch			; CONVERT TO COMPATIBLE OUTPUT
  2574                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
  2575 00000D7F C3                  <1> 	retn
  2576                              <1> _KIO_S2:		
  2577 00000D80 80FC84              <1> 	cmp	ah, 84h			; IS IT ONE OF EXTENDED ONES?
  2578 00000D83 7715                <1> 	ja	short _KIO_DIS		; YES, THROW AWAY AND GET ANOTHER CHAR
  2579 00000D85 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
  2580 00000D87 7506                <1>         jne	short _KIO_S3		; NO, TRY LAST TEST
  2581 00000D89 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
  2582 00000D8B 740C                <1>         jz	short _KIO_USE		; PASS THIS ON UNCHANGED
  2583 00000D8D EB0B                <1> 	jmp	short _KIO_DIS		; THROW AWAY THE REST
  2584                              <1> _KIO_S3:
  2585 00000D8F 3CE0                <1> 	cmp	al, 0E0h		; IS IT AN EXTENSION OF A PREVIOUS ONE?
  2586                              <1> 	;jne	short _KIO_USE		; NO, MUST BE A STANDARD CODE
  2587 00000D91 75E8                <1> 	jne	short _kio_ret
  2588 00000D93 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
  2589 00000D95 7402                <1>         jz	short _KIO_USE		; JUMP IF AH = 0
  2590 00000D97 30C0                <1> 	xor	al, al			; CONVERT TO COMPATIBLE OUTPUT
  2591                              <1> 	;jmp	short _KIO_USE		; PASS IT ON TO CALLER
  2592                              <1> _KIO_USE:
  2593                              <1> 	;clc				; CLEAR CARRY TO INDICATE GOOD CODE
  2594 00000D99 C3                  <1> 	retn				; RETURN	
  2595                              <1> _KIO_DIS:
  2596 00000D9A F9                  <1> 	stc				; SET CARRY TO INDICATE DISCARD CODE
  2597 00000D9B C3                  <1> 	retn				; RETURN
  2598                              <1> 
  2599                              <1> 	;-----	INCREMENT BUFFER POINTER ROUTINE -----
  2600                              <1> _K4:    
  2601 00000D9C 43                  <1> 	inc     ebx
  2602 00000D9D 43                  <1> 	inc	ebx			; MOVE TO NEXT WORD IN LIST
  2603 00000D9E 3B1D[EAB70000]      <1>         cmp     ebx, [BUFFER_END] 	; AT END OF BUFFER?
  2604                              <1>         ;jne    short _K5               ; NO, CONTINUE
  2605 00000DA4 7206                <1> 	jb	short _K5
  2606 00000DA6 8B1D[E6B70000]      <1>         mov     ebx, [BUFFER_START]     ; YES, RESET TO BUFFER BEGINNING
  2607                              <1> _K5:
  2608 00000DAC C3                  <1> 	retn
  2609                              <1> 
  2610                              <1> ; 20/02/2015
  2611                              <1> ; 05/12/2014
  2612                              <1> ; 26/08/2014
  2613                              <1> ; KEYBOARD (HARDWARE) INTERRUPT -  IRQ LEVEL 1
  2614                              <1> ; (INT_09h - Retro UNIX 8086 v1 - U9.ASM, 07/03/2014)
  2615                              <1> ;
  2616                              <1> ; Derived from "KB_INT_1" procedure of IBM "pc-at" 
  2617                              <1> ; rombios source code (06/10/1985)
  2618                              <1> ; 'keybd.asm', HARDWARE INT 09h - (IRQ Level 1)
  2619                              <1> 
  2620                              <1> ; EQUATES (IBM PC-XT-286 BIOS, 1986, 'POSQEQU.INC')
  2621                              <1> 
  2622                              <1> ;--------- 8042 COMMANDS -------------------------------------------------------
  2623                              <1> ENA_KBD		equ	0AEh		; ENABLE KEYBOARD COMMAND
  2624                              <1> DIS_KBD		equ	0ADh		; DISABLE KEYBOARD COMMAND
  2625                              <1> SHUT_CMD	equ	0FEh		; CAUSE A SHUTDOWN COMMAND
  2626                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
  2627                              <1> STATUS_PORT	equ	064h		; 8042 STATUS PORT
  2628                              <1> INPT_BUF_FULL	equ	00000010b 	; 1 = +INPUT BUFFER FULL
  2629                              <1> PORT_A		equ	060h		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
  2630                              <1> ;---------- 8042 KEYBOARD RESPONSE ---------------------------------------------
  2631                              <1> KB_ACK		equ	0FAh		; ACKNOWLEDGE PROM TRANSMISSION
  2632                              <1> KB_RESEND	equ	0FEh		; RESEND REQUEST
  2633                              <1> KB_OVER_RUN	equ	0FFh		; OVER RUN SCAN CODE
  2634                              <1> ;---------- KEYBOARD/LED COMMANDS ----------------------------------------------
  2635                              <1> KB_ENABLE	equ	0F4h		; KEYBOARD ENABLE
  2636                              <1> LED_CMD		equ	0EDh		; LED WRITE COMMAND
  2637                              <1> KB_TYPA_RD	equ	0F3h		; TYPAMATIC RATE/DELAY COMMAND
  2638                              <1> ;---------- KEYBOARD SCAN CODES ------------------------------------------------
  2639                              <1> NUM_KEY		equ	69		; SCAN CODE FOR	 NUMBER LOCK KEY
  2640                              <1> SCROLL_KEY	equ	70		; SCAN CODE FOR	 SCROLL LOCK KEY
  2641                              <1> ALT_KEY		equ	56		; SCAN CODE FOR	 ALTERNATE SHIFT KEY
  2642                              <1> CTL_KEY		equ	29		; SCAN CODE FOR	 CONTROL KEY
  2643                              <1> CAPS_KEY	equ	58		; SCAN CODE FOR	 SHIFT LOCK KEY
  2644                              <1> DEL_KEY		equ	83		; SCAN CODE FOR	 DELETE KEY
  2645                              <1> INS_KEY		equ	82		; SCAN CODE FOR	 INSERT KEY
  2646                              <1> LEFT_KEY	equ	42		; SCAN CODE FOR	 LEFT SHIFT
  2647                              <1> RIGHT_KEY	equ	54		; SCAN CODE FOR	 RIGHT SHIFT
  2648                              <1> SYS_KEY		equ	84		; SCAN CODE FOR	 SYSTEM KEY
  2649                              <1> ;---------- ENHANCED KEYBOARD SCAN CODES ---------------------------------------
  2650                              <1> ID_1		equ	0ABh		; 1ST ID CHARACTER FOR KBX
  2651                              <1> ID_2		equ	041h		; 2ND ID CHARACTER FOR KBX
  2652                              <1> ID_2A		equ	054h		; ALTERNATE 2ND ID CHARACTER FOR KBX
  2653                              <1> F11_M		equ	87		; F11 KEY MAKE
  2654                              <1> F12_M		equ	88		; F12 KEY MAKE
  2655                              <1> MC_E0		equ	224		; GENERAL MARKER CODE
  2656                              <1> MC_E1		equ	225		; PAUSE KEY MARKER CODE
  2657                              <1> ;---------- FLAG EQUATES WITHIN @KB_FLAG----------------------------------------
  2658                              <1> RIGHT_SHIFT	equ	00000001b	; RIGHT SHIFT KEY DEPRESSED
  2659                              <1> LEFT_SHIFT	equ	00000010b	; LEFT SHIFT KEY DEPRESSED
  2660                              <1> CTL_SHIFT	equ	00000100b	; CONTROL SHIFT KEY DEPRESSED
  2661                              <1> ALT_SHIFT	equ	00001000b	; ALTERNATE SHIFT KEY DEPRESSED
  2662                              <1> SCROLL_STATE	equ	00010000b	; SCROLL LOCK STATE IS ACTIVE
  2663                              <1> NUM_STATE	equ	00100000b	; NUM LOCK STATE IS ACTIVE
  2664                              <1> CAPS_STATE	equ	01000000b	; CAPS LOCK STATE IS ACTIVE
  2665                              <1> INS_STATE	equ	10000000b	; INSERT STATE IS ACTIVE
  2666                              <1> ;---------- FLAG EQUATES WITHIN	@KB_FLAG_1 -------------------------------------
  2667                              <1> L_CTL_SHIFT	equ	00000001b	; LEFT CTL KEY DOWN
  2668                              <1> L_ALT_SHIFT	equ	00000010b	; LEFT ALT KEY DOWN
  2669                              <1> SYS_SHIFT	equ	00000100b	; SYSTEM KEY DEPRESSED AND HELD
  2670                              <1> HOLD_STATE	equ	00001000b	; SUSPEND KEY HAS BEEN TOGGLED
  2671                              <1> SCROLL_SHIFT	equ	00010000b	; SCROLL LOCK KEY IS DEPRESSED
  2672                              <1> NUM_SHIFT	equ	00100000b	; NUM LOCK KEY IS DEPRESSED
  2673                              <1> CAPS_SHIFT	equ	01000000b	; CAPS LOCK KEY IS DEPRE55ED
  2674                              <1> INS_SHIFT	equ	10000000b	; INSERT KEY IS DEPRESSED
  2675                              <1> ;---------- FLAGS EQUATES WITHIN @KB_FLAG_2 -----------------------------------
  2676                              <1> KB_LEDS		equ	00000111b	; KEYBOARD LED STATE BITS
  2677                              <1> ;		equ	00000001b	; SCROLL LOCK INDICATOR
  2678                              <1> ;		equ	00000010b	; NUM LOCK INDICATOR
  2679                              <1> ;		equ	00000100b	; CAPS LOCK INDICATOR
  2680                              <1> ;		equ	00001000b	; RESERVED (MUST BE ZERO)
  2681                              <1> KB_FA		equ	00010000b	; ACKNOWLEDGMENT RECEIVED
  2682                              <1> KB_FE		equ	00100000b	; RESEND RECEIVED FLAG
  2683                              <1> KB_PR_LED	equ	01000000b	; MODE INDICATOR UPDATE
  2684                              <1> KB_ERR		equ	10000000b	; KEYBOARD TRANSMIT ERROR FLAG
  2685                              <1> ;----------- FLAGS EQUATES WITHIN @KB_FLAG_3 -----------------------------------
  2686                              <1> LC_E1		equ	00000001b	; LAST CODE WAS THE E1 HIDDEN CODE
  2687                              <1> LC_E0		equ	00000010b	; LAST CODE WAS THE E0 HIDDEN CODE
  2688                              <1> R_CTL_SHIFT	equ	00000100b	; RIGHT CTL KEY DOWN
  2689                              <1> R_ALT_SHIFT	equ	00001000b	; RIGHT ALT KEY DOWN
  2690                              <1> GRAPH_ON	equ	00001000b	; ALT GRAPHICS KEY DOWN (WT ONLY)	
  2691                              <1> KBX		equ	00010000b	; ENHANCED KEYBOARD INSTALLED
  2692                              <1> SET_NUM_LK	equ	00100000b	; FORCE NUM LOCK IF READ ID AND KBX
  2693                              <1> LC_AB		equ	01000000b	; LAST CHARACTER WAS FIRST ID CHARACTER
  2694                              <1> RD_ID		equ	10000000b	; DOING A READ ID (MUST BE BIT0)
  2695                              <1> ;
  2696                              <1> ;----------- INTERRUPT EQUATES -------------------------------------------------
  2697                              <1> EOI		equ	020h		; END OF INTERRUPT COMMAND TO 8259
  2698                              <1> INTA00		equ	020h		; 8259 PORT
  2699                              <1> 
  2700                              <1> 
  2701                              <1> kb_int:
  2702                              <1> 
  2703                              <1> ; 17/10/2015 ('ctrlbrk') 
  2704                              <1> ; 05/12/2014
  2705                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-)
  2706                              <1> ; 26/08/2014
  2707                              <1> ;
  2708                              <1> ; 03/06/86  KEYBOARD BIOS
  2709                              <1> ;
  2710                              <1> ;--- HARDWARE INT 09H -- (IRQ LEVEL 1) ------------------------------------------
  2711                              <1> ;										;
  2712                              <1> ;	KEYBOARD INTERRUPT ROUTINE						;
  2713                              <1> ;										;
  2714                              <1> ;--------------------------------------------------------------------------------
  2715                              <1> 
  2716                              <1> KB_INT_1:
  2717 00000DAD FB                  <1> 	sti				; ENABLE INTERRUPTS
  2718                              <1> 	;push	ebp
  2719 00000DAE 50                  <1> 	push	eax
  2720 00000DAF 53                  <1> 	push	ebx
  2721 00000DB0 51                  <1> 	push	ecx
  2722 00000DB1 52                  <1> 	push	edx
  2723 00000DB2 56                  <1> 	push	esi
  2724 00000DB3 57                  <1> 	push	edi
  2725 00000DB4 1E                  <1> 	push	ds
  2726 00000DB5 06                  <1> 	push	es
  2727 00000DB6 FC                  <1> 	cld				; FORWARD DIRECTION
  2728 00000DB7 66B81000            <1> 	mov	ax, KDATA
  2729 00000DBB 8ED8                <1> 	mov	ds, ax
  2730 00000DBD 8EC0                <1> 	mov	es, ax
  2731                              <1> 	;
  2732                              <1> 	;-----	WAIT FOR KEYBOARD DISABLE COMMAND TO BE ACCEPTED
  2733 00000DBF B0AD                <1> 	mov	al, DIS_KBD		; DISABLE THE KEYBOARD COMMAND
  2734 00000DC1 E8A9050000          <1> 	call	SHIP_IT			; EXECUTE DISABLE
  2735 00000DC6 FA                  <1> 	cli				; DISABLE INTERRUPTS
  2736 00000DC7 B900000100          <1> 	mov	ecx, 10000h		; SET MAXIMUM TIMEOUT
  2737                              <1> KB_INT_01:
  2738 00000DCC E464                <1> 	in	al, STATUS_PORT		; READ ADAPTER STATUS
  2739 00000DCE A802                <1> 	test	al, INPT_BUF_FULL	; CHECK INPUT BUFFER FULL STATUS BIT
  2740 00000DD0 E0FA                <1> 	loopnz	KB_INT_01		; WAIT FOR COMMAND TO BE ACCEPTED
  2741                              <1> 	;
  2742                              <1> 	;-----	READ CHARACTER FROM KEYBOARD INTERFACE
  2743 00000DD2 E460                <1> 	in	al, PORT_A		; READ IN THE CHARACTER
  2744                              <1> 	;
  2745                              <1> 	;-----	SYSTEM HOOK INT 15H - FUNCTION 4FH (ON HARDWARE INT LEVEL 9H) 	
  2746                              <1> 	;MOV	AH, 04FH		; SYSTEM INTERCEPT - KEY CODE FUNCTION
  2747                              <1> 	;STC				; SET CY=1 (IN CASE OF IRET)
  2748                              <1> 	;INT	15H			; CASETTE CALL (AL)=KEY SCAN CODE
  2749                              <1> 	;				; RETURNS CY=1 FOR INVALID FUNCTION
  2750                              <1> 	;JC	KB_INT_02		; CONTINUE IF CARRY FLAG SET ((AL)=CODE)
  2751                              <1> 	;JMP	K26			; EXIT IF SYSTEM HANDLES SCAN CODE
  2752                              <1> 	;				; EXT HANDLES HARDWARE EOI AND ENABLE		
  2753                              <1> 	;
  2754                              <1> 	;-----	CHECK FOR A RESEND COMMAND TO KEYBOARD
  2755                              <1> KB_INT_02:				; 	  (AL)= SCAN CODE
  2756 00000DD4 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  2757 00000DD5 3CFE                <1> 	cmp	al, KB_RESEND		; IS THE INPUT A RESEND
  2758 00000DD7 7411                <1>         je      short KB_INT_4          ; GO IF RESEND
  2759                              <1> 	;
  2760                              <1> 	;-----	CHECK FOR RESPONSE TO A COMMAND TO KEYBOARD
  2761 00000DD9 3CFA                <1> 	cmp	al, KB_ACK		; IS THE INPUT AN ACKNOWLEDGE
  2762 00000DDB 751A                <1>         jne     short KB_INT_2          ; GO IF NOT
  2763                              <1> 	;
  2764                              <1> 	;-----	A COMMAND TO THE KEYBOARD WAS ISSUED
  2765 00000DDD FA                  <1> 	cli				; DISABLE INTERRUPTS
  2766 00000DDE 800D[E3B70000]10    <1> 	or	byte [KB_FLAG_2], KB_FA ; INDICATE ACK RECEIVED
  2767 00000DE5 E97A020000          <1>         jmp     K26                     ; RETURN IF NOT (ACK RETURNED FOR DATA)
  2768                              <1> 	;
  2769                              <1> 	;-----	RESEND THE LAST BYTE
  2770                              <1> KB_INT_4:
  2771 00000DEA FA                  <1> 	cli				; DISABLE INTERRUPTS
  2772 00000DEB 800D[E3B70000]20    <1> 	or	byte [KB_FLAG_2], KB_FE ; INDICATE RESEND RECEIVED
  2773 00000DF2 E96D020000          <1>         jmp     K26                     ; RETURN IF NOT ACK RETURNED FOR DATA)
  2774                              <1> 	;
  2775                              <1> ;-----	UPDATE MODE INDICATORS IF CHANGE IN STATE
  2776                              <1> KB_INT_2:
  2777 00000DF7 6650                <1> 	push 	ax			; SAVE DATA IN
  2778 00000DF9 E83D060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
  2779 00000DFE 8A1D[E3B70000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
  2780 00000E04 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
  2781 00000E06 80E307              <1> 	and	bl, KB_LEDS		; ISOLATE INDICATOR BITS
  2782 00000E09 7405                <1> 	jz	short UP0		; IF NO CHANGE BYPASS UPDATE
  2783 00000E0B E8C0050000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
  2784                              <1> UP0:
  2785 00000E10 6658                <1> 	pop	ax			; RESTORE DATA IN
  2786                              <1> ;------------------------------------------------------------------------
  2787                              <1> ;	START OF KEY PROCESSING						;
  2788                              <1> ;------------------------------------------------------------------------
  2789 00000E12 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE IN AH ALSO
  2790                              <1> 	;
  2791                              <1> 	;-----	TEST FOR OVERRUN SCAN CODE FROM KEYBOARD
  2792 00000E14 3CFF                <1> 	cmp	al, KB_OVER_RUN		; IS THIS AN OVERRUN CHAR
  2793 00000E16 0F843F050000        <1>         je      K62			; BUFFER_FULL_BEEP
  2794                              <1> 	;
  2795                              <1> K16:	
  2796 00000E1C 8A3D[E4B70000]      <1> 	mov	bh, [KB_FLAG_3]		; LOAD FLAGS FOR TESTING
  2797                              <1> 	;
  2798                              <1> 	;-----	TEST TO SEE IF A READ_ID IS IN PROGRESS
  2799 00000E22 F6C7C0              <1> 	test 	bh, RD_ID+LC_AB 	; ARE WE DOING A READ ID?
  2800 00000E25 7449                <1> 	jz	short NOT_ID		; CONTINUE IF NOT
  2801 00000E27 7917                <1> 	jns	short TST_ID_2		; IS THE RD_ID FLAG ON?
  2802 00000E29 3CAB                <1> 	cmp	al, ID_1		; IS THIS THE 1ST ID CHARACTER?
  2803 00000E2B 7507                <1> 	jne	short RST_RD_ID
  2804 00000E2D 800D[E4B70000]40    <1> 	or	byte [KB_FLAG_3], LC_AB ; INDICATE 1ST ID WAS OK
  2805                              <1> RST_RD_ID:
  2806 00000E34 8025[E4B70000]7F    <1> 	and	byte [KB_FLAG_3], ~RD_ID ; RESET THE READ ID FLAG
  2807                              <1>         ;jmp    short ID_EX		; AND EXIT
  2808 00000E3B E924020000          <1> 	jmp	K26
  2809                              <1> 	;
  2810                              <1> TST_ID_2:
  2811 00000E40 8025[E4B70000]BF    <1> 	and	byte [KB_FLAG_3], ~LC_AB ; RESET FLAG
  2812 00000E47 3C54                <1> 	cmp	al, ID_2A		; IS THIS THE 2ND ID CHARACTER?
  2813 00000E49 7419                <1>         je	short KX_BIT		; JUMP IF SO
  2814 00000E4B 3C41                <1> 	cmp	al, ID_2		; IS THIS THE 2ND ID CHARACTER?
  2815                              <1>         ;jne	short ID_EX		; LEAVE IF NOT
  2816 00000E4D 0F8511020000        <1> 	jne	K26
  2817                              <1> 	;
  2818                              <1> 	;-----	A READ ID SAID THAT IT WAS ENHANCED KEYBOARD
  2819 00000E53 F6C720              <1> 	test	bh, SET_NUM_LK 		; SHOULD WE SET NUM LOCK?
  2820 00000E56 740C                <1>         jz      short KX_BIT		; EXIT IF NOT
  2821 00000E58 800D[E1B70000]20    <1> 	or	byte [KB_FLAG], NUM_STATE ; FORCE NUM LOCK ON
  2822 00000E5F E86C050000          <1> 	call	SND_LED			; GO SET THE NUM LOCK INDICATOR
  2823                              <1> KX_BIT:
  2824 00000E64 800D[E4B70000]10    <1> 	or	byte [KB_FLAG_3], KBX	; INDICATE ENHANCED KEYBOARD WAS FOUND
  2825 00000E6B E9F4010000          <1> ID_EX:	jmp     K26			; EXIT
  2826                              <1> 	;
  2827                              <1> NOT_ID:
  2828 00000E70 3CE0                <1> 	cmp	al, MC_E0		; IS THIS THE GENERAL MARKER CODE?
  2829 00000E72 750C                <1> 	jne	short TEST_E1
  2830 00000E74 800D[E4B70000]12    <1> 	or	byte [KB_FLAG_3], LC_E0+KBX ; SET FLAG BIT, SET KBX, AND
  2831                              <1> 	;jmp	short EXIT		; THROW AWAY THIS CODE
  2832 00000E7B E9EB010000          <1> 	jmp	K26A	
  2833                              <1> TEST_E1:	
  2834 00000E80 3CE1                <1> 	cmp	al, MC_E1		; IS THIS THE PAUSE KEY?
  2835 00000E82 750C                <1> 	jne	short NOT_HC
  2836 00000E84 800D[E4B70000]11    <1> 	or	byte [KB_FLAG_3], LC_E1+KBX ; SET FLAG BIT, SET KBX, AND
  2837 00000E8B E9DB010000          <1> EXIT:	jmp	K26A			; THROW AWAY THIS CODE
  2838                              <1> 	;
  2839                              <1> NOT_HC:
  2840 00000E90 247F                <1> 	and	al, 07Fh		; TURN OFF THE BREAK BIT
  2841 00000E92 F6C702              <1> 	test	bh, LC_E0		; LAST CODE THE E0 MARKER CODE
  2842 00000E95 7414                <1> 	jz	short NOT_LC_E0		; JUMP IF NOT
  2843                              <1> 	;
  2844 00000E97 BF[CEB60000]        <1> 	mov	edi, _K6+6		; IS THIS A SHIFT KEY?
  2845 00000E9C AE                  <1> 	scasb
  2846 00000E9D 0F84C1010000        <1>         je      K26 ; K16B              ; YES, THROW AWAY & RESET FLAG
  2847 00000EA3 AE                  <1> 	scasb
  2848 00000EA4 757C                <1> 	jne	short K16A		; NO, CONTINUE KEY PROCESSING
  2849                              <1> 	;jmp	short K16B		; YES, THROW AWAY & RESET FLAG
  2850 00000EA6 E9B9010000          <1> 	jmp	K26
  2851                              <1> 	;
  2852                              <1> NOT_LC_E0:
  2853 00000EAB F6C701              <1> 	test	bh, LC_E1		; LAST CODE THE E1 MARKER CODE?
  2854 00000EAE 7435                <1> 	jz	short T_SYS_KEY		; JUMP IF NOT
  2855 00000EB0 B904000000          <1> 	mov	ecx, 4			; LENGHT OF SEARCH
  2856 00000EB5 BF[CCB60000]        <1> 	mov	edi, _K6+4		; IS THIS AN ALT, CTL, OR SHIFT?
  2857 00000EBA F2AE                <1> 	repne	scasb			; CHECK IT
  2858                              <1> 	;je	short EXIT		; THROW AWAY IF SO
  2859 00000EBC 0F84A9010000        <1> 	je	K26A			
  2860                              <1> 	;
  2861 00000EC2 3C45                <1> 	cmp	al, NUM_KEY		; IS IT THE PAUSE KEY?
  2862                              <1> 	;jne	short K16B		; NO, THROW AWAY & RESET FLAG
  2863 00000EC4 0F859A010000        <1> 	jne	K26
  2864 00000ECA F6C480              <1> 	test	ah, 80h			; YES, IS IT THE BREAK OF THE KEY?
  2865                              <1> 	;jnz	short K16B		; YES, THROW THIS AWAY, TOO	
  2866 00000ECD 0F8591010000        <1> 	jnz	K26
  2867                              <1>         ; 20/02/2015 
  2868 00000ED3 F605[E2B70000]08    <1> 	test	byte [KB_FLAG_1],HOLD_STATE ;  NO, ARE WE PAUSED ALREADY?
  2869                              <1> 	;jnz	short K16B		;  YES, THROW AWAY
  2870 00000EDA 0F8584010000        <1> 	jnz	K26
  2871 00000EE0 E9E1020000          <1> 	jmp     K39P                    ; NO, THIS IS THE REAL PAUSE STATE
  2872                              <1> 	;
  2873                              <1> 	;-----	TEST FOR SYSTEM KEY
  2874                              <1> T_SYS_KEY:
  2875 00000EE5 3C54                <1> 	cmp	al, SYS_KEY		; IS IT THE SYSTEM KEY?
  2876 00000EE7 7539                <1> 	jnz	short K16A		; CONTINUE IF NOT
  2877                              <1> 	;
  2878 00000EE9 F6C480              <1> 	test	ah, 80h			; CHECK IF THIS A BREAK CODE
  2879 00000EEC 7524                <1> 	jnz	short K16C		; DO NOT TOUCH SYSTEM INDICATOR IF TRUE
  2880                              <1> 	;
  2881 00000EEE F605[E2B70000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; SEE IF IN SYSTEM KEY HELD DOWN 
  2882                              <1>         ;jnz	short K16B		; IF YES, DO NOT PROCESS SYSTEM INDICATOR	
  2883 00000EF5 0F8569010000        <1> 	jnz     K26			
  2884                              <1> 	;
  2885 00000EFB 800D[E2B70000]04    <1> 	or	byte [KB_FLAG_1], SYS_SHIFT ; INDICATE SYSTEM KEY DEPRESSED
  2886 00000F02 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  2887 00000F04 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  2888                              <1> 					; INTERRUPT-RETURN-NO-EOI
  2889 00000F06 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  2890 00000F08 E862040000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  2891                              <1> 	; !!! SYSREQ !!! function/system call (INTERRUPT) must be here !!!
  2892                              <1> 	;MOV	AL, 8500H		; FUNCTION VALUE FOR MAKE OF SYSTEM KEY
  2893                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
  2894                              <1> 	;INT	15H			; USER INTERRUPT	
  2895 00000F0D E965010000          <1>         jmp     K27A                    ; END PROCESSING
  2896                              <1> 	;
  2897                              <1> ;K16B:	jmp	K26			; IGNORE SYSTEM KEY
  2898                              <1> 	;
  2899                              <1> K16C:
  2900 00000F12 8025[E2B70000]FB    <1> 	and	byte [KB_FLAG_1], ~SYS_SHIFT ; TURN OFF SHIFT KEY HELD DOWN
  2901 00000F19 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  2902 00000F1B E620                <1> 	out	20h, al ;out INTA00, al ; SEND COMMAND TO INTERRUPT CONTROL PORT
  2903                              <1> 					; INTERRUPT-RETURN-NO-EOI
  2904                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  2905                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
  2906                              <1> 	;
  2907                              <1> 	;MOV	AX, 8501H		; FUNCTION VALUE FOR BREAK OF SYSTEM KEY
  2908                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
  2909                              <1> 	;INT	15H			; USER INTERRUPT
  2910                              <1> 	;JMP	K27A			; INGONRE SYSTEM KEY				
  2911                              <1> 	;
  2912 00000F1D E94E010000          <1> 	jmp     K27			; IGNORE SYSTEM KEY
  2913                              <1> 	;
  2914                              <1> 	;-----	TEST FOR SHIFT KEYS
  2915                              <1> K16A:
  2916 00000F22 8A1D[E1B70000]      <1> 	mov	bl, [KB_FLAG]		; PUT STATE FLAGS IN BL
  2917 00000F28 BF[C8B60000]        <1> 	mov	edi, _K6		; SHIFT KEY TABLE offset
  2918 00000F2D B908000000          <1> 	mov	ecx, _K6L		; LENGTH
  2919 00000F32 F2AE                <1> 	repne	scasb			; LOOK THROUGH THE TABLE FOR A MATCH
  2920 00000F34 88E0                <1> 	mov	al, ah			; RECOVER SCAN CODE
  2921 00000F36 0F8510010000        <1>         jne     K25                     ; IF NO MATCH, THEN SHIFT NOT FOUND
  2922                              <1> 	;
  2923                              <1> 	;------	SHIFT KEY FOUND
  2924                              <1> K17:
  2925 00000F3C 81EF[C9B60000]      <1>         sub     edi, _K6+1              ; ADJUST PTR TO SCAN CODE MATCH
  2926 00000F42 8AA7[D0B60000]      <1>        	mov     ah, [edi+_K7]       	; GET MASK INTO AH
  2927 00000F48 B102                <1> 	mov	cl, 2			; SETUP COUNT FOR FLAG SHIFTS
  2928 00000F4A A880                <1> 	test	al, 80h			; TEST FOR BREAK KEY
  2929 00000F4C 0F8596000000        <1>         jnz     K23                     ; JUMP OF BREAK
  2930                              <1> 	;
  2931                              <1> 	;-----	SHIFT MAKE FOUND, DETERMINE SET OR TOGGLE
  2932                              <1> K17C:
  2933 00000F52 80FC10              <1> 	cmp	ah, SCROLL_SHIFT
  2934 00000F55 732B                <1> 	jae	short K18		; IF SCROLL SHIFT OR ABOVE, TOGGLE KEY
  2935                              <1> 	;
  2936                              <1> 	;-----	PLAIN SHIFT KEY, SET SHIFT ON
  2937 00000F57 0825[E1B70000]      <1> 	or	[KB_FLAG], ah		; TURN ON SHIFT BIT
  2938 00000F5D A80C                <1>         test	al, CTL_SHIFT+ALT_SHIFT ; IS IT ALT OR CTRL?
  2939                              <1> 	;jnz	short K17D		; YES, MORE FLAGS TO SET
  2940 00000F5F 0F84FF000000        <1> 	jz	K26			; NO, INTERRUPT RETURN
  2941                              <1> K17D:
  2942 00000F65 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF NEW KEYS?
  2943 00000F68 740B                <1> 	jz 	short K17E		; NO, JUMP
  2944 00000F6A 0825[E4B70000]      <1> 	or	[KB_FLAG_3], ah		; SET BITS FOR RIGHT CTRL, ALT
  2945 00000F70 E9EF000000          <1> 	jmp	K26			; INTERRUPT RETURN
  2946                              <1> K17E:
  2947 00000F75 D2EC                <1> 	shr	ah, cl			; MOVE FLAG BITS TWO POSITIONS
  2948 00000F77 0825[E2B70000]      <1> 	or	[KB_FLAG_1], ah		; SET BITS FOR LEFT CTRL, ALT
  2949 00000F7D E9E2000000          <1> 	jmp	K26
  2950                              <1> 	;
  2951                              <1> 	;-----	TOGGLED SHIFT KEY, TEST FOR 1ST MAKE OR NOT
  2952                              <1> K18:					; SHIFT-TOGGLE
  2953 00000F82 F6C304              <1> 	test	bl, CTL_SHIFT 		; CHECK CTL SHIFT STATE
  2954                              <1>         ;jz    	short K18A              ; JUMP IF NOT CTL STATE
  2955 00000F85 0F85C1000000        <1>         jnz     K25                     ; JUMP IF CTL STATE
  2956                              <1> K18A:
  2957 00000F8B 3C52                <1> 	cmp	al, INS_KEY		; CHECK FOR INSERT KEY
  2958 00000F8D 7524                <1> 	jne	short K22		; JUMP IF NOT INSERT KEY
  2959 00000F8F F6C308              <1> 	test	bl, ALT_SHIFT 		; CHECK FOR ALTERNATE SHIFT
  2960                              <1>       	;jz	short K18B		; JUMP IF NOT ALTERNATE SHIFT	
  2961 00000F92 0F85B4000000        <1>         jnz     K25                     ; JUMP IF ALTERNATE SHIFT
  2962                              <1> K18B:
  2963 00000F98 F6C702              <1> 	test	bh, LC_E0 ;20/02/2015	; IS THIS NEW INSERT KEY?
  2964 00000F9B 7516                <1> 	jnz	short K22		; YES, THIS ONE'S NEVER A '0'
  2965                              <1> K19:	
  2966 00000F9D F6C320              <1> 	test	bl, NUM_STATE 		; CHECK FOR BASE STATE
  2967 00000FA0 750C                <1> 	jnz	short K21		; JUMP IF NUM LOCK IS ON
  2968 00000FA2 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST FOR SHIFT STATE
  2969 00000FA5 740C                <1> 	jz	short K22		; JUMP IF BASE STATE
  2970                              <1> K20:					; NUMERIC ZERO, NOT INSERT KEY
  2971 00000FA7 88C4                <1> 	mov	ah, al			; PUT SCAN CODE BACK IN AH
  2972 00000FA9 E99E000000          <1>         jmp     K25                     ; NUMERAL '0', STNDRD. PROCESSING
  2973                              <1> K21:					; MIGHT BE NUMERIC
  2974 00000FAE F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT
  2975 00000FB1 74F4                <1> 	jz	short K20		; IS NUMERIC, STD. PROC.
  2976                              <1> 	;
  2977                              <1> K22:					; SHIFT TOGGLE KEY HIT; PROCESS IT
  2978 00000FB3 8425[E2B70000]      <1> 	test	ah, [KB_FLAG_1] 	; IS KEY ALREADY DEPRESSED
  2979 00000FB9 0F85A5000000        <1>         jnz     K26                     ; JUMP IF KEY ALREADY DEPRESSED
  2980                              <1> K22A:
  2981 00000FBF 0825[E2B70000]      <1>         or      [KB_FLAG_1], ah 	; INDICATE THAT THE KEY IS DEPRESSED
  2982 00000FC5 3025[E1B70000]      <1> 	xor	[KB_FLAG], ah		; TOGGLE THE SHIFT STATE
  2983                              <1> 	;
  2984                              <1> 	;-----	TOGGLE LED IF CAPS, NUM  OR SCROLL KEY DEPRESSED
  2985 00000FCB F6C470              <1> 	test	ah, CAPS_SHIFT+NUM_SHIFT+SCROLL_SHIFT ; SHIFT TOGGLE?
  2986 00000FCE 7409                <1> 	jz	short K22B		; GO IF NOT
  2987                              <1> 	;
  2988 00000FD0 6650                <1> 	push	ax			; SAVE SCAN CODE AND SHIFT MASK
  2989 00000FD2 E8F9030000          <1> 	call	SND_LED			; GO TURN MODE INDICATORS ON
  2990 00000FD7 6658                <1> 	pop	ax			; RESTORE SCAN CODE
  2991                              <1> K22B:
  2992 00000FD9 3C52                <1> 	cmp	al, INS_KEY		; TEST FOR 1ST MAKE OF INSERT KEY
  2993 00000FDB 0F8583000000        <1>         jne     K26                     ; JUMP IF NOT INSERT KEY
  2994 00000FE1 88C4                <1> 	mov	ah, al		        ; SCAN CODE IN BOTH HALVES OF AX
  2995 00000FE3 E999000000          <1>         jmp     K28                     ; FLAGS UPDATED, PROC. FOR BUFFER
  2996                              <1> 	;
  2997                              <1> 	;-----	BREAK SHIFT FOUND
  2998                              <1> K23:					; BREAK-SHIFT-FOUND
  2999 00000FE8 80FC10              <1> 	cmp	ah, SCROLL_SHIFT	; IS THIS A TOGGLE KEY
  3000 00000FEB F6D4                <1> 	not	ah			; INVERT MASK
  3001 00000FED 7355                <1> 	jae	short K24		; YES, HANDLE BREAK TOGGLE
  3002 00000FEF 2025[E1B70000]      <1> 	and	[KB_FLAG], ah		; TURN OFF SHIFT BIT
  3003 00000FF5 80FCFB              <1> 	cmp	ah, ~CTL_SHIFT		; IS THIS ALT OR CTL?
  3004 00000FF8 7730                <1> 	ja	short K23D		; NO, ALL DONE
  3005                              <1> 	;
  3006 00000FFA F6C702              <1> 	test	bh, LC_E0		; 2ND ALT OR CTL?
  3007 00000FFD 7408                <1> 	jz	short K23A		; NO, HANSLE NORMALLY
  3008 00000FFF 2025[E4B70000]      <1> 	and 	[KB_FLAG_3], ah		; RESET BIT FOR RIGHT ALT OR CTL
  3009 00001005 EB08                <1> 	jmp	short K23B		; CONTINUE
  3010                              <1> K23A:
  3011 00001007 D2FC                <1> 	sar	ah, cl			; MOVE THE MASK BIT TWO POSITIONS
  3012 00001009 2025[E2B70000]      <1> 	and	[KB_FLAG_1], ah		; RESET BIT FOR LEFT ALT AND CTL
  3013                              <1> K23B:
  3014 0000100F 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE
  3015 00001011 A0[E4B70000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT ALT & CTRL FLAGS
  3016 00001016 D2E8                <1> 	shr	al, cl			; MOVE TO BITS 1 & 0
  3017 00001018 0A05[E2B70000]      <1> 	or	al, [KB_FLAG_1]		; PUT IN LEFT ALT & CTL FLAGS
  3018 0000101E D2E0                <1> 	shl	al, cl			; MOVE BACK TO BITS 3 & 2
  3019 00001020 240C                <1> 	and	al, ALT_SHIFT+CTL_SHIFT ; FILTER OUT OTHER GARBAGE
  3020 00001022 0805[E1B70000]      <1> 	or	[KB_FLAG], al		; PUT RESULT IN THE REAL FLAGS	
  3021 00001028 88E0                <1> 	mov	al, ah
  3022                              <1> K23D:
  3023 0000102A 3CB8                <1> 	cmp	al, ALT_KEY+80h		; IS THIS ALTERNATE SHIFT RELEASE
  3024 0000102C 7536                <1> 	jne	short K26		; INTERRUPT RETURN
  3025                              <1> 	;	
  3026                              <1> 	;-----	ALTERNATE SHIFT KEY RELEASED, GET THE VALUE INTO BUFFER
  3027 0000102E A0[E5B70000]        <1> 	mov	al, [ALT_INPUT]
  3028 00001033 B400                <1> 	mov	ah, 0			; SCAN CODE OF 0
  3029 00001035 8825[E5B70000]      <1> 	mov	[ALT_INPUT], ah 	; ZERO OUT THE FIELD
  3030 0000103B 3C00                <1> 	cmp	al, 0			; WAS THE INPUT = 0?
  3031 0000103D 7425                <1> 	je	short K26		; INTERRUPT_RETURN
  3032                              <1>         ; 29/01/2016
  3033                              <1> 	;jmp     K61                    ; IT WASN'T, SO PUT IN BUFFER
  3034 0000103F E9D0020000          <1> 	jmp	_K60
  3035                              <1> 	;
  3036                              <1> K24:					; BREAK-TOGGLE
  3037 00001044 2025[E2B70000]      <1> 	and	[KB_FLAG_1], ah 	; INDICATE NO LONGER DEPRESSED
  3038 0000104A EB18                <1> 	jmp	short K26		; INTERRUPT_RETURN
  3039                              <1> 	;
  3040                              <1> 	;-----	TEST FOR HOLD STATE
  3041                              <1> 					; AL, AH = SCAN CODE
  3042                              <1> K25:					; NO-SHIFT-FOUND
  3043 0000104C 3C80                <1> 	cmp	al, 80h			; TEST FOR BREAK KEY
  3044 0000104E 7314                <1> 	jae	short K26		; NOTHING FOR BREAK CHARS FROM HERE ON
  3045 00001050 F605[E2B70000]08    <1> 	test	byte [KB_FLAG_1], HOLD_STATE ; ARE WE IN HOLD STATE
  3046 00001057 7428                <1> 	jz	short K28		; BRANCH AROUND TEST IF NOT
  3047 00001059 3C45                <1> 	cmp	al, NUM_KEY
  3048 0000105B 7407                <1> 	je	short K26		; CAN'T END HOLD ON NUM_LOCK
  3049 0000105D 8025[E2B70000]F7    <1> 	and	byte [KB_FLAG_1], ~HOLD_STATE ; TURN OFF THE HOLD STATE BIT
  3050                              <1> 	;
  3051                              <1> K26:
  3052 00001064 8025[E4B70000]FC    <1> 	and	byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
  3053                              <1> K26A:					; INTERRUPT-RETURN
  3054 0000106B FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3055 0000106C B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  3056 0000106E E620                <1> 	out	20h, al	;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  3057                              <1> K27:					; INTERRUPT-RETURN-NO-EOI
  3058 00001070 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  3059 00001072 E8F8020000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3060                              <1> K27A:
  3061 00001077 FA                  <1> 	cli				; DISABLE INTERRUPTS
  3062 00001078 07                  <1> 	pop	es			; RESTORE REGISTERS
  3063 00001079 1F                  <1> 	pop	ds
  3064 0000107A 5F                  <1> 	pop	edi
  3065 0000107B 5E                  <1> 	pop	esi
  3066 0000107C 5A                  <1> 	pop	edx
  3067 0000107D 59                  <1> 	pop	ecx
  3068 0000107E 5B                  <1> 	pop	ebx
  3069 0000107F 58                  <1> 	pop	eax
  3070                              <1> 	;pop	ebp
  3071 00001080 CF                  <1> 	iret				; RETURN
  3072                              <1> 
  3073                              <1> 	;-----	NOT IN	HOLD STATE
  3074                              <1> K28:					; NO-HOLD-STATE
  3075 00001081 3C58                <1> 	cmp	al, 88			; TEST FOR OUT-OF-RANGE SCAN CODES
  3076 00001083 77DF                <1> 	ja	short K26		; IGNORE IF OUT-OF-RANGE	
  3077                              <1> 	;
  3078 00001085 F6C308              <1> 	test	bl, ALT_SHIFT 		; ARE WE IN ALTERNATE SHIFT
  3079                              <1>         ;jz	short K28A		; IF NOT ALTERNATE
  3080 00001088 0F84F1000000        <1>         jz      K38
  3081                              <1> 	;
  3082 0000108E F6C710              <1> 	test	bh, KBX			; IS THIS THE ENCHANCED KEYBOARD?
  3083 00001091 740D                <1> 	jz	short K29		; NO, ALT STATE IS REAL
  3084                              <1> 	 ;28/02/2015
  3085 00001093 F605[E2B70000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; YES, IS SYSREQ KEY DOWN?
  3086                              <1> 	;jz	short K29		;  NO, ALT STATE IS REAL
  3087 0000109A 0F85DF000000        <1> 	jnz	K38			; YES, THIS IS PHONY ALT STATE 
  3088                              <1>         ;				; DUE TO PRESSING SYSREQ	
  3089                              <1> ;K28A:	jmp	short K38
  3090                              <1> 	;
  3091                              <1> 	;-----	TEST FOR RESET KEY SEQUENCE (CTL ALT DEL)
  3092                              <1> K29:					; TEST-RESET
  3093 000010A0 F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT ALSO?
  3094 000010A3 740B                <1> 	jz	short K31		; NO_RESET
  3095 000010A5 3C53                <1> 	cmp	al, DEL_KEY		; CTL-ALT STATE, TEST FOR DELETE KEY
  3096 000010A7 7507                <1> 	jne	short K31		; NO_RESET, IGNORE
  3097                              <1> 	;
  3098                              <1> 	;-----	CTL-ALT-DEL HAS BEEN FOUND
  3099                              <1>  	; 26/08/2014
  3100                              <1> cpu_reset:
  3101                              <1> 	; IBM PC/AT ROM BIOS source code - 10/06/85 (TEST4.ASM - PROC_SHUTDOWN)
  3102                              <1> 	; Send FEh (system reset command) to the keyboard controller.
  3103 000010A9 B0FE                <1> 	mov	al, SHUT_CMD		; SHUTDOWN COMMAND
  3104 000010AB E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROL PORT
  3105                              <1> khere:
  3106 000010AD F4                  <1> 	hlt				; WAIT FOR 80286 RESET
  3107 000010AE EBFD                <1> 	jmp 	short khere		; INSURE HALT
  3108                              <1> 
  3109                              <1> 	;
  3110                              <1> 	;-----	IN ALTERNATE SHIFT, RESET NOT FOUND
  3111                              <1> K31:					; NO-RESET
  3112 000010B0 3C39                <1> 	cmp	al, 57			; TEST FOR SPACE KEY
  3113 000010B2 7507                <1> 	jne	short K311		; NOT THERE
  3114 000010B4 B020                <1> 	mov	al, ' '			; SET SPACE CHAR
  3115 000010B6 E948020000          <1>         jmp     K57                     ; BUFFER_FILL
  3116                              <1> K311:
  3117 000010BB 3C0F                <1> 	cmp	al, 15			; TEST FOR TAB KEY
  3118 000010BD 7509                <1> 	jne	short K312		; NOT THERE
  3119 000010BF 66B800A5            <1> 	mov	ax, 0A500h		; SET SPECIAL CODE FOR ALT-TAB
  3120 000010C3 E93B020000          <1>         jmp     K57                     ; BUFFER_FILL
  3121                              <1> K312:
  3122 000010C8 3C4A                <1> 	cmp	al, 74			; TEST FOR KEY PAD -
  3123 000010CA 0F84A2000000        <1>         je      K37B                    ; GO PROCESS
  3124 000010D0 3C4E                <1> 	cmp	al, 78			; TEST FOR KEY PAD +
  3125 000010D2 0F849A000000        <1>         je      K37B                    ; GO PROCESS
  3126                              <1> 	;
  3127                              <1> 	;-----	LOOK FOR KEY PAD ENTRY
  3128                              <1> K32:					; ALT-KEY-PAD
  3129 000010D8 BF[A4B60000]        <1> 	mov	edi, K30		; ALT-INPUT-TABLE offset
  3130 000010DD B90A000000          <1> 	mov	ecx, 10			; LOOK FOR ENTRY USING KEYPAD
  3131 000010E2 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH
  3132 000010E4 7525                <1> 	jne	short K33		; NO_ALT_KEYPAD
  3133 000010E6 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF THE NEW KEYS?
  3134 000010E9 0F858A000000        <1>         jnz     K37C                    ; YES, JUMP, NOT NUMPAD KEY
  3135 000010EF 81EF[A5B60000]      <1> 	sub	edi, K30+1		; DI NOW HAS ENTRY VALUE
  3136 000010F5 A0[E5B70000]        <1> 	mov	al, [ALT_INPUT] 	; GET THE CURRENT BYTE
  3137 000010FA B40A                <1> 	mov	ah, 10			; MULTIPLY BY 10
  3138 000010FC F6E4                <1> 	mul	ah
  3139 000010FE 6601F8              <1> 	add	ax, di			; ADD IN THE LATEST ENTRY
  3140 00001101 A2[E5B70000]        <1> 	mov	[ALT_INPUT], al 	; STORE IT AWAY
  3141                              <1> ;K32A:
  3142 00001106 E959FFFFFF          <1>         jmp     K26                     ; THROW AWAY THAT KEYSTROKE
  3143                              <1> 	;
  3144                              <1> 	;-----	LOOK FOR SUPERSHIFT ENTRY
  3145                              <1> K33:					; NO-ALT-KEYPAD
  3146 0000110B C605[E5B70000]00    <1>         mov     byte [ALT_INPUT], 0     ; ZERO ANY PREVIOUS ENTRY INTO INPUT
  3147 00001112 B91A000000          <1> 	mov	ecx, 26			; (DI),(ES) ALREADY POINTING
  3148 00001117 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH IN ALPHABET
  3149 00001119 7450                <1> 	je	short K37A		; MATCH FOUND, GO FILLL THE BUFFER
  3150                              <1> 	;
  3151                              <1> 	;-----	LOOK FOR TOP ROW OF ALTERNATE SHIFT
  3152                              <1> K34:					; ALT-TOP-ROW
  3153 0000111B 3C02                <1> 	cmp	al, 2			; KEY WITH '1' ON IT
  3154 0000111D 7253                <1> 	jb	short K37B		; MUST BE ESCAPE
  3155 0000111F 3C0D                <1> 	cmp	al, 13			; IS IT IN THE REGION
  3156 00001121 7705                <1> 	ja	short K35		; NO, ALT SOMETHING ELSE
  3157 00001123 80C476              <1> 	add	ah, 118			; CONVERT PSEUDO SCAN CODE TO RANGE
  3158 00001126 EB43                <1> 	jmp	short K37A		; GO FILL THE BUFFER
  3159                              <1> 	;
  3160                              <1> 	;-----	TRANSLATE ALTERNATE SHIFT PSEUDO SCAN CODES
  3161                              <1> K35:					; ALT-FUNCTION
  3162 00001128 3C57                <1> 	cmp	al, F11_M		; IS IT F11?	
  3163 0000112A 7209                <1> 	jb	short K35A ; 20/02/2015	; NO, BRANCH
  3164 0000112C 3C58                <1> 	cmp	al, F12_M		; IS IT F12?
  3165 0000112E 7705                <1> 	ja	short K35A ; 20/02/2015	; NO, BRANCH
  3166 00001130 80C434              <1> 	add	ah, 52			; CONVERT TO PSEUDO SCAN CODE
  3167 00001133 EB36                <1> 	jmp	short K37A		; GO FILL THE BUFFER
  3168                              <1> K35A:
  3169 00001135 F6C702              <1> 	test	bh, LC_E0		; DO WE HAVE ONE OF THE NEW KEYS?
  3170 00001138 7422                <1> 	jz	short K37		; NO, JUMP
  3171 0000113A 3C1C                <1> 	cmp	al, 28			; TEST FOR KEYPAD ENTER
  3172 0000113C 7509                <1>         jne     short K35B              ; NOT THERE
  3173 0000113E 66B800A6            <1> 	mov	ax, 0A600h		; SPECIAL CODE
  3174 00001142 E9BC010000          <1> 	jmp	K57			; BUFFER FILL
  3175                              <1> K35B:
  3176 00001147 3C53                <1> 	cmp	al, 83			; TEST FOR DELETE KEY
  3177 00001149 742E                <1> 	je	short K37C		; HANDLE WITH OTHER EDIT KEYS
  3178 0000114B 3C35                <1> 	cmp	al, 53			; TEST FOR KEYPAD /
  3179                              <1> 	;jne	short K32A		; NOT THERE, NO OTHER E0 SPECIALS	
  3180 0000114D 0F8511FFFFFF        <1>         jne     K26
  3181 00001153 66B800A4            <1> 	mov	ax, 0A400h		; SPECIAL CODE
  3182 00001157 E9A7010000          <1> 	jmp	K57			; BUFFER FILL
  3183                              <1> K37:
  3184 0000115C 3C3B                <1> 	cmp	al, 59			; TEST FOR FUNCTION KEYS (F1)
  3185 0000115E 7212                <1>         jb      short K37B		; NO FN, HANDLE W/OTHER EXTENDED
  3186 00001160 3C44                <1> 	cmp	al, 68			; IN KEYPAD REGION?
  3187                              <1>         ;ja	short K32A		; IF SO, IGNORE
  3188 00001162 0F87FCFEFFFF        <1>         ja      K26
  3189 00001168 80C42D              <1> 	add	ah, 45			; CONVERT TO PSEUDO SCAN CODE
  3190                              <1> K37A:
  3191 0000116B B000                <1> 	mov	al, 0			; ASCII CODE OF ZERO
  3192 0000116D E991010000          <1>         jmp     K57                     ; PUT IT IN THE BUFFER
  3193                              <1> K37B:
  3194 00001172 B0F0                <1> 	mov	al, 0F0h		; USE SPECIAL ASCII CODE
  3195 00001174 E98A010000          <1> 	jmp     K57                     ; PUT IT IN THE BUFFER
  3196                              <1> K37C:
  3197 00001179 0450                <1> 	add	al, 80			; CONVERT SCAN CODE (EDIT KEYS)
  3198 0000117B 88C4                <1> 	mov	ah, al			; (SCAN CODE NOT IN AH FOR INSERT)
  3199 0000117D EBEC                <1> 	jmp     short K37A              ; PUT IT IN THE BUFFER
  3200                              <1> 	;
  3201                              <1> 	;-----	NOT IN ALTERNATE SHIFT
  3202                              <1> K38:					; NOT-ALT-SHIFT
  3203                              <1> 					; BL STILL HAS SHIFT FLAGS
  3204 0000117F F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT?
  3205                              <1> 	;jnz	short K38A		; YES, START PROCESSING	
  3206 00001182 0F84B0000000        <1>         jz      K44                     ; NOT-CTL-SHIFT
  3207                              <1> 	;
  3208                              <1> 	;-----	CONTROL SHIFT, TEST SPECIAL CHARACTERS
  3209                              <1> 	;-----	TEST FOR BREAK
  3210                              <1> K38A:
  3211 00001188 3C46                <1> 	cmp	al, SCROLL_KEY		; TEST FOR BREAK
  3212 0000118A 7531                <1> 	jne	short K39		; JUMP, NO-BREAK
  3213 0000118C F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  3214 0000118F 7405                <1> 	jz	short K38B		; NO, BREAK IS VALID	
  3215 00001191 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  3216 00001194 7427                <1> 	jz	short K39		; NO-BREAK, TEST FOR PAUSE	
  3217                              <1> K38B:
  3218 00001196 8B1D[EEB70000]      <1> 	mov	ebx, [BUFFER_HEAD] 	; RESET BUFFER TO EMPTY
  3219 0000119C 891D[F2B70000]      <1> 	mov	[BUFFER_TAIL], ebx
  3220 000011A2 C605[E0B70000]80    <1> 	mov	byte [BIOS_BREAK], 80h  ; TURN ON BIOS_BREAK BIT
  3221                              <1> 	;
  3222                              <1> 	;-----	ENABLE KEYBOARD
  3223 000011A9 B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  3224 000011AB E8BF010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3225                              <1> 	;
  3226                              <1> 	; CTRL+BREAK code here !!!
  3227                              <1> 	;INT	1BH			; BREAK INTERRUPT VECTOR
  3228                              <1> 	; 17/10/2015	
  3229 000011B0 E84E2D0000          <1> 	call	ctrlbrk ; control+break subroutine
  3230                              <1> 	;
  3231 000011B5 6629C0              <1> 	sub	ax, ax			; PUT OUT DUMMY CHARACTER
  3232 000011B8 E946010000          <1>         jmp     K57                     ; BUFFER_FILL
  3233                              <1> 	;
  3234                              <1> 	;-----	TEST FOR PAUSE
  3235                              <1> K39:					; NO_BREAK
  3236 000011BD F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  3237 000011C0 7537                <1> 	jnz	short K41		; YES, THEN THIS CAN'T BE PAUSE	
  3238 000011C2 3C45                <1> 	cmp	al, NUM_KEY		; LOOK FOR PAUSE KEY
  3239 000011C4 7533                <1> 	jne	short K41		; NO-PAUSE
  3240                              <1> K39P:
  3241 000011C6 800D[E2B70000]08    <1> 	or	byte [KB_FLAG_1], HOLD_STATE ; TURN ON THE HOLD FLAG
  3242                              <1> 	;
  3243                              <1> 	;-----	ENABLE KEYBOARD
  3244 000011CD B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  3245 000011CF E89B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3246                              <1> K39A:
  3247 000011D4 B020                <1> 	mov	al, EOI			; END OF INTERRUPT TO CONTROL PORT
  3248 000011D6 E620                <1> 	out	20h, al ;out INTA00, al	; ALLOW FURTHER KEYSTROKE INTERRUPTS
  3249                              <1> 	;
  3250                              <1> 	;-----	DURING PAUSE INTERVAL, TURN COLOR CRT BACK ON
  3251 000011D8 803D[16B80000]07    <1>         cmp     byte [CRT_MODE], 7      ; IS THIS BLACK AND WHITE CARD
  3252 000011DF 740A                <1>         je      short K40              	; YES, NOTHING TO DO
  3253 000011E1 66BAD803            <1> 	mov	dx, 03D8h		; PORT FOR COLOR CARD
  3254 000011E5 A0[17B80000]        <1>         mov     al, [CRT_MODE_SET] 	; GET THE VALUE OF THE CURRENT MODE
  3255 000011EA EE                  <1> 	out	dx, al			; SET THE CRT MODE, SO THAT CRT IS ON
  3256                              <1> 	;
  3257                              <1> K40:					; PAUSE-LOOP
  3258 000011EB F605[E2B70000]08    <1>         test    byte [KB_FLAG_1], HOLD_STATE ; CHECK HOLD STATE FLAG
  3259 000011F2 75F7                <1> 	jnz	short K40		; LOOP UNTIL FLAG TURNED OFF
  3260                              <1> 	;
  3261 000011F4 E977FEFFFF          <1>         jmp     K27                     ; INTERRUPT_RETURN_NO_EOI
  3262                              <1>         ;
  3263                              <1> 	;-----	TEST SPECIAL CASE KEY 55
  3264                              <1> K41:					; NO-PAUSE
  3265 000011F9 3C37                <1> 	cmp	al, 55			; TEST FOR */PRTSC KEY
  3266 000011FB 7513                <1> 	jne	short K42		; NOT-KEY-55
  3267 000011FD F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  3268 00001200 7405                <1> 	jz	short K41A		; NO, CTL-PRTSC IS VALID	
  3269 00001202 F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  3270 00001205 7421                <1> 	jz	short K42B		; NO, TRANSLATE TO A FUNCTION
  3271                              <1> K41A:	
  3272 00001207 66B80072            <1> 	mov	ax, 114*256		; START/STOP PRINTING SWITCH
  3273 0000120B E9F3000000          <1>         jmp     K57                     ; BUFFER_FILL
  3274                              <1> 	;
  3275                              <1> 	;-----	SET UP TO TRANSLATE CONTROL SHIFT
  3276                              <1> K42:					; NOT-KEY-55
  3277 00001210 3C0F                <1> 	cmp	al, 15			; IS IT THE TAB KEY?
  3278 00001212 7414                <1> 	je	short K42B		; YES, XLATE TO FUNCTION CODE
  3279 00001214 3C35                <1> 	cmp	al, 53			; IS IT THE / KEY?
  3280 00001216 750E                <1> 	jne	short K42A		; NO, NO MORE SPECIAL CASES	
  3281 00001218 F6C702              <1> 	test	bh, LC_E0		; YES, IS IT FROM THE KEY PAD?
  3282 0000121B 7409                <1> 	jz	short K42A		; NO, JUST TRANSLATE
  3283 0000121D 66B80095            <1> 	mov	ax, 9500h		; YES, SPECIAL CODE FOR THIS ONE
  3284 00001221 E9DD000000          <1> 	jmp	K57			; BUFFER FILL	
  3285                              <1> K42A: 
  3286                              <1> 	;;mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  3287 00001226 3C3B                <1> 	cmp	al, 59			; IS IT IN CHARACTER TABLE?
  3288                              <1>         ;jb	short K45F              ; YES, GO TRANSLATE CHAR
  3289                              <1> 	;;jb	K56 ; 20/02/2015
  3290                              <1> 	;;jmp	K64 ; 20/02/2015
  3291                              <1> K42B:
  3292 00001228 BB[D8B60000]        <1> 	mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  3293 0000122D 0F82AE000000        <1> 	jb	K56 ;; 20/02/2015	
  3294 00001233 E9B9000000          <1> 	jmp	K64	
  3295                              <1>         ;
  3296                              <1> 	;-----	NOT IN CONTROL SHIFT
  3297                              <1> K44:					; NOT-CTL-SHIFT
  3298 00001238 3C37                <1> 	cmp	al, 55			; PRINT SCREEN KEY?
  3299 0000123A 7528                <1> 	jne	short K45		; NOT PRINT SCREEN
  3300 0000123C F6C710              <1> 	test	bh, KBX			; IS THIS ENHANCED KEYBOARD?
  3301 0000123F 7407                <1> 	jz	short K44A		; NO, TEST FOR SHIFT STATE	
  3302 00001241 F6C702              <1> 	test	bh, LC_E0		; YES, LAST CODE A MARKER?
  3303 00001244 7507                <1> 	jnz	short K44B		; YES, IS PRINT SCREEN
  3304 00001246 EB41                <1> 	jmp	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  3305                              <1> K44A:
  3306 00001248 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; NOT 101 KBD, SHIFT KEY DOWN?
  3307 0000124B 743C                <1> 	jz	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  3308                              <1> 	;
  3309                              <1> 	;-----	ISSUE INTERRUPT TO INDICATE PRINT SCREEN FUNCTION
  3310                              <1> K44B:
  3311 0000124D B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  3312 0000124F E81B010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  3313 00001254 B020                <1> 	mov	al, EOI			; END OF CURRENT INTERRUPT
  3314 00001256 E620                <1> 	out	20h, al ;out INTA00, al	; SO FURTHER THINGS CAN HAPPEN
  3315                              <1> 	; Print Screen !!!		; ISSUE PRINT SCREEN INTERRUPT (INT 05h)
  3316                              <1> 	;PUSH 	BP			; SAVE POINTER
  3317                              <1> 	;INT 	5H			; ISSUE PRINT SCREEN INTERRUPT
  3318                              <1> 	;POP	BP			; RESTORE POINTER
  3319 00001258 8025[E4B70000]FC    <1>         and     byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; ZERO OUT THESE FLAGS
  3320 0000125F E90CFEFFFF          <1>         jmp     K27                     ; GO BACK WITHOUT EOI OCCURRING
  3321                              <1> 	;
  3322                              <1> 	;-----	HANDLE IN-CORE KEYS
  3323                              <1> K45:					; NOT-PRINT-SCREEN
  3324 00001264 3C3A                <1> 	cmp	al, 58			; TEST FOR IN-CORE AREA
  3325 00001266 7734                <1> 	ja	short K46		; JUMP IF NOT
  3326 00001268 3C35                <1> 	cmp	al, 53			; IS THIS THE '/' KEY?
  3327 0000126A 7505                <1> 	jne	short K45A		; NO, JUMP
  3328 0000126C F6C702              <1> 	test	bh, LC_E0		; WAS THE LAST CODE THE MARKER?
  3329 0000126F 7518                <1> 	jnz	short K45C		; YES, TRANSLATE TO CHARACTER
  3330                              <1> K45A:
  3331 00001271 B91A000000          <1> 	mov	ecx, 26			; LENGHT OF SEARCH
  3332 00001276 BF[AEB60000]        <1> 	mov	edi, K30+10		; POINT TO TABLE OF A-Z CHARS
  3333 0000127B F2AE                <1> 	repne	scasb			; IS THIS A LETTER KEY?
  3334                              <1> 		; 20/02/2015
  3335 0000127D 7505                <1> 	jne	short K45B              ; NO, SYMBOL KEY
  3336                              <1> 	;
  3337 0000127F F6C340              <1> 	test	bl, CAPS_STATE		; ARE WE IN CAPS_LOCK?
  3338 00001282 750C                <1> 	jnz	short K45D		; TEST FOR SURE
  3339                              <1> K45B:
  3340 00001284 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  3341 00001287 750C                <1> 	jnz	short K45E		; YES, UPPERCASE
  3342                              <1> 					; NO, LOWERCASE
  3343                              <1> K45C:
  3344 00001289 BB[30B70000]        <1> 	mov	ebx, K10		; TRANSLATE TO LOWERCASE LETTERS
  3345 0000128E EB51                <1> 	jmp	short K56	
  3346                              <1> K45D:					; ALMOST-CAPS-STATE
  3347 00001290 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; CL ON. IS SHIFT ON, TOO?
  3348 00001293 75F4                <1> 	jnz	short K45C		; SHIFTED TEMP OUT OF CAPS STATE
  3349                              <1> K45E:
  3350 00001295 BB[88B70000]        <1> 	mov	ebx, K11		; TRANSLATE TO UPPER CASE LETTERS
  3351 0000129A EB45                <1> K45F:	jmp	short K56
  3352                              <1> 	;
  3353                              <1> 	;-----	TEST FOR KEYS F1 - F10
  3354                              <1> K46:					; NOT IN-CORE AREA
  3355 0000129C 3C44                <1> 	cmp	al, 68			; TEST FOR F1 - F10
  3356                              <1> 	;ja	short K47		; JUMP IF NOT
  3357                              <1> 	;jmp	short K53		; YES, GO DO FN KEY PROCESS			
  3358 0000129E 7635                <1> 	jna	short K53		
  3359                              <1> 	;
  3360                              <1> 	;-----	HANDLE THE NUMERIC PAD KEYS
  3361                              <1> K47:					; NOT F1 - F10
  3362 000012A0 3C53                <1> 	cmp	al, 83			; TEST NUMPAD KEYS
  3363 000012A2 772D                <1> 	ja	short K52		; JUMP IF NOT
  3364                              <1> 	;
  3365                              <1> 	;-----	KEYPAD KEYS, MUST TEST NUM LOCK FOR DETERMINATION
  3366                              <1> K48:
  3367 000012A4 3C4A                <1> 	cmp	al , 74			; SPECIAL CASE FOR MINUS
  3368 000012A6 74ED                <1> 	je	short K45E		; GO TRANSLATE
  3369 000012A8 3C4E                <1> 	cmp	al , 78			; SPECIAL CASE FOR PLUS
  3370 000012AA 74E9                <1> 	je	short K45E		; GO TRANSLATE
  3371 000012AC F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OFTHE NEW KEYS?
  3372 000012AF 750A                <1> 	jnz	short K49		; YES, TRANSLATE TO BASE STATE
  3373                              <1> 	;		
  3374 000012B1 F6C320              <1> 	test 	bl, NUM_STATE		; ARE WE IN NUM LOCK
  3375 000012B4 7514                <1> 	jnz	short K50		; TEST FOR SURE
  3376 000012B6 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  3377                              <1> 	;jnz	short K51		; IF SHIFTED, REALLY NUM STATE
  3378 000012B9 75DA                <1> 	jnz	short K45E
  3379                              <1> 	;
  3380                              <1> 	;-----	BASE CASE FOR KEYPAD
  3381                              <1> K49:					
  3382 000012BB 3C4C                <1> 	cmp	al, 76			; SPECIAL CASE FOR BASE STATE 5
  3383 000012BD 7504                <1> 	jne	short K49A		; CONTINUE IF NOT KEYPAD 5
  3384 000012BF B0F0                <1> 	mov	al, 0F0h		; SPECIAL ASCII CODE	
  3385 000012C1 EB40                <1> 	jmp	short K57		; BUFFER FILL
  3386                              <1> K49A:
  3387 000012C3 BB[30B70000]        <1> 	mov	ebx, K10		; BASE CASE TABLE	
  3388 000012C8 EB27                <1> 	jmp	short K64		; CONVERT TO PSEUDO SCAN
  3389                              <1> 	;
  3390                              <1> 	;-----	MIGHT BE NUM LOCK, TEST SHIFT STATUS
  3391                              <1> K50:					; ALMOST-NUM-STATE
  3392 000012CA F6C303              <1>         test    bl, LEFT_SHIFT+RIGHT_SHIFT
  3393 000012CD 75EC                <1> 	jnz 	short K49		; SHIFTED TEMP OUT OF NUM STATE
  3394 000012CF EBC4                <1> K51:	jmp	short K45E		; REALLY NUM STATE
  3395                              <1> 	;
  3396                              <1> 	;-----	TEST FOR THE NEW KEYS ON WT KEYBOARDS 
  3397                              <1> K52:					; NOT A NUMPAD KEY
  3398 000012D1 3C56                <1> 	cmp	al, 86			; IS IT THE NEW WT KEY?
  3399                              <1> 	;jne	short K53		; JUMP IF NOT
  3400                              <1> 	;jmp	short K45B		; HANDLE WITH REST OF LETTER KEYS
  3401 000012D3 74AF                <1> 	je	short K45B		
  3402                              <1> 	;
  3403                              <1> 	;-----	MUST BE F11 OR F12 
  3404                              <1> K53:					; F1 - F10 COME HERE, TOO
  3405 000012D5 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST SHIFT STATE
  3406 000012D8 74E1                <1> 	jz	short K49		; JUMP, LOWER CASE PSEUDO SC'S
  3407                              <1> 		; 20/02/2015 
  3408 000012DA BB[88B70000]        <1> 	mov	ebx, K11		; UPPER CASE PSEUDO SCAN CODES
  3409 000012DF EB10                <1> 	jmp	short K64		; TRANSLATE SCAN
  3410                              <1> 	;
  3411                              <1> 	;-----	TRANSLATE THE CHARACTER
  3412                              <1> K56:					; TRANSLATE-CHAR
  3413 000012E1 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  3414 000012E3 D7                  <1> 	xlat    			; CONVERT THE SCAN CODE TO ASCII
  3415 000012E4 F605[E4B70000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  3416 000012EB 7416                <1> 	jz	short K57		; NO, GO FILL BUFFER
  3417 000012ED B4E0                <1> 	mov	ah, MC_E0		; YES, PUT SPECIAL MARKER IN AH
  3418 000012EF EB12                <1> 	jmp	short K57		; PUT IT INTO THE BUFFER	
  3419                              <1> 	;
  3420                              <1> 	;-----	TRANSLATE SCAN FOR PSEUDO SCAN CODES
  3421                              <1> K64:					; TRANSLATE-SCAN-ORGD
  3422 000012F1 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  3423 000012F3 D7                  <1>        	xlat    	                ; CTL TABLE SCAN
  3424 000012F4 88C4                <1> 	mov	ah, al			; PUT VALUE INTO AH
  3425 000012F6 B000                <1> 	mov	al, 0			; ZERO ASCII CODE
  3426 000012F8 F605[E4B70000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  3427 000012FF 7402                <1> 	jz	short K57		; NO, GO FILL BUFFER
  3428 00001301 B0E0                <1> 	mov	al, MC_E0		; YES, PUT SPECIAL MARKER IN AL
  3429                              <1> 	;
  3430                              <1> 	;-----	PUT CHARACTER INTO BUFFER
  3431                              <1> K57:					; BUFFER_FILL
  3432 00001303 3CFF                <1> 	cmp	al, -1			; IS THIS AN IGNORE CHAR
  3433                              <1>         ;je	short K59		; YES, DO NOTHING WITH IT
  3434 00001305 0F8459FDFFFF        <1> 	je      K26			; YES, DO NOTHING WITH IT
  3435 0000130B 80FCFF              <1> 	cmp	ah, -1			; LOOK FOR -1 PSEUDO SCAN
  3436                              <1>         ;jne	short K61		; NEAR_INTERRUPT_RETURN
  3437 0000130E 0F8450FDFFFF        <1> 	je      K26			; INTERRUPT_RETURN
  3438                              <1> ;K59:					; NEAR_INTERRUPT_RETURN
  3439                              <1> ;	jmp	K26			; INTERRUPT_RETURN
  3440                              <1> 
  3441                              <1> _K60: ; 29/01/2016
  3442 00001314 80FC68              <1> 	cmp	ah, 68h	; ALT + F1 key
  3443 00001317 721F                <1> 	jb	short K61
  3444 00001319 80FC6F              <1> 	cmp	ah, 6Fh ; ALT + F8 key	
  3445 0000131C 771A                <1> 	ja	short K61
  3446                              <1> 	;
  3447 0000131E 8A1D[18BE0000]      <1> 	mov	bl, [ACTIVE_PAGE]
  3448 00001324 80C368              <1> 	add	bl, 68h
  3449 00001327 38E3                <1> 	cmp	bl, ah
  3450 00001329 740D                <1> 	je	short K61
  3451 0000132B 6650                <1> 	push	ax
  3452 0000132D 88E0                <1> 	mov	al, ah
  3453 0000132F 2C68                <1> 	sub	al, 68h
  3454 00001331 E85E020000          <1> 	call	set_active_page
  3455 00001336 6658                <1> 	pop	ax
  3456                              <1> K61:					; NOT-CAPS-STATE
  3457 00001338 8B1D[F2B70000]      <1> 	mov	ebx, [BUFFER_TAIL] 	; GET THE END POINTER TO THE BUFFER
  3458 0000133E 89DE                <1> 	mov	esi, ebx		; SAVE THE VALUE
  3459 00001340 E857FAFFFF          <1> 	call	_K4			; ADVANCE THE TAIL
  3460 00001345 3B1D[EEB70000]      <1> 	cmp	ebx, [BUFFER_HEAD] 	; HAS THE BUFFER WRAPPED AROUND
  3461 0000134B 740E                <1> 	je	short K62		; BUFFER_FULL_BEEP
  3462 0000134D 668906              <1> 	mov	[esi], ax		; STORE THE VALUE
  3463 00001350 891D[F2B70000]      <1> 	mov	[BUFFER_TAIL], ebx 	; MOVE THE POINTER UP
  3464 00001356 E909FDFFFF          <1> 	jmp	K26
  3465                              <1> 	;;cli				; TURN OFF INTERRUPTS
  3466                              <1> 	;;mov	al, EOI			; END OF INTERRUPT COMMAND
  3467                              <1> 	;;out	INTA00, al		; SEND COMMAND TO INTERRUPT CONTROL PORT
  3468                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  3469                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
  3470                              <1> 	;MOV	AX, 9102H		; MOVE IN POST CODE & TYPE
  3471                              <1> 	;INT	15H			; PERFORM OTHER FUNCTION
  3472                              <1> 	;;and	byte [KB_FLAG_3],~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
  3473                              <1> 	;JMP	K27A			; INTERRUPT_RETURN
  3474                              <1> 	;;jmp   K27                    
  3475                              <1> 	;
  3476                              <1> 	;-----	BUFFER IS FULL SOUND THE BEEPER
  3477                              <1> K62:
  3478 0000135B B020                <1> 	mov	al, EOI			; ENABLE INTERRUPT CONTROLLER CHIP
  3479 0000135D E620                <1> 	out	INTA00, al
  3480 0000135F 66B9A602            <1> 	mov	cx, 678			; DIVISOR FOR 1760 HZ
  3481 00001363 B304                <1> 	mov	bl, 4			; SHORT BEEP COUNT (1/16 + 1/64 DELAY)
  3482 00001365 E83A050000          <1> 	call	beep			; GO TO COMMON BEEP HANDLER
  3483 0000136A E901FDFFFF          <1> 	jmp     K27			; EXIT   
  3484                              <1> 
  3485                              <1> SHIP_IT:
  3486                              <1> 	;---------------------------------------------------------------------------------
  3487                              <1> 	; SHIP_IT
  3488                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  3489                              <1> 	;	TO THE KEYBOARD CONTROLLER.
  3490                              <1> 	;---------------------------------------------------------------------------------
  3491                              <1> 	;
  3492 0000136F 6650                <1> 	push	ax			; SAVE DATA TO SEND
  3493                              <1> 
  3494                              <1> 	;-----	WAIT FOR COMMAND TO ACCEPTED
  3495 00001371 FA                  <1> 	cli				; DISABLE INTERRUPTS TILL DATA SENT
  3496                              <1> 	; xor	ecx, ecx		; CLEAR TIMEOUT COUNTER
  3497 00001372 B900000100          <1> 	mov	ecx, 10000h			
  3498                              <1> S10:
  3499 00001377 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD CONTROLLER STATUS
  3500 00001379 A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ITS INPUT BUFFER BUSY
  3501 0000137B E0FA                <1> 	loopnz	S10			; WAIT FOR COMMAND TO BE ACCEPTED
  3502                              <1> 
  3503 0000137D 6658                <1> 	pop	ax			; GET DATA TO SEND
  3504 0000137F E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROLLER
  3505 00001381 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  3506 00001382 C3                  <1> 	retn				; RETURN TO CALLER
  3507                              <1> 
  3508                              <1> SND_DATA:
  3509                              <1> 	; ---------------------------------------------------------------------------------
  3510                              <1> 	; SND_DATA
  3511                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  3512                              <1> 	;	TO THE KEYBOARD AND RECEIPT OF ACKNOWLEDGEMENTS. IT ALSO
  3513                              <1> 	;	HANDLES ANY RETRIES IF REQUIRED
  3514                              <1> 	; ---------------------------------------------------------------------------------
  3515                              <1> 	;
  3516 00001383 6650                <1> 	push	ax			; SAVE REGISTERS
  3517 00001385 6653                <1> 	push	bx
  3518 00001387 51                  <1> 	push	ecx
  3519 00001388 88C7                <1> 	mov	bh, al			; SAVE TRANSMITTED BYTE FOR RETRIES
  3520 0000138A B303                <1> 	mov	bl, 3			; LOAD RETRY COUNT
  3521                              <1> SD0:
  3522 0000138C FA                  <1> 	cli				; DISABLE INTERRUPTS
  3523 0000138D 8025[E3B70000]CF    <1> 	and	byte [KB_FLAG_2], ~(KB_FE+KB_FA) ; CLEAR ACK AND RESEND FLAGS
  3524                              <1> 	;
  3525                              <1> 	;-----	WAIT FOR COMMAND TO BE ACCEPTED
  3526 00001394 B900000100          <1> 	mov	ecx, 10000h		; MAXIMUM WAIT COUNT
  3527                              <1> SD5:
  3528 00001399 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD PROCESSOR STATUS PORT
  3529 0000139B A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ANY PENDING COMMAND
  3530 0000139D E0FA                <1> 	loopnz	SD5			; WAIT FOR COMMAND TO BE ACCEPTED
  3531                              <1> 	;
  3532 0000139F 88F8                <1> 	mov	al, bh			; REESTABLISH BYTE TO TRANSMIT
  3533 000013A1 E660                <1> 	out	PORT_A, al		; SEND BYTE
  3534 000013A3 FB                  <1> 	sti				; ENABLE INTERRUPTS
  3535                              <1> 	;mov	cx, 01A00h		; LOAD COUNT FOR 10 ms+
  3536 000013A4 B9FFFF0000          <1> 	mov	ecx, 0FFFFh
  3537                              <1> SD1:
  3538 000013A9 F605[E3B70000]30    <1> 	test	byte [KB_FLAG_2], KB_FE+KB_FA ; SEE IF EITHER BIT SET
  3539 000013B0 750F                <1> 	jnz	short SD3		; IF SET, SOMETHING RECEIVED GO PROCESS
  3540 000013B2 E2F5                <1> 	loop	SD1			; OTHERWISE WAIT
  3541                              <1> SD2:
  3542 000013B4 FECB                <1> 	dec	bl			; DECREMENT RETRY COUNT
  3543 000013B6 75D4                <1> 	jnz	short SD0		; RETRY TRANSMISSION
  3544 000013B8 800D[E3B70000]80    <1> 	or	byte [KB_FLAG_2], KB_ERR ; TURN ON TRANSMIT ERROR FLAG
  3545 000013BF EB09                <1> 	jmp	short SD4		; RETRIES EXHAUSTED FORGET TRANSMISSION
  3546                              <1> SD3:
  3547 000013C1 F605[E3B70000]10    <1> 	test	byte [KB_FLAG_2], KB_FA ; SEE IF THIS IS AN ACKNOWLEDGE
  3548 000013C8 74EA                <1> 	jz	short SD2		; IF NOT, GO RESEND
  3549                              <1> SD4:	
  3550 000013CA 59                  <1> 	pop	ecx			; RESTORE REGISTERS
  3551 000013CB 665B                <1> 	pop	bx
  3552 000013CD 6658                <1> 	pop	ax
  3553 000013CF C3                  <1> 	retn				; RETURN, GOOD TRANSMISSION
  3554                              <1> 
  3555                              <1> SND_LED:
  3556                              <1> 	; ---------------------------------------------------------------------------------
  3557                              <1> 	; SND_LED
  3558                              <1> 	;	THIS ROUTINES TURNS ON THE MODE INDICATORS.
  3559                              <1> 	;
  3560                              <1> 	;----------------------------------------------------------------------------------
  3561                              <1> 	;
  3562 000013D0 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3563 000013D1 F605[E3B70000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  3564 000013D8 755F                <1> 	jnz 	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  3565                              <1> 	;
  3566 000013DA 800D[E3B70000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  3567 000013E1 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  3568 000013E3 E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  3569 000013E5 EB11                <1> 	jmp	short SL0		; GO SEND MODE INDICATOR COMMAND
  3570                              <1> SND_LED1:
  3571 000013E7 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3572 000013E8 F605[E3B70000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  3573 000013EF 7548                <1> 	jnz	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  3574                              <1> 	;
  3575 000013F1 800D[E3B70000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  3576                              <1> SL0:
  3577 000013F8 B0ED                <1> 	mov	al, LED_CMD		; LED CMD BYTE
  3578 000013FA E884FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  3579 000013FF FA                  <1> 	cli
  3580 00001400 E836000000          <1> 	call	MAKE_LED		; GO FORM INDICATOR DATA BYTE
  3581 00001405 8025[E3B70000]F8    <1> 	and	byte [KB_FLAG_2], 0F8h	; ~KB_LEDS ; CLEAR MODE INDICATOR BITS
  3582 0000140C 0805[E3B70000]      <1> 	or	[KB_FLAG_2], al 	; SAVE PRESENT INDICATORS FOR NEXT TIME
  3583 00001412 F605[E3B70000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  3584 00001419 750F                <1> 	jnz	short SL2		; IF SO, BYPASS SECOND BYTE TRANSMISSION
  3585                              <1> 	;
  3586 0000141B E863FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  3587 00001420 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3588 00001421 F605[E3B70000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  3589 00001428 7408                <1> 	jz	short SL3		; IF NOT, DON'T SEND AN ENABLE COMMAND
  3590                              <1> SL2:
  3591 0000142A B0F4                <1> 	mov	al, KB_ENABLE		; GET KEYBOARD CSA ENABLE COMMAND
  3592 0000142C E852FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  3593 00001431 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  3594                              <1> SL3:
  3595 00001432 8025[E3B70000]3F    <1> 	and	byte [KB_FLAG_2], ~(KB_PR_LED+KB_ERR) ; TURN OFF MODE INDICATOR
  3596                              <1> SL1:					; UPDATE AND TRANSMIT ERROR FLAG
  3597 00001439 FB                  <1> 	sti				; ENABLE INTERRUPTS
  3598 0000143A C3                  <1> 	retn				; RETURN TO CALLER
  3599                              <1> 
  3600                              <1> MAKE_LED:
  3601                              <1> 	;---------------------------------------------------------------------------------
  3602                              <1> 	; MAKE_LED
  3603                              <1> 	;	THIS ROUTINES FORMS THE DATA BYTE NECESSARY TO TURN ON/OFF
  3604                              <1> 	;	THE MODE INDICATORS.
  3605                              <1> 	;---------------------------------------------------------------------------------
  3606                              <1> 	;
  3607                              <1> 	;push 	cx			; SAVE CX
  3608 0000143B A0[E1B70000]        <1> 	mov	al, [KB_FLAG]		; GET CAPS & NUM LOCK INDICATORS
  3609 00001440 2470                <1> 	and	al, CAPS_STATE+NUM_STATE+SCROLL_STATE ; ISOLATE INDICATORS
  3610                              <1> 	;mov	cl, 4			; SHIFT COUNT
  3611                              <1> 	;rol	al, cl			; SHIFT BITS OVER TO TURN ON INDICATORS
  3612 00001442 C0C004              <1> 	rol	al, 4 ; 20/02/2015
  3613 00001445 2407                <1> 	and	al, 07h			; MAKE SURE ONLY MODE BITS ON
  3614                              <1> 	;pop	cx
  3615 00001447 C3                  <1> 	retn				; RETURN TO CALLER
  3616                              <1> 
  3617                              <1> ; % include 'kybdata.s'   ; KEYBOARD DATA
  3618                              <1> 
  3619                              <1> 
  3620                              <1> ; /// End Of KEYBOARD FUNCTIONS ///
  3621                                  
  3622                                  %include 'video.s' ; 07/03/2015
  3623                              <1> ; ****************************************************************************
  3624                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - video.s
  3625                              <1> ; ----------------------------------------------------------------------------
  3626                              <1> ; Last Update: 23/03/2016
  3627                              <1> ; ----------------------------------------------------------------------------
  3628                              <1> ; Beginning: 16/01/2016
  3629                              <1> ; ----------------------------------------------------------------------------
  3630                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
  3631                              <1> ; ----------------------------------------------------------------------------
  3632                              <1> ; Turkish Rational DOS
  3633                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
  3634                              <1> ;
  3635                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
  3636                              <1> ; video.inc (13/08/2015)
  3637                              <1> ;
  3638                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
  3639                              <1> ; ****************************************************************************
  3640                              <1> 
  3641                              <1> ; Retro UNIX 386 v1 Kernel - VIDEO.INC
  3642                              <1> ; Last Modification: 13/08/2015
  3643                              <1> ;		  (Video Data is in 'VIDATA.INC')
  3644                              <1> ;
  3645                              <1> ; ///////// VIDEO (CGA) FUNCTIONS ///////////////
  3646                              <1> 
  3647                              <1> ; 16/01/2016 (32 bit modifications, TRDOS386 - TRDOS v2.0, video.s)
  3648                              <1> ; INT 32H (TRDOS 386) = INT 10H (IBM PC/AT REAL MODE)
  3649                              <1> 
  3650                              <1> ; IBM PC-AT BIOS Source Code
  3651                              <1> ; TITLE VIDEO1 --- 06/10/85  VIDEO DISPLAY BIOS
  3652                              <1> 
  3653                              <1> int10h:
  3654                              <1> 	; 23/03/2016
  3655                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3656 00001448 9C                  <1> 	pushfd
  3657 00001449 0E                  <1> 	push 	cs
  3658 0000144A E851000000          <1> 	call 	VIDEO_IO_1
  3659 0000144F C3                  <1> 	retn
  3660                              <1> 
  3661                              <1> ;--- INT 10 H -------------------------------------------------------------------
  3662                              <1> ; VIDEO_IO									:	
  3663                              <1> ;	THESE ROUTINES PROVIDE THE CRT DISPLAY INTERFACE			:
  3664                              <1> ;	THE FOLLOWING FUNCTIONS ARE PROVIDED:					:
  3665                              <1> ;										:
  3666                              <1> ;    (AH)= 00H	SET MODE (AL) CONTAINS MODE VALUE				:
  3667                              <1> ;		(AL) = 00H  40X25 BW MODE (POWER ON DEFAULT)			:
  3668                              <1> ;		(AL) = 01H  40X25 COLOR						:
  3669                              <1> ;		(AL) = 02H  80X25 BW						:
  3670                              <1> ;		(AL) = 03H  80X25 COLOR						:
  3671                              <1> ;		              GRAPHICS MODES					:
  3672                              <1> ;		(AL) = 04H  320X200 COLOR					:
  3673                              <1> ;		(AL) = 05H  320X200 BW MODE					:
  3674                              <1> ;		(AL) = 06H  640X200 BW MODE					:
  3675                              <1> ;		(AL) = 07H   80X25 MONOCHROME (USED INTERNAL TO VIDEO ONLY)	:
  3676                              <1> ;		*** NOTES -BW MODES OPERATE SAME AS COLOR MODES, BUT COLOR	:
  3677                              <1> ;		           BURST IS NOT ENABLED					:
  3678                              <1> ;		          -CURSOR IS NOT DISPLAYED IN GRAPHICS MODE		:
  3679                              <1> ;    (AH)= 01H	SET CURSOR TYPE							:
  3680                              <1> ;		(CH) = BITS 4-0 = START LINE FOR CURSOR				:
  3681                              <1> ;		       ** HARDWARE WILL ALWAYS CAUSE BLINK			:
  3682                              <1> ;		       ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING	:
  3683                              <1> ;		          OR NO CURSOR AT ALL					:
  3684                              <1> ;		(CL) = BITS 4-0 = END LINE FOR CURSOR				:
  3685                              <1> ;    (AH)= 02H	SET CURSOR POSITION						:
  3686                              <1> ;		(DH,DL) = ROW,COLUMN  (00H,00H) IS UPPER LEFT			:
  3687                              <1> ;		(BH) = A PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
  3688                              <1> ;    (AH)= 03H	READ CURSOR POSITION						:
  3689                              <1> ;		(BH) = PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
  3690                              <1> ;		ON EXIT (DH,DL) = ROW,COLUMN OF CURRENT CURSOR			:
  3691                              <1> ;		        (CH,CL) = CURSOR MODE CURRENTLY SET			:
  3692                              <1> ;    (AH)= 04H	READ LIGHT PEN POSITION						:
  3693                              <1> ;		ON EXIT:							:
  3694                              <1> ;		(AH) = 00H -- LIGHT PEN SWITCH NOT DOWN/NOT TRIGGERED		:
  3695                              <1> ;		(AH) = 01H -- VALID LIGHT PEN VALUE IN REGISTERS		:
  3696                              <1> ;		        (DH,DL) = ROW,COLUMN OF CHARACTER LP POSITION		:
  3697                              <1> ;		        (CH) = RASTER LINE (0-199)				:
  3698                              <1> ;		        (BX) = PIXEL COLUMN (0-319,639)				:
  3699                              <1> ;    (AH)= 05H	SELECT ACTIVE DISPLAY PAGE (VALID ONLY FOR ALPHA MODES)		:
  3700                              <1> ;		(AL) = NEW PAGE VALUE (0-7 FOR MODES 0&1, 0-3 FOR MODES 2&3)	:
  3701                              <1> ;    (AH)= 06H	SCROLL ACTIVE PAGE UP						:
  3702                              <1> ;		(AL) = NUMBER OF LINES. ( LINES BLANKED AT BOTTOM OF WINDOW )	:
  3703                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
  3704                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
  3705                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
  3706                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
  3707                              <1> ;    (AH)= 07H	SCROLL ACTIVE PAGE DOWN						:
  3708                              <1> ;		(AL) = NUMBER OF LINES, INPUT LINES BLANKED AT TOP OF WINDOW	:
  3709                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
  3710                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
  3711                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
  3712                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
  3713                              <1> ;										:
  3714                              <1> ;   CHARACTER HANDLING ROUTINES							:
  3715                              <1> ;										:
  3716                              <1> ;    (AH)= 08H	READ ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
  3717                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3718                              <1> ;		ON EXIT:							:
  3719                              <1> ;		(AL) = CHAR READ						:
  3720                              <1> ;		(AH) = ATTRIBUTE OF CHARACTER READ (ALPHA MODES ONLY)		:
  3721                              <1> ;    (AH)= 09H	WRITE ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
  3722                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3723                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
  3724                              <1> ;		(AL) = CHAR TO WRITE						:
  3725                              <1> ;		(BL) = ATTRIBUTE OF CHARACTER (ALPHA)/COLOR OF CHAR (GRAPHICS)	:
  3726                              <1> ;		         SEE NOTE ON WRITE DOT FOR BIT 7 OF BL = 1.		:
  3727                              <1> ;    (AH) = 0AH	WRITE CHARACTER ONLY AT CURRENT CURSOR POSITION			:
  3728                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3729                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
  3730                              <1> ;		(AL) = CHAR TO WRITE						:
  3731                              <1> ;		       NOTE: USE FUNCTION (AH)= 09H IN GRAPHICS MODES		:
  3732                              <1> ;	FOR READ/WRITE CHARACTER INTERFACE WHILE IN GRAPHICS MODE, THE		:
  3733                              <1> ;		CHARACTERS ARE FORMED FROM A CHARACTER GENERATOR IMAGE		:
  3734                              <1> ;		MAINTAINED IN THE SYSTEM ROM. ONLY THE 1ST 128 CHARS		:
  3735                              <1> ;		ARE CONTAINED THERE. TO READ/WRITE THE SECOND 128 CHARS,	:
  3736                              <1> ;		THE USER MUST INITIALIZE THE POINTER AT INTERRUPT 1FH		:
  3737                              <1> ;		(LOCATION 0007CH) TO POINT TO THE 1K BYTE TABLE CONTAINING	:
  3738                              <1> ;		THE CODE POINTS FOR THE SECOND 128 CHARS (128-255).		:
  3739                              <1> ;	FOR WRITE CHARACTER INTERFACE IN GRAPHICS MODE, THE REPLICATION FACTOR	:
  3740                              <1> ;		CONTAINED IN (CX) ON ENTRY WILL PRODUCE VALID RESULTS ONLY	:
  3741                              <1> ;		FOR CHARACTERS CONTAINED ON THE SAME ROW. CONTINUATION TO	:
  3742                              <1> ;		SUCCEEDING LINES WILL NOT PRODUCE CORRECTLY.			:
  3743                              <1> ;										:
  3744                              <1> ;    GRAPHICS INTERFACE								:
  3745                              <1> ;    (AH)= 0BH	SET COLOR PALETTE						:
  3746                              <1> ;		(BH) = PALETTE COLOR ID BEING SET (0-127)			:
  3747                              <1> ;		(BL) = COLOR VALUE TO BE USED WITH THAT COLOR ID		:
  3748                              <1> ;		       NOTE: FOR THE CURRENT COLOR CARD, THIS ENTRY POINT HAS	:
  3749                              <1> ;		               MEANING ONLY FOR 320X200 GRAPHICS.		:
  3750                              <1> ;		       COLOR ID = 0 SELECTS THE BACKGROUND COLOR (0-15)		:
  3751                              <1> ;		       COLOR ID = 1 SELECTS THE PALETTE TO BE USED:		:
  3752                              <1> ;		               0 = GREEN(1)/RED(2)/YELLOW(3)			:
  3753                              <1> ;		               1 = CYAN(1)/MAGENTA(2)/WHITE(3)			:
  3754                              <1> ;		       IN 40X25 OR 80X25 ALPHA MODES, THE VALUE SET FOR 	:
  3755                              <1> ;		               PALETTE COLOR 0 INDICATES THE BORDER COLOR	:
  3756                              <1> ;		               TO BE USED (VALUES 0-31, WHERE 16-31 SELECT	:
  3757                              <1> ;		               THE HIGH INTENSITY BACKGROUND SET.		:
  3758                              <1> ;    (AH)= 0CH	WRITE DOT							:
  3759                              <1> ;		(DX) = ROW NUMBER						:
  3760                              <1> ;		(CX) = COLUMN NUMBER						:
  3761                              <1> ;		(AL) = COLOR VALUE						:
  3762                              <1> ;		        IF BIT 7 OF AL = 1, THEN THE COLOR VALUE IS EXCLUSIVE	:
  3763                              <1> ;		        ORed WITH THE CURRENT CONTENTS OF THE DOT		:
  3764                              <1> ;    (AH)= ODH	READ DOT							:
  3765                              <1> ;		(DX) = ROW NUMBER						:
  3766                              <1> ;		(CX) = COLUMN NUMBER						:
  3767                              <1> ;		(AL) = RETURNS THE DOT READ					:
  3768                              <1> ;										:
  3769                              <1> ;    ASCII TELETYPE ROUTINE FOR OUTPUT						:
  3770                              <1> ;										:
  3771                              <1> ;    (AH)= 0EH	WRITE TELETYPE TO ACTIVE PAGE					:
  3772                              <1> ;		(AL) = CHAR TO WRITE						:
  3773                              <1> ;		(BL) = FOREGROUND COLOR IN GRAPHICS MODE			:
  3774                              <1> ;		NOTE -- SCREEN WIDTH IS CONTROLLED BY PREVIOUS MODE SET		:
  3775                              <1> ;    (AH)= 0FH	CURRENT VIDEO STATE						:
  3776                              <1> ;		RETURNS THE CURRENT VIDEO STATE					:
  3777                              <1> ;		(AL) = MODE CURRENTLY SET ( SEE (AH)=00H FOR EXPLANATION)	:
  3778                              <1> ;		(AH) = NUMBER OR CHARACTER COLUMNS ON SCREEN			:
  3779                              <1> ;		(BH) = CURRENT ACTIVE DISPLAY PAGE				:
  3780                              <1> ;    (AH)= 10H	RESERVED							:
  3781                              <1> ;    (AH)= 11H	RESERVED							:
  3782                              <1> ;    (AH)= 12H	RESERVED							:
  3783                              <1> ;    (AH)= 13H	WRITE STRING							:
  3784                              <1> ;			ES:BP  -  POINTER T0 STRING TO BE WRITTEN		:
  3785                              <1> ;			CX     -  LENGTH OF CHARACTER STRING TO WRITTEN		:
  3786                              <1> ;			DX     -  CURSOR POSITION FOR STRING TO BE WRITTEN	:
  3787                              <1> ;			BH     -  PAGE NUMBER					:
  3788                              <1> ;		(AL)= 00H	WRITE CHARACTER STRING				:
  3789                              <1> ;			BL     -  ATTRIBUTE					:
  3790                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
  3791                              <1> ;			CURSOR NOT MOVED					:
  3792                              <1> ;		(AL)= 01H	WRITE CHARACTER STRING AND MOVE CURSOR		:
  3793                              <1> ;			BL     -  ATTRIBUTE					:
  3794                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
  3795                              <1> ;			CURSOR MOVED						:
  3796                              <1> ;		(AL)= 02H	WRITE CHARACTER AND ATTRIBUTE STRING		:
  3797                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
  3798                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
  3799                              <1> ;			CURSOR IS NOT MOVED					:
  3800                              <1> ;		(AL)= 03H WRITE CHARACTER AND ATTRIBUTE STRING AND MOVE CURSOR	:
  3801                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
  3802                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
  3803                              <1> ;			CURSOR IS MOVED						:
  3804                              <1> ;		 NOTE:  CARRIAGE RETURN, LINE FEED, BACKSPACE, AND BELL ARE	:
  3805                              <1> ;		        TREATED AS COMMANDS RATHER THAN PRINTABLE CHARACTERS.	:
  3806                              <1> ;										:
  3807                              <1> ;	BX,CX,DX,SI,DI,BP,SP,DS,ES,SS PRESERVED DURING CALLS EXCEPT FOR		:
  3808                              <1> ;	BX,CX,DX RETURN VALUES ON FUNCTIONS 03H,04H,0DH AND 0FH. ON ALL CALLS	:
  3809                              <1> ;	AX IS MODIFIED.								:
  3810                              <1> ;--------------------------------------------------------------------------------
  3811                              <1> 
  3812 00001450 [EC140000]          <1> M1:	dd	SET_MODE	; TABLE OF ROUTINES WITHIN VIDEO I/O
  3813 00001454 [4C150000]          <1> 	dd	SET_CTYPE
  3814 00001458 [61150000]          <1> 	dd	SET_CPOS
  3815 0000145C [68150000]          <1> 	dd	READ_CURSOR
  3816 00001460 [F1140000]          <1> 	dd	VIDEO_RETURN	; READ_LPEN
  3817 00001464 [8A150000]          <1> 	dd	ACT_DISP_PAGE
  3818 00001468 [03160000]          <1> 	dd	SCROLL_UP
  3819 0000146C [E7160000]          <1> 	dd	SCROLL_DOWN
  3820 00001470 [32170000]          <1> 	dd	READ_AC_CURRENT
  3821 00001474 [60170000]          <1> 	dd	WRITE_AC_CURRENT
  3822 00001478 [73170000]          <1> 	dd	WRITE_C_CURRENT
  3823 0000147C [F1140000]          <1> 	dd	VIDEO_RETURN	; SET_COLOR
  3824 00001480 [F1140000]          <1> 	dd	VIDEO_RETURN	; WRITE_DOT
  3825 00001484 [F1140000]          <1> 	dd	VIDEO_RETURN	; READ_DOT
  3826 00001488 [B7170000]          <1> 	dd	WRITE_TTY
  3827 0000148C [D9140000]          <1> 	dd	VIDEO_STATE
  3828 00001490 [F1140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3829 00001494 [F1140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3830 00001498 [F1140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3831 0000149C [F1140000]          <1> 	dd	VIDEO_RETURN	; WRITE_STRING
  3832                              <1> M1L	EQU	$ - M1
  3833                              <1> 
  3834                              <1> VIDEO_IO_1:
  3835 000014A0 FB                  <1> 	sti				; INTERRUPTS BACK ON
  3836 000014A1 FC                  <1> 	cld				; SET DIRECTION FORWARD
  3837 000014A2 80FC14              <1> 	cmp	ah, M1L/4		; TEST FOR WITHIN TABLE RANGE
  3838 000014A5 7321                <1> 	jnb	short M4		; BRANCH TO EXIT IF NOT A VALID COMMAND
  3839                              <1> 
  3840 000014A7 06                  <1> 	push	es
  3841 000014A8 1E                  <1> 	push	ds			; SAVE WORK AND PARAMETER REGISTERS
  3842 000014A9 52                  <1> 	push	edx
  3843 000014AA 51                  <1> 	push	ecx
  3844 000014AB 53                  <1> 	push	ebx
  3845 000014AC 56                  <1> 	push	esi
  3846 000014AD 57                  <1> 	push	edi
  3847 000014AE 55                  <1> 	push	ebp
  3848 000014AF 66BE1000            <1> 	mov	si, KDATA 		; POINT DS: TO DATA SEGMENT
  3849 000014B3 8EDE                <1> 	mov	ds, si
  3850 000014B5 8EC6                <1> 	mov	es, si
  3851 000014B7 BF00800B00          <1> 	mov	edi, 0B8000h		; GET offset FOR COLOR CARD
  3852                              <1> 	; 23/03/2016
  3853 000014BC C0E402              <1> 	shl	ah, 2  ; dword		; TIMES 2 FOR WORD TABLE LOOKUP
  3854 000014BF 0FB6F4              <1> 	movzx	esi, ah			; MOVE OFFSET INTO LOOK UP REGISTER (SI)
  3855                              <1> 	;mov	ah, [CRT_MODE]		; MOVE CURRENT MODE INTO (AH) REGISTER
  3856                              <1> 
  3857 000014C2 FFA6[50140000]      <1> 	JMP	dword [esi+M1]		; GO TO SELECTED FUNCTION
  3858                              <1> 
  3859                              <1> M4:					;	COMMAND NOT VALID
  3860 000014C8 CF                  <1> 	iret				; DO NOTHING IF NOT IN VALID RANGE
  3861                              <1> 
  3862                              <1> 
  3863                              <1> ; 02/09/2014 (Retro UNIX 386 v1)
  3864                              <1> ;
  3865                              <1> ; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3866                              <1> 
  3867                              <1> set_mode_3:  	; will be called from 'write_tty' 
  3868 000014C9 53                  <1> 	push	ebx
  3869 000014CA 52                  <1> 	push	edx
  3870 000014CB 50                  <1> 	push	eax
  3871 000014CC 57                  <1> 	push	edi
  3872 000014CD 51                  <1> 	push	ecx
  3873 000014CE E827000000          <1> 	call	set_txt_mode
  3874 000014D3 59                  <1> 	pop	ecx
  3875 000014D4 5F                  <1> 	pop	edi
  3876 000014D5 58                  <1> 	pop	eax
  3877 000014D6 5A                  <1> 	pop	edx
  3878 000014D7 5B                  <1> 	pop	ebx
  3879 000014D8 C3                  <1> 	retn
  3880                              <1> 
  3881                              <1> VIDEO_STATE:
  3882                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3883                              <1> 
  3884                              <1> ;---------------------------------------------------
  3885                              <1> ; VIDEO STATE
  3886                              <1> ;  RETURNS THE CURRENT VIDEO STATE IN AX
  3887                              <1> ;  AH = NUMBER OF COLUMNS ON THE SCREEN
  3888                              <1> ;  AL = CURRENT VIDEO MODE
  3889                              <1> ;  BH = CURRENT ACTIVE PAGE
  3890                              <1> ;---------------------------------------------------
  3891                              <1> 
  3892                              <1> 	;mov	ah, [CRT_COLS]	; GET NUMBER OF COLUMNS
  3893 000014D9 B480                <1> 	mov	ah, 80h
  3894 000014DB A0[16B80000]        <1> 	mov	al, [CRT_MODE]	; CURRENT MODE
  3895                              <1> 	;movzx	esi, al
  3896                              <1> 	;mov	ah, [esi+M6] 
  3897                              <1> 	; BL = active page (not BH!)
  3898 000014E0 8A1D[18BE0000]      <1> 	mov	bl, [ACTIVE_PAGE] ; GET CURRENT ACTIVE PAGE
  3899 000014E6 5D                  <1> 	pop	ebp		; RECOVER REGISTERS
  3900 000014E7 5F                  <1> 	pop	edi
  3901 000014E8 5E                  <1> 	pop	esi
  3902 000014E9 59                  <1> 	pop	ecx	; DISCARD SAVED BX
  3903 000014EA EB09                <1> 	jmp	short M15	; RETURN TO CALLER
  3904                              <1> 
  3905                              <1> SET_MODE:
  3906                              <1> 	; For 32 bit TRDOS and Retro UNIX 386:
  3907                              <1> 	;	valid video mode: 03h only!
  3908                              <1> 	;	(VGA modes will be selected with another routine)
  3909                              <1> 	;
  3910                              <1> 	; set_txt_mode ; 80*25 (16 fore colors, 8 back colors)
  3911                              <1> 
  3912                              <1> ;------------------------------------------------------
  3913                              <1> ; SET MODE					      :
  3914                              <1> ;	THIS ROUTINE INITIALIZES THE ATTACHMENT TO    :
  3915                              <1> ;	THE SELECTED MODE, THE SCREEN IS BLANKED.     :
  3916                              <1> ; INPUT						      :
  3917                              <1> ;	(AL) - MODE SELECTED (RANGE 0-7)	      :
  3918                              <1> ; OUTPUT					      :
  3919                              <1> ;	NONE					      :
  3920                              <1> ;------------------------------------------------------
  3921                              <1> 
  3922 000014EC E809000000          <1> 	call	set_txt_mode
  3923                              <1> 
  3924                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3925                              <1> 
  3926                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  3927                              <1> 
  3928                              <1> VIDEO_RETURN:
  3929 000014F1 5D                  <1> 	pop	ebp
  3930 000014F2 5F                  <1> 	pop	edi
  3931 000014F3 5E                  <1> 	pop	esi
  3932 000014F4 5B                  <1> 	pop	ebx
  3933                              <1> M15:			; VIDEO_RETURN_C
  3934 000014F5 59                  <1> 	pop	ecx
  3935 000014F6 5A                  <1> 	pop	edx
  3936 000014F7 1F                  <1> 	pop	ds
  3937 000014F8 07                  <1> 	pop	es	; RECOVER SEGMENTS
  3938 000014F9 CF                  <1> 	iret		; ALL DONE
  3939                              <1> 
  3940                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3941                              <1> set_txt_mode:
  3942                              <1> 	;mov	dx, 03D4h 	; address of color card
  3943 000014FA B003                <1> 	mov	al, 3
  3944                              <1> ;M8:
  3945 000014FC A2[16B80000]        <1> 	mov	[CRT_MODE], al  ; save mode in global variable
  3946 00001501 B029                <1> 	mov	al, 29h
  3947                              <1> 	;mov	[CRT_MODE_SET], al ; save the mode set value
  3948 00001503 2437                <1> 	and	al, 037h	; video off, save high resolution bit	
  3949                              <1> 	;push	dx  		; save port value
  3950                              <1> 	;add	dx, 4		; point to control register
  3951 00001505 66BAD803            <1> 	mov	dx, 3D8h
  3952 00001509 EE                  <1> 	out	dx, al		; reset video to off to suppress rolling
  3953                              <1> 	;pop	dx
  3954                              <1> ;M9:
  3955 0000150A BB[18B80000]        <1> 	mov	ebx, video_params ; initialization table
  3956 0000150F 668B430A            <1> 	mov	ax, [ebx+10]      ; get the cursor mode from the table	
  3957 00001513 86E0                <1> 	xchg 	ah, al
  3958 00001515 66A3[06BE0000]      <1> 	mov	[CURSOR_MODE], ax ; save cursor mode
  3959 0000151B 30E4                <1> 	xor	ah, ah		  ; ah is register number during loop 
  3960                              <1> 	
  3961                              <1> ;-----	LOOP THROUGH TABLE, OUTPUTTING REGISTER ADDRESS, THEN VALUE FROM TABLE
  3962 0000151D B910000000          <1> 	mov	ecx, 16 ; 16/01/2016
  3963                              <1> M10:			;  initialization loop
  3964 00001522 88E0                <1> 	mov	al, ah 	; get 6845 register number
  3965 00001524 EE                  <1> 	out	dx, al
  3966 00001525 6642                <1> 	inc	dx      ; point to data port
  3967 00001527 FEC4                <1> 	inc	ah	; next register value
  3968 00001529 8A03                <1> 	mov	al, [ebx] ; get table value
  3969 0000152B EE                  <1> 	out	dx, al	; out to chip
  3970 0000152C 43                  <1> 	inc	ebx	; next in table
  3971 0000152D 664A                <1> 	dec	dx	; back to pointer register
  3972 0000152F E2F1                <1> 	loop	M10	; do the whole table
  3973                              <1> 
  3974                              <1> ;-----	FILL REGEN AREA WITH BLANK
  3975                              <1> 	;xor	ax, ax  
  3976                              <1> 	;mov	[CRT_START], ax  ; start address saved in global
  3977                              <1> 	;mov	[ACTIVE_PAGE], al ; 0 ; (re)set page value
  3978                              <1> 	;mov	ecx, 8192 ; number of words in color card
  3979                              <1> 	; black background, light gray characeter color, space character
  3980                              <1> 	;mov	ax, 0720h ; fill char for alpha - attribute
  3981                              <1> ;M13:			  ; clear buffer
  3982                              <1> 	;add	edi, 0B8000h ; [crt_base]
  3983                              <1> 	;rep	stosw	; FILL THE REGEN BUFFER WITH BLANKS
  3984                              <1> 
  3985                              <1> ;-----	ENABLE VIDEO AND CORRECT PORT SETTING
  3986                              <1> 	;mov	dx, 3D4h ; mov dx, word [ADDR_6845]
  3987                              <1> 			 ; prepare to output to video enable port
  3988                              <1> 	;add	dx,4	 ; point to the mode control gerister
  3989 00001531 66BAD803            <1> 	mov	dx, 3D8h
  3990                              <1> 	;mov	al, [CRT_MODE_SET] ; get the mode set value
  3991 00001535 B029                <1> 	mov	al, 29h
  3992 00001537 EE                  <1> 	out	dx, al	 ; set video enable port
  3993                              <1> 
  3994                              <1> ;----- 	DETERMINE NUMBER OF COLUMNS, BOTH FOR ENTIRE DISPLAY
  3995                              <1> ;----- 	AND THE NUMBER TO BE USED FOR TTY INTERFACE
  3996                              <1> 	;
  3997                              <1> 	;mov	byte [CRT_COLS], 80h ; initialize number of columns count
  3998                              <1> 	;
  3999                              <1> ;-----	SET CURSOR POSITIONS
  4000                              <1> 	;mov	word [CRT_LEN], 80*25*2
  4001 00001538 BF[08BE0000]        <1> 	mov	edi, CURSOR_POSN
  4002 0000153D B904000000          <1> 	mov	ecx, 4	; clear all cursor positions (16 bytes)
  4003 00001542 31C0                <1> 	xor	eax, eax
  4004 00001544 F3AB                <1> 	rep 	stosd	; fill with zeroes
  4005                              <1> 
  4006                              <1> ;-----	SET UP OVERSCAN REGISTER
  4007 00001546 6642                <1> 	inc	dx	; set overscan port to a default
  4008 00001548 B030                <1> 	mov	al, 30h	; 30H value for all modes except 640X200 bw
  4009                              <1> ;M14:
  4010 0000154A EE                  <1> 	out	dx, al	; output the correct value to 3D9 port
  4011                              <1> 	;mov	[CRT_PALETTE], al ; save the value for future use
  4012                              <1> 
  4013                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  4014 0000154B C3                  <1> 	retn
  4015                              <1> 
  4016                              <1> SET_CTYPE:
  4017                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4018 0000154C E802000000          <1> 	call	_set_ctype
  4019 00001551 EB9E                <1> 	jmp	short VIDEO_RETURN
  4020                              <1> 
  4021                              <1> _set_ctype:
  4022                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
  4023                              <1> 	;
  4024                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4025                              <1> 
  4026                              <1> 	; (CH) = BITS 4-0 = START LINE FOR CURSOR
  4027                              <1> 	;  ** HARDWARE WILL ALWAYS CAUSE BLINK
  4028                              <1> 	;  ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING
  4029                              <1> 	;     OR NO CURSOR AT ALL
  4030                              <1> 	; (CL) = BITS 4-0 = END LINE FOR CURSOR
  4031                              <1> 
  4032                              <1> ;------------------------------------------------
  4033                              <1> ; SET_CTYPE
  4034                              <1> ;	THIS ROUTINE SETS THE CURSOR VALUE
  4035                              <1> ; INPUT
  4036                              <1> ;	(CX) HAS CURSOR VALUE CH-START LINE, CL-STOP LINE
  4037                              <1> ; OUTPUT	
  4038                              <1> ;	NONE
  4039                              <1> ;------------------------------------------------
  4040                              <1> 
  4041 00001553 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  4042 00001555 66890D[06BE0000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
  4043                              <1> 	;call	m16	; output cx register
  4044                              <1> 	;retn
  4045 0000155C E915030000          <1>         jmp     m16
  4046                              <1> 
  4047                              <1> SET_CPOS:
  4048                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4049 00001561 E8E5020000          <1> 	call	_set_cpos
  4050 00001566 EB89                <1> 	jmp	short VIDEO_RETURN
  4051                              <1> 
  4052                              <1> READ_CURSOR:
  4053                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4054                              <1> 	;
  4055                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4056                              <1> 
  4057                              <1> ;------------------------------------------------------
  4058                              <1> ; READ_CURSOR
  4059                              <1> ;	THIS ROUTINE READS THE CURRENT CURSOR VALUE FROM THE
  4060                              <1> ;	845, FORMATS IT, AND SENDS IT BACK TO THE CALLER
  4061                              <1> ; INPUT
  4062                              <1> ;	BH - PAGE OF CURSOR
  4063                              <1> ; OUTPUT
  4064                              <1> ;	DX - ROW, COLUMN OF THE CURRENT CURSOR POSITION
  4065                              <1> ;	CX - CURRENT CURSOR MODE
  4066                              <1> ;------------------------------------------------------
  4067                              <1> 
  4068                              <1> 	; BL = Video page number (0 to 7)
  4069                              <1> 	
  4070                              <1> 
  4071 00001568 E810000000          <1> 	call	get_cpos
  4072 0000156D 0FB70D[06BE0000]    <1> 	movzx	ecx, word [CURSOR_MODE]
  4073                              <1> 
  4074 00001574 5D                  <1> 	pop	ebp
  4075 00001575 5F                  <1> 	pop	edi
  4076 00001576 5E                  <1> 	pop	esi
  4077 00001577 5B                  <1> 	pop	ebx
  4078 00001578 58                  <1> 	pop	eax	; DISCARD SAVED CX AND DX
  4079 00001579 58                  <1> 	pop	eax
  4080 0000157A 1F                  <1> 	pop	ds
  4081 0000157B 07                  <1> 	pop	es
  4082 0000157C CF                  <1> 	iret
  4083                              <1> 
  4084                              <1> get_cpos:
  4085                              <1> 	; 16/01/2016
  4086                              <1> 	; BL = Video page number (0 to 7)
  4087                              <1> 	;
  4088 0000157D D0E3                <1> 	shl	bl, 1 ; WORD OFFSET
  4089 0000157F 0FB6F3              <1> 	movzx	esi, bl 
  4090 00001582 0FB796[08BE0000]    <1> 	movzx	edx, word [esi+CURSOR_POSN]
  4091 00001589 C3                  <1> 	retn
  4092                              <1> 
  4093                              <1> ACT_DISP_PAGE:
  4094                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4095                              <1> 	;
  4096                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4097                              <1> 	;
  4098                              <1> ;-----------------------------------------------------
  4099                              <1> ; ACT_DISP_PAGE
  4100                              <1> ;	THIS ROUTINE SETS THE ACTIVE DISPLAY PAGE, ALLOWING
  4101                              <1> ;	THE FULL USE OF THE MEMORY SET ASIDE FOR THE VIDEO ATTACHMENT
  4102                              <1> ; INPUT
  4103                              <1> ;	AL HAS THE NEW ACTIVE DISPLAY PAGE
  4104                              <1> ; OUTPUT
  4105                              <1> ;	THE 6845 IS RESET TO DISPLAY THAT PAGE
  4106                              <1> ;-----------------------------------------------------
  4107                              <1> 
  4108 0000158A E805000000          <1> 	call	set_active_page
  4109 0000158F E95DFFFFFF          <1>         jmp     VIDEO_RETURN
  4110                              <1> 
  4111                              <1> set_active_page:   ; tty_sw
  4112                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4113                              <1> 	; 30/06/2015
  4114                              <1> 	; 04/03/2014  (act_disp_page --> tty_sw)
  4115                              <1> 	; 10/12/2013
  4116                              <1> 	; 04/12/2013
  4117                              <1> 	;
  4118 00001594 A2[18BE0000]        <1> 	mov	[ACTIVE_PAGE], al ; save active page value ; [ptty]
  4119                              <1> 	;mov	cx, [CRT_LEN] ; get saved length of regen buffer
  4120 00001599 66B9A00F            <1> 	mov	cx, 25*80*2
  4121                              <1> 	; 27/06/2015
  4122 0000159D 0FB6D8              <1> 	movzx	ebx, al
  4123                              <1> 	;
  4124 000015A0 6698                <1> 	cbw	; 07/09/2014 (ah=0)
  4125 000015A2 66F7E1              <1> 	mul 	cx	; display page times regen length
  4126                              <1> 	; 10/12/2013
  4127 000015A5 66A3[04BE0000]      <1> 	mov	[CRT_START], ax ; save start address for later
  4128 000015AB 6689C1              <1> 	mov	cx, ax ; start address to cx
  4129                              <1> 	;sar	cx, 1
  4130 000015AE 66D1E9              <1> 	shr	cx, 1	; divide by 2 for 6845 handling
  4131 000015B1 B40C                <1> 	mov	ah, 12	; 6845 register for start address
  4132 000015B3 E8BE020000          <1> 	call	m16
  4133                              <1> 	;sal	bx, 1
  4134                              <1> 	; 01/09/2014
  4135 000015B8 D0E3                <1> 	shl	bl, 1	; *2 for word offset
  4136 000015BA 81C3[08BE0000]      <1> 	add	ebx, CURSOR_POSN
  4137 000015C0 668B13              <1> 	mov	dx, [ebx] ; get cursor for this page
  4138                              <1> 	; 16/01/2016
  4139                              <1> 	;call	m18
  4140                              <1> 	;retn
  4141 000015C3 E99A020000          <1> 	jmp	m18
  4142                              <1> 
  4143                              <1> position:
  4144                              <1> 	; 27/06/2015
  4145                              <1> 	; 02/09/2014
  4146                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4147                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1)
  4148                              <1> 	;
  4149                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4150                              <1> 	;
  4151                              <1> ;-----------------------------------------
  4152                              <1> ; POSITION
  4153                              <1> ;	THIS SERVICE ROUTINE CALCULATES THE REGEN BUFFER ADDRESS
  4154                              <1> ;	OF A CHARACTER IN THE ALPHA MODE
  4155                              <1> ; INPUT
  4156                              <1> ;	AX = ROW, COLUMN POSITION
  4157                              <1> ; OUTPUT
  4158                              <1> ;	AX = OFFSET OF CHAR POSITION IN REGEN BUFFER
  4159                              <1> ;-----------------------------------------
  4160                              <1> 
  4161                              <1> 		; DX = ROW, COLUMN POSITION
  4162                              <1> 	;movzx	eax, byte [CRT_COLS] ; 27/06/2015
  4163 000015C8 31C0                <1> 	xor	eax, eax ; 02/09/2014
  4164 000015CA B050                <1> 	mov	al, 80   ; determine bytes to row	
  4165 000015CC F6E6                <1> 	mul	dh	 ; row value
  4166 000015CE 30F6                <1> 	xor	dh, dh   ; 0	
  4167 000015D0 6601D0              <1> 	add	ax, dx	 ; add column value to the result
  4168 000015D3 66D1E0              <1> 	shl	ax, 1	; * 2 for attribute bytes
  4169                              <1> 		; EAX = AX = OFFSET OF CHAR POSITION IN REGEN BUFFER 
  4170 000015D6 C3                  <1> 	retn
  4171                              <1> 
  4172                              <1> find_position:
  4173                              <1> 	; 27/06/2015
  4174                              <1> 	; 07/09/2014
  4175                              <1> 	; 02/09/2014
  4176                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4177                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4178 000015D7 0FB6CB              <1> 	movzx	ecx, bl ; video page number ; 27/06/2015 (movzx)
  4179 000015DA 89CE                <1> 	mov	esi, ecx
  4180 000015DC 66D1E6              <1> 	shl	si, 1
  4181 000015DF 668B96[08BE0000]    <1> 	mov	dx, [esi + CURSOR_POSN]
  4182 000015E6 740A                <1> 	jz	short p21
  4183 000015E8 6631F6              <1> 	xor	si, si
  4184                              <1> p20:
  4185                              <1> 	;add	si, [CRT_LEN]
  4186 000015EB 6681C6A00F          <1> 	add	si, 80*25*2 ; add length of buffer for one page		
  4187 000015F0 E2F9                <1> 	loop	p20
  4188                              <1> p21:
  4189 000015F2 6621D2              <1> 	and	dx, dx
  4190 000015F5 7407                <1> 	jz	short p22
  4191 000015F7 E8CCFFFFFF          <1> 	call 	position ; determine location in regen in page
  4192 000015FC 01C6                <1> 	add	esi, eax ; add location to start of regen page
  4193                              <1> p22:	
  4194                              <1> 	;mov	dx, [addr_6845] ; get base address of active display			
  4195                              <1> 	;mov	dx, 03D4h ; I/O address of color card
  4196                              <1> 	;add	dx, 6	; point at status port
  4197 000015FE 66BADA03            <1> 	mov	dx, 03DAh ; status port
  4198                              <1> 	; cx = 0
  4199 00001602 C3                  <1> 	retn
  4200                              <1> 
  4201                              <1> SCROLL_UP:
  4202                              <1> 	; 30/01/2016
  4203                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4204                              <1> 	; 07/09/2014
  4205                              <1> 	; 02/09/2014
  4206                              <1> 	; 01/09/2014 (Retro UNIX 386 v1 - beginning)
  4207                              <1> 	; 04/04/2014
  4208                              <1> 	; 04/12/2013
  4209                              <1> 	;
  4210                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4211                              <1> 	;
  4212                              <1> ;----------------------------------------------
  4213                              <1> ; SCROLL UP
  4214                              <1> ;	THIS ROUTINE MOVES A BLOCK OF CHARACTERS UP
  4215                              <1> ;	ON THE SCREEN
  4216                              <1> ; INPUT
  4217                              <1> ;	(AH) = CURRENT CRT MODE
  4218                              <1> ;	(AL) = NUMBER OF ROWS TO SCROLL
  4219                              <1> ;	(CX) = ROW/COLUMN OF UPPER LEFT CORNER
  4220                              <1> ;	(DX) = ROW/COLUMN OF LOWER RIGHT CORNER
  4221                              <1> ;	(BH) = ATTRIBUTE TO BE USED ON BLANKED LINE
  4222                              <1> ;	(DS) = DATA SEGMENT
  4223                              <1> ;	(ES) = REGEN BUFFER SEGMENT
  4224                              <1> ; OUTPUT
  4225                              <1> ;	NONE -- THE REGEN BUFFER IS MODIFIED
  4226                              <1> ;--------------------------------------------
  4227                              <1> 
  4228 00001603 E805000000          <1> 	call	_scroll_up
  4229 00001608 E9E4FEFFFF          <1>         jmp     VIDEO_RETURN
  4230                              <1> 
  4231                              <1> _scroll_up:  ; from 'write_tty'
  4232                              <1> 	;
  4233                              <1> 	; ((ah = 3))
  4234                              <1> 	; cl = left upper column
  4235                              <1> 	; ch = left upper row
  4236                              <1> 	; dl = right lower column
  4237                              <1> 	; dh = right lower row
  4238                              <1> 	;
  4239                              <1> 	; al = line count 
  4240                              <1> 	; ah = attribute to be used on blanked line	
  4241                              <1> 	; bl = video page number (0 to 7)
  4242                              <1> 	; 
  4243                              <1> 
  4244 0000160D E86C000000          <1> 	call	test_line_count ; 16/01/2016
  4245                              <1> 
  4246                              <1> 	;mov	bh, [CRT_MODE] ; current video mode	
  4247                              <1> 	;cmp	bh, 4
  4248                              <1>  	;jb	short n1
  4249                              <1> 
  4250                              <1> 	;cmp	bh, 7 ; TEST FOR BW CARD
  4251                              <1> 	;jne	GRAPHICS_UP
  4252                              <1> n1:
  4253 00001612 30FF                <1> 	xor	bh, bh	; 0
  4254 00001614 6650                <1> 	push	ax ; *
  4255                              <1> 	;mov 	esi, [CRT_BASE]
  4256 00001616 BE00800B00          <1>         mov     esi, 0B8000h  
  4257 0000161B 3A1D[18BE0000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4258 00001621 750B                <1> 	jne	short n2
  4259                              <1> 	;
  4260 00001623 66A1[04BE0000]      <1>         mov     ax, [CRT_START]
  4261 00001629 6601C6              <1>         add     si, ax
  4262 0000162C EB0F                <1>         jmp     short n4
  4263                              <1> n2:
  4264 0000162E 20DB                <1>         and     bl, bl
  4265 00001630 740B                <1> 	jz	short n4
  4266 00001632 88D8                <1> 	mov	al, bl
  4267                              <1> n3:
  4268                              <1>         ;add    si, [CRT_LEN]
  4269                              <1>         ;add    esi, 80*25*2 
  4270 00001634 6681C6A00F          <1>         add     si, 80*25*2
  4271 00001639 FEC8                <1>         dec	al
  4272 0000163B 75F7                <1> 	jnz	short n3
  4273                              <1> n4:	
  4274 0000163D E84D000000          <1> 	call	scroll_position ; 16/01/2016
  4275 00001642 7419                <1>         jz      short n6 
  4276                              <1> 
  4277 00001644 01CE                <1>         add     esi, ecx ; from address for scroll
  4278 00001646 88F7                <1> 	mov	bh, dh  ; #rows in block
  4279 00001648 28C7                <1> 	sub	bh, al	; #rows to be moved
  4280                              <1> n5:
  4281 0000164A E880000000          <1> 	call	n10 ; 16/01/2016
  4282                              <1> 	
  4283                              <1>         ;mov    cl, [CRT_COLS] 
  4284                              <1> 	;add	cl, cl
  4285                              <1>         ;mov    ecx, 80*2
  4286 0000164F 66B9A000            <1>         mov     cx, 80*2
  4287 00001653 01CE                <1>         add     esi, ecx  ; next line
  4288 00001655 01CF                <1>         add     edi, ecx
  4289 00001657 FECF                <1> 	dec	bh	 ; count of lines to move
  4290 00001659 75EF                <1> 	jnz	short n5 ; row loop
  4291                              <1> 	; bh = 0
  4292 0000165B 88C6                <1> 	mov	dh, al	 ; #rows	
  4293                              <1> n6:
  4294                              <1> 	; attribute in ah
  4295 0000165D B020                <1> 	mov	al, ' '	 ; fill with blanks
  4296                              <1> n7:
  4297 0000165F E878000000          <1> 	call	n11 ; 16/01/2016
  4298                              <1> 
  4299                              <1> 	;mov	cl, [CRT_COLS]
  4300                              <1> 	;add	cl, cl
  4301                              <1>         ;mov    ecx, 80*2
  4302 00001664 66B9A000            <1>         mov	cx, 80*2
  4303 00001668 01CF                <1>         add     edi, ecx
  4304 0000166A FECE                <1> 	dec	dh
  4305 0000166C 75F1                <1> 	jnz	short n7
  4306                              <1> 	;
  4307 0000166E 3A1D[18BE0000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4308 00001674 7507                <1> 	jne	short n8
  4309                              <1> 	;mov	al, [CRT_MODE_SET] ; get the value of mode set
  4310 00001676 B029                <1> 	mov	al, 29h ; (ORGS.ASM), M7 mode set table value for mode 3	
  4311 00001678 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  4312 0000167C EE                  <1> 	out	dx, al
  4313                              <1> n8:
  4314 0000167D C3                  <1> 	retn
  4315                              <1> 
  4316                              <1> 
  4317                              <1> test_line_count:
  4318                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4319                              <1> 	; 07/09/2014 (scroll_up)
  4320 0000167E 08C0                <1> 	or	al, al
  4321 00001680 740C                <1> 	jz	short al_set
  4322 00001682 88F7                <1> 	mov	bh, dh	; subtract lower row from upper row
  4323 00001684 28EF                <1> 	sub	bh, ch
  4324 00001686 FEC7                <1> 	inc	bh	; adjust difference by 1
  4325 00001688 38C7                <1> 	cmp	bh, al 	; line count = amount of rows in window?
  4326 0000168A 7502                <1> 	jne	short al_set ; if not the we're all set
  4327 0000168C 30C0                <1> 	xor	al, al	; otherwise set al to zero
  4328                              <1> al_set:
  4329 0000168E C3                  <1> 	retn
  4330                              <1> 
  4331                              <1> scroll_position:
  4332                              <1> 	; 30/01/2016
  4333                              <1>         ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4334                              <1> 	; 07/09/2014 (scroll_up)
  4335                              <1> 
  4336 0000168F 6652                <1> 	push	dx
  4337 00001691 6689CA              <1> 	mov	dx, cx	; now, upper left position in DX
  4338 00001694 E82FFFFFFF          <1> 	call	position
  4339 00001699 01C6                <1> 	add	esi, eax
  4340 0000169B 89F7                <1> 	mov	edi, esi
  4341 0000169D 665A                <1> 	pop	dx	; lower right position in DX
  4342 0000169F 6629CA              <1> 	sub	dx, cx
  4343 000016A2 FEC6                <1> 	inc	dh	; dh = #rows 
  4344 000016A4 FEC2                <1> 	inc	dl	; dl = #cols in block
  4345 000016A6 59                  <1> 	pop	ecx 	; return address
  4346 000016A7 6658                <1> 	pop	ax	; * ; al = line count, ah = attribute
  4347 000016A9 51                  <1> 	push	ecx	; return address
  4348 000016AA 0FB7C8              <1> 	movzx	ecx, ax
  4349                              <1> 	;mov	ah, [CRT_COLS]
  4350 000016AD B450                <1> 	mov	ah, 80
  4351 000016AF F6E4                <1> 	mul	ah	; determine offset to from address
  4352 000016B1 6601C0              <1> 	add	ax, ax  ; *2 for attribute byte
  4353                              <1> 	;
  4354 000016B4 6650                <1> 	push	ax	; offset 
  4355 000016B6 6652                <1> 	push	dx
  4356                              <1> 	;
  4357                              <1> 	; 04/04/2014
  4358 000016B8 66BADA03            <1> 	mov	dx, 3DAh ; guaranteed to be color card here	
  4359                              <1> n9:                      ; wait_display_enable
  4360 000016BC EC                  <1>         in      al, dx   ; get port
  4361 000016BD A808                <1> 	test	al, RVRT ; wait for vertical retrace	
  4362 000016BF 74FB                <1> 	jz	short n9 ; wait_display_enable
  4363 000016C1 B025                <1> 	mov	al, 25h
  4364 000016C3 B2D8                <1> 	mov	dl, 0D8h ; address control port
  4365 000016C5 EE                  <1> 	out	dx, al	; turn off video during vertical retrace
  4366 000016C6 665A                <1> 	pop	dx	; #rows, #cols
  4367 000016C8 6658                <1>        	pop	ax	; offset
  4368 000016CA 6691                <1> 	xchg	ax, cx	; 
  4369                              <1> 	; ecx = offset, al = line count, ah = attribute
  4370                              <1> 	;
  4371 000016CC 08C0                <1> 	or	al, al
  4372 000016CE C3                  <1> 	retn
  4373                              <1> 
  4374                              <1> n10:
  4375                              <1> 	; Move rows
  4376 000016CF 88D1                <1> 	mov	cl, dl	; get # of cols to move
  4377 000016D1 56                  <1> 	push	esi
  4378 000016D2 57                  <1> 	push	edi	; save start address
  4379                              <1> n10r:
  4380 000016D3 66A5                <1> 	movsw		; move that line on screen
  4381 000016D5 FEC9                <1> 	dec	cl
  4382 000016D7 75FA                <1>         jnz     short n10r
  4383 000016D9 5F                  <1> 	pop	edi
  4384 000016DA 5E                  <1> 	pop	esi	; recover addresses
  4385 000016DB C3                  <1> 	retn
  4386                              <1> n11:
  4387                              <1> 	; Clear rows
  4388                              <1>                 ; dh =  #rows
  4389 000016DC 88D1                <1>         mov	cl, dl	; get # of cols to clear
  4390 000016DE 57                  <1>         push    edi     ; save address
  4391                              <1> n11r:
  4392 000016DF 66AB                <1>         stosw           ; store fill character
  4393 000016E1 FEC9                <1> 	dec	cl
  4394 000016E3 75FA                <1>         jnz     short n11r
  4395 000016E5 5F                  <1>         pop     edi     ; recover address
  4396 000016E6 C3                  <1> 	retn
  4397                              <1> 
  4398                              <1> SCROLL_DOWN:
  4399                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4400                              <1> 	;
  4401                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4402                              <1> 
  4403                              <1> ;------------------------------------------
  4404                              <1> ; SCROLL DOWN
  4405                              <1> ;	THIS ROUTINE MOVES THE CHARACTERS WITHIN A DEFINED
  4406                              <1> ;	BLOCK DOWN ON THE SCREEN, FILLING THE TOP LINES
  4407                              <1> ;	WITH A DEFINED CHARACTER
  4408                              <1> ; INPUT
  4409                              <1> ;	(AH) = CURRENT CRT MODE
  4410                              <1> ;	(AL) = NUMBER OF LINES TO SCROLL
  4411                              <1> ;	(CX) = UPPER LEFT CORNER OF RECION
  4412                              <1> ;	(DX) = LOWER RIGHT CORNER OF REGION
  4413                              <1> ;	(BH) = FILL CHARACTER
  4414                              <1> ;	(DS) = DATA SEGMENT
  4415                              <1> ;	(ES) = REGEN SEGMENT
  4416                              <1> ; OUTPUT
  4417                              <1> ;	NONE -- SCREEN IS SCROLLED
  4418                              <1> ;------------------------------------------
  4419                              <1> 
  4420                              <1> 	; ((ah = 3))
  4421                              <1> 	; cl = left upper column
  4422                              <1> 	; ch = left upper row
  4423                              <1> 	; dl = right lower column
  4424                              <1> 	; dh = right lower row
  4425                              <1> 	;
  4426                              <1> 	; al = line count 
  4427                              <1> 	; ah = attribute to be used on blanked line	
  4428                              <1> 	; bl = video page number (0 to 7)
  4429                              <1> 	; 
  4430                              <1> 
  4431                              <1> 	; !!!!
  4432 000016E7 FD                  <1> 	std		; DIRECTION FOR SCROLL DOWN
  4433                              <1> 	; !!!!
  4434 000016E8 E891FFFFFF          <1> 	call	test_line_count ; 16/01/2016
  4435                              <1> 	
  4436                              <1> 	;mov	bh, [CRT_MODE] ; current video mode
  4437                              <1> 	;cmp	bh, 4
  4438                              <1>  	;jb	short n12
  4439                              <1> 
  4440                              <1> 	;cmp	bh, 7 ; TEST FOR BW CARD
  4441                              <1> 	;jne	GRAPHICS_DOWN
  4442                              <1> 
  4443                              <1> n12:			; CONTINUE_DOWN
  4444 000016ED 6650                <1> 	push	ax	; * ; save attribute in ah
  4445 000016EF 6689D0              <1> 	mov	ax, dx	; LOWER RIGHT CORNER
  4446 000016F2 E898FFFFFF          <1> 	call	scroll_position	; GET REGEN LOCATION
  4447 000016F7 7419                <1> 	jz	short n14
  4448 000016F9 29CE                <1> 	sub	esi, ecx  ; SI IS FROM ADDRESS
  4449 000016FB 88F7                <1> 	mov	bh, dh  ; #rows in block
  4450 000016FD 28C7                <1> 	sub	bh, al	; #rows to be moved
  4451                              <1> n13:
  4452 000016FF E8CBFFFFFF          <1> 	call	n10	; MOVE ONE ROW
  4453                              <1> 
  4454                              <1> 	;mov    cl, [CRT_COLS] 
  4455                              <1> 	;add	cl, cl
  4456                              <1>         ;mov    ecx, 80*2
  4457 00001704 66B9A000            <1>         mov     cx, 80*2
  4458 00001708 29CE                <1>         sub     esi, ecx  ; next line
  4459 0000170A 29CF                <1>         sub     edi, ecx
  4460 0000170C FECF                <1> 	dec	bh	 ; count of lines to move
  4461 0000170E 75EF                <1> 	jnz	short n13 ; row loop
  4462                              <1> 	; bh = 0
  4463 00001710 88C6                <1> 	mov	dh, al	 ; #rows
  4464                              <1> n14:
  4465                              <1> 	; attribute in ah
  4466 00001712 B020                <1> 	mov	al, ' '	 ; fill with blanks
  4467                              <1> n15:
  4468 00001714 E8C3FFFFFF          <1> 	call	n11 ; 16/01/2016
  4469                              <1> 
  4470                              <1> 	;mov	cl, [CRT_COLS]
  4471                              <1> 	;add	cl, cl
  4472                              <1>         ;mov    ecx, 80*2
  4473 00001719 B1A0                <1>         mov	cl, 80*2
  4474 0000171B 29CF                <1>         sub     edi, ecx
  4475 0000171D FECE                <1> 	dec	dh
  4476 0000171F 75F3                <1> 	jnz	short n15
  4477                              <1> 	;
  4478 00001721 3A1D[18BE0000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4479 00001727 7507                <1> 	jne	short n16
  4480                              <1> 	;mov	al, [CRT_MODE_SET] ; get the value of mode set
  4481 00001729 B029                <1> 	mov	al, 29h ; (ORGS.ASM), M7 mode set table value for mode 3	
  4482 0000172B 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  4483 0000172F EE                  <1> 	out	dx, al
  4484                              <1> n16:
  4485                              <1> 	; !!!!
  4486 00001730 FC                  <1> 	cld		; Clear direction flag !
  4487                              <1> 	; !!!!
  4488 00001731 C3                  <1> 	retn
  4489                              <1> 
  4490                              <1> READ_AC_CURRENT:
  4491                              <1> 	; 18/01/2016
  4492                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4493                              <1> 	;
  4494                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4495                              <1> 	;
  4496                              <1> 
  4497 00001732 E805000000          <1> 	call	_read_ac_current
  4498 00001737 E9B5FDFFFF          <1>         jmp     VIDEO_RETURN
  4499                              <1> 
  4500                              <1> ;------------------------------------------------------------------------
  4501                              <1> ; READ_AC_CURRENT							:
  4502                              <1> ;	THIS ROUTINE READS THE ATTRIBUTE AND CHARACTER AT THE CURRENT	:
  4503                              <1> ;	CURSOR POSITION AND RETURNS THEM TO THE CALLER			:
  4504                              <1> ; INPUT									:
  4505                              <1> ;	(AH) = CURRENT CRT MODE						:
  4506                              <1> ;	(BH) = DISPLAY PAGE ( ALPHA MODES ONLY )			:
  4507                              <1> ;	(DS) = DATA SEGMENT						:
  4508                              <1> ;	(ES) = REGEN SEGMENT						:
  4509                              <1> ; OUTPUT								:
  4510                              <1> ;	(AL) = CHARACTER READ						:
  4511                              <1> ;	(AH) = ATTRIBUTE READ						:
  4512                              <1> ;------------------------------------------------------------------------
  4513                              <1> 
  4514                              <1> _read_ac_current: ; 18/01/2016
  4515                              <1> 
  4516                              <1> p10:
  4517 0000173C E896FEFFFF          <1> 	call	find_position	; GET REGEN LOCATION AND PORT ADDRESS
  4518                              <1> 	;
  4519                              <1> 	; esi = regen location
  4520                              <1> 	; dx = status port
  4521                              <1> 	;
  4522                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE
  4523                              <1> 	;
  4524                              <1> p11:			; wait for horizontal retrace is low or vertical
  4525 00001741 FB                  <1> 	sti		; enable interrupts first
  4526 00001742 3A1D[18BE0000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4527 00001748 750C                <1> 	jne	short p14 
  4528 0000174A FA                  <1> 	cli 		; block interrupts for single loop
  4529 0000174B EC                  <1> 	in	al, dx	; get status from the adapter
  4530 0000174C A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  4531 0000174E 75F1                <1> 	jnz	short p11 ; wait until it is
  4532                              <1> p12:			;  wait for either retrace high
  4533 00001750 EC                  <1> 	in	al, dx ; get status again
  4534 00001751 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  4535 00001753 74FB                <1> 	jz	short p12 ; wait until either retrace active
  4536 00001755 FB                  <1> 	sti
  4537                              <1> p14:
  4538 00001756 81C600800B00        <1> 	add	esi, 0B8000h 
  4539 0000175C 668B06              <1> 	mov	ax, [esi]
  4540                              <1> 
  4541 0000175F C3                  <1> 	retn	; 18/01/2016
  4542                              <1> 
  4543                              <1> 
  4544                              <1> WRITE_AC_CURRENT:
  4545                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4546                              <1> 	;
  4547                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4548                              <1> 	;
  4549                              <1> ;----------------------------------------------------------------
  4550                              <1> ; WRITE_AC_CURRENT						:
  4551                              <1> ;	THTS ROUTINE WRITES THE ATTRIBUTE AND CHARACTER		:
  4552                              <1> ;	AT THE CURRENT CURSOR POSITION				:
  4553                              <1> ; INPUT								:
  4554                              <1> ;	(AH) = CURRENT CRT MODE					:
  4555                              <1> ;	(BH) = DISPLAY PAGE					:
  4556                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  4557                              <1> ;	(AL) = CHAR TO WRITE					:
  4558                              <1> ;	(BL) = ATTRIBUTE OF CHAR TO WRITE			:
  4559                              <1> ;	(DS) = DATA SEGMENT					:
  4560                              <1> ;	(ES) = REGEN SEGMENT					:
  4561                              <1> ; OUTPUT							:
  4562                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  4563                              <1> ;----------------------------------------------------------------
  4564                              <1> 
  4565 00001760 E821000000          <1> 	call	_write_c_current
  4566                              <1> 
  4567 00001765 0FB6F3              <1> 	movzx	esi, bl ; video page number (0 to 7)	
  4568 00001768 88A6[28B80000]      <1> 	mov	[esi+chr_attrib], ah ; color/attribute
  4569                              <1> 
  4570 0000176E E97EFDFFFF          <1>         jmp     VIDEO_RETURN
  4571                              <1> 
  4572                              <1> WRITE_C_CURRENT:
  4573                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4574                              <1> 	;
  4575                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4576                              <1> 	;
  4577                              <1> 
  4578                              <1> 	;and	bl, 7 ; video page number (<= 7)
  4579 00001773 0FB6F3              <1> 	movzx	esi, bl	
  4580 00001776 8AA6[28B80000]      <1> 	mov	ah, [esi+chr_attrib]
  4581                              <1> 
  4582 0000177C E805000000          <1> 	call	_write_c_current
  4583 00001781 E96BFDFFFF          <1>         jmp     VIDEO_RETURN
  4584                              <1> 
  4585                              <1> ;----------------------------------------------------------------
  4586                              <1> ; WRITE_C_CURRENT						:
  4587                              <1> ;	THIS ROUTINE WRITES THE CHARACTER AT			:
  4588                              <1> ;	THE CURRENT CURSOR POSITION, ATTRIBUTE UNCHANGED	:
  4589                              <1> ; INPUT								:
  4590                              <1> ;	(AH) = CURRENT CRT MODE					:
  4591                              <1> ;	(BH) = DISPLAY PAGE					:
  4592                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  4593                              <1> ;	(AL) = CHAR TO WRITE					:
  4594                              <1> ;	(DS) = DATA SEGMENT					:
  4595                              <1> ;	(ES) = REGEN SEGMENT					:
  4596                              <1> ; OUTPUT							:
  4597                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  4598                              <1> ;----------------------------------------------------------------
  4599                              <1> 
  4600                              <1> _write_c_current:  ; from 'write_tty'
  4601                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4602                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4603                              <1> 	; 18/01/2014
  4604                              <1> 	; 04/12/2013
  4605                              <1> 	;
  4606                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4607                              <1> 	;
  4608                              <1> 
  4609 00001786 FA                  <1> 	cli		
  4610                              <1> 	; bl = video page
  4611                              <1> 	; al = character
  4612                              <1> 	; ah = color/attribute
  4613 00001787 6652                <1> 	push	dx
  4614 00001789 6650                <1> 	push	ax	; save character & attribute/color
  4615 0000178B E847FEFFFF          <1> 	call 	find_position  ; get regen location and port address
  4616                              <1> 	; esi = regen location
  4617                              <1> 	; dx = status port
  4618                              <1> 	;
  4619                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE
  4620                              <1> 	;
  4621                              <1> p41:			; wait for horizontal retrace is low or vertical
  4622 00001790 FB                  <1> 	sti		; enable interrupts first
  4623 00001791 3A1D[18BE0000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4624 00001797 7510                <1> 	jne	short p44 
  4625 00001799 FA                  <1> 	cli 		; block interrupts for single loop
  4626 0000179A EC                  <1> 	in	al, dx	; get status from the adapter
  4627 0000179B A808                <1> 	test	al, RVRT ; check for vertical retrace first
  4628 0000179D 7509                <1> 	jnz	short p43 ; Do fast write now if vertical retrace
  4629 0000179F A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  4630 000017A1 75ED                <1> 	jnz	short p41 ; wait until it is
  4631                              <1> p42:			;  wait for either retrace high
  4632 000017A3 EC                  <1> 	in	al, dx ; get status again
  4633 000017A4 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  4634 000017A6 74FB                <1> 	jz	short p42 ; wait until either retrace active
  4635                              <1> p43:	
  4636 000017A8 FB                  <1> 	sti
  4637                              <1> p44:
  4638 000017A9 6658                <1> 	pop	ax	; restore the character (al) & attribute (ah)
  4639 000017AB 81C600800B00        <1> 	add	esi, 0B8000h ; 30/08/2014 (crt_base) 
  4640                              <1> 				; Retro UNIX 386 v1 feature only!
  4641 000017B1 668906              <1> 	mov	[esi], ax
  4642 000017B4 665A                <1> 	pop	dx
  4643 000017B6 C3                  <1> 	retn
  4644                              <1> 
  4645                              <1> ; 18/01/2016
  4646                              <1> ; 16/01/2016
  4647                              <1> ; 30/06/2015
  4648                              <1> ; 27/06/2015
  4649                              <1> ; 11/03/2015
  4650                              <1> ; 02/09/2014
  4651                              <1> ; 30/08/2014
  4652                              <1> ; VIDEO FUNCTIONS
  4653                              <1> ; (write_tty - Retro UNIX 8086 v1 - U9.ASM, 01/02/2014)
  4654                              <1> 
  4655                              <1> WRITE_TTY:
  4656                              <1> 	; 30/01/2016
  4657                              <1> 	; 18/01/2016
  4658                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4659                              <1> 	; 13/08/2015
  4660                              <1> 	; 02/09/2014
  4661                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  4662                              <1> 	; 01/02/2014 (Retro UNIX 8086 v1 - last update)
  4663                              <1> 	; 03/12/2013 (Retro UNIX 8086 v1 - beginning)	
  4664                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
  4665                              <1> 	;
  4666                              <1> 	; INPUT -> AH = Color (Forecolor, Backcolor)
  4667                              <1> 	;	   AL = Character to be written
  4668                              <1> 	;	   EBX = Video Page (0 to 7)
  4669                              <1> 	;	   (BH = 0 --> Video Mode 3)
  4670                              <1> 
  4671                              <1> RVRT	equ	00001000b	; VIDEO VERTICAL RETRACE BIT
  4672                              <1> RHRZ	equ	00000001b	; VIDEO HORIZONTAL RETRACE BIT
  4673                              <1> 
  4674                              <1> ; Derived from "WRITE_TTY" procedure of IBM "pc-at" rombios source code
  4675                              <1> ; (06/10/1985), 'video.asm', INT 10H, VIDEO_IO
  4676                              <1> ;
  4677                              <1> ; 06/10/85  VIDEO DISPLAY BIOS
  4678                              <1> ;
  4679                              <1> ;--- WRITE_TTY ------------------------------------------------------------------
  4680                              <1> ;										:
  4681                              <1> ;   THIS INTERFACE PROVIDES A TELETYPE LIKE INTERFACE TO THE			:
  4682                              <1> ;   VIDEO CARDS. THE INPUT CHARACTER IS WRITTEN TO THE CURRENT			:
  4683                              <1> ;   CURSOR POSITION, AND THE CURSOR IS MOVED TO THE NEXT POSITION.		:
  4684                              <1> ;   IF THE CURSOR LEAVES THE LAST COLUMN OF THE FIELD, THE COLUMN		:
  4685                              <1> ;   IS SET TO ZERO, AND THE ROW VALUE IS INCREMENTED. IF THE ROW		:
  4686                              <1> ;   ROW VALUE LEAVES THE FIELD, THE CURSOR IS PLACED ON THE LAST ROW,		:
  4687                              <1> ;   FIRST COLUMN, AND THE ENTIRE SCREEN IS SCROLLED UP ONE LINE.		:
  4688                              <1> ;   WHEN THE SCREEN IS SCROLLED UP, THE ATTRIBUTE FOR FILLING THE		:
  4689                              <1> ;   NEWLY BLANKED LINE IS READ FROM THE CURSOR POSITION ON THE PREVIOUS		:
  4690                              <1> ;   LINE BEFORE THE SCROLL, IN CHARACTER MODE. IN GRAPHICS MODE,		:
  4691                              <1> ;   THE 0 COLOR IS USED.							:
  4692                              <1> ;   ENTRY --									:
  4693                              <1> ;     (AH) = CURRENT CRT MODE							:
  4694                              <1> ;     (AL) = CHARACTER TO BE WRITTEN						:
  4695                              <1> ;	    NOTE THAT BACK SPACE, CARRIAGE RETURN, BELL AND LINE FEED ARE	:
  4696                              <1> ;	    HANDLED AS COMMANDS RATHER THAN AS DISPLAY GRAPHICS CHARACTERS	:
  4697                              <1> ;     (BL) = FOREGROUND COLOR FOR CHAR WRITE IF CURRENTLY IN A GRAPHICS MODE	:
  4698                              <1> ;   EXIT -- 									:
  4699                              <1> ;     ALL REGISTERS SAVED							:
  4700                              <1> ;--------------------------------------------------------------------------------
  4701                              <1> 
  4702 000017B7 FA                  <1> 	cli
  4703                              <1> 	;
  4704                              <1> 	; READ CURSOR (04/12/2013)
  4705                              <1> 	; Retro UNIX 386 v1 Modifications: 30/08/2014
  4706 000017B8 08FF                <1> 	or	bh, bh
  4707 000017BA 0F85D5000000        <1> 	jnz	beeper
  4708                              <1> 	; 01/09/2014
  4709 000017C0 803D[16B80000]03    <1> 	cmp	byte [CRT_MODE], 3
  4710 000017C7 7405                <1> 	je	short m3
  4711                              <1> 	;
  4712 000017C9 E8FBFCFFFF          <1> 	call	set_mode_3 ; 16/01/2016
  4713                              <1> m3:
  4714 000017CE 89DE                <1> 	mov 	esi, ebx ; 13/08/2015 (0 to 7)
  4715 000017D0 66D1E6              <1> 	shl	si, 1
  4716 000017D3 81C6[08BE0000]      <1> 	add	esi, CURSOR_POSN
  4717 000017D9 668B16              <1> 	mov	dx, [esi]
  4718                              <1> 	;
  4719                              <1> 	; dx now has the current cursor position
  4720                              <1> 	;
  4721 000017DC 3C0D                <1> 	cmp	al, 0Dh		; is it carriage return or control character
  4722 000017DE 762F                <1> 	jbe	short u8
  4723                              <1> 	;
  4724                              <1> 	; write the char to the screen
  4725                              <1> u0:	
  4726                              <1> 	; ah = attribute/color
  4727                              <1> 	; al = character
  4728                              <1> 	; bl = video page number (0 to 7)
  4729                              <1> 	; bh = 0
  4730                              <1> 	;
  4731 000017E0 E8A1FFFFFF          <1> 	call	_write_c_current ; 16/01/2015
  4732                              <1> 	;
  4733                              <1> 	; position the cursor for next char
  4734 000017E5 FEC2                <1> 	inc	dl		; next column
  4735                              <1> 	;cmp	dl, [CRT_COLS]
  4736 000017E7 80FA50              <1> 	cmp	dl, 80		; test for column overflow 
  4737 000017EA 755F                <1>         jne     _set_cpos
  4738 000017EC B200                <1> 	mov	dl, 0		; column = 0
  4739                              <1> u10:				; (line feed found)
  4740 000017EE 80FE18              <1> 	cmp	dh, 25-1 	; check for last row
  4741 000017F1 7218                <1> 	jb 	short u6
  4742                              <1> 	;
  4743                              <1> 	; scroll required
  4744                              <1> u1:	
  4745                              <1> 	; SET CURSOR POSITION (04/12/2013)
  4746 000017F3 E853000000          <1> 	call	_set_cpos
  4747                              <1> 	;
  4748                              <1> 	; determine value to fill with during scroll
  4749                              <1> u2:
  4750                              <1> 	; bl = video page number
  4751                              <1> 	;
  4752 000017F8 E83FFFFFFF          <1> 	call _read_ac_current ; 18/01/2016
  4753                              <1> 	;
  4754                              <1> 	; al = character, ah = attribute
  4755                              <1> 	; bl = video page number 	
  4756                              <1> u3:
  4757                              <1> 	;;mov	ax, 0601h 	; scroll one line
  4758                              <1> 	;;sub	cx, cx		; upper left corner
  4759                              <1> 	;;mov	dh, 25-1 	; lower right row
  4760                              <1> 	;;;mov	dl, [CRT_COLS]
  4761                              <1> 	;mov	dl, 80		; lower right column	
  4762                              <1> 	;;dec	dl
  4763                              <1> 	;;mov	dl, 79
  4764                              <1> 
  4765                              <1> 	;;call	scroll_up	; 04/12/2013
  4766                              <1> 	;;; 11/03/2015
  4767                              <1> 	; 02/09/2014
  4768                              <1> 	;;;mov	cx, [crt_ulc] ; Upper left corner  (0000h)
  4769                              <1> 	;;;mov	dx, [crt_lrc] ; Lower right corner (184Fh)
  4770                              <1> 	; 11/03/2015
  4771 000017FD 6629C9              <1> 	sub	cx, cx
  4772 00001800 66BA4F18            <1> 	mov	dx, 184Fh ; dl = 79 (column), dh = 24 (row)
  4773                              <1> 	;
  4774 00001804 B001                <1> 	mov	al, 1		; scroll 1 line up
  4775                              <1> 		; ah = attribute
  4776 00001806 E902FEFFFF          <1> 	jmp	_scroll_up	; 16/01/2016
  4777                              <1> ;u4:
  4778                              <1> 	;;int	10h		; video-call return
  4779                              <1> 				; scroll up the screen
  4780                              <1> 				; tty return
  4781                              <1> ;u5:
  4782                              <1> 	;retn			; return to the caller
  4783                              <1> 
  4784                              <1> u6:				; set-cursor-inc
  4785 0000180B FEC6                <1> 	inc	dh		; next row
  4786                              <1> 				; set cursor
  4787                              <1> ;u7:					
  4788                              <1> 	;;mov	ah, 02h
  4789                              <1> 	;;jmp	short u4 	; establish the new cursor
  4790                              <1> 	;call	_set_cpos
  4791                              <1> 	;jmp 	short u5
  4792 0000180D EB3C                <1> 	jmp     _set_cpos
  4793                              <1> 
  4794                              <1> 	; check for control characters
  4795                              <1> u8:
  4796 0000180F 7438                <1> 	je	short u9
  4797 00001811 3C0A                <1> 	cmp	al, 0Ah		; is it a line feed (0Ah)
  4798 00001813 74D9                <1> 	je	short u10
  4799 00001815 3C07                <1> 	cmp	al, 07h 	; is it a bell
  4800 00001817 747C                <1> 	je	short u11
  4801 00001819 3C08                <1> 	cmp	al, 08h		; is it a backspace
  4802                              <1> 	;jne	short u0
  4803 0000181B 7424                <1> 	je	short bs	; 12/12/2013
  4804                              <1> 	; 12/12/2013 (tab stop)
  4805 0000181D 3C09                <1> 	cmp	al, 09h		; is it a tab stop
  4806 0000181F 75BF                <1> 	jne	short u0
  4807 00001821 88D0                <1> 	mov	al, dl
  4808 00001823 6698                <1> 	cbw
  4809 00001825 B108                <1> 	mov	cl, 8
  4810 00001827 F6F1                <1> 	div	cl
  4811 00001829 28E1                <1> 	sub	cl, ah
  4812                              <1> ts:
  4813                              <1> 	; 02/09/2014
  4814                              <1> 	; 01/09/2014
  4815 0000182B B020                <1> 	mov	al, 20h
  4816                              <1> tsloop:
  4817 0000182D 6651                <1> 	push	cx
  4818 0000182F 6650                <1> 	push	ax
  4819 00001831 30FF                <1> 	xor 	bh, bh
  4820                              <1> 	;mov	bl, [ACTIVE_PAGE]
  4821 00001833 E896FFFFFF          <1> 	call	m3
  4822 00001838 6658                <1> 	pop	ax  ; ah = attribute/color
  4823 0000183A 6659                <1> 	pop	cx
  4824 0000183C FEC9                <1> 	dec	cl
  4825 0000183E 75ED                <1> 	jnz	short tsloop
  4826 00001840 C3                  <1> 	retn
  4827                              <1> bs:	
  4828                              <1> 	; back space found
  4829                              <1> 
  4830 00001841 08D2                <1> 	or	dl, dl 		; is it already at start of line
  4831                              <1> 	;je	short u7 	; set_cursor
  4832 00001843 7406                <1> 	jz	short _set_cpos
  4833 00001845 664A                <1> 	dec	dx     		; no -- just move it back
  4834                              <1> 	;jmp	short u7
  4835 00001847 EB02                <1> 	jmp	short _set_cpos
  4836                              <1> 
  4837                              <1> 	; carriage return found
  4838                              <1> u9:
  4839 00001849 B200                <1> 	mov	dl, 0 		; move to first column
  4840                              <1> 	;jmp	short u7
  4841                              <1> 	;jmp	short _set_cpos ; 30/01/2016
  4842                              <1> 
  4843                              <1> 	; line feed found
  4844                              <1> ;u10:
  4845                              <1> ;	cmp	dh, 25-1 	; bottom of screen
  4846                              <1> ;	jne	short u6 	; no, just set the cursor
  4847                              <1> ;       jmp     u1              ; yes, scroll the screen
  4848                              <1> 
  4849                              <1> _set_cpos:
  4850                              <1> 	; 27/06/2015
  4851                              <1> 	; 01/09/2014
  4852                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  4853                              <1> 	;
  4854                              <1> 	; 12/12/2013 (Retro UNIX 8086 v1 - last update) 
  4855                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1 - beginning)
  4856                              <1> 	;
  4857                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4858                              <1> 	;
  4859                              <1> ;----------------------------------------------
  4860                              <1> ; SET_CPOS
  4861                              <1> ;	THIS ROUTINE SETS THE CURRENT CURSOR POSITION TO THE
  4862                              <1> ;	NEW X-Y VALUES PASSED
  4863                              <1> ; INPUT
  4864                              <1> ;	DX - ROW,COLUMN OF NEW CURSOR
  4865                              <1> ;	BH - DISPLAY PAGE OF CURSOR
  4866                              <1> ; OUTPUT
  4867                              <1> ;	CURSOR ID SET AT 6845 IF DISPLAY PAGE IS CURRENT DISPLAY
  4868                              <1> ;----------------------------------------------
  4869                              <1> 	;
  4870 0000184B BE[08BE0000]        <1> 	mov	esi, CURSOR_POSN
  4871 00001850 0FB6C3              <1>         movzx   eax, bl	; BL = video page number ; 27/06/2015 (movzx)
  4872                              <1> ;	or	al, al
  4873                              <1> ;	jz	short _set_cpos_0
  4874 00001853 D0E0                <1>         shl     al, 1   ; word offset
  4875 00001855 01C6                <1>         add     esi, eax
  4876                              <1> ;_set_cpos_0:
  4877 00001857 668916              <1> 	mov	[esi], dx ; save the pointer
  4878 0000185A 381D[18BE0000]      <1> 	cmp	[ACTIVE_PAGE], bl
  4879 00001860 7532                <1> 	jne	short m17
  4880                              <1> 	;call	m18	; CURSOR SET
  4881                              <1> ;m17:			; SET_CPOS_RETURN
  4882                              <1> 	; 01/09/2014
  4883                              <1> ;	retn
  4884                              <1> 		; DX  = row/column
  4885                              <1> m18:
  4886 00001862 E861FDFFFF          <1> 	call	position ; determine location in regen buffer	
  4887 00001867 668B0D[04BE0000]    <1> 	mov	cx, [CRT_START]
  4888 0000186E 6601C1              <1> 	add	cx, ax  ; add char position in regen buffer
  4889                              <1> 			; to the start address (offset) for this page
  4890 00001871 66D1E9              <1> 	shr	cx, 1	; divide by 2 for char only count
  4891 00001874 B40E                <1> 	mov	ah, 14	; register number for cursor
  4892                              <1> 	;call	m16	; output value to the 6845	
  4893                              <1> 	;retn
  4894                              <1> 
  4895                              <1> 	;-----	THIS ROUTINE OUTPUTS THE CX REGISTER
  4896                              <1> 	;	TO THE 6845 REGISTERS NAMED IN (AH)
  4897                              <1> m16:
  4898 00001876 FA                  <1> 	cli
  4899                              <1> 	;mov	dx, [addr_6845] ; address register
  4900 00001877 66BAD403            <1> 	mov 	dx, 03D4h ; I/O address of color card
  4901 0000187B 88E0                <1> 	mov	al, ah	; get value
  4902 0000187D EE                  <1> 	out	dx, al	; register set
  4903 0000187E 6642                <1> 	inc	dx	; data register
  4904 00001880 EB00                <1> 	jmp	$+2	; i/o delay
  4905 00001882 88E8                <1> 	mov	al, ch	; data
  4906 00001884 EE                  <1> 	out	dx, al	
  4907 00001885 664A                <1> 	dec	dx	
  4908 00001887 88E0                <1> 	mov	al, ah
  4909 00001889 FEC0                <1> 	inc	al	; point to other data register
  4910 0000188B EE                  <1> 	out	dx, al	; set for second register
  4911 0000188C 6642                <1> 	inc	dx
  4912 0000188E EB00                <1> 	jmp	$+2	; i/o delay
  4913 00001890 88C8                <1> 	mov	al, cl	; second data value
  4914 00001892 EE                  <1> 	out	dx, al
  4915 00001893 FB                  <1> 	sti
  4916                              <1> m17:
  4917 00001894 C3                  <1> 	retn
  4918                              <1> 
  4919                              <1> beeper: 
  4920                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4921                              <1> 	; 18/01/2014
  4922                              <1> 	; 03/12/2013
  4923                              <1> 	; bell found
  4924                              <1> u11:
  4925 00001895 FB                  <1> 	sti
  4926 00001896 3A1D[18BE0000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4927 0000189C 7551                <1> 	jne	short u12	; Do not sound the beep 
  4928                              <1> 				; if it is not written on the active page
  4929 0000189E 66B93305            <1> 	mov	cx, 1331 	; divisor for 896 hz tone
  4930 000018A2 B31F                <1> 	mov	bl, 31		; set count for 31/64 second for beep
  4931                              <1> 	;call	beep		; sound the pod bell
  4932                              <1> 	;jmp	short u5 	; tty_return
  4933                              <1> 	;retn
  4934                              <1> 	
  4935                              <1> TIMER	equ 	040h   		; 8254 TIMER - BASE ADDRESS
  4936                              <1> PORT_B	equ	061h		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  4937                              <1> GATE2	equ	00000001b	; TIMER 2 INPUT CATE CLOCK BIT
  4938                              <1> SPK2	equ	00000010b	; SPEAKER OUTPUT DATA ENABLE BIT
  4939                              <1> 
  4940                              <1> beep:
  4941                              <1> 	; 07/02/2015
  4942                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4943                              <1> 	; 18/01/2014
  4944                              <1> 	; 03/12/2013
  4945                              <1> 	;
  4946                              <1> 	; TEST4.ASM - 06/10/85  POST AND BIOS UTILITY ROUTINES
  4947                              <1> 	;
  4948                              <1> 	; ROUTINE TO SOUND THE BEEPER USING TIMER 2 FOR TONE
  4949                              <1> 	;
  4950                              <1> 	; ENTRY:
  4951                              <1> 	;    (BL) = DURATION COUNTER ( 1 FOR 1/64 SECOND )
  4952                              <1> 	;    (CX) = FREQUENCY DIVISOR (1193180/FREQUENCY) (1331 FOR 886 HZ)
  4953                              <1> 	; EXIT:				:
  4954                              <1> 	;    (AX),(BL),(CX) MODIFIED.
  4955                              <1> 
  4956 000018A4 9C                  <1> 	pushf  ; 18/01/2014	; save interrupt status
  4957 000018A5 FA                  <1> 	cli			; block interrupts during update
  4958 000018A6 B0B6                <1> 	mov	al, 10110110b	; select timer 2, lsb, msb binary
  4959 000018A8 E643                <1> 	out	TIMER+3, al 	; write timer mode register
  4960 000018AA EB00                <1> 	jmp	$+2		; I/O delay
  4961 000018AC 88C8                <1> 	mov	al, cl		; divisor for hz (low)
  4962 000018AE E642                <1> 	out	TIMER+2,AL	; write timer 2 count - lsb
  4963 000018B0 EB00                <1> 	jmp	$+2		; I/O delay
  4964 000018B2 88E8                <1> 	mov	al, ch		; divisor for hz (high)
  4965 000018B4 E642                <1> 	out	TIMER+2, al	; write timer 2 count - msb
  4966 000018B6 E461                <1> 	in	al, PORT_B	; get current setting of port
  4967 000018B8 88C4                <1> 	mov	ah, al		; save that setting
  4968 000018BA 0C03                <1> 	or	al, GATE2+SPK2	; gate timer 2 and turn speaker on
  4969 000018BC E661                <1> 	out	PORT_B, al	; and restore interrupt status
  4970                              <1> 	;popf	; 18/01/2014
  4971 000018BE FB                  <1> 	sti
  4972                              <1> g7:				; 1/64 second per count (bl)
  4973 000018BF B90B040000          <1> 	mov	ecx, 1035	; delay count for 1/64 of a second	
  4974 000018C4 E827000000          <1> 	call	waitf		; go to beep delay 1/64 count
  4975 000018C9 FECB                <1> 	dec	bl		; (bl) length count expired?
  4976 000018CB 75F2                <1> 	jnz	short g7	; no - continue beeping speaker
  4977                              <1> 	;
  4978                              <1> 	;pushf			; save interrupt status
  4979 000018CD FA                  <1> 	cli  	; 18/01/2014	; block interrupts during update
  4980 000018CE E461                <1> 	in	al, PORT_B	; get current port value
  4981                              <1>         ;or      al, not (GATE2+SPK2) ; isolate current speaker bits in case
  4982 000018D0 0CFC                <1>         or      al, ~(GATE2+SPK2)
  4983 000018D2 20C4                <1>         and	ah, al		; someone turned them off during beep
  4984 000018D4 88E0                <1> 	mov	al, ah		; recover value of port
  4985                              <1>         ;or      al, not (GATE2+SPK2) ; force speaker data off
  4986 000018D6 0CFC                <1> 	or 	al, ~(GATE2+SPK2) ; isolate current speaker bits in case
  4987 000018D8 E661                <1> 	out	PORT_B, al	; and stop speaker timer
  4988                              <1> 	;popf			; restore interrupt flag state
  4989 000018DA FB                  <1> 	sti
  4990 000018DB B90B040000          <1> 	mov	ecx, 1035	; force 1/64 second delay (short)
  4991 000018E0 E80B000000          <1> 	call	waitf		; minimum delay between all beeps
  4992                              <1> 	;pushf			; save interrupt status
  4993 000018E5 FA                  <1> 	cli			; block interrupts during update
  4994 000018E6 E461                <1> 	in	al, PORT_B	; get current port value in case	
  4995 000018E8 2403                <1> 	and	al, GATE2+SPK2	; someone turned them on
  4996 000018EA 08E0                <1> 	or	al, ah		; recover value of port_b
  4997 000018EC E661                <1> 	out	PORT_B, al	; restore speaker status
  4998 000018EE 9D                  <1> 	popf			; restore interrupt flag state
  4999                              <1> u12:	
  5000 000018EF C3                  <1> 	retn
  5001                              <1> 
  5002                              <1> REFRESH_BIT equ	00010000b 	; REFRESH TEST BIT
  5003                              <1> 
  5004                              <1> WAITF:
  5005                              <1> waitf:
  5006                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  5007                              <1> 	; 03/12/2013
  5008                              <1> 	;
  5009                              <1> ;	push ax			; save work register (ah)	
  5010                              <1> ;waitf1:
  5011                              <1> 				; use timer 1 output bits
  5012                              <1> ;	in	al, PORT_B	; read current counter output status
  5013                              <1> ;	and	al, REFRESH_BIT	; mask for refresh determine bit
  5014                              <1> ;	cmp	al, ah		; did it just change
  5015                              <1> ;	je	short waitf1	; wait for a change in output line
  5016                              <1> ;	;
  5017                              <1> ;	mov	ah, al		; save new lflag state
  5018                              <1> ;	loop	waitf1		; decrement half cycles till count end		
  5019                              <1> ;	;
  5020                              <1> ;	pop	ax		; restore (ah)
  5021                              <1> ;	retn			; return (cx)=0
  5022                              <1> 
  5023                              <1> ; 06/02/2015 (unix386.s <-- dsectrm2.s)
  5024                              <1> ; 17/12/2014 (dsectrm2.s)
  5025                              <1> ; WAITF
  5026                              <1> ; /// IBM PC-XT Model 286 System BIOS Source Code - Test 4 - 06/10/85 ///
  5027                              <1> ;
  5028                              <1> ;---WAITF-----------------------------------------------------------------------
  5029                              <1> ;	FIXED TIME WAIT ROUTINE (HARDWARE CONTROLLED - NOT PROCESSOR)
  5030                              <1> ; ENTRY:
  5031                              <1> ;	(CX) =	COUNT OF 15.085737 MICROSECOND INTERVALS TO WAIT
  5032                              <1> ;	      	MEMORY REFRESH TIMER 1 OUTPUT USED AS REFERENCE
  5033                              <1> ; EXIT:
  5034                              <1> ;	       	AFTER (CX) TIME COUNT (PLUS OR MINUS 16 MICROSECONDS)
  5035                              <1> ;	(CX) = 0	
  5036                              <1> ;-------------------------------------------------------------------------------
  5037                              <1> 
  5038                              <1> ; Refresh period: 30 micro seconds (15-80 us)
  5039                              <1> ; (16/12/2014 - AWARDBIOS 1999 - ATORGS.ASM, WAIT_REFRESH)
  5040                              <1> 
  5041                              <1> ;WAITF:					; DELAY FOR (CX)*15.085737 US
  5042 000018F0 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER (AH)
  5043                              <1> 	; 16/12/2014
  5044                              <1> 	;shr	cx, 1			; convert to count of 30 micro seconds
  5045 000018F2 D1E9                <1> 	shr	ecx, 1	; 21/02/2015
  5046                              <1> ;17/12/2014	
  5047                              <1> ;WAITF1:
  5048                              <1> ;	IN	AL, PORT_B   ;061h	; READ CURRENT COUNTER OUTPUT STATUS
  5049                              <1> ;	AND	AL, REFRESH_BIT	;00010000b ; MASK FOR REFRESH DETERMINE BIT
  5050                              <1> ;	CMP	AL, AH			; DID IT JUST CHANGE
  5051                              <1> ;	JE	short WAITF1		; WAIT FOR A CHANGE IN OUTPUT LINE
  5052                              <1> ;	MOV	AH, AL			; SAVE NEW FLAG STATE
  5053                              <1> ;	LOOP	WAITF1			; DECREMENT HALF CYCLES TILL COUNT END		
  5054                              <1> 	;
  5055                              <1> 	; 17/12/2014
  5056                              <1> 	;
  5057                              <1> 	; Modification from 'WAIT_REFRESH' procedure of AWARD BIOS - 1999
  5058                              <1> 	;
  5059                              <1> ;WAIT_REFRESH:  Uses port 61, bit 4 to have CPU speed independent waiting.
  5060                              <1> ;   	INPUT:  CX = number of refresh periods to wait
  5061                              <1> ;     	       (refresh periods = 1 per 30 microseconds on most machines)
  5062                              <1> WR_STATE_0:
  5063 000018F4 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  5064 000018F6 A810                <1> 	TEST	AL,010H
  5065 000018F8 74FA                <1> 	JZ	SHORT WR_STATE_0
  5066                              <1> WR_STATE_1:
  5067 000018FA E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  5068 000018FC A810                <1> 	TEST	AL,010H
  5069 000018FE 75FA                <1> 	JNZ	SHORT WR_STATE_1
  5070 00001900 E2F2                <1>         LOOP    WR_STATE_0
  5071                              <1> 	;
  5072 00001902 6658                <1> 	POP	AX			; RESTORE (AH)
  5073 00001904 C3                  <1> 	RETn				; (CX) = 0
  5074                              <1> 
  5075                              <1> ; % include 'vidata.s' ; VIDEO DATA
  5076                              <1> 
  5077                              <1> ; /// End Of VIDEO FUNCTIONS ///
  5078                                  
  5079                                  setup_rtc_int:
  5080                                  ; source: http://wiki.osdev.org/RTC
  5081 00001905 FA                      	cli		; disable interrupts
  5082                                  	; default int frequency is 1024 Hz (Lower 4 bits of register A is 0110b or 6)
  5083                                  	; in order to change this ...
  5084                                  	; frequency  = 32768 >> (rate-1) --> 32768 >> 5 = 1024
  5085                                  	; (rate must be above 2 and not over 15)
  5086                                  	; new rate = 15 --> 32768 >> (15-1) = 2 Hz
  5087 00001906 B08A                    	mov	al, 8Ah 
  5088 00001908 E670                    	out	70h, al ; set index to register A, disable NMI
  5089 0000190A 90                      	nop
  5090 0000190B E471                    	in	al, 71h ; get initial value of register A
  5091 0000190D 88C4                    	mov 	ah, al
  5092 0000190F 80E4F0                  	and	ah, 0F0h
  5093 00001912 B08A                    	mov	al, 8Ah 
  5094 00001914 E670                    	out	70h, al ; reset index to register A
  5095 00001916 88E0                    	mov	al, ah
  5096 00001918 0C0F                    	or	al, 0Fh	; new rate (0Fh -> 15)
  5097 0000191A E671                    	out	71h, al ; write only our rate to A. Note, rate is the bottom 4 bits. 
  5098                                  	; enable RTC interrupt
  5099 0000191C B08B                    	mov	al, 8Bh ;
  5100 0000191E E670                    	out	70h, al ; select register B and disable NMI
  5101 00001920 90                      	nop
  5102 00001921 E471                    	in	al, 71h ; read the current value of register B
  5103 00001923 88C4                    	mov	ah, al  ;
  5104 00001925 B08B                    	mov 	al, 8Bh ;
  5105 00001927 E670                    	out	70h, al ; set the index again (a read will reset the index to register B)	
  5106 00001929 88E0                    	mov	al, ah  ;
  5107 0000192B 0C40                    	or	al, 40h ;
  5108 0000192D E671                    	out	71h, al ; write the previous value ORed with 0x40. This turns on bit 6 of register B
  5109 0000192F FB                      	sti
  5110 00001930 C3                      	retn
  5111                                  
  5112                                  ; Write memory information
  5113                                  ; 29/01/2016
  5114                                  ; 06/11/2014
  5115                                  ; 14/08/2015 
  5116                                  memory_info:	
  5117 00001931 A1[ECBD0000]            	mov	eax, [memory_size] ; in pages
  5118 00001936 50                      	push	eax
  5119 00001937 C1E00C                  	shl	eax, 12		   ; in bytes
  5120 0000193A BB0A000000              	mov	ebx, 10
  5121 0000193F 89D9                    	mov	ecx, ebx	   ; 10
  5122 00001941 BE[37BA0000]            	mov	esi, mem_total_b_str	
  5123 00001946 E8BE000000              	call	bintdstr
  5124 0000194B 58                      	pop	eax
  5125 0000194C B107                    	mov	cl, 7
  5126 0000194E BE[5BBA0000]            	mov	esi, mem_total_p_str
  5127 00001953 E8B1000000              	call	bintdstr	
  5128                                  	; 14/08/2015
  5129 00001958 E8C9000000              	call	calc_free_mem
  5130                                  	; edx = calculated free pages
  5131                                  	; ecx = 0
  5132 0000195D A1[F0BD0000]            	mov 	eax, [free_pages]
  5133 00001962 39D0                    	cmp	eax, edx ; calculated free mem value 
  5134                                  		; and initial free mem value are same or not?
  5135 00001964 751D                    	jne 	short pmim ; print mem info with '?' if not
  5136 00001966 52                      	push 	edx ; free memory in pages	
  5137                                  	;mov 	eax, edx
  5138 00001967 C1E00C                  	shl	eax, 12 ; convert page count
  5139                                  			; to byte count
  5140 0000196A B10A                    	mov	cl, 10
  5141 0000196C BE[7BBA0000]            	mov	esi, free_mem_b_str
  5142 00001971 E893000000              	call	bintdstr
  5143 00001976 58                      	pop	eax
  5144 00001977 B107                    	mov	cl, 7
  5145 00001979 BE[9FBA0000]            	mov	esi, free_mem_p_str
  5146 0000197E E886000000              	call	bintdstr
  5147                                  pmim:
  5148 00001983 BE[25BA0000]            	mov	esi, msg_memory_info
  5149                                  	;
  5150 00001988 B407                    	mov	ah, 07h ; Black background, 
  5151                                  			; light gray forecolor
  5152                                  print_kmsg: ; 29/01/2016
  5153 0000198A 8825[19BE0000]          	mov	[ccolor], ah
  5154                                  pkmsg_loop:
  5155 00001990 AC                      	lodsb
  5156 00001991 08C0                    	or	al, al
  5157 00001993 7411                    	jz	short pkmsg_ok
  5158 00001995 56                      	push	esi
  5159 00001996 31DB                    	xor	ebx, ebx ; 0
  5160                                  			; Video page 0 (bl=0)
  5161 00001998 8A25[19BE0000]          	mov	ah, [ccolor]
  5162 0000199E E814FEFFFF              	call	WRITE_TTY
  5163 000019A3 5E                      	pop	esi
  5164 000019A4 EBEA                    	jmp	short pkmsg_loop
  5165                                  pkmsg_ok:
  5166 000019A6 C3                      	retn
  5167                                  
  5168                                  ; Convert binary number to hexadecimal string
  5169                                  ; 10/05/2015  
  5170                                  ; dsectpm.s (28/02/2015)
  5171                                  ; Retro UNIX 386 v1 - Kernel v0.2.0.6  
  5172                                  ; 01/12/2014
  5173                                  ; 25/11/2014
  5174                                  ;
  5175                                  bytetohex:
  5176                                  	; INPUT ->
  5177                                  	; 	AL = byte (binary number)
  5178                                  	; OUTPUT ->
  5179                                  	;	AX = hexadecimal string
  5180                                  	;
  5181 000019A7 53                      	push	ebx
  5182 000019A8 31DB                    	xor	ebx, ebx
  5183 000019AA 88C3                    	mov	bl, al
  5184 000019AC C0EB04                  	shr	bl, 4
  5185 000019AF 8A9B[F9190000]          	mov	bl, [ebx+hexchrs] 	 	
  5186 000019B5 86D8                    	xchg	bl, al
  5187 000019B7 80E30F                  	and	bl, 0Fh
  5188 000019BA 8AA3[F9190000]          	mov	ah, [ebx+hexchrs] 
  5189 000019C0 5B                      	pop	ebx	
  5190 000019C1 C3                      	retn
  5191                                  
  5192                                  wordtohex:
  5193                                  	; INPUT ->
  5194                                  	; 	AX = word (binary number)
  5195                                  	; OUTPUT ->
  5196                                  	;	EAX = hexadecimal string
  5197                                  	;
  5198 000019C2 53                      	push	ebx
  5199 000019C3 31DB                    	xor	ebx, ebx
  5200 000019C5 86E0                    	xchg	ah, al
  5201 000019C7 6650                    	push	ax
  5202 000019C9 88E3                    	mov	bl, ah
  5203 000019CB C0EB04                  	shr	bl, 4
  5204 000019CE 8A83[F9190000]          	mov	al, [ebx+hexchrs] 	 	
  5205 000019D4 88E3                    	mov	bl, ah
  5206 000019D6 80E30F                  	and	bl, 0Fh
  5207 000019D9 8AA3[F9190000]          	mov	ah, [ebx+hexchrs]
  5208 000019DF C1E010                  	shl	eax, 16
  5209 000019E2 6658                    	pop	ax
  5210 000019E4 5B                      	pop	ebx
  5211 000019E5 EBC0                    	jmp	short bytetohex
  5212                                  	;mov	bl, al
  5213                                  	;shr	bl, 4
  5214                                  	;mov	bl, [ebx+hexchrs] 	 	
  5215                                  	;xchg	bl, al	 	
  5216                                  	;and	bl, 0Fh
  5217                                  	;mov	ah, [ebx+hexchrs] 
  5218                                  	;pop	ebx	
  5219                                  	;retn
  5220                                  
  5221                                  dwordtohex:
  5222                                  	; INPUT ->
  5223                                  	; 	EAX = dword (binary number)
  5224                                  	; OUTPUT ->
  5225                                  	;	EDX:EAX = hexadecimal string
  5226                                  	;
  5227 000019E7 50                      	push	eax
  5228 000019E8 C1E810                  	shr	eax, 16
  5229 000019EB E8D2FFFFFF              	call	wordtohex
  5230 000019F0 89C2                    	mov	edx, eax
  5231 000019F2 58                      	pop	eax
  5232 000019F3 E8CAFFFFFF              	call	wordtohex
  5233 000019F8 C3                      	retn
  5234                                  
  5235                                  ; 10/05/2015
  5236                                  hex_digits:
  5237                                  hexchrs:
  5238 000019F9 303132333435363738-     	db '0123456789ABCDEF'
  5239 00001A02 39414243444546     
  5240                                  
  5241                                  ; Convert binary number to decimal/numeric string
  5242                                  ; 06/11/2014
  5243                                  ; Temporary Code
  5244                                  ;
  5245                                  
  5246                                  bintdstr:
  5247                                  	; EAX = binary number
  5248                                  	; ESI = decimal/numeric string address
  5249                                  	; EBX = divisor (10)
  5250                                  	; ECX = string length (<=10)
  5251 00001A09 01CE                    	add	esi, ecx
  5252                                  btdstr0:
  5253 00001A0B 4E                      	dec	esi
  5254 00001A0C 31D2                    	xor	edx, edx
  5255 00001A0E F7F3                    	div	ebx
  5256 00001A10 80C230                  	add	dl, 30h
  5257 00001A13 8816                    	mov	[esi], dl
  5258 00001A15 FEC9                    	dec	cl
  5259 00001A17 740C                    	jz	btdstr2
  5260 00001A19 09C0                    	or	eax, eax
  5261 00001A1B 75EE                    	jnz	short btdstr0
  5262                                  btdstr1:
  5263 00001A1D 4E                      	dec	esi
  5264 00001A1E C60620                          mov     byte [esi], 20h ; blank space
  5265 00001A21 FEC9                    	dec	cl
  5266 00001A23 75F8                    	jnz	short btdstr1
  5267                                  btdstr2:
  5268 00001A25 C3                      	retn
  5269                                  
  5270                                  ; Calculate free memory pages on M.A.T.
  5271                                  ; 06/11/2014
  5272                                  ; Temporary Code
  5273                                  ;
  5274                                  
  5275                                  calc_free_mem:
  5276 00001A26 31D2                    	xor	edx, edx
  5277                                  	;xor	ecx, ecx
  5278 00001A28 668B0D[00BE0000]        	mov	cx, [mat_size] ; in pages
  5279 00001A2F C1E10A                  	shl	ecx, 10	; 1024 dwords per page
  5280 00001A32 BE00001000              	mov	esi, MEM_ALLOC_TBL
  5281                                  cfm0:
  5282 00001A37 AD                      	lodsd
  5283 00001A38 51                      	push	ecx
  5284 00001A39 B920000000              	mov	ecx, 32
  5285                                  cfm1:
  5286 00001A3E D1E8                    	shr	eax, 1
  5287 00001A40 7301                    	jnc	short cfm2
  5288 00001A42 42                      	inc	edx
  5289                                  cfm2:
  5290 00001A43 E2F9                    	loop	cfm1
  5291 00001A45 59                      	pop	ecx
  5292 00001A46 E2EF                    	loop	cfm0
  5293 00001A48 C3                      	retn
  5294                                  
  5295                                  %include 'diskio.s'  ; 07/03/2015
  5296                              <1> ; ****************************************************************************
  5297                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskio.s
  5298                              <1> ; ----------------------------------------------------------------------------
  5299                              <1> ; Last Update: 18/02/2016
  5300                              <1> ; ----------------------------------------------------------------------------
  5301                              <1> ; Beginning: 24/01/2016
  5302                              <1> ; ----------------------------------------------------------------------------
  5303                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
  5304                              <1> ; ----------------------------------------------------------------------------
  5305                              <1> ; Turkish Rational DOS
  5306                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
  5307                              <1> ;
  5308                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
  5309                              <1> ; diskio.inc (22/08/2015)
  5310                              <1> ;
  5311                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
  5312                              <1> ; ****************************************************************************
  5313                              <1> 
  5314                              <1> ; Retro UNIX 386 v1 Kernel - DISKIO.INC
  5315                              <1> ; Last Modification: 22/08/2015
  5316                              <1> ; 	(Initialized Disk Parameters Data is in 'DISKDATA.INC') 
  5317                              <1> ; 	(Uninitialized Disk Parameters Data is in 'DISKBSS.INC') 
  5318                              <1> 
  5319                              <1> ; DISK I/O SYSTEM - Erdogan Tan (Retro UNIX 386 v1 project)
  5320                              <1> 
  5321                              <1> ; ///////// DISK I/O SYSTEM ///////////////
  5322                              <1> 
  5323                              <1> ; 06/02/2015
  5324                              <1> diskette_io:
  5325 00001A49 9C                  <1> 	pushfd
  5326 00001A4A 0E                  <1> 	push 	cs
  5327 00001A4B E809000000          <1> 	call 	DISKETTE_IO_1
  5328 00001A50 C3                  <1> 	retn
  5329                              <1> 	
  5330                              <1> ;;;;;; DISKETTE I/O ;;;;;;;;;;;;;;;;;;;; 06/02/2015 ;;;
  5331                              <1> ;//////////////////////////////////////////////////////
  5332                              <1> 
  5333                              <1> ; DISKETTE I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  5334                              <1> ; 20/02/2015
  5335                              <1> ; 06/02/2015 (unix386.s)
  5336                              <1> ; 16/12/2014 - 02/01/2015 (dsectrm2.s)
  5337                              <1> ;
  5338                              <1> ; Code (DELAY) modifications - AWARD BIOS 1999 (ADISK.EQU, COMMON.MAC)
  5339                              <1> ;
  5340                              <1> ; ADISK.EQU
  5341                              <1> 
  5342                              <1> ;----- Wait control constants 
  5343                              <1> 
  5344                              <1> ;amount of time to wait while RESET is active.
  5345                              <1> 
  5346                              <1> WAITCPU_RESET_ON	EQU	21		;Reset on must last at least 14us
  5347                              <1> 						;at 250 KBS xfer rate.
  5348                              <1> 						;see INTEL MCS, 1985, pg. 5-456
  5349                              <1> 
  5350                              <1> WAITCPU_FOR_STATUS	EQU	100		;allow 30 microseconds for
  5351                              <1> 						;status register to become valid
  5352                              <1> 						;before re-reading.
  5353                              <1> 
  5354                              <1> ;After sending a byte to NEC, status register may remain
  5355                              <1> ;incorrectly set for 24 us.
  5356                              <1> 
  5357                              <1> WAITCPU_RQM_LOW		EQU	24		;number of loops to check for
  5358                              <1> 						;RQM low.
  5359                              <1> 
  5360                              <1> ; COMMON.MAC
  5361                              <1> ;
  5362                              <1> ;	Timing macros
  5363                              <1> ;
  5364                              <1> 
  5365                              <1> %macro 		SIODELAY 0 			; SHORT IODELAY
  5366                              <1> 		jmp short $+2
  5367                              <1> %endmacro		
  5368                              <1> 
  5369                              <1> %macro		IODELAY  0			; NORMAL IODELAY
  5370                              <1> 		jmp short $+2
  5371                              <1> 		jmp short $+2
  5372                              <1> %endmacro
  5373                              <1> 
  5374                              <1> %macro		NEWIODELAY 0
  5375                              <1> 		out	0ebh,al
  5376                              <1> %endmacro 
  5377                              <1> 
  5378                              <1> ; (According to) AWARD BIOS 1999 - ATORGS.ASM (dw -> equ, db -> equ)
  5379                              <1> ;;; WAIT_FOR_MEM
  5380                              <1> ;WAIT_FDU_INT_LO	equ	017798		; 2.5 secs in 30 micro units.
  5381                              <1> ;WAIT_FDU_INT_HI	equ	1
  5382                              <1> WAIT_FDU_INT_LH		equ	83334		; 27/02/2015 (2.5 seconds waiting)
  5383                              <1> ;;; WAIT_FOR_PORT
  5384                              <1> ;WAIT_FDU_SEND_LO	equ	16667		; .5 secons in 30 us units.
  5385                              <1> ;WAIT_FDU_SEND_HI	equ	0
  5386                              <1> WAIT_FDU_SEND_LH	equ 	16667		; 27/02/2015	
  5387                              <1> ;Time to wait while waiting for each byte of NEC results = .5
  5388                              <1> ;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  5389                              <1> ;WAIT_FDU_RESULTS_LO	equ	16667		; .5 seconds in 30 micro units.
  5390                              <1> ;WAIT_FDU_RESULTS_HI	equ	0
  5391                              <1> WAIT_FDU_RESULTS_LH	equ	16667  ; 27/02/2015
  5392                              <1> ;;; WAIT_REFRESH
  5393                              <1> ;amount of time to wait for head settle, per unit in parameter
  5394                              <1> ;table = 1 ms.
  5395                              <1> WAIT_FDU_HEAD_SETTLE	equ	33		; 1 ms in 30 micro units.
  5396                              <1> 
  5397                              <1> 
  5398                              <1> ; //////////////// DISKETTE I/O ////////////////
  5399                              <1> 
  5400                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - POSTEQU.INC)
  5401                              <1> 
  5402                              <1> ;----------------------------------------
  5403                              <1> ;	EQUATES USED BY POST AND BIOS	:
  5404                              <1> ;----------------------------------------
  5405                              <1> 
  5406                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
  5407                              <1> ;PORT_A		EQU	060H		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
  5408                              <1> ;PORT_B		EQU	061H		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  5409                              <1> ;REFRESH_BIT	EQU	00010000B	; REFRESH TEST BIT
  5410                              <1> 
  5411                              <1> ;----------------------------------------
  5412                              <1> ;	CMOS EQUATES FOR THIS SYSTEM	:
  5413                              <1> ;-------------------------------------------------------------------------------
  5414                              <1> ;CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
  5415                              <1> ;CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
  5416                              <1> ;NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
  5417                              <1> 					;  HIGH BIT OF CMOS LOCATION ADDRESS
  5418                              <1> 
  5419                              <1> ;---------- CMOS TABLE LOCATION ADDRESS'S ## -----------------------------------
  5420                              <1> CMOS_DISKETTE	EQU	010H		; DISKETTE DRIVE TYPE BYTE	      ;
  5421                              <1> ;		EQU	011H		; - RESERVED			      ;C
  5422                              <1> CMOS_DISK	EQU	012H		; FIXED DISK TYPE BYTE		      ;H
  5423                              <1> ;		EQU	013H		; - RESERVED			      ;E
  5424                              <1> CMOS_EQUIP	EQU	014H		; EQUIPMENT WORD LOW BYTE	      ;C
  5425                              <1> 
  5426                              <1> ;---------- DISKETTE EQUATES ---------------------------------------------------
  5427                              <1> INT_FLAG	EQU	10000000B	; INTERRUPT OCCURRENCE FLAG
  5428                              <1> DSK_CHG 	EQU	10000000B	; DISKETTE CHANGE FLAG MASK BIT
  5429                              <1> DETERMINED	EQU	00010000B	; SET STATE DETERMINED IN STATE BITS
  5430                              <1> HOME		EQU	00010000B	; TRACK 0 MASK
  5431                              <1> SENSE_DRV_ST	EQU	00000100B	; SENSE DRIVE STATUS COMMAND
  5432                              <1> TRK_SLAP	EQU	030H		; CRASH STOP (48 TPI DRIVES)
  5433                              <1> QUIET_SEEK	EQU	00AH		; SEEK TO TRACK 10
  5434                              <1> ;MAX_DRV 	EQU	2		; MAX NUMBER OF DRIVES
  5435                              <1> HD12_SETTLE	EQU	15		; 1.2 M HEAD SETTLE TIME
  5436                              <1> HD320_SETTLE	EQU	20		; 320 K HEAD SETTLE TIME
  5437                              <1> MOTOR_WAIT	EQU	37		; 2 SECONDS OF COUNTS FOR MOTOR TURN OFF
  5438                              <1> 
  5439                              <1> ;---------- DISKETTE ERRORS ----------------------------------------------------
  5440                              <1> ;TIME_OUT	EQU	080H		; ATTACHMENT FAILED TO RESPOND
  5441                              <1> ;BAD_SEEK	EQU	040H		; SEEK OPERATION FAILED
  5442                              <1> BAD_NEC 	EQU	020H		; DISKETTE CONTROLLER HAS FAILED
  5443                              <1> BAD_CRC 	EQU	010H		; BAD CRC ON DISKETTE READ
  5444                              <1> MED_NOT_FND	EQU	00CH		; MEDIA TYPE NOT FOUND
  5445                              <1> DMA_BOUNDARY	EQU	009H		; ATTEMPT TO DMA ACROSS 64K BOUNDARY
  5446                              <1> BAD_DMA 	EQU	008H		; DMA OVERRUN ON OPERATION
  5447                              <1> MEDIA_CHANGE	EQU	006H		; MEDIA REMOVED ON DUAL ATTACH CARD
  5448                              <1> RECORD_NOT_FND	EQU	004H		; REQUESTED SECTOR NOT FOUND
  5449                              <1> WRITE_PROTECT	EQU	003H		; WRITE ATTEMPTED ON WRITE PROTECT DISK
  5450                              <1> BAD_ADDR_MARK	EQU	002H		; ADDRESS MARK NOT FOUND
  5451                              <1> BAD_CMD 	EQU	001H		; BAD COMMAND PASSED TO DISKETTE I/O
  5452                              <1> 
  5453                              <1> ;---------- DISK CHANGE LINE EQUATES -------------------------------------------
  5454                              <1> NOCHGLN 	EQU	001H		; NO DISK CHANGE LINE AVAILABLE
  5455                              <1> CHGLN		EQU	002H		; DISK CHANGE LINE AVAILABLE
  5456                              <1> 
  5457                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS ---------------------------------------
  5458                              <1> TRK_CAPA	EQU	00000001B	; 80 TRACK CAPABILITY
  5459                              <1> FMT_CAPA	EQU	00000010B	; MULTIPLE FORMAT CAPABILITY (1.2M)
  5460                              <1> DRV_DET 	EQU	00000100B	; DRIVE DETERMINED
  5461                              <1> MED_DET 	EQU	00010000B	; MEDIA DETERMINED BIT
  5462                              <1> DBL_STEP	EQU	00100000B	; DOUBLE STEP BIT
  5463                              <1> RATE_MSK	EQU	11000000B	; MASK FOR CLEARING ALL BUT RATE
  5464                              <1> RATE_500	EQU	00000000B	; 500 KBS DATA RATE
  5465                              <1> RATE_300	EQU	01000000B	; 300 KBS DATA RATE
  5466                              <1> RATE_250	EQU	10000000B	; 250 KBS DATA RATE
  5467                              <1> STRT_MSK	EQU	00001100B	; OPERATION START RATE MASK
  5468                              <1> SEND_MSK	EQU	11000000B	; MASK FOR SEND RATE BITS
  5469                              <1> 
  5470                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS COMPATIBILITY -------------------------
  5471                              <1> M3D3U		EQU	00000000B	; 360 MEDIA/DRIVE NOT ESTABLISHED
  5472                              <1> M3D1U		EQU	00000001B	; 360 MEDIA,1.2DRIVE NOT ESTABLISHED
  5473                              <1> M1D1U		EQU	00000010B	; 1.2 MEDIA/DRIVE NOT ESTABLISHED
  5474                              <1> MED_UNK 	EQU	00000111B	; NONE OF THE ABOVE
  5475                              <1> 
  5476                              <1> ;---------- INTERRUPT EQUATES --------------------------------------------------
  5477                              <1> ;EOI		EQU	020H		; END OF INTERRUPT COMMAND TO 8259
  5478                              <1> ;INTA00		EQU	020H		; 8259 PORT
  5479                              <1> INTA01		EQU	021H		; 8259 PORT
  5480                              <1> INTB00		EQU	0A0H		; 2ND 8259
  5481                              <1> INTB01		EQU	0A1H		;
  5482                              <1> 
  5483                              <1> ;-------------------------------------------------------------------------------
  5484                              <1> DMA08		EQU	008H		; DMA STATUS REGISTER PORT ADDRESS
  5485                              <1> DMA		EQU	000H		; DMA CH.0 ADDRESS REGISTER PORT ADDRESS
  5486                              <1> DMA18		EQU	0D0H		; 2ND DMA STATUS PORT ADDRESS
  5487                              <1> DMA1		EQU	0C0H		; 2ND DMA CH.0 ADDRESS REGISTER ADDRESS
  5488                              <1> ;-------------------------------------------------------------------------------
  5489                              <1> ;TIMER		EQU	040H		; 8254 TIMER - BASE ADDRESS
  5490                              <1> 
  5491                              <1> ;-------------------------------------------------------------------------------
  5492                              <1> DMA_PAGE	EQU	081H		; START OF DMA PAGE REGISTERS
  5493                              <1> 
  5494                              <1> ; 06/02/2015 (unix386.s, protected mode modifications)
  5495                              <1> ; (unix386.s <-- dsectrm2.s)
  5496                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - DSEG.INC)
  5497                              <1> 
  5498                              <1> ; 10/12/2014
  5499                              <1> ;
  5500                              <1> ;int40h:
  5501                              <1> ;	pushf
  5502                              <1> ;	push 	cs
  5503                              <1> ;	;cli
  5504                              <1> ;	call 	DISKETTE_IO_1
  5505                              <1> ;	retn
  5506                              <1> 
  5507                              <1> ; DSKETTE ----- 04/21/86 DISKETTE BIOS
  5508                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  5509                              <1> ;
  5510                              <1> 
  5511                              <1> ;-- INT13H ---------------------------------------------------------------------
  5512                              <1> ; DISKETTE I/O
  5513                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO THE 5 1/4 INCH 360 KB,
  5514                              <1> ;	1.2 MB, 720 KB AND 1.44 MB DISKETTE DRIVES.
  5515                              <1> ; INPUT
  5516                              <1> ;	(AH) =  00H RESET DISKETTE SYSTEM
  5517                              <1> ;		HARD RESET TO NEC, PREPARE COMMAND, RECALIBRATE REQUIRED
  5518                              <1> ;		ON ALL DRIVES
  5519                              <1> ;------------------------------------------------------------------------------- 
  5520                              <1> ;	(AH)= 01H  READ THE STATUS OF THE SYSTEM INTO (AH)
  5521                              <1> ;		@DISKETTE_STATUS FROM LAST OPERATION IS USED
  5522                              <1> ;-------------------------------------------------------------------------------
  5523                              <1> ;	REGISTERS FOR READ/WRITE/VERIFY/FORMAT
  5524                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5525                              <1> ;	(DH) - HEAD NUMBER (0-1 ALLOWED, NOT VALUE CHECKED)
  5526                              <1> ;	(CH) - TRACK NUMBER (NOT VALUE CHECKED)
  5527                              <1> ;		MEDIA	DRIVE	TRACK NUMBER
  5528                              <1> ;		320/360	320/360	    0-39
  5529                              <1> ;		320/360	1.2M	    0-39
  5530                              <1> ;		1.2M	1.2M	    0-79
  5531                              <1> ;		720K	720K	    0-79
  5532                              <1> ;		1.44M	1.44M	    0-79	
  5533                              <1> ;	(CL) - 	SECTOR NUMBER (NOT VALUE CHECKED, NOT USED FOR FORMAT)
  5534                              <1> ;		MEDIA	DRIVE	SECTOR NUMBER
  5535                              <1> ;		320/360	320/360	     1-8/9
  5536                              <1> ;		320/360	1.2M	     1-8/9
  5537                              <1> ;		1.2M	1.2M	     1-15
  5538                              <1> ;		720K	720K	     1-9
  5539                              <1> ;		1.44M	1.44M	     1-18		
  5540                              <1> ;	(AL)	NUMBER OF SECTORS (NOT VALUE CHECKED)
  5541                              <1> ;		MEDIA	DRIVE	MAX NUMBER OF SECTORS
  5542                              <1> ;		320/360	320/360	        8/9
  5543                              <1> ;		320/360	1.2M	        8/9
  5544                              <1> ;		1.2M	1.2M		15
  5545                              <1> ;		720K	720K		9
  5546                              <1> ;		1.44M	1.44M		18
  5547                              <1> ;
  5548                              <1> ;	(ES:BX) - ADDRESS OF BUFFER (NOT REQUIRED FOR VERIFY)
  5549                              <1> ;
  5550                              <1> ;-------------------------------------------------------------------------------
  5551                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY
  5552                              <1> ;-------------------------------------------------------------------------------
  5553                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY
  5554                              <1> ;-------------------------------------------------------------------------------
  5555                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS
  5556                              <1> ;-------------------------------------------------------------------------------
  5557                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK
  5558                              <1> ;		(ES,BX) MUST POINT TO THE COLLECTION OF DESIRED ADDRESS FIELDS
  5559                              <1> ;		FOR THE	TRACK. EACH FIELD IS COMPOSED OF 4 BYTES, (C,H,R,N),
  5560                              <1> ;		WHERE C = TRACK NUMBER, H=HEAD NUMBER, R = SECTOR NUMBER, 
  5561                              <1> ;		N= NUMBER OF BYTES PER SECTOR (00=128,01=256,02=512,03=1024),
  5562                              <1> ;		THERE MUST BE ONE ENTRY FOR EVERY SECTOR ON THE TRACK.
  5563                              <1> ;		THIS INFORMATION IS USED TO FIND THE REQUESTED SECTOR DURING 
  5564                              <1> ;		READ/WRITE ACCESS.
  5565                              <1> ;		PRIOR TO FORMATTING A DISKETTE, IF THERE EXISTS MORE THAN
  5566                              <1> ;		ONE SUPPORTED MEDIA FORMAT TYPE WITHIN THE DRIVE IN QUESTION,
  5567                              <1> ;		THEN "SET DASD TYPE" (INT 13H, AH = 17H) OR 'SET MEDIA TYPE'
  5568                              <1> ;		(INT 13H, AH =  18H) MUST BE CALLED TO SET THE DISKETTE TYPE
  5569                              <1> ;		THAT IS TO BE FORMATTED. IF "SET DASD TYPE" OR "SET MEDIA TYPE"
  5570                              <1> ;		IS NOT CALLED, THE FORMAT ROUTINE WILL ASSUME THE 
  5571                              <1> ;		MEDIA FORMAT TO BE THE MAXIMUM CAPACITY OF THE DRIVE.
  5572                              <1> ;
  5573                              <1> ;		THESE PARAMETERS OF DISK BASE MUST BE CHANGED IN ORDER TO
  5574                              <1> ;		FORMAT THE FOLLOWING MEDIAS:
  5575                              <1> ;		---------------------------------------------
  5576                              <1> ;		: MEDIA  :     DRIVE      : PARM 1 : PARM 2 :
  5577                              <1> ;		---------------------------------------------
  5578                              <1> ;		: 320K	 : 320K/360K/1.2M :  50H   :   8    :
  5579                              <1> ;		: 360K	 : 320K/360K/1.2M :  50H   :   9    :
  5580                              <1> ;		: 1.2M	 : 1.2M           :  54H   :  15    :
  5581                              <1> ;		: 720K	 : 720K/1.44M     :  50H   :   9    :
  5582                              <1> ;		: 1.44M	 : 1.44M          :  6CH   :  18    :		  	
  5583                              <1> ;		---------------------------------------------
  5584                              <1> ;		NOTES: - PARM 1 = GAP LENGTH FOR FORMAT
  5585                              <1> ;		       - PARM 2 = EOT (LAST SECTOR ON TRACK)
  5586                              <1> ;		       - DISK BASE IS POINTED BY DISK POINTER LOCATED
  5587                              <1> ;			 AT ABSOLUTE ADDRESS 0:78.
  5588                              <1> ;		       - WHEN FORMAT OPERATIONS ARE COMPLETE, THE PARAMETERS
  5589                              <1> ;			 SHOULD BE RESTORED TO THEIR RESPECTIVE INITIAL VALUES.			
  5590                              <1> ;-------------------------------------------------------------------------------
  5591                              <1> ;	(AH) = 08H READ DRIVE PARAMETERS
  5592                              <1> ;	REGISTERS
  5593                              <1> ;	  INPUT
  5594                              <1> ;	    (DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5595                              <1> ;	  OUTPUT
  5596                              <1> ;	    (ES:DI) POINTS TO DRIVE PARAMETER TABLE
  5597                              <1> ;	    (CH) - LOW ORDER 8 OF 10 BITS MAXIMUM NUMBER OF TRACKS
  5598                              <1> ;	    (CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
  5599                              <1> ;	           BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
  5600                              <1> ;	    (DH) - MAXIMUM HEAD NUMBER
  5601                              <1> ;	    (DL) - NUMBER OF DISKETTE DRIVES INSTALLED
  5602                              <1> ;	    (BH) - 0
  5603                              <1> ;	    (BL) - BITS 7 THRU 4 - 0
  5604                              <1> ;	           BITS 3 THRU 0 - VALID DRIVE TYPE VALUE IN CMOS
  5605                              <1> ;	    (AX) - 0
  5606                              <1> ;	 UNDER THE FOLLOWING CIRCUMSTANCES:
  5607                              <1> ;	    (1) THE DRIVE NUMBER IS INVALID,
  5608                              <1> ;	    (2) THE DRIVE TYPE IS UNKNOWN AND CMOS IS NOT PRESENT, 
  5609                              <1> ;	    (3) THE DRIVE TYPE IS UNKNOWN AND CMOS IS BAD,
  5610                              <1> ;	    (4) OR THE DRIVE TYPE IS UNKNOWN AND THE CMOS DRIVE TYPE IS INVALID
  5611                              <1> ;	    THEN ES,AX,BX,CX,DH,DI=0 ; DL=NUMBER OF DRIVES. 
  5612                              <1> ;	    IF NO DRIVES ARE PRESENT THEN: ES,AX,BX,CX,DX,DI=0.
  5613                              <1> ;	    @DISKETTE_STATUS = 0 AND CY IS RESET.
  5614                              <1> ;-------------------------------------------------------------------------------
  5615                              <1> ;	(AH)= 15H  READ DASD TYPE
  5616                              <1> ;	OUTPUT REGISTERS
  5617                              <1> ;	(AH) - ON RETURN IF CARRY FLAG NOT SET, OTHERWISE ERROR	
  5618                              <1> ;		00 - DRIVE NOT PRESENT	
  5619                              <1> ;		01 - DISKETTE, NO CHANGE LINE AVAILABLE
  5620                              <1> ;		02 - DISKETTE, CHANGE LINE AVAILABLE	
  5621                              <1> ;		03 - RESERVED (FIXED DISK)
  5622                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5623                              <1> ;-------------------------------------------------------------------------------
  5624                              <1> ;	(AH)= 16H  DISK CHANGE LINE STATUS
  5625                              <1> ;	OUTPUT REGISTERS
  5626                              <1> ;	(AH) - 00 - DISK CHANGE LINE NOT ACTIVE	
  5627                              <1> ;	       06 - DISK CHANGE LINE ACTIVE & CARRY BIT ON
  5628                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5629                              <1> ;-------------------------------------------------------------------------------
  5630                              <1> ;	(AH)= 17H  SET DASD TYPE FOR FORMAT
  5631                              <1> ;	INPUT REGISTERS
  5632                              <1> ;	(AL) -	00 - NOT USED	
  5633                              <1> ;		01 - DISKETTE 320/360K IN 360K DRIVE	
  5634                              <1> ;		02 - DISKETTE 360K IN 1.2M DRIVE
  5635                              <1> ;		03 - DISKETTE 1.2M IN 1.2M DRIVE
  5636                              <1> ;		04 - DISKETTE 720K IN 720K DRIVE
  5637                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED:
  5638                              <1> ;	       (DO NOT USE WHEN DISKETTE ATTACH CARD USED)
  5639                              <1> ;-------------------------------------------------------------------------------
  5640                              <1> ;	(AH)= 18H  SET MEDIA TYPE FOR FORMAT
  5641                              <1> ;	INPUT REGISTERS
  5642                              <1> ;	(CH) - LOW ORDER 8 OF 10 BITS MAXIMUM TRACKS
  5643                              <1> ;	(CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
  5644                              <1> ;	       BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
  5645                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHACKED)
  5646                              <1> ;	OUTPUT REGISTERS:
  5647                              <1> ;	(ES:DI) - POINTER TO DRIVE PARAMETERS TABLE FOR THIS MEDIA TYPE,
  5648                              <1> ;		  UNCHANGED IF (AH) IS NON-ZERO
  5649                              <1> ;	(AH) - 00H, CY = 0, TRACK AND SECTORS/TRACK COMBINATION IS SUPPORTED
  5650                              <1> ;	     - 01H, CY = 1, FUNCTION IS NOT AVAILABLE
  5651                              <1> ;	     - 0CH, CY = 1, TRACK AND SECTORS/TRACK COMBINATION IS NOT SUPPORTED
  5652                              <1> ;	     - 80H, CY = 1, TIME OUT (DISKETTE NOT PRESENT)		
  5653                              <1> ;-------------------------------------------------------------------------------
  5654                              <1> ;	DISK CHANGE STATUS IS ONLY CHECKED WHEN A MEDIA SPECIFIED IS OTHER
  5655                              <1> ;	THAN 360 KB DRIVE. IF THE DISK CHANGE LINE IS FOUND TO BE
  5656                              <1> ;	ACTIVE THE FOLLOWING ACTIONS TAKE PLACE:
  5657                              <1> ;		ATTEMPT TO RESET DISK CHANGE LINE TO INACTIVE STATE. 
  5658                              <1> ;		IF ATTEMPT SUCCEEDS SET DASD TYPE FOR FORMAT AND RETURN DISK 
  5659                              <1> ;		CHANGE ERROR CODE
  5660                              <1> ;		IF ATTEMPT FAILS RETURN TIMEOUT ERROR CODE AND SET DASD TYPE 
  5661                              <1> ;		TO A PREDETERMINED STATE INDICATING MEDIA TYPE UNKNOWN.
  5662                              <1> ;	IF THE DISK CHANGE LINE IN INACTIVE PERFORM SET DASD TYPE FOR FORMAT.
  5663                              <1> ;
  5664                              <1> ; DATA VARIABLE -- @DISK_POINTER
  5665                              <1> ;	DOUBLE WORD POINTER TO THE CURRENT SET OF DISKETTE PARAMETERS
  5666                              <1> ;-------------------------------------------------------------------------------
  5667                              <1> ; OUTPUT FOR ALL FUNCTIONS
  5668                              <1> ;	AH = STATUS OF OPERATION
  5669                              <1> ;		STATUS BITS ARE DEFINED IN THE EQUATES FOR @DISKETTE_STATUS
  5670                              <1> ;		VARIABLE IN THE DATA SEGMENT OF THIS MODULE
  5671                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN, EXCEPT FOR READ DASD
  5672                              <1> ;		TYPE AH=(15)).
  5673                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)
  5674                              <1> ;	FOR READ/WRITE/VERIFY
  5675                              <1> ;		DS,BX,DX,CX PRESERVED
  5676                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISKETTE CODE, THE APPROPRIATE 
  5677                              <1> ;		ACTION IS TO RESET THE DISKETTE, THEN RETRY THE OPERATION.
  5678                              <1> ;		ON READ ACCESSES, NO MOTOR START DELAY IS TAKEN, SO THAT 
  5679                              <1> ;		THREE RETRIES ARE REQUIRED ON READS TO ENSURE THAT THE 
  5680                              <1> ;		PROBLEM IS NOT DUE TO MOTOR START-UP.
  5681                              <1> ;-------------------------------------------------------------------------------
  5682                              <1> ;
  5683                              <1> ; DISKETTE STATE MACHINE - ABSOLUTE ADDRESS 40:90 (DRIVE A) & 91 (DRIVE B)
  5684                              <1> ;
  5685                              <1> ;   -----------------------------------------------------------------
  5686                              <1> ;   |       |       |       |       |       |       |       |       |
  5687                              <1> ;   |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
  5688                              <1> ;   |       |       |       |       |       |       |       |       |
  5689                              <1> ;   -----------------------------------------------------------------
  5690                              <1> ;	|	|	|	|	|	|	|	|
  5691                              <1> ;	|	|	|	|	|	-----------------
  5692                              <1> ;	|	|	|	|	|		|
  5693                              <1> ;	|	|	|	|    RESERVED		|
  5694                              <1> ;	|	|	|	|		  PRESENT STATE
  5695                              <1> ;	|	|	|	|	000: 360K IN 360K DRIVE UNESTABLISHED
  5696                              <1> ;	|	|	|	|	001: 360K IN 1.2M DRIVE UNESTABLISHED
  5697                              <1> ;	|	|	|	|	010: 1.2M IN 1.2M DRIVE UNESTABLISHED
  5698                              <1> ;	|	|	|	|	011: 360K IN 360K DRIVE ESTABLISHED
  5699                              <1> ;	|	|	|	|	100: 360K IN 1.2M DRIVE ESTABLISHED
  5700                              <1> ;	|	|	|	|	101: 1.2M IN 1.2M DRIVE ESTABLISHED
  5701                              <1> ;	|	|	|	|	110: RESERVED
  5702                              <1> ;	|	|	|	|	111: NONE OF THE ABOVE
  5703                              <1> ;	|	|	|	|
  5704                              <1> ;	|	|	|	------>	MEDIA/DRIVE ESTABLISHED
  5705                              <1> ;	|	|	|
  5706                              <1> ;	|	|	-------------->	DOUBLE STEPPING REQUIRED (360K IN 1.2M
  5707                              <1> ;	|	|			DRIVE)
  5708                              <1> ;	|	|
  5709                              <1> ;	------------------------------>	DATA TRANSFER RATE FOR THIS DRIVE:
  5710                              <1> ;
  5711                              <1> ;						00: 500 KBS
  5712                              <1> ;						01: 300 KBS
  5713                              <1> ;						10: 250 KBS
  5714                              <1> ;						11: RESERVED
  5715                              <1> ;
  5716                              <1> ;
  5717                              <1> ;-------------------------------------------------------------------------------
  5718                              <1> ; STATE OPERATION STARTED - ABSOLUTE ADDRESS 40:92 (DRIVE A) & 93 (DRIVE B)
  5719                              <1> ;-------------------------------------------------------------------------------
  5720                              <1> ; PRESENT CYLINDER NUMBER - ABSOLUTE ADDRESS 40:94 (DRIVE A) & 95 (DRIVE B)
  5721                              <1> ;-------------------------------------------------------------------------------
  5722                              <1> 
  5723                              <1> struc MD
  5724 00000000 <res 00000001>      <1> 	.SPEC1		resb	1	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
  5725 00000001 <res 00000001>      <1> 	.SPEC2		resb	1	; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
  5726 00000002 <res 00000001>      <1> 	.OFF_TIM	resb	1	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
  5727 00000003 <res 00000001>      <1> 	.BYT_SEC	resb	1	; 512 BYTES/SECTOR
  5728 00000004 <res 00000001>      <1> 	.SEC_TRK	resb	1	; EOT (LAST SECTOR ON TRACK)
  5729 00000005 <res 00000001>      <1> 	.GAP		resb	1	; GAP LENGTH
  5730 00000006 <res 00000001>      <1> 	.DTL		resb	1	; DTL
  5731 00000007 <res 00000001>      <1> 	.GAP3		resb	1	; GAP LENGTH FOR FORMAT
  5732 00000008 <res 00000001>      <1> 	.FIL_BYT	resb	1	; FILL BYTE FOR FORMAT
  5733 00000009 <res 00000001>      <1> 	.HD_TIM		resb	1	; HEAD SETTLE TIME (MILLISECONDS)
  5734 0000000A <res 00000001>      <1> 	.STR_TIM	resb	1	; MOTOR START TIME (1/8 SECONDS)
  5735 0000000B <res 00000001>      <1> 	.MAX_TRK	resb	1	; MAX. TRACK NUMBER
  5736 0000000C <res 00000001>      <1> 	.RATE		resb	1	; DATA TRANSFER RATE
  5737                              <1> endstruc
  5738                              <1> 
  5739                              <1> BIT7OFF	EQU	7FH
  5740                              <1> BIT7ON	EQU	80H
  5741                              <1> 
  5742                              <1> ;;int13h: ; 16/02/2015
  5743                              <1> ;; 16/02/2015 - 21/02/2015
  5744                              <1> int40h:
  5745 00001A51 9C                  <1> 	pushfd
  5746 00001A52 0E                  <1> 	push 	cs
  5747 00001A53 E801000000          <1> 	call 	DISKETTE_IO_1
  5748 00001A58 C3                  <1> 	retn	
  5749                              <1> 
  5750                              <1> DISKETTE_IO_1:
  5751                              <1> 
  5752 00001A59 FB                  <1> 	STI				; INTERRUPTS BACK ON
  5753 00001A5A 55                  <1> 	PUSH	eBP			; USER REGISTER
  5754 00001A5B 57                  <1> 	PUSH	eDI			; USER REGISTER
  5755 00001A5C 52                  <1> 	PUSH	eDX			; HEAD #, DRIVE # OR USER REGISTER
  5756 00001A5D 53                  <1> 	PUSH	eBX			; BUFFER OFFSET PARAMETER OR REGISTER
  5757 00001A5E 51                  <1> 	PUSH	eCX			; TRACK #-SECTOR # OR USER REGISTER
  5758 00001A5F 89E5                <1> 	MOV	eBP,eSP			; BP     => PARAMETER LIST DEP. ON AH
  5759                              <1> 					; [BP]   = SECTOR #
  5760                              <1> 					; [BP+1] = TRACK #
  5761                              <1> 					; [BP+2] = BUFFER OFFSET
  5762                              <1> 					; FOR RETURN OF DRIVE PARAMETERS:
  5763                              <1> 					; CL/[BP] = BITS 7&6 HI BITS OF MAX CYL
  5764                              <1> 					; 	    BITS 0-5 MAX SECTORS/TRACK
  5765                              <1> 					; CH/[BP+1] = LOW 8 BITS OF MAX CYL.
  5766                              <1> 					; BL/[BP+2] = BITS 7-4 = 0
  5767                              <1> 					;	      BITS 3-0 = VALID CMOS TYPE
  5768                              <1> 					; BH/[BP+3] = 0
  5769                              <1> 					; DL/[BP+4] = # DRIVES INSTALLED
  5770                              <1> 					; DH/[BP+5] = MAX HEAD #
  5771                              <1> 					; DI/[BP+6] = OFFSET TO DISK BASE
  5772 00001A61 06                  <1> 	push	es ; 06/02/2015	
  5773 00001A62 1E                  <1> 	PUSH	DS			; BUFFER SEGMENT PARM OR USER REGISTER
  5774 00001A63 56                  <1> 	PUSH	eSI			; USER REGISTERS
  5775                              <1> 	;CALL	DDS			; SEGMENT OF BIOS DATA AREA TO DS
  5776                              <1> 	;mov	cx, cs
  5777                              <1> 	;mov	ds, cx
  5778 00001A64 66B91000            <1> 	mov	cx, KDATA
  5779 00001A68 8ED9                <1>         mov     ds, cx
  5780 00001A6A 8EC1                <1>         mov     es, cx
  5781                              <1> 
  5782                              <1> 	;CMP	AH,(FNC_TAE-FNC_TAB)/2	; CHECK FOR > LARGEST FUNCTION
  5783 00001A6C 80FC19              <1> 	cmp	ah,(FNC_TAE-FNC_TAB)/4 ; 18/02/2015
  5784 00001A6F 7202                <1> 	JB	short OK_FUNC		; FUNCTION OK
  5785 00001A71 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
  5786                              <1> OK_FUNC:
  5787 00001A73 80FC01              <1> 	CMP	AH,1			; RESET OR STATUS ?
  5788 00001A76 760C                <1> 	JBE	short OK_DRV		; IF RESET OR STATUS DRIVE ALWAYS OK
  5789 00001A78 80FC08              <1> 	CMP	AH,8			; READ DRIVE PARMS ?
  5790 00001A7B 7407                <1> 	JZ	short OK_DRV		; IF SO DRIVE CHECKED LATER
  5791 00001A7D 80FA01              <1> 	CMP	DL,1			; DRIVES 0 AND 1 OK
  5792 00001A80 7602                <1> 	JBE	short OK_DRV		; IF 0 OR 1 THEN JUMP
  5793 00001A82 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
  5794                              <1> OK_DRV:
  5795 00001A84 31C9                <1> 	xor	ecx, ecx
  5796                              <1> 	;mov	esi, ecx ; 08/02/2015
  5797 00001A86 89CF                <1> 	mov	edi, ecx ; 08/02/2015
  5798 00001A88 88E1                <1> 	MOV	CL,AH			; CL = FUNCTION
  5799                              <1> 	;XOR	CH,CH			; CX = FUNCTION
  5800                              <1> 	;SHL	CL, 1			; FUNCTION TIMES 2
  5801 00001A8A C0E102              <1> 	SHL	CL, 2 ; 20/02/2015	; FUNCTION TIMES 4 (for 32 bit offset)
  5802 00001A8D BB[C51A0000]        <1> 	MOV	eBX,FNC_TAB		; LOAD START OF FUNCTION TABLE
  5803 00001A92 01CB                <1> 	ADD	eBX,eCX			; ADD OFFSET INTO TABLE => ROUTINE
  5804 00001A94 88F4                <1> 	MOV	AH,DH			; AX = HEAD #,# OF SECTORS OR DASD TYPE
  5805 00001A96 30F6                <1> 	XOR	DH,DH			; DX = DRIVE #
  5806 00001A98 6689C6              <1> 	MOV	SI,AX			; SI = HEAD #,# OF SECTORS OR DASD TYPE
  5807 00001A9B 6689D7              <1> 	MOV     DI,DX                   ; DI = DRIVE #
  5808                              <1> 	;
  5809                              <1> 	; 11/12/2014
  5810 00001A9E 8815[B1B80000]      <1>         mov     [cfd], dl               ; current floppy drive (for 'GET_PARM')        
  5811                              <1> 	;
  5812 00001AA4 8A25[74BE0000]      <1> 	MOV	AH, [DSKETTE_STATUS]	; LOAD STATUS TO AH FOR STATUS FUNCTION
  5813 00001AAA C605[74BE0000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; INITIALIZE FOR ALL OTHERS
  5814                              <1> 
  5815                              <1> ;	THROUGHOUT THE DISKETTE BIOS, THE FOLLOWING INFORMATION IS CONTAINED IN
  5816                              <1> ;	THE FOLLOWING MEMORY LOCATIONS AND REGISTERS. NOT ALL DISKETTE BIOS
  5817                              <1> ;	FUNCTIONS REQUIRE ALL OF THESE PARAMETERS.
  5818                              <1> ;
  5819                              <1> ;		DI	: DRIVE #
  5820                              <1> ;		SI-HI	: HEAD #
  5821                              <1> ;		SI-LOW	: # OF SECTORS OR DASD TYPE FOR FORMAT
  5822                              <1> ;		ES	: BUFFER SEGMENT
  5823                              <1> ;		[BP]	: SECTOR #
  5824                              <1> ;		[BP+1]	: TRACK #
  5825                              <1> ;		[BP+2]	: BUFFER OFFSET
  5826                              <1> ;
  5827                              <1> ;	ACROSS CALLS TO SUBROUTINES THE CARRY FLAG (CY=1), WHERE INDICATED IN 
  5828                              <1> ;	SUBROUTINE PROLOGUES, REPRESENTS AN EXCEPTION RETURN (NORMALLY AN ERROR 
  5829                              <1> ;	CONDITION). IN MOST CASES, WHEN CY = 1, @DSKETTE_STATUS CONTAINS THE 
  5830                              <1> ;	SPECIFIC ERROR CODE.
  5831                              <1> ;
  5832                              <1> 					; (AH) = @DSKETTE_STATUS
  5833 00001AB1 FF13                <1> 	CALL	dWORD [eBX]		; CALL THE REQUESTED FUNCTION
  5834 00001AB3 5E                  <1> 	POP	eSI			; RESTORE ALL REGISTERS
  5835 00001AB4 1F                  <1> 	POP	DS
  5836 00001AB5 07                  <1> 	pop	es	; 06/02/2015
  5837 00001AB6 59                  <1> 	POP	eCX
  5838 00001AB7 5B                  <1> 	POP	eBX
  5839 00001AB8 5A                  <1> 	POP	eDX
  5840 00001AB9 5F                  <1> 	POP	eDI
  5841 00001ABA 89E5                <1> 	MOV	eBP, eSP
  5842 00001ABC 50                  <1> 	PUSH	eAX
  5843 00001ABD 9C                  <1> 	PUSHFd
  5844 00001ABE 58                  <1> 	POP	eAX
  5845                              <1> 	;MOV	[BP+6], AX
  5846 00001ABF 89450C              <1> 	mov	[ebp+12], eax  ; 18/02/2015, flags
  5847 00001AC2 58                  <1> 	POP	eAX
  5848 00001AC3 5D                  <1> 	POP	eBP
  5849 00001AC4 CF                  <1> 	IRETd
  5850                              <1> 
  5851                              <1> ;-------------------------------------------------------------------------------
  5852                              <1> ; DW --> dd (06/02/2015)
  5853 00001AC5 [291B0000]          <1> FNC_TAB	dd	DSK_RESET		; AH = 00H; RESET
  5854 00001AC9 [A21B0000]          <1> 	dd	DSK_STATUS		; AH = 01H; STATUS
  5855 00001ACD [B31B0000]          <1> 	dd	DSK_READ		; AH = 02H; READ
  5856 00001AD1 [C41B0000]          <1> 	dd	DSK_WRITE		; AH = 03H; WRITE
  5857 00001AD5 [D51B0000]          <1> 	dd	DSK_VERF		; AH = 04H; VERIFY
  5858 00001AD9 [E61B0000]          <1> 	dd	DSK_FORMAT		; AH = 05H; FORMAT
  5859 00001ADD [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 06H; INVALID
  5860 00001AE1 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 07H; INVALID
  5861 00001AE5 [781C0000]          <1> 	dd	DSK_PARMS		; AH = 08H; READ DRIVE PARAMETERS
  5862 00001AE9 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 09H; INVALID
  5863 00001AED [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0AH; INVALID
  5864 00001AF1 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0BH; INVALID
  5865 00001AF5 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0CH; INVALID
  5866 00001AF9 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0DH; INVALID
  5867 00001AFD [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0EH; INVALID
  5868 00001B01 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 0FH; INVALID
  5869 00001B05 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 10H; INVALID
  5870 00001B09 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 11H; INVALID
  5871 00001B0D [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 12H; INVALID
  5872 00001B11 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 13H; INVALID
  5873 00001B15 [6B1C0000]          <1> 	dd	FNC_ERR			; AH = 14H; INVALID
  5874 00001B19 [391D0000]          <1> 	dd	DSK_TYPE		; AH = 15H; READ DASD TYPE
  5875 00001B1D [641D0000]          <1> 	dd	DSK_CHANGE		; AH = 16H; CHANGE STATUS
  5876 00001B21 [9E1D0000]          <1> 	dd	FORMAT_SET		; AH = 17H; SET DASD TYPE
  5877 00001B25 [211E0000]          <1> 	dd	SET_MEDIA		; AH = 18H; SET MEDIA TYPE	
  5878                              <1> FNC_TAE EQU     $                       ; END
  5879                              <1> 
  5880                              <1> ;-------------------------------------------------------------------------------
  5881                              <1> ; DISK_RESET	(AH = 00H)	
  5882                              <1> ;		RESET THE DISKETTE SYSTEM.
  5883                              <1> ;
  5884                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  5885                              <1> ;-------------------------------------------------------------------------------
  5886                              <1> DSK_RESET:
  5887 00001B29 66BAF203            <1> 	MOV	DX,03F2H		; ADAPTER CONTROL PORT
  5888 00001B2D FA                  <1> 	CLI				; NO INTERRUPTS
  5889 00001B2E A0[72BE0000]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  5890 00001B33 243F                <1> 	AND	AL,00111111B		; KEEP SELECTED AND MOTOR ON BITS
  5891 00001B35 C0C004              <1> 	ROL	AL,4			; MOTOR VALUE TO HIGH NIBBLE
  5892                              <1> 					; DRIVE SELECT TO LOW NIBBLE
  5893 00001B38 0C08                <1> 	OR	AL,00001000B		; TURN ON INTERRUPT ENABLE
  5894 00001B3A EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
  5895 00001B3B C605[71BE0000]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  5896                              <1> 	;JMP	$+2			; WAIT FOR I/O
  5897                              <1> 	;JMP	$+2			; WAIT FOR I/O (TO INSURE MINIMUM
  5898                              <1> 					;      PULSE WIDTH)
  5899                              <1> 	; 19/12/2014
  5900                              <1> 	NEWIODELAY
  5901 00001B42 E6EB                <2>  out 0ebh,al
  5902                              <1> 
  5903                              <1> 	; 17/12/2014 
  5904                              <1> 	; AWARD BIOS 1999 - RESETDRIVES (ADISK.ASM)
  5905 00001B44 B915000000          <1> 	mov	ecx, WAITCPU_RESET_ON	; cx = 21 -- Min. 14 micro seconds !?
  5906                              <1> wdw1:
  5907                              <1> 	NEWIODELAY   ; 27/02/2015
  5908 00001B49 E6EB                <2>  out 0ebh,al
  5909 00001B4B E2FC                <1> 	loop	wdw1
  5910                              <1> 	;
  5911 00001B4D 0C04                <1> 	OR	AL,00000100B		; TURN OFF RESET BIT
  5912 00001B4F EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
  5913                              <1> 	; 16/12/2014
  5914                              <1> 	IODELAY
  5915 00001B50 EB00                <2>  jmp short $+2
  5916 00001B52 EB00                <2>  jmp short $+2
  5917                              <1> 	;
  5918                              <1> 	;STI				; ENABLE THE INTERRUPTS
  5919 00001B54 E8250C0000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  5920 00001B59 723E                <1> 	JC	short DR_ERR		; IF ERROR, RETURN IT
  5921 00001B5B 66B9C000            <1> 	MOV	CX,11000000B		; CL = EXPECTED @NEC_STATUS
  5922                              <1> NXT_DRV:
  5923 00001B5F 6651                <1> 	PUSH	CX			; SAVE FOR CALL
  5924 00001B61 B8[971B0000]        <1> 	MOV	eAX, DR_POP_ERR 	; LOAD NEC_OUTPUT ERROR ADDRESS
  5925 00001B66 50                  <1> 	PUSH	eAX			; "
  5926 00001B67 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  5927 00001B69 E8030B0000          <1> 	CALL	NEC_OUTPUT
  5928 00001B6E 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  5929 00001B6F E83A0C0000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  5930 00001B74 6659                <1> 	POP	CX			; RESTORE AFTER CALL
  5931 00001B76 7221                <1> 	JC	short DR_ERR		; ERROR RETURN
  5932 00001B78 3A0D[75BE0000]      <1> 	CMP	CL, [NEC_STATUS]	; TEST FOR DRIVE READY TRANSITION
  5933 00001B7E 7519                <1> 	JNZ	short DR_ERR		; EVERYTHING OK
  5934 00001B80 FEC1                <1> 	INC	CL			; NEXT EXPECTED @NEC_STATUS
  5935 00001B82 80F9C3              <1> 	CMP	CL,11000011B		; ALL POSSIBLE DRIVES CLEARED
  5936 00001B85 76D8                <1> 	JBE	short NXT_DRV		; FALL THRU IF 11000100B OR >
  5937                              <1> 	;
  5938 00001B87 E852030000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
  5939                              <1> RESBAC:
  5940 00001B8C E806090000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  5941 00001B91 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  5942 00001B94 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  5943 00001B96 C3                  <1> 	RETn		
  5944                              <1> DR_POP_ERR:
  5945 00001B97 6659                <1> 	POP	CX			; CLEAR STACK
  5946                              <1> DR_ERR:
  5947 00001B99 800D[74BE0000]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; SET ERROR CODE
  5948 00001BA0 EBEA                <1> 	JMP	SHORT RESBAC		; RETURN FROM RESET
  5949                              <1> 
  5950                              <1> ;-------------------------------------------------------------------------------
  5951                              <1> ; DISK_STATUS	(AH = 01H)
  5952                              <1> ;	DISKETTE STATUS.
  5953                              <1> ;
  5954                              <1> ; ON ENTRY:	AH : STATUS OF PREVIOUS OPERATION
  5955                              <1> ;
  5956                              <1> ; ON EXIT:	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF PREVIOUS OPERATION.
  5957                              <1> ;-------------------------------------------------------------------------------
  5958                              <1> DSK_STATUS:
  5959 00001BA2 8825[74BE0000]      <1> 	MOV	[DSKETTE_STATUS],AH	; PUT BACK FOR SETUP END
  5960 00001BA8 E8EA080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  5961 00001BAD 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  5962 00001BB0 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  5963 00001BB2 C3                  <1> 	RETn		
  5964                              <1> 
  5965                              <1> ;-------------------------------------------------------------------------------
  5966                              <1> ; DISK_READ	(AH = 02H)	
  5967                              <1> ;	DISKETTE READ.
  5968                              <1> ;
  5969                              <1> ; ON ENTRY:	DI	: DRIVE #
  5970                              <1> ;		SI-HI	: HEAD #
  5971                              <1> ;		SI-LOW	: # OF SECTORS
  5972                              <1> ;		ES	: BUFFER SEGMENT
  5973                              <1> ;		[BP]	: SECTOR #
  5974                              <1> ;		[BP+1]	: TRACK #
  5975                              <1> ;		[BP+2]	: BUFFER OFFSET
  5976                              <1> ;
  5977                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  5978                              <1> ;-------------------------------------------------------------------------------
  5979                              <1> 
  5980                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
  5981                              <1> 
  5982                              <1> DSK_READ:
  5983 00001BB3 8025[72BE0000]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
  5984 00001BBA 66B846E6            <1> 	MOV	AX,0E646H		; AX = NEC COMMAND, DMA COMMAND
  5985 00001BBE E825040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  5986 00001BC3 C3                  <1> 	RETn
  5987                              <1> 
  5988                              <1> ;-------------------------------------------------------------------------------
  5989                              <1> ; DISK_WRITE	(AH = 03H)
  5990                              <1> ;	DISKETTE WRITE.
  5991                              <1> ;
  5992                              <1> ; ON ENTRY:	DI	: DRIVE #
  5993                              <1> ;		SI-HI	: HEAD #
  5994                              <1> ;		SI-LOW	: # OF SECTORS
  5995                              <1> ;		ES	: BUFFER SEGMENT
  5996                              <1> ;		[BP]	: SECTOR #
  5997                              <1> ;		[BP+1]	: TRACK #
  5998                              <1> ;		[BP+2]	: BUFFER OFFSET
  5999                              <1> ;
  6000                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6001                              <1> ;-------------------------------------------------------------------------------
  6002                              <1> 
  6003                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
  6004                              <1> 
  6005                              <1> DSK_WRITE:
  6006 00001BC4 66B84AC5            <1> 	MOV	AX,0C54AH		; AX = NEC COMMAND, DMA COMMAND
  6007 00001BC8 800D[72BE0000]80    <1>         OR      byte [MOTOR_STATUS],10000000B ; INDICATE WRITE OPERATION
  6008 00001BCF E814040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  6009 00001BD4 C3                  <1> 	RETn
  6010                              <1> 
  6011                              <1> ;-------------------------------------------------------------------------------
  6012                              <1> ; DISK_VERF	(AH = 04H)
  6013                              <1> ;	DISKETTE VERIFY.
  6014                              <1> ;
  6015                              <1> ; ON ENTRY:	DI	: DRIVE #
  6016                              <1> ;		SI-HI	: HEAD #
  6017                              <1> ;		SI-LOW	: # OF SECTORS
  6018                              <1> ;		ES	: BUFFER SEGMENT
  6019                              <1> ;		[BP]	: SECTOR #
  6020                              <1> ;		[BP+1]	: TRACK #
  6021                              <1> ;		[BP+2]	: BUFFER OFFSET
  6022                              <1> ;
  6023                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6024                              <1> ;-------------------------------------------------------------------------------
  6025                              <1> DSK_VERF:
  6026 00001BD5 8025[72BE0000]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
  6027 00001BDC 66B842E6            <1> 	MOV	AX,0E642H		; AX = NEC COMMAND, DMA COMMAND
  6028 00001BE0 E803040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  6029 00001BE5 C3                  <1> 	RETn
  6030                              <1> 
  6031                              <1> ;-------------------------------------------------------------------------------
  6032                              <1> ; DISK_FORMAT	(AH = 05H)
  6033                              <1> ;	DISKETTE FORMAT.
  6034                              <1> ;
  6035                              <1> ; ON ENTRY:	DI	: DRIVE #
  6036                              <1> ;		SI-HI	: HEAD #
  6037                              <1> ;		SI-LOW	: # OF SECTORS
  6038                              <1> ;		ES	: BUFFER SEGMENT
  6039                              <1> ;		[BP]	: SECTOR #
  6040                              <1> ;		[BP+1]	: TRACK #
  6041                              <1> ;		[BP+2]	: BUFFER OFFSET
  6042                              <1> ;		@DISK_POINTER POINTS TO THE PARAMETER TABLE OF THIS DRIVE
  6043                              <1> ;
  6044                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6045                              <1> ;-------------------------------------------------------------------------------
  6046                              <1> DSK_FORMAT:
  6047 00001BE6 E83C030000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6048 00001BEB E838050000          <1> 	CALL	FMT_INIT		; ESTABLISH STATE IF UNESTABLISHED
  6049 00001BF0 800D[72BE0000]80    <1>         OR      byte [MOTOR_STATUS], 10000000B ; INDICATE WRITE OPERATION
  6050 00001BF7 E880050000          <1> 	CALL	MED_CHANGE		; CHECK MEDIA CHANGE AND RESET IF SO
  6051 00001BFC 725D                <1>         JC      short FM_DON            ; MEDIA CHANGED, SKIP
  6052 00001BFE E8DB020000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
  6053 00001C03 E8E6050000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMPT RATE IS SAME AS LAST RATE
  6054 00001C08 7405                <1>         JZ      short FM_WR             ; YES, SKIP SPECIFY COMMAND
  6055 00001C0A E8BD050000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO CONTROLLER
  6056                              <1> FM_WR:
  6057 00001C0F E873060000          <1> 	CALL	FMTDMA_SET		; SET UP THE DMA FOR FORMAT
  6058 00001C14 7245                <1>         JC      short FM_DON            ; RETURN WITH ERROR
  6059 00001C16 B44D                <1> 	MOV	AH,04DH			; ESTABLISH THE FORMAT COMMAND
  6060 00001C18 E8D0060000          <1> 	CALL	NEC_INIT		; INITIALIZE THE NEC
  6061 00001C1D 723C                <1>         JC      short FM_DON            ; ERROR - EXIT
  6062 00001C1F B8[5B1C0000]        <1>         MOV     eAX, FM_DON             ; LOAD ERROR ADDRESS
  6063 00001C24 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6064 00001C25 B203                <1> 	MOV	DL,3			; BYTES/SECTOR VALUE TO NEC
  6065 00001C27 E83F090000          <1> 	CALL	GET_PARM
  6066 00001C2C E8400A0000          <1> 	CALL	NEC_OUTPUT
  6067 00001C31 B204                <1> 	MOV	DL,4			; SECTORS/TRACK VALUE TO NEC
  6068 00001C33 E833090000          <1> 	CALL	GET_PARM
  6069 00001C38 E8340A0000          <1> 	CALL	NEC_OUTPUT
  6070 00001C3D B207                <1> 	MOV	DL,7			; GAP LENGTH VALUE TO NEC
  6071 00001C3F E827090000          <1> 	CALL	GET_PARM
  6072 00001C44 E8280A0000          <1> 	CALL	NEC_OUTPUT
  6073 00001C49 B208                <1> 	MOV	DL,8			; FILLER BYTE TO NEC
  6074 00001C4B E81B090000          <1> 	CALL	GET_PARM
  6075 00001C50 E81C0A0000          <1> 	CALL	NEC_OUTPUT
  6076 00001C55 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  6077 00001C56 E810070000          <1> 	CALL	NEC_TERM		; TERMINATE, RECEIVE STATUS, ETC,
  6078                              <1> FM_DON:
  6079 00001C5B E8F8020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6080 00001C60 E832080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6081 00001C65 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6082 00001C68 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6083 00001C6A C3                  <1> 	RETn
  6084                              <1> 
  6085                              <1> ;-------------------------------------------------------------------------------
  6086                              <1> ; FNC_ERR
  6087                              <1> ;	INVALID FUNCTION REQUESTED OR INVALID DRIVE: 
  6088                              <1> ;	SET BAD COMMAND IN STATUS.
  6089                              <1> ;
  6090                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6091                              <1> ;-------------------------------------------------------------------------------
  6092                              <1> FNC_ERR:				; INVALID FUNCTION REQUEST
  6093 00001C6B 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
  6094 00001C6E B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
  6095 00001C70 8825[74BE0000]      <1> 	MOV	[DSKETTE_STATUS],AH	; STORE IN DATA AREA
  6096 00001C76 F9                  <1> 	STC				; SET CARRY INDICATING ERROR
  6097 00001C77 C3                  <1> 	RETn
  6098                              <1> 
  6099                              <1> ;-------------------------------------------------------------------------------
  6100                              <1> ; DISK_PARMS	(AH = 08H)	
  6101                              <1> ;	READ DRIVE PARAMETERS.
  6102                              <1> ;
  6103                              <1> ; ON ENTRY:	DI : DRIVE #
  6104                              <1> ;
  6105                              <1> ; ON EXIT:	CL/[BP]   = BITS 7 & 6 HI 2 BITS OF MAX CYLINDER
  6106                              <1> ;		            BITS 0-5 MAX SECTORS/TRACK
  6107                              <1> ;		CH/[BP+1] = LOW 8 BITS OF MAX CYLINDER
  6108                              <1> ;		BL/[BP+2] = BITS 7-4 = 0
  6109                              <1> ;		            BITS 3-0 = VALID CMOS DRIVE TYPE
  6110                              <1> ;		BH/[BP+3] = 0
  6111                              <1> ;		DL/[BP+4] = # DRIVES INSTALLED (VALUE CHECKED)
  6112                              <1> ;		DH/[BP+5] = MAX HEAD #
  6113                              <1> ;		DI/[BP+6] = OFFSET TO DISK_BASE
  6114                              <1> ;		ES        = SEGMENT OF DISK_BASE
  6115                              <1> ;		AX        = 0
  6116                              <1> ;
  6117                              <1> ;		NOTE : THE ABOVE INFORMATION IS STORED IN THE USERS STACK AT
  6118                              <1> ;		       THE LOCATIONS WHERE THE MAIN ROUTINE WILL POP THEM
  6119                              <1> ;		       INTO THE APPROPRIATE REGISTERS BEFORE RETURNING TO THE
  6120                              <1> ;		       CALLER.
  6121                              <1> ;-------------------------------------------------------------------------------
  6122                              <1> DSK_PARMS:
  6123 00001C78 E8AA020000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  6124                              <1>      ;	MOV	WORD [BP+2],0		; DRIVE TYPE = 0
  6125 00001C7D 29D2                <1> 	sub     edx, edx ; 20/02/2015
  6126 00001C7F 895504              <1>         mov	[ebp+4], edx ; 20/02/2015
  6127                              <1>      ;  MOV     AX, [EQUIP_FLAG]        ; LOAD EQUIPMENT FLAG FOR # DISKETTES
  6128                              <1>      ;  AND     AL,11000001B            ; KEEP DISKETTE DRIVE BITS
  6129                              <1>      ;  MOV     DL,2                    ; DISKETTE DRIVES = 2
  6130                              <1>      ;  CMP     AL,01000001B            ; 2 DRIVES INSTALLED ?
  6131                              <1>      ;  JZ      short STO_DL            ; IF YES JUMP
  6132                              <1>      ;  DEC     DL                      ; DISKETTE DRIVES = 1
  6133                              <1>      ;  CMP     AL,00000001B            ; 1 DRIVE INSTALLED ?
  6134                              <1>      ;  JNZ     short NON_DRV           ; IF NO JUMP
  6135                              <1> 	;sub	edx, edx
  6136 00001C82 66A1[BEB80000]      <1> 	mov     ax, [fd0_type]
  6137 00001C88 6621C0              <1> 	and     ax, ax
  6138 00001C8B 7474                <1> 	jz      short NON_DRV
  6139 00001C8D FEC2                <1> 	inc     dl
  6140 00001C8F 20E4                <1> 	and     ah, ah
  6141 00001C91 7402                <1> 	jz      short STO_DL
  6142 00001C93 FEC2                <1> 	inc     dl
  6143                              <1> STO_DL:
  6144                              <1> 	;MOV	[BP+4],DL		; STORE NUMBER OF DRIVES
  6145 00001C95 895508              <1> 	mov	[ebp+8], edx ; 20/02/2015	 	
  6146 00001C98 6683FF01            <1> 	CMP	DI,1			; CHECK FOR VALID DRIVE
  6147 00001C9C 7766                <1> 	JA	short NON_DRV1		; DRIVE INVALID
  6148                              <1> 	;MOV	BYTE [BP+5],1		; MAXIMUM HEAD NUMBER =	1
  6149 00001C9E C6450901            <1> 	mov	byte [ebp+9], 1  ; 20/02/2015	
  6150 00001CA2 E8BB080000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  6151                              <1> 	;;20/02/2015
  6152                              <1> 	;;JC	short CHK_EST		; IF CMOS BAD CHECKSUM ESTABLISHED
  6153                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE TYPE
  6154 00001CA7 7412                <1> 	JZ	short CHK_EST		; JUMP IF SO
  6155 00001CA9 E805020000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6156 00001CAE 720B                <1> 	JC	short CHK_EST		; TYPE NOT IN TABLE (POSSIBLE BAD CMOS)
  6157                              <1> 	;MOV	[BP+2],AL		; STORE VALID CMOS DRIVE TYPE
  6158 00001CB0 884504              <1>         mov	[ebp+4], al ; 06/02/2015
  6159 00001CB3 8A4B04              <1> 	MOV     CL, [eBX+MD.SEC_TRK]     ; GET SECTOR/TRACK
  6160 00001CB6 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]     ; GET MAX. TRACK NUMBER
  6161 00001CB9 EB36                <1> 	JMP	SHORT STO_CX		; CMOS GOOD, USE CMOS
  6162                              <1> CHK_EST:
  6163 00001CBB 8AA7[81BE0000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; LOAD STATE FOR THIS DRIVE
  6164 00001CC1 F6C410              <1> 	TEST	AH,MED_DET		; CHECK FOR ESTABLISHED STATE
  6165 00001CC4 743E                <1> 	JZ	short NON_DRV1		; CMOS BAD/INVALID OR UNESTABLISHED
  6166                              <1> USE_EST:
  6167 00001CC6 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE STATE
  6168 00001CC9 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  6169 00001CCC 7557                <1> 	JNE	short USE_EST2		; NO, GO CHECK OTHER RATE
  6170                              <1> 
  6171                              <1> ;-----	DATA RATE IS 250 KBS, TRY 360 KB TABLE FIRST
  6172                              <1> 
  6173 00001CCE B001                <1> 	MOV	AL,01			; DRIVE TYPE 1 (360KB)
  6174 00001CD0 E8DE010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6175 00001CD5 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6176 00001CD8 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6177 00001CDB F687[81BE0000]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; 80 TRACK ?
  6178 00001CE2 740D                <1> 	JZ	short STO_CX		; MUST BE 360KB DRIVE 
  6179                              <1> 
  6180                              <1> ;-----	IT IS 1.44 MB DRIVE
  6181                              <1> 
  6182                              <1> PARM144:
  6183 00001CE4 B004                <1> 	MOV	AL,04			; DRIVE TYPE 4 (1.44MB)
  6184 00001CE6 E8C8010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6185 00001CEB 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6186 00001CEE 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6187                              <1> STO_CX:
  6188 00001CF1 894D00              <1> 	MOV	[eBP],eCX		; SAVE POINTER IN STACK FOR RETURN
  6189                              <1> ES_DI:
  6190                              <1> 	;MOV	[BP+6],BX		; ADDRESS OF MEDIA/DRIVE PARM TABLE 
  6191 00001CF4 895D0C              <1> 	mov	[ebp+12], ebx ; 06/02/2015
  6192                              <1> 	;MOV	AX,CS			; SEGMENT MEDIA/DRIVE PARAMETER TABLE
  6193                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
  6194                              <1> DP_OUT:
  6195 00001CF7 E85C020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6196 00001CFC 6631C0              <1> 	XOR	AX,AX			; CLEAR
  6197 00001CFF F8                  <1> 	CLC
  6198 00001D00 C3                  <1> 	RETn
  6199                              <1> 
  6200                              <1> ;-----	NO DRIYE PRESENT HANDLER
  6201                              <1> 
  6202                              <1> NON_DRV:
  6203                              <1> 	;MOV	BYTE [BP+4],0		; CLEAR NUMBER OF DRIVES
  6204 00001D01 895508              <1> 	mov	[ebp+8], edx ; 0 ; 20/02/2015
  6205                              <1> NON_DRV1:
  6206 00001D04 6681FF8000          <1> 	CMP	DI,80H			; CHECK FOR FIXED MEDIA TYPE REQUEST
  6207 00001D09 720C                <1> 	JB	short NON_DRV2		; CONTINUE IF NOT REQUEST FALL THROUGH
  6208                              <1> 
  6209                              <1> ;-----	FIXED DISK REQUEST FALL THROUGH ERROR
  6210                              <1> 	
  6211 00001D0B E848020000          <1> 	CALL	XLAT_OLD		; ELSE TRANSLATE TO COMPATIBLE MODE
  6212 00001D10 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
  6213 00001D13 B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
  6214 00001D15 F9                  <1> 	STC
  6215 00001D16 C3                  <1> 	RETn
  6216                              <1> 
  6217                              <1> NON_DRV2:
  6218                              <1> 	;XOR	AX,AX			; CLEAR PARMS IF NO DRIVES OR CMOS BAD
  6219 00001D17 31C0                <1> 	xor	eax, eax	
  6220 00001D19 66894500            <1> 	MOV	[eBP],AX		; TRACKS, SECTORS/TRACK = 0
  6221                              <1> 	;MOV	[BP+5],AH		; HEAD = 0
  6222 00001D1D 886509              <1> 	mov	[ebp+9], ah ; 06/02/2015
  6223                              <1> 	;MOV	[BP+6],AX		; OFFSET TO DISK_BASE = 0
  6224 00001D20 89450C              <1> 	mov	[ebp+12], eax
  6225                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
  6226 00001D23 EBD2                <1> 	JMP	SHORT DP_OUT
  6227                              <1> 
  6228                              <1> ;-----	DATA RATE IS EITHER 300 KBS OR 500 KBS, TRY 1.2 MB TABLE FIRST
  6229                              <1> 
  6230                              <1> USE_EST2:
  6231 00001D25 B002                <1> 	MOV	AL,02			; DRIVE TYPE 2 (1.2MB)
  6232 00001D27 E887010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6233 00001D2C 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6234 00001D2F 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6235 00001D32 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  6236 00001D35 74BA                <1> 	JZ	short STO_CX		; MUST BE 1.2MB DRIVE
  6237 00001D37 EBAB                <1> 	JMP	SHORT PARM144		; ELSE, IT IS 1.44MB DRIVE 
  6238                              <1> 
  6239                              <1> ;-------------------------------------------------------------------------------
  6240                              <1> ; DISK_TYPE (AH = 15H)	
  6241                              <1> ;	THIS ROUTINE RETURNS THE TYPE OF MEDIA INSTALLED.
  6242                              <1> ;
  6243                              <1> ;  ON ENTRY:	DI = DRIVE #
  6244                              <1> ;
  6245                              <1> ;  ON EXIT:	AH = DRIVE TYPE, CY=0
  6246                              <1> ;-------------------------------------------------------------------------------
  6247                              <1> DSK_TYPE:
  6248 00001D39 E8E9010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6249 00001D3E 8A87[81BE0000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET PRESENT STATE INFORMATION
  6250 00001D44 08C0                <1> 	OR	AL,AL			; CHECK FOR NO DRIVE
  6251 00001D46 7418                <1> 	JZ	short NO_DRV
  6252 00001D48 B401                <1> 	MOV	AH,NOCHGLN		; NO CHANGE LINE FOR 40 TRACK DRIVE
  6253 00001D4A A801                <1> 	TEST	AL,TRK_CAPA		; IS THIS DRIVE AN 80 TRACK DRIVE?
  6254 00001D4C 7402                <1> 	JZ	short DT_BACK			; IF NO JUMP
  6255 00001D4E B402                <1> 	MOV	AH,CHGLN		; CHANGE LINE FOR 80 TRACK DRIVE
  6256                              <1> DT_BACK:
  6257 00001D50 6650                <1> 	PUSH	AX			; SAVE RETURN VALUE
  6258 00001D52 E801020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6259 00001D57 6658                <1> 	POP	AX			; RESTORE RETURN VALUE
  6260 00001D59 F8                  <1> 	CLC				; NO ERROR
  6261 00001D5A 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6262 00001D5D 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6263 00001D5F C3                  <1> 	RETn
  6264                              <1> NO_DRV:	
  6265 00001D60 30E4                <1> 	XOR	AH,AH			; NO DRIVE PRESENT OR UNKNOWN
  6266 00001D62 EBEC                <1> 	JMP	SHORT DT_BACK
  6267                              <1> 
  6268                              <1> ;-------------------------------------------------------------------------------
  6269                              <1> ; DISK_CHANGE	(AH = 16H)
  6270                              <1> ;	THIS ROUTINE RETURNS THE STATE OF THE DISK CHANGE LINE.
  6271                              <1> ;
  6272                              <1> ; ON ENTRY:	DI = DRIVE #
  6273                              <1> ;
  6274                              <1> ; ON EXIT:	AH = @DSKETTE_STATUS
  6275                              <1> ;		     00 - DISK CHANGE LINE INACTIVE, CY = 0
  6276                              <1> ;		     06 - DISK CHANGE LINE ACTIVE, CY = 1
  6277                              <1> ;-------------------------------------------------------------------------------
  6278                              <1> DSK_CHANGE:
  6279 00001D64 E8BE010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6280 00001D69 8A87[81BE0000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET MEDIA STATE INFORMATION
  6281 00001D6F 08C0                <1> 	OR	AL,AL			; DRIVE PRESENT ?
  6282 00001D71 7422                <1> 	JZ	short DC_NON		; JUMP IF NO DRIVE
  6283 00001D73 A801                <1> 	TEST	AL,TRK_CAPA		; 80 TRACK DRIVE ?
  6284 00001D75 7407                <1> 	JZ	short SETIT		; IF SO , CHECK CHANGE LINE
  6285                              <1> DC0:
  6286 00001D77 E88D0A0000          <1>         CALL    READ_DSKCHNG            ; GO CHECK STATE OF DISK CHANGE LINE
  6287 00001D7C 7407                <1> 	JZ	short FINIS		; CHANGE LINE NOT ACTIVE
  6288                              <1> 
  6289 00001D7E C605[74BE0000]06    <1> SETIT:	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; INDICATE MEDIA REMOVED
  6290                              <1> 
  6291 00001D85 E8CE010000          <1> FINIS:	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6292 00001D8A E808070000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6293 00001D8F 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6294 00001D92 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6295 00001D94 C3                  <1> 	RETn
  6296                              <1> DC_NON:
  6297 00001D95 800D[74BE0000]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; SET TIMEOUT, NO DRIVE
  6298 00001D9C EBE7                <1> 	JMP	SHORT FINIS
  6299                              <1> 
  6300                              <1> ;-------------------------------------------------------------------------------
  6301                              <1> ; FORMAT_SET	(AH = 17H)
  6302                              <1> ;	THIS ROUTINE IS USED TO ESTABLISH THE TYPE OF MEDIA TO BE USED
  6303                              <1> ;	FOR THE FOLLOWING FORMAT OPERATION.
  6304                              <1> ;
  6305                              <1> ; ON ENTRY:	SI LOW = DASD TYPE FOR FORMAT
  6306                              <1> ;		DI     = DRIVE #
  6307                              <1> ;
  6308                              <1> ; ON EXIT:	@DSKETTE_STATUS REFLECTS STATUS
  6309                              <1> ;		AH = @DSKETTE_STATUS
  6310                              <1> ;		CY = 1 IF ERROR
  6311                              <1> ;-------------------------------------------------------------------------------
  6312                              <1> FORMAT_SET:
  6313 00001D9E E884010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6314 00001DA3 6656                <1> 	PUSH	SI			; SAVE DASD TYPE
  6315 00001DA5 6689F0              <1> 	MOV	AX,SI			; AH = ? , AL , DASD TYPE
  6316 00001DA8 30E4                <1> 	XOR	AH,AH			; AH , 0 , AL , DASD TYPE
  6317 00001DAA 6689C6              <1> 	MOV	SI,AX			; SI = DASD TYPE
  6318 00001DAD 80A7[81BE0000]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  6319 00001DB4 664E                <1> 	DEC	SI			; CHECK FOR 320/360K MEDIA & DRIVE
  6320 00001DB6 7509                <1> 	JNZ	short NOT_320		; BYPASS IF NOT
  6321 00001DB8 808F[81BE0000]90    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_250 ; SET TO 320/360
  6322 00001DBF EB48                <1> 	JMP	SHORT S0
  6323                              <1> 
  6324                              <1> NOT_320:
  6325 00001DC1 E8B6030000          <1> 	CALL	MED_CHANGE		; CHECK FOR TIME_OUT
  6326 00001DC6 803D[74BE0000]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT
  6327 00001DCD 743A                <1> 	JZ	short S0		; IF TIME OUT TELL CALLER
  6328                              <1> S3:
  6329 00001DCF 664E                <1> 	DEC	SI			; CHECK FOR 320/360K IN 1.2M DRIVE
  6330 00001DD1 7509                <1> 	JNZ	short NOT_320_12	; BYPASS IF NOT
  6331 00001DD3 808F[81BE0000]70    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+DBL_STEP+RATE_300 ; SET STATE
  6332 00001DDA EB2D                <1> 	JMP	SHORT S0
  6333                              <1> 
  6334                              <1> NOT_320_12:
  6335 00001DDC 664E                <1> 	DEC	SI			; CHECK FOR 1.2M MEDIA IN 1.2M DRIVE
  6336 00001DDE 7509                <1> 	JNZ	short NOT_12		; BYPASS IF NOT
  6337 00001DE0 808F[81BE0000]10    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_500 ; SET STATE VARIABLE
  6338 00001DE7 EB20                <1> 	JMP	SHORT S0		; RETURN TO CALLER
  6339                              <1> 
  6340                              <1> NOT_12:	
  6341 00001DE9 664E                <1> 	DEC	SI			; CHECK FOR SET DASD TYPE 04
  6342 00001DEB 752B                <1> 	JNZ	short FS_ERR		; BAD COMMAND EXIT IF NOT VALID TYPE
  6343                              <1> 
  6344 00001DED F687[81BE0000]04    <1> 	TEST	byte [DSK_STATE+eDI], DRV_DET ; DRIVE DETERMINED ?
  6345 00001DF4 740B                <1> 	JZ	short ASSUME		; IF STILL NOT DETERMINED ASSUME
  6346 00001DF6 B050                <1> 	MOV	AL,MED_DET+RATE_300
  6347 00001DF8 F687[81BE0000]02    <1>         TEST    byte [DSK_STATE+eDI], FMT_CAPA ; MULTIPLE FORMAT CAPABILITY ?
  6348 00001DFF 7502                <1> 	JNZ	short OR_IT_IN		; IF 1.2 M THEN DATA RATE 300
  6349                              <1> 
  6350                              <1> ASSUME:
  6351 00001E01 B090                <1> 	MOV	AL,MED_DET+RATE_250	; SET UP
  6352                              <1> 
  6353                              <1> OR_IT_IN:
  6354 00001E03 0887[81BE0000]      <1> 	OR	[DSK_STATE+eDI], AL	; OR IN THE CORRECT STATE
  6355                              <1> S0:
  6356 00001E09 E84A010000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6357 00001E0E E884060000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6358 00001E13 665B                <1> 	POP	BX			; GET SAVED AL TO BL
  6359 00001E15 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6360 00001E17 C3                  <1> 	RETn
  6361                              <1> 
  6362                              <1> FS_ERR:
  6363 00001E18 C605[74BE0000]01    <1> 	MOV	byte [DSKETTE_STATUS], BAD_CMD ; UNKNOWN STATE,BAD COMMAND
  6364 00001E1F EBE8                <1> 	JMP	SHORT S0
  6365                              <1> 
  6366                              <1> ;-------------------------------------------------------------------------------
  6367                              <1> ; SET_MEDIA	(AH = 18H)
  6368                              <1> ;	THIS ROUTINE SETS THE TYPE OF MEDIA AND DATA RATE 
  6369                              <1> ;	TO BE USED FOR THE FOLLOWING FORMAT OPERATION.
  6370                              <1> ;
  6371                              <1> ; ON ENTRY:
  6372                              <1> ;	[BP]	= SECTOR PER TRACK
  6373                              <1> ;	[BP+1]	= TRACK #
  6374                              <1> ;	DI	= DRIVE #
  6375                              <1> ;
  6376                              <1> ; ON EXIT:
  6377                              <1> ;	@DSKETTE_STATUS REFLECTS STATUS
  6378                              <1> ;	IF NO ERROR:
  6379                              <1> ;		AH = 0
  6380                              <1> ;		CY = 0
  6381                              <1> ;		ES = SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  6382                              <1> ;		DI/[BP+6] = OFFSET OF MEDIA/DRIVE PARAMETER TABLE
  6383                              <1> ;	IF ERROR:	
  6384                              <1> ;		AH = @DSKETTE_STATUS
  6385                              <1> ;		CY = 1
  6386                              <1> ;-------------------------------------------------------------------------------
  6387                              <1> SET_MEDIA:
  6388 00001E21 E801010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6389 00001E26 F687[81BE0000]01    <1>         TEST    byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR CHANGE LINE AVAILABLE
  6390 00001E2D 7415                <1> 	JZ	short SM_CMOS		; JUMP IF 40 TRACK DRIVE
  6391 00001E2F E848030000          <1> 	CALL	MED_CHANGE		; RESET CHANGE LINE
  6392 00001E34 803D[74BE0000]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT ; IF TIME OUT TELL CALLER
  6393 00001E3B 746B                <1> 	JE	short SM_RTN
  6394 00001E3D C605[74BE0000]00    <1> 	MOV	byte [DSKETTE_STATUS], 0 ; CLEAR STATUS
  6395                              <1> SM_CMOS:
  6396 00001E44 E819070000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  6397                              <1> 	;;20/02/2015
  6398                              <1> 	;;JC	short MD_NOT_FND	; ERROR IN CMOS
  6399                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE
  6400 00001E49 745D                <1> 	JZ	short SM_RTN		; RETURN IF SO
  6401 00001E4B E863000000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6402 00001E50 7231                <1> 	JC	short MD_NOT_FND	; TYPE NOT IN TABLE (BAD CMOS)
  6403 00001E52 57                  <1> 	PUSH	eDI			; SAVE REG.
  6404 00001E53 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR. TYPE TABLE
  6405 00001E55 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6406                              <1> DR_SEARCH:
  6407 00001E5A 8AA3[3CB80000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  6408 00001E60 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  6409 00001E63 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH ?
  6410 00001E65 7516                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT DRIVE TYPE
  6411                              <1> DR_FND:
  6412 00001E67 8BBB[3DB80000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAM TABLE
  6413                              <1> MD_SEARCH:
  6414 00001E6D 8A6704              <1>         MOV     AH, [eDI+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6415 00001E70 386500              <1> 	CMP	[eBP],AH		; MATCH?
  6416 00001E73 7508                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT MEDIA
  6417 00001E75 8A670B              <1>         MOV     AH, [eDI+MD.MAX_TRK]    ; GET MAX. TRACK #
  6418 00001E78 386501              <1> 	CMP 	[eBP+1],AH		; MATCH?
  6419 00001E7B 740F                <1> 	JE	short MD_FND		; YES, GO GET RATE
  6420                              <1> NXT_MD:
  6421                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6422 00001E7D 83C305              <1>         add	ebx, 5 ; 18/02/2015
  6423 00001E80 E2D8                <1> 	LOOP    DR_SEARCH
  6424 00001E82 5F                  <1> 	POP	eDI			; RESTORE REG.
  6425                              <1> MD_NOT_FND:
  6426 00001E83 C605[74BE0000]0C    <1> 	MOV	byte [DSKETTE_STATUS], MED_NOT_FND ; ERROR, MEDIA TYPE NOT FOUND
  6427 00001E8A EB1C                <1> 	JMP	SHORT SM_RTN		; RETURN
  6428                              <1> MD_FND:
  6429 00001E8C 8A470C              <1>         MOV     AL, [eDI+MD.RATE]       ; GET RATE
  6430 00001E8F 3C40                <1> 	CMP	AL,RATE_300		; DOUBLE STEP REQUIRED FOR RATE 300
  6431 00001E91 7502                <1> 	JNE	short MD_SET
  6432 00001E93 0C20                <1> 	OR	AL,DBL_STEP
  6433                              <1> MD_SET:
  6434                              <1> 	;MOV	[BP+6],DI		; SAVE TABLE POINTER IN STACK
  6435 00001E95 897D0C              <1> 	mov	[ebp+12], edi ; 18/02/2015
  6436 00001E98 0C10                <1> 	OR	AL,MED_DET		; SET MEDIA ESTABLISHED
  6437 00001E9A 5F                  <1> 	POP	eDI
  6438 00001E9B 80A7[81BE0000]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  6439 00001EA2 0887[81BE0000]      <1> 	OR	[DSK_STATE+eDI], AL
  6440                              <1> 	;MOV	AX, CS			; SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  6441                              <1> 	;MOV	ES, AX			; ES IS SEGMENT OF TABLE
  6442                              <1> SM_RTN:
  6443 00001EA8 E8AB000000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6444 00001EAD E8E5050000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6445 00001EB2 C3                  <1> 	RETn
  6446                              <1> 
  6447                              <1> ;----------------------------------------------------------------
  6448                              <1> ; DR_TYPE_CHECK							:
  6449                              <1> ;	CHECK IF THE GIVEN DRIVE TYPE IN REGISTER (AL)		:
  6450                              <1> ;	IS SUPPORTED IN BIOS DRIVE TYPE TABLE			:
  6451                              <1> ; ON ENTRY:							:
  6452                              <1> ;	AL = DRIVE TYPE						:
  6453                              <1> ; ON EXIT:							:
  6454                              <1> ;	CS = SEGMENT MEDIA/DRIVE PARAMETER TABLE (CODE)		:
  6455                              <1> ;	CY = 0 	DRIVE TYPE SUPPORTED				:
  6456                              <1> ;	     BX = OFFSET TO MEDIA/DRIVE PARAMETER TABLE		:
  6457                              <1> ;	CY = 1	DRIVE TYPE NOT SUPPORTED 			:
  6458                              <1> ; REGISTERS ALTERED: eBX						:
  6459                              <1> ;----------------------------------------------------------------		
  6460                              <1> DR_TYPE_CHECK:
  6461 00001EB3 6650                <1> 	PUSH	AX			
  6462 00001EB5 51                  <1> 	PUSH	eCX
  6463 00001EB6 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  6464 00001EB8 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6465                              <1> TYPE_CHK:	
  6466 00001EBD 8AA3[3CB80000]      <1> 	MOV	AH,[DR_TYPE+eBX]	; GET DRIVE TYPE
  6467 00001EC3 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  6468 00001EC5 740D                <1> 	JE	short DR_TYPE_VALID	; YES, RETURN WITH CARRY RESET
  6469                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6470 00001EC7 83C305              <1>         add	ebx, 5	; 16/02/2015 (32 bit address modification)
  6471 00001ECA E2F1                <1> 	LOOP    TYPE_CHK
  6472                              <1> 	;
  6473 00001ECC BB[9BB80000]        <1> 	mov	ebx, MD_TBL6		; 1.44MB fd parameter table
  6474                              <1> 					; Default for GET_PARM (11/12/2014)
  6475                              <1> 	;
  6476 00001ED1 F9                  <1> 	STC				; DRIVE TYPE NOT FOUND IN TABLE
  6477 00001ED2 EB06                <1> 	JMP	SHORT TYPE_RTN
  6478                              <1> DR_TYPE_VALID:
  6479 00001ED4 8B9B[3DB80000]      <1> 	MOV	eBX,[DR_TYPE+eBX+1] 	; BX = MEDIA TABLE
  6480                              <1> TYPE_RTN:
  6481 00001EDA 59                  <1> 	POP	eCX
  6482 00001EDB 6658                <1> 	POP	AX
  6483 00001EDD C3                  <1> 	RETn	
  6484                              <1> 		
  6485                              <1> ;----------------------------------------------------------------
  6486                              <1> ; SEND_SPEC							:
  6487                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  6488                              <1> ;	THE DRIVE PARAMETER TABLE POINTED BY @DISK_POINTER	:
  6489                              <1> ; ON ENTRY:	@DISK_POINTER = DRIVE PARAMETER TABLE		:
  6490                              <1> ; ON EXIT:	NONE						:	
  6491                              <1> ; REGISTERS ALTERED: CX, DX					:
  6492                              <1> ;----------------------------------------------------------------		
  6493                              <1> SEND_SPEC:
  6494 00001EDE 50                  <1> 	PUSH	eAX			; SAVE AX
  6495 00001EDF B8[051F0000]        <1> 	MOV	eAX, SPECBAC		; LOAD ERROR ADDRESS
  6496 00001EE4 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6497 00001EE5 B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  6498 00001EE7 E885070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6499 00001EEC 28D2                <1> 	SUB	DL,DL			; FIRST SPECIFY BYTE
  6500 00001EEE E878060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  6501 00001EF3 E879070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6502 00001EF8 B201                <1> 	MOV	DL,1			; SECOND SPECIFY BYTE
  6503 00001EFA E86C060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  6504 00001EFF E86D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6505 00001F04 58                  <1> 	POP	eAX			; POP ERROR RETURN
  6506                              <1> SPECBAC:
  6507 00001F05 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  6508 00001F06 C3                  <1> 	RETn
  6509                              <1> 
  6510                              <1> ;----------------------------------------------------------------
  6511                              <1> ; SEND_SPEC_MD							:
  6512                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  6513                              <1> ;	THE MEDIA/DRIVE PARAMETER TABLE POINTED BY (CS:BX)	:
  6514                              <1> ; ON ENTRY:	CS:BX = MEDIA/DRIVE PARAMETER TABLE		:
  6515                              <1> ; ON EXIT:	NONE						:	
  6516                              <1> ; REGISTERS ALTERED: AX						:
  6517                              <1> ;----------------------------------------------------------------		
  6518                              <1> SEND_SPEC_MD:
  6519 00001F07 50                  <1> 	PUSH	eAX			; SAVE RATE DATA
  6520 00001F08 B8[251F0000]        <1> 	MOV	eAX, SPEC_ESBAC		; LOAD ERROR ADDRESS
  6521 00001F0D 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6522 00001F0E B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  6523 00001F10 E85C070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6524 00001F15 8A23                <1>         MOV     AH, [eBX+MD.SPEC1]      ; GET 1ST SPECIFY BYTE
  6525 00001F17 E855070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6526 00001F1C 8A6301              <1>         MOV     AH, [eBX+MD.SPEC2]      ; GET SECOND SPECIFY BYTE
  6527 00001F1F E84D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6528 00001F24 58                  <1> 	POP	eAX			; POP ERROR RETURN
  6529                              <1> SPEC_ESBAC:
  6530 00001F25 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  6531 00001F26 C3                  <1> 	RETn
  6532                              <1> 
  6533                              <1> ;-------------------------------------------------------------------------------
  6534                              <1> ; XLAT_NEW  
  6535                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM COMPATIBLE
  6536                              <1> ;	MODE TO NEW ARCHITECTURE.
  6537                              <1> ;
  6538                              <1> ; ON ENTRY:	DI = DRIVE #
  6539                              <1> ;-------------------------------------------------------------------------------
  6540                              <1> XLAT_NEW:
  6541 00001F27 83FF01              <1> 	CMP	eDI,1				; VALID DRIVE
  6542 00001F2A 7725                <1> 	JA	short XN_OUT			; IF INVALID BACK
  6543 00001F2C 80BF[81BE0000]00    <1> 	CMP	byte [DSK_STATE+eDI], 0		; NO DRIVE ?
  6544 00001F33 741D                <1> 	JZ	short DO_DET			; IF NO DRIVE ATTEMPT DETERMINE
  6545 00001F35 6689F9              <1> 	MOV	CX,DI				; CX = DRIVE NUMBER
  6546 00001F38 C0E102              <1> 	SHL	CL,2				; CL = SHIFT COUNT, A=0, B=4
  6547 00001F3B A0[80BE0000]        <1> 	MOV	AL, [HF_CNTRL]			; DRIVE INFORMATION
  6548 00001F40 D2C8                <1> 	ROR	AL,CL				; TO LOW NIBBLE
  6549 00001F42 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA	; KEEP DRIVE BITS
  6550 00001F44 80A7[81BE0000]F8    <1>         AND     byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA)
  6551 00001F4B 0887[81BE0000]      <1> 	OR	[DSK_STATE+eDI], AL		; UPDATE DRIVE STATE
  6552                              <1> XN_OUT:
  6553 00001F51 C3                  <1> 	RETn
  6554                              <1> DO_DET:
  6555 00001F52 E8BF080000          <1> 	CALL	DRIVE_DET			; TRY TO DETERMINE
  6556 00001F57 C3                  <1> 	RETn
  6557                              <1> 
  6558                              <1> ;-------------------------------------------------------------------------------
  6559                              <1> ; XLAT_OLD 
  6560                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM NEW
  6561                              <1> ;	ARCHITECTURE TO COMPATIBLE MODE.
  6562                              <1> ;
  6563                              <1> ; ON ENTRY:	DI = DRIVE
  6564                              <1> ;-------------------------------------------------------------------------------
  6565                              <1> XLAT_OLD:
  6566 00001F58 83FF01              <1> 	CMP	eDI,1			; VALID DRIVE ?
  6567                              <1>         ;JA     short XO_OUT            ; IF INVALID BACK
  6568 00001F5B 0F8786000000        <1>         ja      XO_OUT
  6569 00001F61 80BF[81BE0000]00    <1>         CMP	byte [DSK_STATE+eDI],0	; NO DRIVE ?
  6570 00001F68 747D                <1> 	JZ	short XO_OUT		; IF NO DRIVE TRANSLATE DONE
  6571                              <1> 
  6572                              <1> ;-----	TEST FOR SAVED DRIVE INFORMATION ALREADY SET
  6573                              <1> 
  6574 00001F6A 6689F9              <1> 	MOV	CX,DI			; CX = DRIVE NUMBER
  6575 00001F6D C0E102              <1> 	SHL	CL,2			; CL = SHIFT COUNT, A=0, B=4
  6576 00001F70 B402                <1> 	MOV	AH,FMT_CAPA		; LOAD MULTIPLE DATA RATE BIT MASK
  6577 00001F72 D2CC                <1> 	ROR	AH,CL			; ROTATE BY MASK
  6578 00001F74 8425[80BE0000]      <1> 	TEST	[HF_CNTRL], AH		; MULTIPLE-DATA RATE DETERMINED ?
  6579 00001F7A 751C                <1> 	JNZ	short SAVE_SET		; IF SO, NO NEED TO RE-SAVE
  6580                              <1> 
  6581                              <1> ;-----	ERASE DRIVE BITS IN @HF_CNTRL FOR THIS DRIVE
  6582                              <1> 
  6583 00001F7C B407                <1> 	MOV	AH,DRV_DET+FMT_CAPA+TRK_CAPA ; MASK TO KEEP
  6584 00001F7E D2CC                <1> 	ROR	AH,CL			; FIX MASK TO KEEP
  6585 00001F80 F6D4                <1> 	NOT	AH			; TRANSLATE MASK
  6586 00001F82 2025[80BE0000]      <1> 	AND	[HF_CNTRL], AH		; KEEP BITS FROM OTHER DRIVE INTACT
  6587                              <1> 
  6588                              <1> ;-----	ACCESS CURRENT DRIVE BITS AND STORE IN @HF_CNTRL
  6589                              <1> 
  6590 00001F88 8A87[81BE0000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; ACCESS STATE
  6591 00001F8E 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA ; KEEP DRIVE BITS
  6592 00001F90 D2C8                <1> 	ROR	AL,CL			; FIX FOR THIS DRIVE
  6593 00001F92 0805[80BE0000]      <1> 	OR	[HF_CNTRL], AL		; UPDATE SAVED DRIVE STATE
  6594                              <1> 
  6595                              <1> ;-----	TRANSLATE TO COMPATIBILITY MODE
  6596                              <1> 
  6597                              <1> SAVE_SET:
  6598 00001F98 8AA7[81BE0000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  6599 00001F9E 88E7                <1> 	MOV	BH,AH			; TO BH FOR LATER
  6600 00001FA0 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE
  6601 00001FA3 80FC00              <1> 	CMP	AH,RATE_500		; RATE 500 ?
  6602 00001FA6 7410                <1> 	JZ	short CHK_144		; YES 1.2/1.2 OR 1.44/1.44
  6603 00001FA8 B001                <1> 	MOV	AL,M3D1U		; AL = 360 IN 1.2 UNESTABLISHED
  6604 00001FAA 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  6605 00001FAD 7518                <1> 	JNZ	short CHK_250		; NO, 360/360, 720/720 OR 720/1.44
  6606 00001FAF F6C720              <1> 	TEST	BH,DBL_STEP		; CHECK FOR DOUBLE STEP
  6607 00001FB2 751F                <1> 	JNZ	short TST_DET		; MUST BE 360 IN 1.2
  6608                              <1> UNKNO:
  6609 00001FB4 B007                <1> 	MOV	AL,MED_UNK		; NONE OF THE ABOVE
  6610 00001FB6 EB22                <1> 	JMP	SHORT AL_SET		; PROCESS COMPLETE
  6611                              <1> CHK_144:
  6612 00001FB8 E8A5050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  6613                              <1> 	;;20/02/2015
  6614                              <1> 	;;JC	short UNKNO		; ERROR, SET 'NONE OF ABOVE'
  6615 00001FBD 74F5                <1> 	jz	short UNKNO ;; 20/02/2015
  6616 00001FBF 3C02                <1> 	CMP	AL,2			; 1.2MB DRIVE ?
  6617 00001FC1 75F1                <1> 	JNE	short UNKNO		; NO, GO SET 'NONE OF ABOVE'
  6618 00001FC3 B002                <1> 	MOV	AL,M1D1U		; AL = 1.2 IN 1.2 UNESTABLISHED
  6619 00001FC5 EB0C                <1> 	JMP	SHORT TST_DET
  6620                              <1> CHK_250:
  6621 00001FC7 B000                <1> 	MOV	AL,M3D3U		; AL = 360 IN 360 UNESTABLISHED
  6622 00001FC9 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  6623 00001FCC 75E6                <1> 	JNZ	short UNKNO		; IF SO FALL IHRU
  6624 00001FCE F6C701              <1> 	TEST	BH,TRK_CAPA		; 80 TRACK CAPABILITY ?
  6625 00001FD1 75E1                <1> 	JNZ	short UNKNO		; IF SO JUMP, FALL THRU TEST DET
  6626                              <1> TST_DET:
  6627 00001FD3 F6C710              <1> 	TEST	BH,MED_DET		; DETERMINED ?
  6628 00001FD6 7402                <1> 	JZ	short AL_SET		; IF NOT THEN SET
  6629 00001FD8 0403                <1> 	ADD	AL,3			; MAKE DETERMINED/ESTABLISHED
  6630                              <1> AL_SET:
  6631 00001FDA 80A7[81BE0000]F8    <1> 	AND	byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA) ; CLEAR DRIVE
  6632 00001FE1 0887[81BE0000]      <1> 	OR	[DSK_STATE+eDI], AL	; REPLACE WITH COMPATIBLE MODE
  6633                              <1> XO_OUT:
  6634 00001FE7 C3                  <1> 	RETn
  6635                              <1> 
  6636                              <1> ;-------------------------------------------------------------------------------
  6637                              <1> ; RD_WR_VF
  6638                              <1> ;	COMMON READ, WRITE AND VERIFY: 
  6639                              <1> ;	MAIN LOOP FOR STATE RETRIES.
  6640                              <1> ;
  6641                              <1> ; ON ENTRY:	AH = READ/WRITE/VERIFY NEC PARAMETER
  6642                              <1> ;		AL = READ/WRITE/VERIFY DMA PARAMETER
  6643                              <1> ;
  6644                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6645                              <1> ;-------------------------------------------------------------------------------
  6646                              <1> RD_WR_VF:
  6647 00001FE8 6650                <1> 	PUSH	AX			; SAVE DMA, NEC PARAMETERS
  6648 00001FEA E838FFFFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6649 00001FEF E8F3000000          <1> 	CALL	SETUP_STATE		; INITIALIZE START AND END RATE
  6650 00001FF4 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  6651                              <1> DO_AGAIN:
  6652 00001FF6 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  6653 00001FF8 E87F010000          <1> 	CALL	MED_CHANGE		; MEDIA CHANGE AND RESET IF CHANGED
  6654 00001FFD 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  6655 00001FFF 0F82C9000000        <1>         JC      RWV_END                 ; MEDIA CHANGE ERROR OR TIME-OUT
  6656                              <1> RWV:
  6657 00002005 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  6658 00002007 8AB7[81BE0000]      <1> 	MOV	DH, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6659 0000200D 80E6C0              <1> 	AND	DH,RATE_MSK		; KEEP ONLY RATE
  6660 00002010 E84D050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL (AL)
  6661                              <1> 	;;20/02/2015
  6662                              <1> 	;;JC	short RWV_ASSUME	; ERROR IN CMOS
  6663 00002015 7451                <1> 	jz	short RWV_ASSUME ; 20/02/2015
  6664 00002017 3C01                <1> 	CMP	AL,1			; 40 TRACK DRIVE?
  6665 00002019 750D                <1> 	JNE	short RWV_1		; NO, BYPASS CMOS VALIDITY CHECK
  6666 0000201B F687[81BE0000]01    <1> 	TEST	byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR 40 TRACK DRIVE
  6667 00002022 7413                <1> 	JZ	short RWV_2		; YES, CMOS IS CORRECT
  6668 00002024 B002                <1> 	MOV	AL,2			; CHANGE TO 1.2M
  6669 00002026 EB0F                <1> 	JMP	SHORT RWV_2
  6670                              <1> RWV_1:
  6671 00002028 720D                <1> 	JB	short RWV_2		; NO DRIVE SPECIFIED, CONTINUE
  6672 0000202A F687[81BE0000]01    <1> 	TEST    byte [DSK_STATE+eDI], TRK_CAPA ; IS IT REALLY 40 TRACK?
  6673 00002031 7504                <1> 	JNZ	short RWV_2		; NO, 80 TRACK
  6674 00002033 B001                <1> 	MOV	AL,1			; IT IS 40 TRACK, FIX CMOS VALUE
  6675 00002035 EB04                <1> 	jmp	short rwv_3
  6676                              <1> RWV_2:
  6677 00002037 08C0                <1> 	OR	AL,AL			; TEST FOR NO DRIVE
  6678 00002039 742D                <1> 	JZ	short RWV_ASSUME	; ASSUME TYPE, USE MAX TRACK
  6679                              <1> rwv_3:
  6680 0000203B E873FEFFFF          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL.
  6681 00002040 7226                <1> 	JC	short RWV_ASSUME	; TYPE NOT IN TABLE (BAD CMOS)
  6682                              <1> 
  6683                              <1> ;-----	SEARCH FOR MEDIA/DRIVE PARAMETER TABLE
  6684                              <1> 
  6685 00002042 57                  <1> 	PUSH	eDI			; SAVE DRIVE #
  6686 00002043 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  6687 00002045 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6688                              <1> RWV_DR_SEARCH:
  6689 0000204A 8AA3[3CB80000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  6690 00002050 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  6691 00002053 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  6692 00002055 750B                <1> 	JNE	short RWV_NXT_MD	; NO, CHECK NEXT DRIVE TYPE
  6693                              <1> RWV_DR_FND:
  6694 00002057 8BBB[3DB80000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAMETER TABLE
  6695                              <1> RWV_MD_SEARH:
  6696 0000205D 3A770C              <1>         CMP     DH, [eDI+MD.RATE]       ; MATCH?
  6697 00002060 741B                <1> 	JE	short RWV_MD_FND	; YES, GO GET 1ST SPECIFY BYTE
  6698                              <1> RWV_NXT_MD:
  6699                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6700 00002062 83C305              <1> 	add	eBX, 5
  6701 00002065 E2E3                <1> 	LOOP	RWV_DR_SEARCH
  6702 00002067 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  6703                              <1> 
  6704                              <1> ;-----	ASSUME PRIMARY DRIVE IS INSTALLED AS SHIPPED
  6705                              <1> 
  6706                              <1> RWV_ASSUME:
  6707 00002068 BB[5AB80000]        <1> 	MOV	eBX, MD_TBL1		; POINT TO 40 TRACK 250 KBS
  6708 0000206D F687[81BE0000]01    <1> 	TEST 	byte [DSK_STATE+eDI], TRK_CAPA ; TEST FOR 80 TRACK
  6709 00002074 740A                <1> 	JZ	short RWV_MD_FND1	; MUST BE 40 TRACK
  6710 00002076 BB[74B80000]        <1> 	MOV	eBX, MD_TBL3		; POINT TO 80 TRACK 500 KBS
  6711 0000207B EB03                <1> 	JMP	short RWV_MD_FND1	; GO SPECIFY PARAMTERS
  6712                              <1> 
  6713                              <1> ;-----	CS:BX POINTS TO MEDIA/DRIVE PARAMETER TABLE
  6714                              <1> 	 			
  6715                              <1> RWV_MD_FND:
  6716 0000207D 89FB                <1> 	MOV	eBX,eDI			; BX = MEDIA/DRIVE PARAMETER TABLE
  6717 0000207F 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  6718                              <1> 	
  6719                              <1> ;-----	SEND THE SPECIFY COMMAND TO THE CONTROLLER
  6720                              <1> 
  6721                              <1> RWV_MD_FND1:
  6722 00002080 E882FEFFFF          <1> 	CALL	SEND_SPEC_MD
  6723 00002085 E864010000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMP RATE IS SAME AS LAST RATE
  6724 0000208A 7405                <1> 	JZ	short RWV_DBL		; YES,SKIP SEND RATE COMMAND
  6725 0000208C E83B010000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO NEC
  6726                              <1> RWV_DBL:
  6727 00002091 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6728 00002092 E822040000          <1> 	CALL	SETUP_DBL		; CHECK FOR DOUBLE STEP
  6729 00002097 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  6730 00002098 7226                <1> 	JC	short CHK_RET		; ERROR FROM READ ID, POSSIBLE RETRY
  6731 0000209A 6658                <1> 	POP	AX			; RESTORE NEC, DMA COMMAND
  6732 0000209C 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  6733 0000209E 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6734 0000209F E861010000          <1> 	CALL	DMA_SETUP		; SET UP THE DMA
  6735 000020A4 5B                  <1> 	POP	eBX 
  6736 000020A5 6658                <1> 	POP	AX			; RESTORE NEC COMMAND
  6737 000020A7 722F                <1> 	JC	short RWV_BAC		; CHECK FOR DMA BOUNDARY ERROR
  6738 000020A9 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  6739 000020AB 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6740 000020AC E83C020000          <1> 	CALL	NEC_INIT		; INITIALIZE NEC
  6741 000020B1 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  6742 000020B2 720C                <1> 	JC	short CHK_RET		; ERROR - EXIT
  6743 000020B4 E866020000          <1> 	CALL	RWV_COM			; OP CODE COMMON TO READ/WRITE/VERIFY
  6744 000020B9 7205                <1> 	JC	short CHK_RET		; ERROR - EXIT
  6745 000020BB E8AB020000          <1> 	CALL	NEC_TERM		; TERMINATE, GET STATUS, ETC.
  6746                              <1> CHK_RET:
  6747 000020C0 E84A030000          <1> 	CALL	RETRY			; CHECK FOR, SETUP RETRY
  6748 000020C5 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY PARAMETER
  6749 000020C7 7305                <1> 	JNC	short RWV_END		; CY = 0 NO RETRY
  6750 000020C9 E928FFFFFF          <1>         JMP     DO_AGAIN                ; CY = 1 MEANS RETRY
  6751                              <1> RWV_END:
  6752 000020CE E8F4020000          <1> 	CALL	DSTATE			; ESTABLISH STATE IF SUCCESSFUL
  6753 000020D3 E887030000          <1> 	CALL	NUM_TRANS		; AL = NUMBER TRANSFERRED
  6754                              <1> RWV_BAC:				; BAD DMA ERROR ENTRY
  6755 000020D8 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  6756 000020DA E879FEFFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6757 000020DF 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  6758 000020E1 E8B1030000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6759 000020E6 C3                  <1> 	RETn
  6760                              <1> 
  6761                              <1> ;-------------------------------------------------------------------------------
  6762                              <1> ; SETUP_STATE:	INITIALIZES START AND END RATES.
  6763                              <1> ;-------------------------------------------------------------------------------
  6764                              <1> SETUP_STATE:
  6765 000020E7 F687[81BE0000]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; MEDIA DETERMINED ?
  6766 000020EE 7537                <1> 	JNZ	short J1C		; NO STATES IF DETERMINED
  6767 000020F0 66B84000            <1>         MOV     AX,(RATE_500*256)+RATE_300  ; AH = START RATE, AL = END RATE
  6768 000020F4 F687[81BE0000]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE ?
  6769 000020FB 740D                <1> 	JZ	short AX_SET		; DO NOT KNOW DRIVE
  6770 000020FD F687[81BE0000]02    <1> 	TEST	byte [DSK_STATE+eDI], FMT_CAPA ; MULTI-RATE?
  6771 00002104 7504                <1> 	JNZ	short AX_SET		; JUMP IF YES
  6772 00002106 66B88080            <1>         MOV     AX,RATE_250*257         ; START A END RATE 250 FOR 360 DRIVE
  6773                              <1> AX_SET:	
  6774 0000210A 80A7[81BE0000]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP) ; TURN OFF THE RATE
  6775 00002111 08A7[81BE0000]      <1> 	OR	[DSK_STATE+eDI], AH	; RATE FIRST TO TRY
  6776 00002117 8025[7CBE0000]F3    <1> 	AND	byte [LASTRATE], ~STRT_MSK ; ERASE LAST TO TRY RATE BITS
  6777 0000211E C0C804              <1> 	ROR	AL,4			; TO OPERATION LAST RATE LOCATION
  6778 00002121 0805[7CBE0000]      <1> 	OR	[LASTRATE], AL		; LAST RATE
  6779                              <1> J1C:	
  6780 00002127 C3                  <1> 	RETn
  6781                              <1> 
  6782                              <1> ;-------------------------------------------------------------------------------
  6783                              <1> ;  FMT_INIT: ESTABLISH STATE IF UNESTABLISHED AT FORMAT TIME.
  6784                              <1> ;-------------------------------------------------------------------------------
  6785                              <1> FMT_INIT:
  6786 00002128 F687[81BE0000]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; IS MEDIA ESTABLISHED
  6787 0000212F 7546                <1> 	JNZ	short F1_OUT		; IF SO RETURN
  6788 00002131 E82C040000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  6789                              <1> 	;; 20/02/2015
  6790                              <1> 	;;JC	short CL_DRV		; ERROR IN CMOS ASSUME NO DRIVE
  6791 00002136 7440                <1> 	jz	short CL_DRV ;; 20/02/2015
  6792 00002138 FEC8                <1> 	DEC	AL			; MAKE ZERO ORIGIN
  6793                              <1> 	;;JS	short CL_DRV		; NO DRIVE IF AL 0
  6794 0000213A 8AA7[81BE0000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; AH = CURRENT STATE
  6795 00002140 80E40F              <1> 	AND	AH, ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR
  6796 00002143 08C0                <1> 	OR	AL,AL			; CHECK FOR 360
  6797 00002145 7505                <1> 	JNZ	short N_360		; IF 360 WILL BE 0
  6798 00002147 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; ESTABLISH MEDIA
  6799 0000214A EB25                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  6800                              <1> N_360:	
  6801 0000214C FEC8                <1> 	DEC	AL			; 1.2 M DRIVE
  6802 0000214E 7505                <1> 	JNZ	short N_12		; JUMP IF NOT
  6803                              <1> F1_RATE:
  6804 00002150 80CC10              <1> 	OR	AH,MED_DET+RATE_500	; SET FORMAT RATE
  6805 00002153 EB1C                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  6806                              <1> N_12:	
  6807 00002155 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 3
  6808 00002157 750F                <1> 	JNZ	short N_720		; JUMP IF NOT
  6809 00002159 F6C404              <1> 	TEST	AH,DRV_DET		; IS DRIVE DETERMINED
  6810 0000215C 7410                <1> 	JZ	short ISNT_12		; TREAT AS NON 1.2 DRIVE
  6811 0000215E F6C402              <1> 	TEST	AH,FMT_CAPA		; IS 1.2M
  6812 00002161 740B                <1> 	JZ	short ISNT_12		; JUMP IF NOT
  6813 00002163 80CC50              <1> 	OR	AH,MED_DET+RATE_300	; RATE 300
  6814 00002166 EB09                <1> 	JMP	SHORT SKP_STATE		; CONTINUE
  6815                              <1> N_720:
  6816 00002168 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 4
  6817 0000216A 750C                <1> 	JNZ	short CL_DRV		; NO DRIVE, CMOS BAD
  6818 0000216C EBE2                <1> 	JMP	SHORT F1_RATE
  6819                              <1> ISNT_12: 
  6820 0000216E 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; MUST BE RATE 250
  6821                              <1> 
  6822                              <1> SKP_STATE:
  6823 00002171 88A7[81BE0000]      <1> 	MOV	[DSK_STATE+eDI], AH	; STORE AWAY
  6824                              <1> F1_OUT:
  6825 00002177 C3                  <1> 	RETn
  6826                              <1> CL_DRV:	
  6827 00002178 30E4                <1> 	XOR	AH,AH			; CLEAR STATE
  6828 0000217A EBF5                <1> 	JMP	SHORT SKP_STATE		; SAVE IT
  6829                              <1> 
  6830                              <1> ;-------------------------------------------------------------------------------
  6831                              <1> ; MED_CHANGE	
  6832                              <1> ;	CHECKS FOR MEDIA CHANGE, RESETS MEDIA CHANGE, 
  6833                              <1> ;	CHECKS MEDIA CHANGE AGAIN.
  6834                              <1> ;
  6835                              <1> ; ON EXIT:	CY = 1 MEANS MEDIA CHANGE OR TIMEOUT
  6836                              <1> ;		@DSKETTE_STATUS = ERROR CODE
  6837                              <1> ;-------------------------------------------------------------------------------
  6838                              <1> MED_CHANGE:
  6839 0000217C E888060000          <1> 	CALL	READ_DSKCHNG		; READ DISK CHANCE LINE STATE
  6840 00002181 7447                <1> 	JZ	short MC_OUT		; BYPASS HANDLING DISK CHANGE LINE
  6841 00002183 80A7[81BE0000]EF    <1> 	AND	byte [DSK_STATE+eDI], ~MED_DET ; CLEAR STATE FOR THIS DRIVE
  6842                              <1> 
  6843                              <1> ;	THIS SEQUENCE ENSURES WHENEVER A DISKETTE IS CHANGED THAT
  6844                              <1> ;	ON THE NEXT OPERATION THE REQUIRED MOTOR START UP TIME WILL
  6845                              <1> ;	BE WAITED. (DRIVE MOTOR MAY GO OFF UPON DOOR OPENING).
  6846                              <1> 
  6847 0000218A 6689F9              <1> 	MOV	CX,DI			; CL = DRIVE 0
  6848 0000218D B001                <1> 	MOV	AL,1			; MOTOR ON BIT MASK
  6849 0000218F D2E0                <1> 	SHL	AL,CL			; TO APPROPRIATE POSITION
  6850 00002191 F6D0                <1> 	NOT	AL			; KEEP ALL BUT MOTOR ON
  6851 00002193 FA                  <1> 	CLI				; NO INTERRUPTS
  6852 00002194 2005[72BE0000]      <1> 	AND	[MOTOR_STATUS], AL	; TURN MOTOR OFF INDICATOR
  6853 0000219A FB                  <1> 	STI				; INTERRUPTS ENABLED
  6854 0000219B E810040000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON
  6855                              <1> 
  6856                              <1> ;-----	THIS SEQUENCE OF SEEKS IS USED TO RESET DISKETTE CHANGE SIGNAL
  6857                              <1> 
  6858 000021A0 E884F9FFFF          <1> 	CALL	DSK_RESET		; RESET NEC
  6859 000021A5 B501                <1> 	MOV	CH,01H			; MOVE TO CYLINDER 1
  6860 000021A7 E8FF040000          <1> 	CALL	SEEK			; ISSUE SEEK
  6861 000021AC 30ED                <1> 	XOR	CH,CH			; MOVE TO CYLINDER 0
  6862 000021AE E8F8040000          <1> 	CALL	SEEK			; ISSUE SEEK
  6863 000021B3 C605[74BE0000]06    <1> 	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; STORE IN STATUS
  6864                              <1> OK1:
  6865 000021BA E84A060000          <1> 	CALL	READ_DSKCHNG		; CHECK MEDIA CHANGED AGAIN
  6866 000021BF 7407                <1> 	JZ	short OK2		; IF ACTIVE, NO DISKETTE, TIMEOUT
  6867                              <1> OK4:
  6868 000021C1 C605[74BE0000]80    <1> 	MOV	byte [DSKETTE_STATUS], TIME_OUT ; TIMEOUT IF DRIVE EMPTY
  6869                              <1> OK2:		
  6870 000021C8 F9                  <1> 	STC				; MEDIA CHANGED, SET CY
  6871 000021C9 C3                  <1> 	RETn
  6872                              <1> MC_OUT:
  6873 000021CA F8                  <1> 	CLC				; NO MEDIA CHANGED, CLEAR CY
  6874 000021CB C3                  <1> 	RETn
  6875                              <1> 
  6876                              <1> ;-------------------------------------------------------------------------------
  6877                              <1> ; SEND_RATE
  6878                              <1> ;	SENDS DATA RATE COMMAND TO NEC
  6879                              <1> ; ON ENTRY:	DI = DRIVE #
  6880                              <1> ; ON EXIT:	NONE
  6881                              <1> ; REGISTERS ALTERED: DX
  6882                              <1> ;-------------------------------------------------------------------------------
  6883                              <1> SEND_RATE:
  6884 000021CC 6650                <1> 	PUSH	AX			; SAVE REG.
  6885 000021CE 8025[7CBE0000]3F    <1> 	AND	byte [LASTRATE], ~SEND_MSK ; ELSE CLEAR LAST RATE ATTEMPTED
  6886 000021D5 8A87[81BE0000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6887 000021DB 24C0                <1> 	AND	AL,SEND_MSK		; KEEP ONLY RATE BITS
  6888 000021DD 0805[7CBE0000]      <1> 	OR	[LASTRATE], AL		; SAVE NEW RATE FOR NEXT CHECK
  6889 000021E3 C0C002              <1> 	ROL	AL,2			; MOVE TO BIT OUTPUT POSITIONS
  6890 000021E6 66BAF703            <1> 	MOV	DX,03F7H		; OUTPUT NEW DATA RATE
  6891 000021EA EE                  <1> 	OUT	DX,AL
  6892 000021EB 6658                <1> 	POP	AX			; RESTORE REG.
  6893 000021ED C3                  <1> 	RETn
  6894                              <1> 
  6895                              <1> ;-------------------------------------------------------------------------------
  6896                              <1> ; CHK_LASTRATE
  6897                              <1> ;	CHECK PREVIOUS DATE RATE SNT TO THE CONTROLLER.
  6898                              <1> ; ON ENTRY:
  6899                              <1> ;	DI = DRIVE #
  6900                              <1> ; ON EXIT:
  6901                              <1> ;	ZF =  1 DATA RATE IS THE SAME AS THE LAST RATE SENT TO NEC
  6902                              <1> ;	ZF =  0 DATA RATE IS DIFFERENT FROM LAST RATE
  6903                              <1> ; REGISTERS ALTERED: DX
  6904                              <1> ;-------------------------------------------------------------------------------
  6905                              <1> CHK_LASTRATE:
  6906 000021EE 6650                <1> 	PUSH	AX			; SAVE REG
  6907 000021F0 2225[7CBE0000]      <1> 	AND	AH, [LASTRATE]		; GET LAST DATA RATE SELECTED
  6908 000021F6 8A87[81BE0000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6909 000021FC 6625C0C0            <1>         AND     AX, SEND_MSK*257        ; KEEP ONLY RATE BITS OF BOTH
  6910 00002200 38E0                <1> 	CMP	AL, AH			; COMPARE TO PREVIOUSLY TRIED
  6911                              <1> 					; ZF = 1 RATE IS THE SAME
  6912 00002202 6658                <1> 	POP	AX			; RESTORE REG.
  6913 00002204 C3                  <1> 	RETn
  6914                              <1> 
  6915                              <1> ;-------------------------------------------------------------------------------
  6916                              <1> ; DMA_SETUP
  6917                              <1> ;	THIS ROUTINE SETS UP THE DMA FOR READ/WRITE/VERIFY OPERATIONS.
  6918                              <1> ;
  6919                              <1> ; ON ENTRY:	AL = DMA COMMAND
  6920                              <1> ;
  6921                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6922                              <1> ;-------------------------------------------------------------------------------
  6923                              <1> 
  6924                              <1> ; SI = Head #, # of Sectors or DASD Type
  6925                              <1> 
  6926                              <1> ; 22/08/2015
  6927                              <1> ; 08/02/2015 - Protected Mode Modification
  6928                              <1> ; 06/02/2015 - 07/02/2015
  6929                              <1> ; NOTE: Buffer address must be in 1st 16MB of Physical Memory (24 bit limit).
  6930                              <1> ; (DMA Addres = Physical Address)
  6931                              <1> ; (Retro UNIX 386 v1 Kernel/System Mode Virtual Address = Physical Address)
  6932                              <1> ;
  6933                              <1> 
  6934                              <1> 
  6935                              <1> ; 04/02/2016 (clc)
  6936                              <1> ; 20/02/2015 modification (source: AWARD BIOS 1999, DMA_SETUP)
  6937                              <1> ; 16/12/2014 (IODELAY)
  6938                              <1> 
  6939                              <1> DMA_SETUP:
  6940                              <1> 
  6941                              <1> ;; 20/02/2015
  6942 00002205 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  6943 00002208 F7C2000000FF        <1> 	test	edx, 0FF000000h		; 16 MB limit (22/08/2015, bugfix)
  6944 0000220E 756E                <1> 	jnz	short dma_bnd_err_stc
  6945                              <1> 	;
  6946 00002210 6650                <1> 	push	ax			; DMA command
  6947 00002212 52                  <1> 	push	edx			; *
  6948 00002213 B203                <1> 	mov	dl, 3			; GET BYTES/SECTOR PARAMETER
  6949 00002215 E851030000          <1> 	call	GET_PARM		; 
  6950 0000221A 88E1                <1> 	mov	cl, ah 			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  6951 0000221C 6689F0              <1> 	mov	ax, si			; Sector count
  6952 0000221F 88C4                <1> 	mov	ah, al			; AH =  # OF SECTORS
  6953 00002221 28C0                <1> 	sub	al, al			; AL = 0, AX = # SECTORS * 256
  6954 00002223 66D1E8              <1> 	shr	ax, 1			; AX = # SECTORS * 128
  6955 00002226 66D3E0              <1> 	shl	ax, cl			; SHIFT BY PARAMETER VALUE
  6956 00002229 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  6957 0000222B 6689C1              <1> 	mov	cx, ax
  6958 0000222E 5A                  <1> 	pop	edx			; *
  6959 0000222F 6658                <1> 	pop	ax
  6960 00002231 3C42                <1> 	cmp	al, 42h
  6961 00002233 7507                <1>         jne     short NOT_VERF
  6962 00002235 BA0000FF00          <1> 	mov	edx, 0FF0000h
  6963 0000223A EB08                <1> 	jmp	short J33
  6964                              <1> NOT_VERF:
  6965 0000223C 6601CA              <1> 	add	dx, cx			; check for overflow
  6966 0000223F 723E                <1> 	jc	short dma_bnd_err
  6967                              <1> 	;
  6968 00002241 6629CA              <1> 	sub	dx, cx			; Restore start address
  6969                              <1> J33:
  6970 00002244 FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  6971 00002245 E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  6972                              <1> 	IODELAY				; WAIT FOR I/O
  6973 00002247 EB00                <2>  jmp short $+2
  6974 00002249 EB00                <2>  jmp short $+2
  6975 0000224B E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  6976 0000224D 89D0                <1> 	mov	eax, edx		; Buffer address
  6977 0000224F E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  6978                              <1> 	IODELAY				; WAIT FOR I/O
  6979 00002251 EB00                <2>  jmp short $+2
  6980 00002253 EB00                <2>  jmp short $+2
  6981 00002255 88E0                <1> 	MOV	AL,AH
  6982 00002257 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  6983 00002259 C1E810              <1> 	shr	eax, 16
  6984                              <1> 	IODELAY				; I/O WAIT STATE
  6985 0000225C EB00                <2>  jmp short $+2
  6986 0000225E EB00                <2>  jmp short $+2
  6987 00002260 E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  6988                              <1> 	IODELAY
  6989 00002262 EB00                <2>  jmp short $+2
  6990 00002264 EB00                <2>  jmp short $+2
  6991 00002266 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  6992 00002269 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  6993                              <1> 	IODELAY				; WAIT FOR I/O
  6994 0000226B EB00                <2>  jmp short $+2
  6995 0000226D EB00                <2>  jmp short $+2
  6996 0000226F 88E0                <1> 	MOV	AL, AH
  6997 00002271 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  6998                              <1> 	IODELAY
  6999 00002273 EB00                <2>  jmp short $+2
  7000 00002275 EB00                <2>  jmp short $+2
  7001 00002277 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  7002 00002278 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  7003 0000227A E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7004                              <1> 
  7005 0000227C F8                  <1> 	clc	; 04/02/2016
  7006 0000227D C3                  <1> 	retn
  7007                              <1> 
  7008                              <1> dma_bnd_err_stc:
  7009 0000227E F9                  <1> 	stc
  7010                              <1> dma_bnd_err:
  7011 0000227F C605[74BE0000]09    <1> 	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7012 00002286 C3                  <1> 	RETn				; CY SET BY ABOVE IF ERROR
  7013                              <1> 
  7014                              <1> ;; 16/12/2014
  7015                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7016                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7017                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7018                              <1> ;;	IODELAY
  7019                              <1> ;; 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7020                              <1> ;;	;SIODELAY
  7021                              <1> ;;      ;CMP	AL, 42H			; DMA VERIFY COMMAND
  7022                              <1> ;;      ;JNE	short NOT_VERF		; NO
  7023                              <1> ;;      ;XOR	AX, AX			; START ADDRESS
  7024                              <1> ;;      ;JMP	SHORT J33
  7025                              <1> ;;;NOT_VERF:	
  7026                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  7027                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  7028                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  7029                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  7030                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  7031                              <1> ;;	mov	eax, [ebp+4] ; 06/02/2015	
  7032                              <1> ;;	;JNC	short J33
  7033                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  7034                              <1> ;;;J33:
  7035                              <1> ;;	PUSH	eAX			; SAVE START ADDRESS
  7036                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7037                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7038                              <1> ;;	IODELAY
  7039                              <1> ;;	MOV	AL,AH
  7040                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7041                              <1> ;;	shr	eax, 16	     ; 07/02/2015
  7042                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  7043                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  7044                              <1> ;;	IODELAY
  7045                              <1> ;;	;AND	AL,00001111B
  7046                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  7047                              <1> ;;	;SIODELAY
  7048                              <1> ;;
  7049                              <1> ;;;----- DETERMINE COUNT
  7050                              <1> ;;	sub	eax, eax ; 08/02/2015
  7051                              <1> ;;	MOV	AX, SI			; AL =  # OF SECTORS
  7052                              <1> ;;	XCHG	AL, AH			; AH =  # OF SECTORS
  7053                              <1> ;;	SUB	AL, AL			; AL = 0, AX = # SECTORS * 256
  7054                              <1> ;;	SHR	AX, 1			; AX = # SECTORS * 128
  7055                              <1> ;;	PUSH	AX			; SAVE # OF SECTORS * 128
  7056                              <1> ;;	MOV	DL, 3			; GET BYTES/SECTOR PARAMETER
  7057                              <1> ;;	CALL	GET_PARM		; "
  7058                              <1> ;;	MOV	CL,AH			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  7059                              <1> ;;	POP	AX			; AX = # SECTORS * 128
  7060                              <1> ;;	SHL	AX,CL			; SHIFT BY PARAMETER VALUE
  7061                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  7062                              <1> ;;	PUSH	eAX  ; 08/02/2015	; SAVE COUNT VALUE
  7063                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7064                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7065                              <1> ;;	IODELAY
  7066                              <1> ;;	MOV	AL, AH
  7067                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7068                              <1> ;;	;IODELAY
  7069                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  7070                              <1> ;;	POP	eCX  ; 08/02/2015 	; RECOVER COUNT VALUE
  7071                              <1> ;;	POP	eAX  ; 08/02/2015	; RECOVER ADDRESS VALUE
  7072                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  7073                              <1> ;;	add	ecx, eax ; 08/02/2015
  7074                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  7075                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7076                              <1> ;;	SIODELAY
  7077                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7078                              <1> ;;	;JNC	short NO_BAD		; CHECK FOR ERROR
  7079                              <1> ;;	jc	short dma_bnd_err ; 08/02/2015
  7080                              <1> ;;	and	ecx, 0FFF00000h ; 16 MB limit
  7081                              <1> ;;	jz	short NO_BAD
  7082                              <1> ;;dma_bnd_err:
  7083                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7084                              <1> ;;NO_BAD:
  7085                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  7086                              <1> 
  7087                              <1> ;-------------------------------------------------------------------------------
  7088                              <1> ; FMTDMA_SET
  7089                              <1> ;	THIS ROUTINE SETS UP THE DMA CONTROLLER FOR A FORMAT OPERATION.
  7090                              <1> ;
  7091                              <1> ; ON ENTRY:	NOTHING REQUIRED
  7092                              <1> ;
  7093                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7094                              <1> ;-------------------------------------------------------------------------------
  7095                              <1> 
  7096                              <1> FMTDMA_SET:
  7097                              <1> ;; 20/02/2015 modification	
  7098 00002287 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  7099 0000228A F7C20000F0FF        <1> 	test	edx, 0FFF00000h		; 16 MB limit
  7100 00002290 75EC                <1> 	jnz	short dma_bnd_err_stc
  7101                              <1> 	;
  7102 00002292 6652                <1> 	push	dx			; *
  7103 00002294 B204                <1> 	mov	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  7104 00002296 E8D0020000          <1> 	call	GET_PARM		; "
  7105 0000229B 88E0                <1> 	mov	al, ah			; AL = SECTORS/TRACK VALUE
  7106 0000229D 28E4                <1> 	sub	ah, ah			; AX = SECTORS/TRACK VALUE
  7107 0000229F 66C1E002            <1> 	shl	ax, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  7108 000022A3 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  7109 000022A5 6689C1              <1> 	mov	cx, ax
  7110 000022A8 665A                <1> 	pop	dx			; *
  7111 000022AA 6601CA              <1> 	add	dx, cx			; check for overflow
  7112 000022AD 72D0                <1> 	jc	short dma_bnd_err
  7113                              <1> 	;
  7114 000022AF 6629CA              <1> 	sub	dx, cx			; Restore start address
  7115                              <1> 	;
  7116 000022B2 B04A                <1> 	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  7117 000022B4 FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7118 000022B5 E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7119                              <1> 	IODELAY				; WAIT FOR I/O
  7120 000022B7 EB00                <2>  jmp short $+2
  7121 000022B9 EB00                <2>  jmp short $+2
  7122 000022BB E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7123 000022BD 89D0                <1> 	mov	eax, edx		; Buffer address
  7124 000022BF E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7125                              <1> 	IODELAY				; WAIT FOR I/O
  7126 000022C1 EB00                <2>  jmp short $+2
  7127 000022C3 EB00                <2>  jmp short $+2
  7128 000022C5 88E0                <1> 	MOV	AL,AH
  7129 000022C7 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7130 000022C9 C1E810              <1> 	shr	eax, 16
  7131                              <1> 	IODELAY				; I/O WAIT STATE
  7132 000022CC EB00                <2>  jmp short $+2
  7133 000022CE EB00                <2>  jmp short $+2
  7134 000022D0 E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  7135                              <1> 	IODELAY
  7136 000022D2 EB00                <2>  jmp short $+2
  7137 000022D4 EB00                <2>  jmp short $+2
  7138 000022D6 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  7139 000022D9 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7140                              <1> 	IODELAY				; WAIT FOR I/O
  7141 000022DB EB00                <2>  jmp short $+2
  7142 000022DD EB00                <2>  jmp short $+2
  7143 000022DF 88E0                <1> 	MOV	AL, AH
  7144 000022E1 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7145                              <1> 	IODELAY
  7146 000022E3 EB00                <2>  jmp short $+2
  7147 000022E5 EB00                <2>  jmp short $+2
  7148 000022E7 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  7149 000022E8 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  7150 000022EA E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7151 000022EC C3                  <1> 	retn
  7152                              <1> 
  7153                              <1> ;; 08/02/2015 - Protected Mode Modification
  7154                              <1> ;;	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  7155                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7156                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7157                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7158                              <1> ;;	IODELAY
  7159                              <1> ;;	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7160                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  7161                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  7162                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  7163                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  7164                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  7165                              <1> ;;	;JNC	short J33A
  7166                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  7167                              <1> ;;	mov	eax, [ebp+4] ; 08/02/2015
  7168                              <1> ;;;J33A:
  7169                              <1> ;;	PUSH	eAX ; 08/02/2015	; SAVE START ADDRESS
  7170                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7171                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7172                              <1> ;;	IODELAY
  7173                              <1> ;;	MOV	AL,AH
  7174                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7175                              <1> ;;	shr 	eax, 16 ; 08/02/2015
  7176                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  7177                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  7178                              <1> ;;	IODELAY
  7179                              <1> ;;	;AND	AL,00001111B
  7180                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  7181                              <1> ;;
  7182                              <1> ;;;----- DETERMINE COUNT
  7183                              <1> ;;	sub	eax, eax ; 08/02/2015
  7184                              <1> ;;	MOV	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  7185                              <1> ;;	CALL	GET_PARM		; "
  7186                              <1> ;;	XCHG	AL, AH			; AL = SECTORS/TRACK VALUE
  7187                              <1> ;;	SUB	AH, AH			; AX = SECTORS/TRACK VALUE
  7188                              <1> ;;	SHL	AX, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  7189                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  7190                              <1> ;;	PUSH	eAX 	; 08/02/2015	; SAVE # OF BYTES TO BE TRANSFERED
  7191                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7192                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7193                              <1> ;;	IODELAY
  7194                              <1> ;;	MOV	AL, AH
  7195                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7196                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  7197                              <1> ;;	POP	eCX	; 08/02/2015	; RECOVER COUNT VALUE
  7198                              <1> ;;	POP	eAX	; 08/02/2015	; RECOVER ADDRESS VALUE
  7199                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  7200                              <1> ;;	add	ecx, eax ; 08/02/2015
  7201                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  7202                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7203                              <1> ;;	SIODELAY
  7204                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7205                              <1> ;;	;JNC	short FMTDMA_OK		; CHECK FOR ERROR
  7206                              <1> ;;	jc	short fmtdma_bnd_err ; 08/02/2015
  7207                              <1> ;;	and	ecx, 0FFF00000h  ; 16 MB limit
  7208                              <1> ;;	jz	short FMTDMA_OK
  7209                              <1> ;;	stc	; 20/02/2015
  7210                              <1> ;;fmtdma_bnd_err:
  7211                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7212                              <1> ;;FMTDMA_OK:
  7213                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  7214                              <1> 
  7215                              <1> ;-------------------------------------------------------------------------------
  7216                              <1> ; NEC_INIT	
  7217                              <1> ;	THIS ROUTINE SEEKS TO THE REQUESTED TRACK AND INITIALIZES
  7218                              <1> ;	THE NEC FOR THE READ/WRITE/VERIFY/FORMAT OPERATION.
  7219                              <1> ;
  7220                              <1> ; ON ENTRY:	AH = NEC COMMAND TO BE PERFORMED
  7221                              <1> ;
  7222                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7223                              <1> ;-------------------------------------------------------------------------------
  7224                              <1> NEC_INIT:
  7225 000022ED 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  7226 000022EF E8BC020000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON FOR SPECIFIC DRIVE
  7227                              <1> 
  7228                              <1> ;-----	DO THE SEEK OPERATION
  7229                              <1> 
  7230 000022F4 8A6D01              <1> 	MOV	CH,[eBP+1]		; CH = TRACK #
  7231 000022F7 E8AF030000          <1> 	CALL	SEEK			; MOVE TO CORRECT TRACK
  7232 000022FC 6658                <1> 	POP	AX			; RECOVER COMMAND
  7233 000022FE 721E                <1> 	JC	short ER_1		; ERROR ON SEEK
  7234 00002300 BB[1E230000]        <1> 	MOV	eBX, ER_1		; LOAD ERROR ADDRESS
  7235 00002305 53                  <1> 	PUSH	eBX			; PUSH NEC_OUT ERROR RETURN
  7236                              <1> 
  7237                              <1> ;-----	SEND OUT THE PARAMETERS TO THE CONTROLLER
  7238                              <1> 
  7239 00002306 E866030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE OPERATION COMMAND
  7240 0000230B 6689F0              <1> 	MOV	AX,SI			; AH = HEAD #
  7241 0000230E 89FB                <1> 	MOV	eBX,eDI			; BL = DRIVE #
  7242 00002310 C0E402              <1> 	SAL	AH,2			; MOVE IT TO BIT 2
  7243 00002313 80E404              <1> 	AND	AH,00000100B		; ISOLATE THAT BIT
  7244 00002316 08DC                <1> 	OR	AH,BL			; OR IN THE DRIVE NUMBER
  7245 00002318 E854030000          <1> 	CALL	NEC_OUTPUT		; FALL THRU CY SET IF ERROR
  7246 0000231D 5B                  <1> 	POP	eBX			; THROW AWAY ERROR RETURN
  7247                              <1> ER_1:
  7248 0000231E C3                  <1> 	RETn
  7249                              <1> 
  7250                              <1> ;-------------------------------------------------------------------------------
  7251                              <1> ; RWV_COM
  7252                              <1> ;	THIS ROUTINE SENDS PARAMETERS TO THE NEC SPECIFIC TO THE 
  7253                              <1> ;	READ/WRITE/VERIFY OPERATIONS.
  7254                              <1> ;
  7255                              <1> ; ON ENTRY:	CS:BX = ADDRESS OF MEDIA/DRIVE PARAMETER TABLE
  7256                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7257                              <1> ;-------------------------------------------------------------------------------
  7258                              <1> RWV_COM:
  7259 0000231F B8[6A230000]        <1> 	MOV	eAX, ER_2		; LOAD ERROR ADDRESS
  7260 00002324 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  7261 00002325 8A6501              <1> 	MOV	AH,[eBP+1]		; OUTPUT TRACK #
  7262 00002328 E844030000          <1> 	CALL	NEC_OUTPUT
  7263 0000232D 6689F0              <1> 	MOV	AX,SI			; OUTPUT HEAD #
  7264 00002330 E83C030000          <1> 	CALL	NEC_OUTPUT
  7265 00002335 8A6500              <1>         MOV     AH,[eBP]                ; OUTPUT SECTOR #
  7266 00002338 E834030000          <1> 	CALL	NEC_OUTPUT
  7267 0000233D B203                <1> 	MOV	DL,3			; BYTES/SECTOR PARAMETER FROM BLOCK
  7268 0000233F E827020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  7269 00002344 E828030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7270 00002349 B204                <1> 	MOV	DL,4			; EOT PARAMETER FROM BLOCK
  7271 0000234B E81B020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  7272 00002350 E81C030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7273 00002355 8A6305              <1>         MOV     AH, [eBX+MD.GAP]        ; GET GAP LENGTH
  7274                              <1> _R15:
  7275 00002358 E814030000          <1> 	CALL	NEC_OUTPUT
  7276 0000235D B206                <1> 	MOV	DL,6			; DTL PARAMETER PROM BLOCK
  7277 0000235F E807020000          <1> 	CALL	GET_PARM		;  TO THE NEC
  7278 00002364 E808030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7279 00002369 58                  <1> 	POP	eAX			; THROW AWAY ERROR EXIT
  7280                              <1> ER_2:
  7281 0000236A C3                  <1> 	RETn
  7282                              <1> 
  7283                              <1> ;-------------------------------------------------------------------------------
  7284                              <1> ; NEC_TERM
  7285                              <1> ;	THIS ROUTINE WAITS FOR THE OPERATION THEN ACCEPTS THE STATUS 
  7286                              <1> ;	FROM THE NEC FOR THE READ/WRITE/VERIFY/FORWAT OPERATION.
  7287                              <1> ;
  7288                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7289                              <1> ;-------------------------------------------------------------------------------
  7290                              <1> NEC_TERM:
  7291                              <1> 
  7292                              <1> ;-----	LET THE OPERATION HAPPEN
  7293                              <1> 
  7294 0000236B 56                  <1> 	PUSH	eSI			; SAVE HEAD #, # OF SECTORS
  7295 0000236C E80D040000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  7296 00002371 9C                  <1> 	PUSHF
  7297 00002372 E837040000          <1> 	CALL	RESULTS			; GET THE NEC STATUS
  7298 00002377 724B                <1> 	JC	short SET_END_POP
  7299 00002379 9D                  <1> 	POPF
  7300 0000237A 723E                <1> 	JC	short SET_END		; LOOK FOR ERROR
  7301                              <1> 
  7302                              <1> ;-----	CHECK THE RESULTS RETURNED BY THE CONTROLLER
  7303                              <1> 
  7304 0000237C FC                  <1> 	CLD				; SET THE CORRECT DIRECTION
  7305 0000237D BE[75BE0000]        <1> 	MOV	eSI, NEC_STATUS		; POINT TO STATUS FIELD
  7306 00002382 AC                  <1> 	lodsb				; GET ST0
  7307 00002383 24C0                <1> 	AND	AL,11000000B		; TEST FOR NORMAL TERMINATION
  7308 00002385 7433                <1> 	JZ	short SET_END
  7309 00002387 3C40                <1> 	CMP	AL,01000000B		; TEST FOR ABNORMAL TERMINATION
  7310 00002389 7527                <1> 	JNZ	short J18		; NOT ABNORMAL, BAD NEC
  7311                              <1> 
  7312                              <1> ;-----	ABNORMAL TERMINATION, FIND OUT WHY
  7313                              <1> 
  7314 0000238B AC                  <1> 	lodsb				; GET ST1
  7315 0000238C D0E0                <1> 	SAL	AL,1			; TEST FOR EDT FOUND
  7316 0000238E B404                <1> 	MOV	AH,RECORD_NOT_FND
  7317 00002390 7222                <1> 	JC	short J19
  7318 00002392 C0E002              <1> 	SAL	AL,2
  7319 00002395 B410                <1> 	MOV	AH,BAD_CRC
  7320 00002397 721B                <1> 	JC	short J19
  7321 00002399 D0E0                <1> 	SAL	AL,1			; TEST FOR DMA OVERRUN
  7322 0000239B B408                <1> 	MOV	AH,BAD_DMA
  7323 0000239D 7215                <1> 	JC	short J19
  7324 0000239F C0E002              <1> 	SAL	AL,2			; TEST FOR RECORD NOT FOUND
  7325 000023A2 B404                <1> 	MOV	AH,RECORD_NOT_FND
  7326 000023A4 720E                <1> 	JC	short J19
  7327 000023A6 D0E0                <1> 	SAL	AL,1
  7328 000023A8 B403                <1> 	MOV	AH,WRITE_PROTECT	; TEST FOR WRITE_PROTECT
  7329 000023AA 7208                <1> 	JC	short J19
  7330 000023AC D0E0                <1> 	SAL	AL,1			; TEST MISSING ADDRESS MARK
  7331 000023AE B402                <1> 	MOV	AH,BAD_ADDR_MARK
  7332 000023B0 7202                <1> 	JC	short J19
  7333                              <1> 
  7334                              <1> ;----- 	NEC MUST HAVE FAILED
  7335                              <1> J18:
  7336 000023B2 B420                <1> 	MOV	AH,BAD_NEC
  7337                              <1> J19:
  7338 000023B4 0825[74BE0000]      <1> 	OR	[DSKETTE_STATUS], AH
  7339                              <1> SET_END:
  7340 000023BA 803D[74BE0000]01    <1> 	CMP	byte [DSKETTE_STATUS], 1 ; SET ERROR CONDITION
  7341 000023C1 F5                  <1> 	CMC
  7342 000023C2 5E                  <1> 	POP	eSI
  7343 000023C3 C3                  <1> 	RETn				; RESTORE HEAD #, # OF SECTORS
  7344                              <1> 
  7345                              <1> SET_END_POP:
  7346 000023C4 9D                  <1> 	POPF
  7347 000023C5 EBF3                <1> 	JMP	SHORT SET_END
  7348                              <1> 
  7349                              <1> ;-------------------------------------------------------------------------------
  7350                              <1> ; DSTATE:	ESTABLISH STATE UPON SUCCESSFUL OPERATION.
  7351                              <1> ;-------------------------------------------------------------------------------
  7352                              <1> DSTATE:
  7353 000023C7 803D[74BE0000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  7354 000023CE 753E                <1> 	JNZ	short SETBAC		    ; IF ERROR JUMP
  7355 000023D0 808F[81BE0000]10    <1> 	OR	byte [DSK_STATE+eDI],MED_DET ; NO ERROR, MARK MEDIA AS DETERMINED
  7356 000023D7 F687[81BE0000]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE DETERMINED ?
  7357 000023DE 752E                <1> 	JNZ	short SETBAC		; IF DETERMINED NO TRY TO DETERMINE
  7358 000023E0 8A87[81BE0000]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  7359 000023E6 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  7360 000023E8 3C80                <1> 	CMP	AL,RATE_250		; RATE 250 ?
  7361 000023EA 751B                <1> 	JNE	short M_12		; NO, MUST BE 1.2M OR 1.44M DRIVE
  7362                              <1> 
  7363                              <1> ;----- 	CHECK IF IT IS 1.44M
  7364                              <1> 
  7365 000023EC E871010000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  7366                              <1> 	;;20/02/2015
  7367                              <1> 	;;JC	short M_12		; CMOS BAD
  7368 000023F1 7414                <1> 	jz	short M_12 ;; 20/02/2015
  7369 000023F3 3C04                <1> 	CMP	AL, 4			; 1.44MB DRIVE ?
  7370 000023F5 7410                <1> 	JE	short M_12		; YES
  7371                              <1> M_720:
  7372 000023F7 80A7[81BE0000]FD    <1> 	AND	byte [DSK_STATE+eDI], ~FMT_CAPA ; TURN OFF FORMAT CAPABILITY
  7373 000023FE 808F[81BE0000]04    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET  ; MARK DRIVE DETERMINED
  7374 00002405 EB07                <1> 	JMP	SHORT SETBAC		; BACK
  7375                              <1> M_12:	
  7376 00002407 808F[81BE0000]06    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET+FMT_CAPA 
  7377                              <1> 					; TURN ON DETERMINED & FMT CAPA
  7378                              <1> SETBAC:
  7379 0000240E C3                  <1> 	RETn
  7380                              <1> 
  7381                              <1> ;-------------------------------------------------------------------------------
  7382                              <1> ; RETRY	
  7383                              <1> ;	DETERMINES WHETHER A RETRY IS NECESSARY. 
  7384                              <1> ;	IF RETRY IS REQUIRED THEN STATE INFORMATION IS UPDATED FOR RETRY.
  7385                              <1> ;
  7386                              <1> ; ON EXIT:	CY = 1 FOR RETRY, CY = 0 FOR NO RETRY
  7387                              <1> ;-------------------------------------------------------------------------------
  7388                              <1> RETRY:
  7389 0000240F 803D[74BE0000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; GET STATUS OF OPERATION
  7390 00002416 7445                <1> 	JZ	short NO_RETRY		; SUCCESSFUL OPERATION
  7391 00002418 803D[74BE0000]80    <1> 	CMP	byte [DSKETTE_STATUS],TIME_OUT ; IF TIME OUT NO RETRY
  7392 0000241F 743C                <1> 	JZ	short NO_RETRY
  7393 00002421 8AA7[81BE0000]      <1> 	MOV	AH,[DSK_STATE+eDI]	; GET MEDIA STATE OF DRIVE
  7394 00002427 F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED/DETERMINED ?
  7395 0000242A 7531                <1> 	JNZ	short NO_RETRY		; IF ESTABLISHED STATE THEN TRUE ERROR
  7396 0000242C 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE RATE
  7397 0000242F 8A2D[7CBE0000]      <1> 	MOV	CH,[LASTRATE]		; GET START OPERATION STATE
  7398 00002435 C0C504              <1> 	ROL	CH,4			; TO CORRESPONDING BITS
  7399 00002438 80E5C0              <1> 	AND	CH,RATE_MSK		; ISOLATE RATE BITS
  7400 0000243B 38E5                <1> 	CMP	CH,AH			; ALL RATES TRIED
  7401 0000243D 741E                <1> 	JE	short NO_RETRY		; IF YES, THEN TRUE ERROR
  7402                              <1> 
  7403                              <1> ;	SETUP STATE INDICATOR FOR RETRY ATTEMPT TO NEXT RATE
  7404                              <1> ;	 00000000B (500) -> 10000000B	(250)
  7405                              <1> ;	 10000000B (250) -> 01000000B	(300)
  7406                              <1> ;	 01000000B (300) -> 00000000B	(500)
  7407                              <1> 
  7408 0000243F 80FC01              <1> 	CMP	AH,RATE_500+1		; SET CY FOR RATE 500
  7409 00002442 D0DC                <1> 	RCR	AH,1			; TO NEXT STATE
  7410 00002444 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE BITS
  7411 00002447 80A7[81BE0000]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP)
  7412                              <1> 					; RATE, DBL STEP OFF
  7413 0000244E 08A7[81BE0000]      <1> 	OR	[DSK_STATE+eDI],AH	; TURN ON NEW RATE
  7414 00002454 C605[74BE0000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; RESET STATUS FOR RETRY
  7415 0000245B F9                  <1> 	STC				; SET CARRY FOR RETRY
  7416 0000245C C3                  <1> 	RETn				; RETRY RETURN
  7417                              <1> 
  7418                              <1> NO_RETRY:
  7419 0000245D F8                  <1> 	CLC				; CLEAR CARRY NO RETRY
  7420 0000245E C3                  <1> 	RETn				; NO RETRY RETURN
  7421                              <1> 
  7422                              <1> ;-------------------------------------------------------------------------------
  7423                              <1> ; NUM_TRANS
  7424                              <1> ;	THIS ROUTINE CALCULATES THE NUMBER OF SECTORS THAT WERE
  7425                              <1> ;	ACTUALLY TRANSFERRED TO/FROM THE DISKETTE.
  7426                              <1> ;
  7427                              <1> ; ON ENTRY:	[BP+1] = TRACK
  7428                              <1> ;		SI-HI  = HEAD
  7429                              <1> ;		[BP]   = START SECTOR
  7430                              <1> ;
  7431                              <1> ; ON EXIT:	AL = NUMBER ACTUALLY TRANSFERRED
  7432                              <1> ;-------------------------------------------------------------------------------
  7433                              <1> NUM_TRANS:
  7434 0000245F 30C0                <1> 	XOR	AL,AL			; CLEAR FOR ERROR
  7435 00002461 803D[74BE0000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  7436 00002468 752C                <1> 	JNZ	NT_OUT			; IF ERROR 0 TRANSFERRED
  7437 0000246A B204                <1> 	MOV	DL,4			; SECTORS/TRACK OFFSET TO DL
  7438 0000246C E8FA000000          <1> 	CALL	GET_PARM		; AH = SECTORS/TRACK
  7439 00002471 8A1D[7ABE0000]      <1> 	MOV	BL, [NEC_STATUS+5]	; GET ENDING SECTOR
  7440 00002477 6689F1              <1> 	MOV	CX,SI			; CH = HEAD # STARTED
  7441 0000247A 3A2D[79BE0000]      <1> 	CMP	CH, [NEC_STATUS+4]	; GET HEAD ENDED UP ON
  7442 00002480 750D                <1> 	JNZ	DIF_HD			; IF ON SAME HEAD, THEN NO ADJUST
  7443 00002482 8A2D[78BE0000]      <1> 	MOV	CH, [NEC_STATUS+3]	; GET TRACK ENDED UP ON
  7444 00002488 3A6D01              <1> 	CMP	CH,[eBP+1]		; IS IT ASKED FOR TRACK
  7445 0000248B 7404                <1> 	JZ	short SAME_TRK		; IF SAME TRACK NO INCREASE
  7446 0000248D 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  7447                              <1> DIF_HD:
  7448 0000248F 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  7449                              <1> SAME_TRK:
  7450 00002491 2A5D00              <1> 	SUB	BL,[eBP]		; SUBTRACT START FROM END
  7451 00002494 88D8                <1> 	MOV	AL,BL			; TO AL
  7452                              <1> NT_OUT:
  7453 00002496 C3                  <1> 	RETn
  7454                              <1> 
  7455                              <1> ;-------------------------------------------------------------------------------
  7456                              <1> ; SETUP_END
  7457                              <1> ;	RESTORES @MOTOR_COUNT TO PARAMETER PROVIDED IN TABLE 
  7458                              <1> ;	AND LOADS @DSKETTE_STATUS TO AH, AND SETS CY.
  7459                              <1> ;
  7460                              <1> ; ON EXIT:
  7461                              <1> ;	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7462                              <1> ;-------------------------------------------------------------------------------
  7463                              <1> SETUP_END:
  7464 00002497 B202                <1> 	MOV	DL,2			; GET THE MOTOR WAIT PARAMETER
  7465 00002499 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  7466 0000249B E8CB000000          <1> 	CALL	GET_PARM
  7467 000024A0 8825[73BE0000]      <1> 	MOV	[MOTOR_COUNT],AH	; STORE UPON RETURN
  7468 000024A6 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  7469 000024A8 8A25[74BE0000]      <1> 	MOV	AH, [DSKETTE_STATUS]	; GET STATUS OF OPERATION
  7470 000024AE 08E4                <1> 	OR	AH,AH			; CHECK FOR ERROR
  7471 000024B0 7402                <1> 	JZ	short NUN_ERR			; NO ERROR
  7472 000024B2 30C0                <1> 	XOR	AL,AL			; CLEAR NUMBER RETURNED
  7473                              <1> NUN_ERR: 
  7474 000024B4 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  7475 000024B7 F5                  <1> 	CMC				; SUCCESS OR FAILURE
  7476 000024B8 C3                  <1> 	RETn
  7477                              <1> 
  7478                              <1> ;-------------------------------------------------------------------------------
  7479                              <1> ; SETUP_DBL
  7480                              <1> ;	CHECK DOUBLE STEP.
  7481                              <1> ;
  7482                              <1> ; ON ENTRY :	DI = DRIVE
  7483                              <1> ;
  7484                              <1> ; ON EXIT :	CY = 1 MEANS ERROR
  7485                              <1> ;-------------------------------------------------------------------------------
  7486                              <1> SETUP_DBL:
  7487 000024B9 8AA7[81BE0000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  7488 000024BF F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED STATE ?
  7489 000024C2 757E                <1> 	JNZ	short NO_DBL			; IF ESTABLISHED THEN DOUBLE DONE
  7490                              <1> 
  7491                              <1> ;-----	CHECK FOR TRACK 0 TO SPEED UP ACKNOWLEDGE OF UNFORMATTED DISKETTE
  7492                              <1> 
  7493 000024C4 C605[71BE0000]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  7494 000024CB E8E0000000          <1> 	CALL	MOTOR_ON		; ENSURE MOTOR STAY ON
  7495 000024D0 B500                <1> 	MOV	CH,0			; LOAD TRACK 0
  7496 000024D2 E8D4010000          <1> 	CALL	SEEK			; SEEK TO TRACK 0
  7497 000024D7 E868000000          <1> 	CALL	READ_ID			; READ ID FUNCTION
  7498 000024DC 7249                <1> 	JC	short SD_ERR		; IF ERROR NO TRACK 0
  7499                              <1> 
  7500                              <1> ;-----	INITIALIZE START AND MAX TRACKS (TIMES 2 FOR BOTH HEADS)
  7501                              <1> 
  7502 000024DE 66B95004            <1> 	MOV	CX,0450H 		; START, MAX TRACKS
  7503 000024E2 F687[81BE0000]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; TEST FOR 80 TRACK CAPABILITY
  7504 000024E9 7402                <1> 	JZ	short CNT_OK		; IF NOT COUNT IS SETUP
  7505 000024EB B1A0                <1> 	MOV	CL,0A0H			; MAXIMUM TRACK 1.2 MB
  7506                              <1> 
  7507                              <1> ;	ATTEMPT READ ID OF ALL TRACKS, ALL HEADS UNTIL SUCCESS; UPON SUCCESS,
  7508                              <1> ;	MUST SEE IF ASKED FOR TRACK IN SINGLE STEP MODE = TRACK ID READ; IF NOT
  7509                              <1> ;	THEN SET DOUBLE STEP ON.
  7510                              <1> 
  7511                              <1> CNT_OK:
  7512 000024ED C605[73BE0000]FF    <1>         MOV     byte [MOTOR_COUNT], 0FFH ; ENSURE MOTOR STAYS ON FOR OPERATION 
  7513 000024F4 6651                <1> 	PUSH	CX			; SAVE TRACK, COUNT
  7514 000024F6 C605[74BE0000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR STATUS, EXPECT ERRORS
  7515 000024FD 6631C0              <1> 	XOR	AX,AX			; CLEAR AX
  7516 00002500 D0ED                <1> 	SHR	CH,1			; HALVE TRACK, CY = HEAD
  7517 00002502 C0D003              <1> 	RCL	AL,3			; AX = HEAD IN CORRECT BIT
  7518 00002505 6650                <1> 	PUSH	AX			; SAVE HEAD
  7519 00002507 E89F010000          <1> 	CALL	SEEK			; SEEK TO TRACK
  7520 0000250C 6658                <1> 	POP	AX			; RESTORE HEAD
  7521 0000250E 6609C7              <1> 	OR	DI,AX			; DI = HEAD OR'ED DRIVE
  7522 00002511 E82E000000          <1> 	CALL	READ_ID			; READ ID HEAD 0
  7523 00002516 9C                  <1> 	PUSHF				; SAVE RETURN FROM READ_ID
  7524 00002517 6681E7FB00          <1> 	AND	DI,11111011B		; TURN OFF HEAD 1 BIT
  7525 0000251C 9D                  <1> 	POPF				; RESTORE ERROR RETURN
  7526 0000251D 6659                <1> 	POP	CX			; RESTORE COUNT
  7527 0000251F 7308                <1> 	JNC	short DO_CHK		; IF OK, ASKED = RETURNED TRACK ?
  7528 00002521 FEC5                <1> 	INC	CH			; INC FOR NEXT TRACK
  7529 00002523 38CD                <1> 	CMP	CH,CL			; REACHED MAXIMUM YET
  7530 00002525 75C6                <1> 	JNZ	short CNT_OK		; CONTINUE TILL ALL TRIED
  7531                              <1> 
  7532                              <1> ;-----	FALL THRU, READ ID FAILED FOR ALL TRACKS
  7533                              <1> 
  7534                              <1> SD_ERR:	
  7535 00002527 F9                  <1> 	STC				; SET CARRY FOR ERROR
  7536 00002528 C3                  <1> 	RETn				; SETUP_DBL ERROR EXIT
  7537                              <1> 
  7538                              <1> DO_CHK:
  7539 00002529 8A0D[78BE0000]      <1> 	MOV	CL, [NEC_STATUS+3]	; LOAD RETURNED TRACK
  7540 0000252F 888F[85BE0000]      <1> 	MOV	[DSK_TRK+eDI], CL	; STORE TRACK NUMBER
  7541 00002535 D0ED                <1> 	SHR	CH,1			; HALVE TRACK
  7542 00002537 38CD                <1> 	CMP	CH,CL			; IS IT THE SAME AS ASKED FOR TRACK
  7543 00002539 7407                <1> 	JZ	short NO_DBL		; IF SAME THEN NO DOUBLE STEP
  7544 0000253B 808F[81BE0000]20    <1> 	OR	byte [DSK_STATE+eDI],DBL_STEP ; TURN ON DOUBLE STEP REQUIRED
  7545                              <1> NO_DBL:
  7546 00002542 F8                  <1> 	CLC				; CLEAR ERROR FLAG
  7547 00002543 C3                  <1> 	RETn
  7548                              <1> 
  7549                              <1> ;-------------------------------------------------------------------------------
  7550                              <1> ; READ_ID
  7551                              <1> ;	READ ID FUNCTION.
  7552                              <1> ;
  7553                              <1> ; ON ENTRY:	DI : BIT 2 = HEAD; BITS 1,0 = DRIVE
  7554                              <1> ;
  7555                              <1> ; ON EXIT: 	DI : BIT 2 IS RESET, BITS 1,0 = DRIVE
  7556                              <1> ;		@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7557                              <1> ;-------------------------------------------------------------------------------
  7558                              <1> READ_ID:
  7559 00002544 B8[61250000]        <1> 	MOV	eAX, ER_3		; MOVE NEC OUTPUT ERROR ADDRESS
  7560 00002549 50                  <1> 	PUSH	eAX
  7561 0000254A B44A                <1> 	MOV	AH,4AH			; READ ID COMMAND
  7562 0000254C E820010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  7563 00002551 6689F8              <1> 	MOV	AX,DI			; DRIVE # TO AH, HEAD 0
  7564 00002554 88C4                <1> 	MOV	AH,AL
  7565 00002556 E816010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  7566 0000255B E80BFEFFFF          <1> 	CALL	NEC_TERM		; WAIT FOR OPERATION, GET STATUS
  7567 00002560 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  7568                              <1> ER_3:
  7569 00002561 C3                  <1> 	RETn
  7570                              <1> 
  7571                              <1> ;-------------------------------------------------------------------------------
  7572                              <1> ; CMOS_TYPE
  7573                              <1> ;	RETURNS DISKETTE TYPE FROM CMOS
  7574                              <1> ;
  7575                              <1> ; ON ENTRY:	DI = DRIVE #
  7576                              <1> ;
  7577                              <1> ; ON EXIT:	AL = TYPE; CY REFLECTS STATUS
  7578                              <1> ;-------------------------------------------------------------------------------
  7579                              <1> 
  7580                              <1> CMOS_TYPE: ; 11/12/2014
  7581 00002562 8A87[BEB80000]      <1> mov	al, [eDI+fd0_type]
  7582 00002568 20C0                <1> and 	al, al ; 18/12/2014
  7583 0000256A C3                  <1> retn
  7584                              <1> 
  7585                              <1> ;CMOS_TYPE:
  7586                              <1> ;	MOV	AL, CMOS_DIAG		; CMOS DIAGNOSTIC STATUS BYTE ADDRESS
  7587                              <1> ;	CALL	CMOS_READ		; GET CMOS STATUS
  7588                              <1> ;	TEST	AL,BAD_BAT+BAD_CKSUM	; BATTERY GOOD AND CHECKSUM VALID
  7589                              <1> ;	STC				; SET CY = 1 INDICATING ERROR FOR RETURN
  7590                              <1> ;	JNZ	short BAD_CM		; ERROR IF EITHER BIT ON
  7591                              <1> ;	MOV	AL,CMOS_DISKETTE	; ADDRESS OF DISKETTE BYTE IN CMOS
  7592                              <1> ;	CALL	CMOS_READ		; GET DISKETTE BYTE
  7593                              <1> ;	OR	DI,DI			; SEE WHICH DRIVE IN QUESTION
  7594                              <1> ;	JNZ	short TB		; IF DRIVE 1, DATA IN LOW NIBBLE
  7595                              <1> ;	ROR	AL,4			; EXCHANGE NIBBLES IF SECOND DRIVE
  7596                              <1> ;TB:
  7597                              <1> ;	AND	AL,0FH			; KEEP ONLY DRIVE DATA, RESET CY, 0
  7598                              <1> ;BAD_CM:
  7599                              <1> ;	RETn				; CY, STATUS OF READ
  7600                              <1> 
  7601                              <1> ;-------------------------------------------------------------------------------
  7602                              <1> ; GET_PARM
  7603                              <1> ;	THIS ROUTINE FETCHES THE INDEXED POINTER FROM THE DISK_BASE
  7604                              <1> ;	BLOCK POINTED TO BY THE DATA VARIABLE @DISK_POINTER. A BYTE FROM
  7605                              <1> ;	THAT TABLE IS THEN MOVED INTO AH, THE INDEX OF THAT BYTE BEING
  7606                              <1> ;	THE PARAMETER IN DL.
  7607                              <1> ;
  7608                              <1> ; ON ENTRY:	DL = INDEX OF BYTE TO BE FETCHED
  7609                              <1> ;
  7610                              <1> ; ON EXIT:	AH = THAT BYTE FROM BLOCK
  7611                              <1> ;		AL,DH DESTROYED
  7612                              <1> ;-------------------------------------------------------------------------------
  7613                              <1> GET_PARM:
  7614                              <1> 	;PUSH	DS
  7615 0000256B 56                  <1> 	PUSH	eSI
  7616                              <1>     	;SUB	AX,AX			; DS = 0, BIOS DATA AREA
  7617                              <1>     	;MOV	DS,AX
  7618                              <1> 	;;mov	ax, cs
  7619                              <1> 	;;mov	ds, ax
  7620                              <1> 	; 08/02/2015 (protected mode modifications, bx -> ebx)
  7621 0000256C 87D3                <1> 	XCHG	eDX,eBX			; BL = INDEX
  7622                              <1> 	;SUB	BH,BH			; BX = INDEX
  7623 0000256E 81E3FF000000        <1> 	and	ebx, 0FFh
  7624                              <1>     	;LDS	SI, [DISK_POINTER]	; POINT TO BLOCK
  7625                              <1> 	;
  7626                              <1> 	; 17/12/2014
  7627 00002574 66A1[B1B80000]      <1> 	mov	ax, [cfd] ; current (AL) and previous fd (AH)
  7628 0000257A 38E0                <1> 	cmp	al, ah
  7629 0000257C 7425                <1> 	je	short gpndc
  7630 0000257E A2[B2B80000]        <1> 	mov	[pfd], al ; current drive -> previous drive
  7631 00002583 53                  <1> 	push	ebx ; 08/02/2015
  7632 00002584 88C3                <1> 	mov	bl, al 
  7633                              <1> 	; 11/12/2014
  7634 00002586 8A83[BEB80000]      <1> 	mov	al, [eBX+fd0_type]	; Drive type (0,1,2,3,4)
  7635                              <1> 	; 18/12/2014
  7636 0000258C 20C0                <1> 	and	al, al
  7637 0000258E 7507                <1> 	jnz	short gpdtc
  7638 00002590 BB[9BB80000]        <1> 	mov	ebx, MD_TBL6		; 1.44 MB param. tbl. (default)
  7639 00002595 EB05                <1>         jmp     short gpdpu
  7640                              <1> gpdtc:	
  7641 00002597 E817F9FFFF          <1> 	call	DR_TYPE_CHECK
  7642                              <1> 	; cf = 1 -> eBX points to 1.44MB fd parameter table (default)
  7643                              <1> gpdpu:
  7644 0000259C 891D[38B80000]      <1> 	mov	[DISK_POINTER], ebx
  7645 000025A2 5B                  <1> 	pop	ebx
  7646                              <1> gpndc:
  7647 000025A3 8B35[38B80000]      <1> 	mov	esi, [DISK_POINTER] ; 08/02/2015, si -> esi
  7648 000025A9 8A241E              <1> 	MOV	AH, [eSI+eBX]		; GET THE WORD
  7649 000025AC 87D3                <1> 	XCHG	eDX,eBX			; RESTORE BX
  7650 000025AE 5E                  <1> 	POP	eSI
  7651                              <1> 	;POP	DS
  7652 000025AF C3                  <1> 	RETn
  7653                              <1> 
  7654                              <1> ;-------------------------------------------------------------------------------
  7655                              <1> ; MOTOR_ON
  7656                              <1> ;	TURN MOTOR ON AND WAIT FOR MOTOR START UP TIME. THE @MOTOR_COUNT
  7657                              <1> ;	IS REPLACED WITH A SUFFICIENTLY HIGH NUMBER (0FFH) TO ENSURE
  7658                              <1> ;	THAT THE MOTOR DOES NOT GO OFF DURING THE OPERATION. IF THE
  7659                              <1> ;	MOTOR NEEDED TO BE TURNED ON, THE MULTI-TASKING HOOK FUNCTION
  7660                              <1> ;	(AX=90FDH, INT 15) IS CALLED TELLING THE OPERATING SYSTEM
  7661                              <1> ;	THAT THE BIOS IS ABOUT TO WAIT FOR MOTOR START UP. IF THIS
  7662                              <1> ;	FUNCTION RETURNS WITH CY = 1, IT MEANS THAT THE MINIMUM WAIT
  7663                              <1> ;	HAS BEEN COMPLETED. AT THIS POINT A CHECK IS MADE TO ENSURE
  7664                              <1> ;	THAT THE MOTOR WASN'T TURNED OFF BY THE TIMER. IF THE HOOK DID
  7665                              <1> ;	NOT WAIT, THE WAIT FUNCTION (AH=086H) IS CALLED TO WAIT THE
  7666                              <1> ;	PRESCRIBED AMOUNT OF TIME. IF THE CARRY FLAG IS SET ON RETURN,
  7667                              <1> ;	IT MEANS THAT THE FUNCTION IS IN USE AND DID NOT PERFORM THE
  7668                              <1> ;	WAIT. A TIMER 1 WAIT LOOP WILL THEN DO THE WAIT.
  7669                              <1> ;
  7670                              <1> ; ON ENTRY:	DI = DRIVE #
  7671                              <1> ; ON EXIT:	AX,CX,DX DESTROYED
  7672                              <1> ;-------------------------------------------------------------------------------
  7673                              <1> MOTOR_ON:
  7674 000025B0 53                  <1> 	PUSH	eBX			; SAVE REG.
  7675 000025B1 E82A000000          <1> 	CALL	TURN_ON			; TURN ON MOTOR
  7676 000025B6 7226                <1> 	JC	short MOT_IS_ON		; IF CY=1 NO WAIT
  7677 000025B8 E89BF9FFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  7678 000025BD E865F9FFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  7679                              <1> 	;CALL	TURN_ON 		; CHECK AGAIN IF MOTOR ON
  7680                              <1> 	;JC	MOT_IS_ON		; IF NO WAIT MEANS IT IS ON
  7681                              <1> M_WAIT:
  7682 000025C2 B20A                <1> 	MOV	DL,10			; GET THE MOTOR WAIT PARAMETER
  7683 000025C4 E8A2FFFFFF          <1> 	CALL	GET_PARM
  7684                              <1> 	;MOV	AL,AH			; AL = MOTOR WAIT PARAMETER
  7685                              <1> 	;XOR	AH,AH			; AX = MOTOR WAIT PARAMETER
  7686                              <1> 	;CMP	AL,8			; SEE IF AT LEAST A SECOND IS SPECIFIED
  7687 000025C9 80FC08              <1> 	cmp	ah, 8
  7688                              <1> 	;JAE	short GP2		; IF YES, CONTINUE
  7689 000025CC 7702                <1> 	ja	short J13
  7690                              <1> 	;MOV	AL,8			; ONE SECOND WAIT FOR MOTOR START UP
  7691 000025CE B408                <1> 	mov	ah, 8
  7692                              <1> 
  7693                              <1> ;-----	AS CONTAINS NUMBER OF 1/8 SECONDS (125000 MICROSECONDS) TO WAIT
  7694                              <1> GP2:	
  7695                              <1> ;----- 	FOLLOWING LOOPS REQUIRED WHEN RTC WAIT FUNCTION IS ALREADY IN USE
  7696                              <1> J13:					; WAIT FOR 1/8 SECOND PER (AL)
  7697 000025D0 B95E200000          <1> 	MOV	eCX,8286		; COUNT FOR 1/8 SECOND AT 15.085737 US
  7698 000025D5 E816F3FFFF          <1> 	CALL	WAITF			; GO TO FIXED WAIT ROUTINE
  7699                              <1> 	;DEC	AL			; DECREMENT TIME VALUE
  7700 000025DA FECC                <1> 	dec	ah
  7701 000025DC 75F2                <1> 	JNZ	short J13		; ARE WE DONE YET
  7702                              <1> MOT_IS_ON:
  7703 000025DE 5B                  <1> 	POP	eBX			; RESTORE REG.
  7704 000025DF C3                  <1> 	RETn
  7705                              <1> 
  7706                              <1> ;-------------------------------------------------------------------------------
  7707                              <1> ; TURN_ON
  7708                              <1> ;	TURN MOTOR ON AND RETURN WAIT STATE.
  7709                              <1> ;
  7710                              <1> ; ON ENTRY:	DI = DRIVE #
  7711                              <1> ;
  7712                              <1> ; ON EXIT:	CY = 0 MEANS WAIT REQUIRED
  7713                              <1> ;		CY = 1 MEANS NO WAIT REQUIRED
  7714                              <1> ;		AX,BX,CX,DX DESTROYED
  7715                              <1> ;-------------------------------------------------------------------------------
  7716                              <1> TURN_ON:
  7717 000025E0 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7718 000025E2 88D9                <1> 	MOV	CL,BL			; CL = DRIVE #
  7719 000025E4 C0C304              <1> 	ROL	BL,4			; BL = DRIVE SELECT
  7720 000025E7 FA                  <1> 	CLI				; NO INTERRUPTS WHILE DETERMINING STATUS
  7721 000025E8 C605[73BE0000]FF    <1> 	MOV	byte [MOTOR_COUNT],0FFH	; ENSURE MOTOR STAYS ON FOR OPERATION
  7722 000025EF A0[72BE0000]        <1> 	MOV	AL, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  7723 000025F4 2430                <1> 	AND	AL,00110000B		; KEEP ONLY DRIVE SELECT BITS
  7724 000025F6 B401                <1> 	MOV	AH,1			; MASK FOR DETERMINING MOTOR BIT
  7725 000025F8 D2E4                <1> 	SHL	AH,CL			; AH = MOTOR ON, A=00000001, B=00000010
  7726                              <1> 
  7727                              <1> ;  AL = DRIVE SELECT FROM @MOTOR_STATUS
  7728                              <1> ;  BL = DRIVE SELECT DESIRED
  7729                              <1> ;  AH = MOTOR ON MASK DESIRED
  7730                              <1> 
  7731 000025FA 38D8                <1> 	CMP	AL,BL			; REQUESTED DRIVE ALREADY SELECTED ?
  7732 000025FC 7508                <1> 	JNZ	short TURN_IT_ON	; IF NOT SELECTED JUMP
  7733 000025FE 8425[72BE0000]      <1> 	TEST	AH, [MOTOR_STATUS]	; TEST MOTOR ON BIT
  7734 00002604 7535                <1> 	JNZ	short NO_MOT_WAIT	; JUMP IF MOTOR ON AND SELECTED
  7735                              <1> 
  7736                              <1> TURN_IT_ON:
  7737 00002606 08DC                <1> 	OR	AH,BL			; AH = DRIVE SELECT AND MOTOR ON
  7738 00002608 8A3D[72BE0000]      <1> 	MOV	BH,[MOTOR_STATUS]	; SAVE COPY OF @MOTOR_STATUS BEFORE
  7739 0000260E 80E70F              <1> 	AND	BH,00001111B		; KEEP ONLY MOTOR BITS
  7740 00002611 8025[72BE0000]CF    <1> 	AND	byte [MOTOR_STATUS],11001111B ; CLEAR OUT DRIVE SELECT
  7741 00002618 0825[72BE0000]      <1> 	OR	[MOTOR_STATUS],AH	; OR IN DRIVE SELECTED AND MOTOR ON
  7742 0000261E A0[72BE0000]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  7743 00002623 88C3                <1> 	MOV	BL,AL			; BL=@MOTOR_STATUS AFTER, BH=BEFORE
  7744 00002625 80E30F              <1> 	AND	BL,00001111B		; KEEP ONLY MOTOR BITS
  7745 00002628 FB                  <1> 	STI				; ENABLE INTERRUPTS AGAIN
  7746 00002629 243F                <1> 	AND	AL,00111111B		; STRIP AWAY UNWANTED BITS
  7747 0000262B C0C004              <1> 	ROL	AL,4			; PUT BITS IN DESIRED POSITIONS
  7748 0000262E 0C0C                <1> 	OR	AL,00001100B		; NO RESET, ENABLE DMA/INTERRUPT
  7749 00002630 66BAF203            <1> 	MOV	DX,03F2H		; SELECT DRIVE AND TURN ON MOTOR
  7750 00002634 EE                  <1> 	OUT	DX,AL
  7751 00002635 38FB                <1> 	CMP	BL,BH			; NEW MOTOR TURNED ON ?
  7752                              <1> 	;JZ	short NO_MOT_WAIT	; NO WAIT REQUIRED IF JUST SELECT
  7753 00002637 7403                <1> 	je	short no_mot_w1 ; 27/02/2015 
  7754 00002639 F8                  <1> 	CLC				; (re)SET CARRY MEANING WAIT
  7755 0000263A C3                  <1> 	RETn
  7756                              <1> 
  7757                              <1> NO_MOT_WAIT:
  7758 0000263B FB                  <1> 	sti
  7759                              <1> no_mot_w1: ; 27/02/2015
  7760 0000263C F9                  <1> 	STC				; SET NO WAIT REQUIRED
  7761                              <1> 	;STI				; INTERRUPTS BACK ON
  7762 0000263D C3                  <1> 	RETn
  7763                              <1> 
  7764                              <1> ;-------------------------------------------------------------------------------
  7765                              <1> ; HD_WAIT
  7766                              <1> ;	WAIT FOR HEAD SETTLE TIME.
  7767                              <1> ;
  7768                              <1> ; ON ENTRY:	DI = DRIVE #
  7769                              <1> ;
  7770                              <1> ; ON EXIT:	AX,BX,CX,DX DESTROYED
  7771                              <1> ;-------------------------------------------------------------------------------
  7772                              <1> HD_WAIT:
  7773 0000263E B209                <1> 	MOV	DL,9			; GET HEAD SETTLE PARAMETER
  7774 00002640 E826FFFFFF          <1> 	CALL	GET_PARM
  7775 00002645 08E4                <1> 	or	ah, ah	; 17/12/2014
  7776 00002647 7519                <1> 	jnz	short DO_WAT
  7777 00002649 F605[72BE0000]80    <1>         TEST    byte [MOTOR_STATUS],10000000B ; SEE IF A WRITE OPERATION
  7778                              <1> 	;JZ	short ISNT_WRITE	; IF NOT, DO NOT ENFORCE ANY VALUES
  7779                              <1> 	;OR	AH,AH			; CHECK FOR ANY WAIT?
  7780                              <1> 	;JNZ	short DO_WAT		; IF THERE DO NOT ENFORCE
  7781 00002650 741E                <1> 	jz	short HW_DONE
  7782 00002652 B40F                <1> 	MOV	AH,HD12_SETTLE		; LOAD 1.2M HEAD SETTLE MINIMUM
  7783 00002654 8A87[81BE0000]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  7784 0000265A 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  7785 0000265C 3C80                <1> 	CMP	AL,RATE_250		; 1.2 M DRIVE ?
  7786 0000265E 7502                <1> 	JNZ	short DO_WAT		; DEFAULT HEAD SETTLE LOADED
  7787                              <1> ;GP3:
  7788 00002660 B414                <1> 	MOV	AH,HD320_SETTLE		; USE 320/360 HEAD SETTLE
  7789                              <1> ;	JMP	SHORT DO_WAT
  7790                              <1> 
  7791                              <1> ;ISNT_WRITE:
  7792                              <1> ;	OR	AH,AH			; CHECK FOR NO WAIT
  7793                              <1> ;	JZ	short HW_DONE		; IF NOT WRITE AND 0 ITS OK
  7794                              <1> 
  7795                              <1> ;-----	AH CONTAINS NUMBER OF MILLISECONDS TO WAIT
  7796                              <1> DO_WAT:
  7797                              <1> ;	MOV	AL,AH			; AL = # MILLISECONDS
  7798                              <1> ;	;XOR	AH,AH			; AX = # MILLISECONDS
  7799                              <1> J29:					; 	1 MILLISECOND LOOP
  7800                              <1> 	;mov	cx, WAIT_FDU_HEAD_SETTLE ; 33 ; 1 ms in 30 micro units.
  7801 00002662 B942000000          <1> 	MOV	eCX,66			; COUNT AT 15.085737 US PER COUNT
  7802 00002667 E884F2FFFF          <1> 	CALL	WAITF			; DELAY FOR 1 MILLISECOND
  7803                              <1> 	;DEC	AL			; DECREMENT THE COUNT
  7804 0000266C FECC                <1> 	dec	ah
  7805 0000266E 75F2                <1> 	JNZ	short J29		; DO AL MILLISECOND # OF TIMES
  7806                              <1> HW_DONE:
  7807 00002670 C3                  <1> 	RETn
  7808                              <1> 
  7809                              <1> ;-------------------------------------------------------------------------------
  7810                              <1> ; NEC_OUTPUT
  7811                              <1> ;	THIS ROUTINE SENDS A BYTE TO THE NEC CONTROLLER AFTER TESTING
  7812                              <1> ;	FOR CORRECT DIRECTION AND CONTROLLER READY THIS ROUTINE WILL
  7813                              <1> ;	TIME OUT IF THE BYTE IS NOT ACCEPTED WITHIN A REASONABLE AMOUNT
  7814                              <1> ;	OF TIME, SETTING THE DISKETTE STATUS ON COMPLETION.
  7815                              <1> ; 
  7816                              <1> ; ON ENTRY: 	AH = BYTE TO BE OUTPUT
  7817                              <1> ;
  7818                              <1> ; ON EXIT:	CY = 0  SUCCESS
  7819                              <1> ;		CY = 1  FAILURE -- DISKETTE STATUS UPDATED
  7820                              <1> ;		        IF A FAILURE HAS OCCURRED, THE RETURN IS MADE ONE LEVEL
  7821                              <1> ;		        HIGHER THAN THE CALLER OF NEC OUTPUT. THIS REMOVES THE
  7822                              <1> ;		        REQUIREMENT OF TESTING AFTER EVERY CALL OF NEC_OUTPUT.
  7823                              <1> ;		AX,CX,DX DESTROYED
  7824                              <1> ;-------------------------------------------------------------------------------
  7825                              <1> 
  7826                              <1> ; 09/12/2014 [Erdogan Tan] 
  7827                              <1> ;	(from 'PS2 Hardware Interface Tech. Ref. May 88', Page 09-05.)
  7828                              <1> ; Diskette Drive Controller Status Register (3F4h)
  7829                              <1> ;	This read only register facilitates the transfer of data between
  7830                              <1> ;	the system microprocessor and the controller.
  7831                              <1> ; Bit 7 - When set to 1, the Data register is ready to transfer data 
  7832                              <1> ;	  with the system micrprocessor.
  7833                              <1> ; Bit 6 - The direction of data transfer. If this bit is set to 0,
  7834                              <1> ;	  the transfer is to the controller.
  7835                              <1> ; Bit 5 - When this bit is set to 1, the controller is in the non-DMA mode.
  7836                              <1> ; Bit 4 - When this bit is set to 1, a Read or Write command is being executed.
  7837                              <1> ; Bit 3 - Reserved.
  7838                              <1> ; Bit 2 - Reserved.
  7839                              <1> ; Bit 1 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  7840                              <1> ; Bit 0 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  7841                              <1> 
  7842                              <1> ; Data Register (3F5h)
  7843                              <1> ; This read/write register passes data, commands and parameters, and provides
  7844                              <1> ; diskette status information.
  7845                              <1>   		
  7846                              <1> NEC_OUTPUT:
  7847                              <1> 	;PUSH	BX			; SAVE REG.
  7848 00002671 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  7849                              <1> 	;MOV	BL,2			; HIGH ORDER COUNTER
  7850                              <1> 	;XOR	CX,CX			; COUNT FOR TIME OUT
  7851                              <1> 	; 16/12/2014
  7852                              <1> 	; waiting for (max.) 0.5 seconds
  7853                              <1>         ;;mov     byte [wait_count], 0 ;; 27/02/2015
  7854                              <1> 	;
  7855                              <1> 	; 17/12/2014
  7856                              <1> 	; Modified from AWARD BIOS 1999 - ADISK.ASM - SEND_COMMAND
  7857                              <1> 	;
  7858                              <1> 	;WAIT_FOR_PORT:	Waits for a bit at a port pointed to by DX to
  7859                              <1> 	;		go on.
  7860                              <1> 	;INPUT:
  7861                              <1> 	;	AH=Mask for isolation bits.
  7862                              <1> 	;	AL=pattern to look for.
  7863                              <1> 	;	DX=Port to test for
  7864                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  7865                              <1> 	;	     (normally 30 microseconds per period.)
  7866                              <1> 	;
  7867                              <1> 	;WFP_SHORT:  
  7868                              <1> 	;	Wait for port if refresh cycle is short (15-80 Us range).
  7869                              <1> 	;
  7870                              <1> 
  7871                              <1> ;	mov	bl, WAIT_FDU_SEND_HI+1	; 0+1
  7872                              <1> ;	mov	cx, WAIT_FDU_SEND_LO	; 16667
  7873 00002675 B91B410000          <1> 	mov	ecx, WAIT_FDU_SEND_LH   ; 16667 (27/02/2015)
  7874                              <1> ;
  7875                              <1> ;WFPS_OUTER_LP:
  7876                              <1> ;	;
  7877                              <1> ;WFPS_CHECK_PORT:
  7878                              <1> J23:
  7879 0000267A EC                  <1> 	IN	AL,DX			; GET STATUS
  7880 0000267B 24C0                <1> 	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  7881 0000267D 3C80                <1> 	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  7882 0000267F 7418                <1> 	JZ	short J27		; STATUS AND DIRECTION OK
  7883                              <1> WFPS_HI:
  7884 00002681 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  7885 00002683 A810                <1> 	TEST	AL,010H			; transition on memory
  7886 00002685 75FA                <1> 	JNZ	SHORT WFPS_HI		; refresh.
  7887                              <1> WFPS_LO:
  7888 00002687 E461                <1> 	IN	AL, PORT_B		; SYS1
  7889 00002689 A810                <1> 	TEST	AL,010H
  7890 0000268B 74FA                <1> 	JZ	SHORT WFPS_LO
  7891                              <1> 	;LOOP	SHORT WFPS_CHECK_PORT
  7892 0000268D E2EB                <1> 	loop	J23	; 27/02/2015
  7893                              <1> ;	;
  7894                              <1> ;	dec	bl
  7895                              <1> ;	jnz	short WFPS_OUTER_LP
  7896                              <1> ;	jmp	short WFPS_TIMEOUT	; fail
  7897                              <1> ;J23:
  7898                              <1> ;	IN	AL,DX			; GET STATUS
  7899                              <1> ;	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  7900                              <1> ;	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  7901                              <1> ;	JZ	short J27		; STATUS AND DIRECTION OK
  7902                              <1> 	;LOOP	J23			; CONTINUE TILL CX EXHAUSTED
  7903                              <1> 	;DEC	BL			; DECREMENT COUNTER
  7904                              <1> 	;JNZ	short J23		; REPEAT TILL DELAY FINISHED, CX = 0
  7905                              <1>    
  7906                              <1> 	;;27/02/2015
  7907                              <1> 	;16/12/2014
  7908                              <1>         ;;cmp     byte [wait_count], 10   ; (10/18.2 seconds)
  7909                              <1> 	;;jb	short J23
  7910                              <1> 
  7911                              <1> ;WFPS_TIMEOUT:
  7912                              <1> 
  7913                              <1> ;-----	FALL THRU TO ERROR RETURN
  7914                              <1> 
  7915 0000268F 800D[74BE0000]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  7916                              <1> 	;POP	BX			; RESTORE REG.
  7917 00002696 58                  <1> 	POP	eAX ; 08/02/2015	; DISCARD THE RETURN ADDRESS
  7918 00002697 F9                  <1> 	STC				; INDICATE ERROR TO CALLER
  7919 00002698 C3                  <1> 	RETn
  7920                              <1> 
  7921                              <1> ;-----	DIRECTION AND STATUS OK; OUTPUT BYTE
  7922                              <1> 
  7923                              <1> J27:	
  7924 00002699 88E0                <1> 	MOV	AL,AH			; GET BYTE TO OUTPUT
  7925 0000269B 6642                <1> 	INC	DX			; DATA PORT = STATUS PORT + 1
  7926 0000269D EE                  <1> 	OUT	DX,AL			; OUTPUT THE BYTE
  7927                              <1> 	;;NEWIODELAY  ;; 27/02/2015
  7928                              <1> 	; 27/02/2015
  7929 0000269E 9C                  <1> 	PUSHF				; SAVE FLAGS
  7930 0000269F B903000000          <1> 	MOV	eCX, 3			; 30 TO 45 MICROSECONDS WAIT FOR
  7931 000026A4 E847F2FFFF          <1> 	CALL 	WAITF			; NEC FLAGS UPDATE CYCLE
  7932 000026A9 9D                  <1> 	POPF				; RESTORE FLAGS FOR EXIT
  7933                              <1> 	;POP	BX			; RESTORE REG
  7934 000026AA C3                  <1> 	RETn				; CY = 0 FROM TEST INSTRUCTION
  7935                              <1> 
  7936                              <1> ;-------------------------------------------------------------------------------
  7937                              <1> ; SEEK
  7938                              <1> ;	THIS ROUTINE WILL MOVE THE HEAD ON THE NAMED DRIVE TO THE NAMED
  7939                              <1> ;	TRACK. IF THE DRIVE HAS NOT BEEN ACCESSED SINCE THE DRIVE
  7940                              <1> ;	RESET COMMAND WAS ISSUED, THE DRIVE WILL BE RECALIBRATED.
  7941                              <1> ;
  7942                              <1> ; ON ENTRY:	DI = DRIVE #
  7943                              <1> ;		CH = TRACK #
  7944                              <1> ;
  7945                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  7946                              <1> ;		AX,BX,CX DX DESTROYED
  7947                              <1> ;-------------------------------------------------------------------------------
  7948                              <1> SEEK:
  7949 000026AB 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7950 000026AD B001                <1> 	MOV	AL,1			; ESTABLISH MASK FOR RECALIBRATE TEST
  7951 000026AF 86CB                <1> 	XCHG	CL,BL			; SET DRIVE VALULE INTO CL
  7952 000026B1 D2C0                <1> 	ROL	AL,CL			; SHIFT MASK BY THE DRIVE VALUE
  7953 000026B3 86CB                <1> 	XCHG	CL,BL			; RECOVER TRACK VALUE
  7954 000026B5 8405[71BE0000]      <1> 	TEST	AL,[SEEK_STATUS]	; TEST FOR RECALIBRATE REQUIRED
  7955 000026BB 7526                <1> 	JNZ	short J28A		; JUMP IF RECALIBRATE NOT REQUIRED
  7956                              <1> 
  7957 000026BD 0805[71BE0000]      <1> 	OR	[SEEK_STATUS],AL	; TURN ON THE NO RECALIBRATE BIT IN FLAG
  7958 000026C3 E862000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  7959 000026C8 730E                <1> 	JNC	short AFT_RECAL		; RECALIBRATE DONE
  7960                              <1> 
  7961                              <1> ;-----	ISSUE RECALIBRATE FOR 80 TRACK DISKETTES
  7962                              <1> 
  7963 000026CA C605[74BE0000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR OUT INVALID STATUS
  7964 000026D1 E854000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  7965 000026D6 7251                <1> 	JC	short RB		; IF RECALIBRATE FAILS TWICE THEN ERROR
  7966                              <1> 
  7967                              <1> AFT_RECAL:
  7968 000026D8 C687[85BE0000]00    <1>         MOV     byte [DSK_TRK+eDI],0    ; SAVE NEW CYLINDER AS PRESENT POSITION
  7969 000026DF 08ED                <1> 	OR	CH,CH			; CHECK FOR SEEK TO TRACK 0
  7970 000026E1 743F                <1> 	JZ	short DO_WAIT		; HEAD SETTLE, CY = 0 IF JUMP
  7971                              <1> 
  7972                              <1> ;-----	DRIVE IS IN SYNCHRONIZATION WITH CONTROLLER, SEEK TO TRACK
  7973                              <1> 
  7974 000026E3 F687[81BE0000]20    <1> J28A:	TEST	byte [DSK_STATE+eDI],DBL_STEP ; CHECK FOR DOUBLE STEP REQUIRED
  7975 000026EA 7402                <1> 	JZ	short _R7		; SINGLE STEP REQUIRED BYPASS DOUBLE
  7976 000026EC D0E5                <1> 	SHL	CH,1			; DOUBLE NUMBER OF STEP TO TAKE
  7977                              <1> 
  7978 000026EE 3AAF[85BE0000]      <1> _R7:	CMP	CH, [DSK_TRK+eDI]	; SEE IF ALREADY AT THE DESIRED TRACK
  7979 000026F4 7433                <1> 	JE	short RB		; IF YES, DO NOT NEED TO SEEK
  7980                              <1> 
  7981 000026F6 BA[29270000]        <1> 	MOV	eDX, NEC_ERR		; LOAD RETURN ADDRESS
  7982 000026FB 52                  <1> 	PUSH	eDX ; (*)		; ON STACK FOR NEC OUTPUT ERROR
  7983 000026FC 88AF[85BE0000]      <1> 	MOV	[DSK_TRK+eDI],CH	; SAVE NEW CYLINDER AS PRESENT POSITION
  7984 00002702 B40F                <1> 	MOV	AH,0FH			; SEEK COMMAND TO NEC
  7985 00002704 E868FFFFFF          <1> 	CALL	NEC_OUTPUT
  7986 00002709 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7987 0000270B 88DC                <1> 	MOV	AH,BL			; OUTPUT DRIVE NUMBER
  7988 0000270D E85FFFFFFF          <1> 	CALL	NEC_OUTPUT
  7989 00002712 8AA7[85BE0000]      <1> 	MOV	AH, [DSK_TRK+eDI]	; GET CYLINDER NUMBER
  7990 00002718 E854FFFFFF          <1> 	CALL	NEC_OUTPUT
  7991 0000271D E829000000          <1> 	CALL	CHK_STAT_2		; ENDING INTERRUPT AND SENSE STATUS
  7992                              <1> 
  7993                              <1> ;-----	WAIT FOR HEAD SETTLE
  7994                              <1> 
  7995                              <1> DO_WAIT:
  7996 00002722 9C                  <1> 	PUSHF				; SAVE STATUS
  7997 00002723 E816FFFFFF          <1> 	CALL	HD_WAIT			; WAIT FOR HEAD SETTLE TIME
  7998 00002728 9D                  <1> 	POPF				; RESTORE STATUS
  7999                              <1> RB:
  8000                              <1> NEC_ERR:
  8001                              <1> 	; 08/02/2015 (code trick here from original IBM PC/AT DISKETTE.ASM)
  8002                              <1> 	; (*) nec_err -> retn (push edx -> pop edx) -> nec_err -> retn
  8003 00002729 C3                  <1> 	RETn				; RETURN TO CALLER
  8004                              <1> 
  8005                              <1> ;-------------------------------------------------------------------------------
  8006                              <1> ; RECAL
  8007                              <1> ;	RECALIBRATE DRIVE
  8008                              <1> ;
  8009                              <1> ; ON ENTRY:	DI = DRIVE #
  8010                              <1> ;
  8011                              <1> ; ON EXIT:	CY REFLECTS STATUS OF OPERATION.
  8012                              <1> ;-------------------------------------------------------------------------------
  8013                              <1> RECAL:
  8014 0000272A 6651                <1> 	PUSH	CX
  8015 0000272C B8[48270000]        <1> 	MOV	eAX, RC_BACK		; LOAD NEC_OUTPUT ERROR
  8016 00002731 50                  <1> 	PUSH	eAX
  8017 00002732 B407                <1> 	MOV	AH,07H			; RECALIBRATE COMMAND
  8018 00002734 E838FFFFFF          <1> 	CALL	NEC_OUTPUT
  8019 00002739 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  8020 0000273B 88DC                <1> 	MOV	AH,BL
  8021 0000273D E82FFFFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE DRIVE NUMBER
  8022 00002742 E804000000          <1> 	CALL	CHK_STAT_2		; GET THE INTERRUPT AND SENSE INT STATUS
  8023 00002747 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  8024                              <1> RC_BACK:
  8025 00002748 6659                <1> 	POP	CX
  8026 0000274A C3                  <1> 	RETn
  8027                              <1> 
  8028                              <1> ;-------------------------------------------------------------------------------
  8029                              <1> ; CHK_STAT_2
  8030                              <1> ;	THIS ROUTINE HANDLES THE INTERRUPT RECEIVED AFTER RECALIBRATE,
  8031                              <1> ;	OR SEEK TO THE ADAPTER. THE INTERRUPT IS WAITED FOR, THE
  8032                              <1> ;	INTERRUPT STATUS SENSED, AND THE RESULT RETURNED TO THE CALLER.
  8033                              <1> ;
  8034                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8035                              <1> ;-------------------------------------------------------------------------------
  8036                              <1> CHK_STAT_2:
  8037 0000274B B8[73270000]        <1>         MOV     eAX, CS_BACK            ; LOAD NEC_OUTPUT ERROR ADDRESS
  8038 00002750 50                  <1> 	PUSH	eAX
  8039 00002751 E828000000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  8040 00002756 721A                <1> 	JC	short J34		; IF ERROR, RETURN IT
  8041 00002758 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  8042 0000275A E812FFFFFF          <1> 	CALL	NEC_OUTPUT
  8043 0000275F E84A000000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  8044 00002764 720C                <1> 	JC	short J34
  8045 00002766 A0[75BE0000]        <1> 	MOV	AL,[NEC_STATUS]		; GET THE FIRST STATUS BYTE
  8046 0000276B 2460                <1> 	AND	AL,01100000B		; ISOLATE THE BITS
  8047 0000276D 3C60                <1> 	CMP	AL,01100000B		; TEST FOR CORRECT VALUE
  8048 0000276F 7403                <1> 	JZ	short J35		; IF ERROR, GO MARK IT
  8049 00002771 F8                  <1> 	CLC				; GOOD RETURN
  8050                              <1> J34:
  8051 00002772 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  8052                              <1> CS_BACK:
  8053 00002773 C3                  <1> 	RETn
  8054                              <1> J35:
  8055 00002774 800D[74BE0000]40    <1> 	OR	byte [DSKETTE_STATUS], BAD_SEEK
  8056 0000277B F9                  <1> 	STC				; ERROR RETURN CODE
  8057 0000277C EBF4                <1> 	JMP	SHORT J34
  8058                              <1> 
  8059                              <1> ;-------------------------------------------------------------------------------
  8060                              <1> ; WAIT_INT
  8061                              <1> ;	THIS ROUTINE WAITS FOR AN INTERRUPT TO OCCUR A TIME OUT ROUTINE
  8062                              <1> ;	TAKES PLACE DURING THE WAIT, SO THAT AN ERROR MAY BE RETURNED
  8063                              <1> ;	IF THE DRIVE IS NOT READY.
  8064                              <1> ;
  8065                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8066                              <1> ;-------------------------------------------------------------------------------
  8067                              <1> 
  8068                              <1> ; 17/12/2014
  8069                              <1> ; 2.5 seconds waiting !
  8070                              <1> ;(AWARD BIOS - 1999, WAIT_FDU_INT_LOW, WAIT_FDU_INT_HI)
  8071                              <1> ; amount of time to wait for completion interrupt from NEC.
  8072                              <1> 
  8073                              <1> 
  8074                              <1> WAIT_INT:
  8075 0000277E FB                  <1> 	STI				; TURN ON INTERRUPTS, JUST IN CASE
  8076 0000277F F8                  <1> 	CLC				; CLEAR TIMEOUT INDICATOR
  8077                              <1>        ;MOV	BL,10			; CLEAR THE COUNTERS
  8078                              <1>        ;XOR	CX,CX			; FOR 2 SECOND WAIT
  8079                              <1> 
  8080                              <1> 	; Modification from AWARD BIOS - 1999 (ATORGS.ASM, WAIT
  8081                              <1> 	;
  8082                              <1> 	;WAIT_FOR_MEM:	
  8083                              <1> 	;	Waits for a bit at a specified memory location pointed
  8084                              <1> 	;	to by ES:[DI] to become set.
  8085                              <1> 	;INPUT:
  8086                              <1> 	;	AH=Mask to test with.
  8087                              <1> 	;	ES:[DI] = memory location to watch.
  8088                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  8089                              <1> 	;	     (normally 30 microseconds per period.)
  8090                              <1> 
  8091                              <1> 	; waiting for (max.) 2.5 secs in 30 micro units.
  8092                              <1> ;	mov 	cx, WAIT_FDU_INT_LO		; 017798
  8093                              <1> ;;	mov 	bl, WAIT_FDU_INT_HI
  8094                              <1> ;	mov 	bl, WAIT_FDU_INT_HI + 1
  8095                              <1> 	; 27/02/2015
  8096 00002780 B986450100          <1> 	mov 	ecx, WAIT_FDU_INT_LH	; 83334 (2.5 seconds)		
  8097                              <1> WFMS_CHECK_MEM:
  8098 00002785 F605[71BE0000]80    <1> 	test	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  8099 0000278C 7516                <1>         jnz     short J37
  8100                              <1> WFMS_HI:
  8101 0000278E E461                <1> 	IN	AL,PORT_B  ; 061h	; SYS1, wait for lo to hi
  8102 00002790 A810                <1> 	TEST	AL,010H			; transition on memory
  8103 00002792 75FA                <1> 	JNZ	SHORT WFMS_HI		; refresh.
  8104                              <1> WFMS_LO:
  8105 00002794 E461                <1> 	IN	AL,PORT_B		;SYS1
  8106 00002796 A810                <1> 	TEST	AL,010H
  8107 00002798 74FA                <1> 	JZ	SHORT WFMS_LO
  8108 0000279A E2E9                <1>         LOOP    WFMS_CHECK_MEM
  8109                              <1> ;WFMS_OUTER_LP:
  8110                              <1> ;;	or	bl, bl			; check outer counter
  8111                              <1> ;;	jz	short J36A		; WFMS_TIMEOUT
  8112                              <1> ;	dec	bl
  8113                              <1> ;	jz	short J36A	
  8114                              <1> ;	jmp	short WFMS_CHECK_MEM
  8115                              <1> 
  8116                              <1> 	;17/12/2014
  8117                              <1> 	;16/12/2014
  8118                              <1> ;        mov     byte [wait_count], 0    ; Reset (INT 08H) counter
  8119                              <1> ;J36:
  8120                              <1> ;	TEST	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  8121                              <1> ;	JNZ	short J37
  8122                              <1> 	;16/12/2014
  8123                              <1> 	;LOOP	J36			; COUNT DOWN WHILE WAITING
  8124                              <1> 	;DEC	BL			; SECOND LEVEL COUNTER
  8125                              <1> 	;JNZ	short J36
  8126                              <1> ;       cmp     byte [wait_count], 46   ; (46/18.2 seconds)
  8127                              <1> ;	jb	short J36
  8128                              <1> 
  8129                              <1> ;WFMS_TIMEOUT:
  8130                              <1> ;J36A:
  8131 0000279C 800D[74BE0000]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; NOTHING HAPPENED
  8132 000027A3 F9                  <1> 	STC				; ERROR RETURN
  8133                              <1> J37:
  8134 000027A4 9C                  <1> 	PUSHF				; SAVE CURRENT CARRY
  8135 000027A5 8025[71BE0000]7F    <1> 	AND	byte [SEEK_STATUS], ~INT_FLAG ; TURN OFF INTERRUPT FLAG
  8136 000027AC 9D                  <1> 	POPF				; RECOVER CARRY
  8137 000027AD C3                  <1> 	RETn				; GOOD RETURN CODE
  8138                              <1> 
  8139                              <1> ;-------------------------------------------------------------------------------
  8140                              <1> ; RESULTS
  8141                              <1> ;	THIS ROUTINE WILL READ ANYTHING THAT THE NEC CONTROLLER RETURNS 
  8142                              <1> ;	FOLLOWING AN INTERRUPT.
  8143                              <1> ;
  8144                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8145                              <1> ;		AX,BX,CX,DX DESTROYED
  8146                              <1> ;-------------------------------------------------------------------------------
  8147                              <1> RESULTS:
  8148 000027AE 57                  <1> 	PUSH	eDI
  8149 000027AF BF[75BE0000]        <1> 	MOV	eDI, NEC_STATUS		; POINTER TO DATA AREA
  8150 000027B4 B307                <1> 	MOV	BL,7			; MAX STATUS BYTES
  8151 000027B6 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  8152                              <1> 
  8153                              <1> ;-----	WAIT FOR REQUEST FOR MASTER
  8154                              <1> 
  8155                              <1> _R10: 
  8156                              <1> 	; 16/12/2014
  8157                              <1> 	; wait for (max) 0.5 seconds
  8158                              <1> 	;MOV	BH,2			; HIGH ORDER COUNTER
  8159                              <1> 	;XOR	CX,CX			; COUNTER
  8160                              <1> 
  8161                              <1> 	;Time to wait while waiting for each byte of NEC results = .5
  8162                              <1> 	;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  8163                              <1> 	; 27/02/2015
  8164 000027BA B91B410000          <1> 	mov 	ecx, WAIT_FDU_RESULTS_LH ; 16667  
  8165                              <1> 	;mov	cx, WAIT_FDU_RESULTS_LO  ; 16667
  8166                              <1> 	;mov	bh, WAIT_FDU_RESULTS_HI+1 ; 0+1
  8167                              <1> 
  8168                              <1> WFPSR_OUTER_LP:
  8169                              <1> 	;
  8170                              <1> WFPSR_CHECK_PORT:
  8171                              <1> J39:					; WAIT FOR MASTER
  8172 000027BF EC                  <1> 	IN	AL,DX			; GET STATUS
  8173 000027C0 24C0                <1> 	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  8174 000027C2 3CC0                <1> 	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  8175 000027C4 7418                <1> 	JZ	short J42		; STATUS AND DIRECTION OK
  8176                              <1> WFPSR_HI:
  8177 000027C6 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  8178 000027C8 A810                <1> 	TEST	AL,010H			; transition on memory
  8179 000027CA 75FA                <1> 	JNZ	SHORT WFPSR_HI		; refresh.
  8180                              <1> WFPSR_LO:
  8181 000027CC E461                <1> 	IN	AL, PORT_B		; SYS1
  8182 000027CE A810                <1> 	TEST	AL,010H
  8183 000027D0 74FA                <1> 	JZ	SHORT WFPSR_LO
  8184 000027D2 E2EB                <1>         LOOP    WFPSR_CHECK_PORT
  8185                              <1> 	;; 27/02/2015
  8186                              <1> 	;;dec	bh
  8187                              <1> 	;;jnz	short WFPSR_OUTER_LP
  8188                              <1> 	;jmp	short WFPSR_TIMEOUT	; fail
  8189                              <1> 
  8190                              <1> 	;;mov	byte [wait_count], 0
  8191                              <1> ;J39:					; WAIT FOR MASTER
  8192                              <1> ;	IN	AL,DX			; GET STATUS
  8193                              <1> ;	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  8194                              <1> ;	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  8195                              <1> ;	JZ	short J42		; STATUS AND DIRECTION OK
  8196                              <1> 	;LOOP	J39			; LOOP TILL TIMEOUT
  8197                              <1> 	;DEC	BH			; DECREMENT HIGH ORDER COUNTER
  8198                              <1> 	;JNZ	short J39		; REPEAT TILL DELAY DONE
  8199                              <1> 	;
  8200                              <1> 	;;cmp	byte [wait_count], 10  ; (10/18.2 seconds)
  8201                              <1> 	;;jb	short J39	
  8202                              <1> 
  8203                              <1> ;WFPSR_TIMEOUT:
  8204 000027D4 800D[74BE0000]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  8205 000027DB F9                  <1> 	STC				; SET ERROR RETURN
  8206 000027DC EB29                <1> 	JMP	SHORT POPRES		; POP REGISTERS AND RETURN
  8207                              <1> 
  8208                              <1> ;-----	READ IN THE STATUS
  8209                              <1> 
  8210                              <1> J42:
  8211 000027DE EB00                <1> 	JMP	$+2			; I/O DELAY
  8212 000027E0 6642                <1> 	INC	DX			; POINT AT DATA PORT
  8213 000027E2 EC                  <1> 	IN	AL,DX			; GET THE DATA
  8214                              <1> 	; 16/12/2014
  8215                              <1> 	NEWIODELAY
  8216 000027E3 E6EB                <2>  out 0ebh,al
  8217 000027E5 8807                <1>         MOV     [eDI],AL                ; STORE THE BYTE
  8218 000027E7 47                  <1> 	INC	eDI			; INCREMENT THE POINTER
  8219                              <1> 	; 16/12/2014
  8220                              <1> ;	push	cx
  8221                              <1> ;	mov	cx, 30
  8222                              <1> ;wdw2:
  8223                              <1> ;	NEWIODELAY
  8224                              <1> ;	loop	wdw2
  8225                              <1> ;	pop	cx
  8226                              <1> 
  8227 000027E8 B903000000          <1> 	MOV	eCX,3			; MINIMUM 24 MICROSECONDS FOR NEC
  8228 000027ED E8FEF0FFFF          <1> 	CALL	WAITF			; WAIT 30 TO 45 MICROSECONDS
  8229 000027F2 664A                <1> 	DEC	DX			; POINT AT STATUS PORT
  8230 000027F4 EC                  <1> 	IN	AL,DX			; GET STATUS
  8231                              <1> 	; 16/12/2014
  8232                              <1> 	NEWIODELAY
  8233 000027F5 E6EB                <2>  out 0ebh,al
  8234                              <1> 	;
  8235 000027F7 A810                <1> 	TEST	AL,00010000B		; TEST FOR NEC STILL BUSY
  8236 000027F9 740C                <1> 	JZ	short POPRES		; RESULTS DONE ?
  8237                              <1> 
  8238 000027FB FECB                <1> 	DEC	BL			; DECREMENT THE STATUS COUNTER
  8239 000027FD 75BB                <1>         JNZ     short _R10              ; GO BACK FOR MORE
  8240 000027FF 800D[74BE0000]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; TOO MANY STATUS BYTES
  8241 00002806 F9                  <1> 	STC				; SET ERROR FLAG
  8242                              <1> 
  8243                              <1> ;-----	RESULT OPERATION IS DONE
  8244                              <1> POPRES:
  8245 00002807 5F                  <1> 	POP	eDI
  8246 00002808 C3                  <1> 	RETn				; RETURN WITH CARRY SET
  8247                              <1> 
  8248                              <1> ;-------------------------------------------------------------------------------
  8249                              <1> ; READ_DSKCHNG
  8250                              <1> ;	READS THE STATE OF THE DISK CHANGE LINE.
  8251                              <1> ;
  8252                              <1> ; ON ENTRY:	DI = DRIVE #
  8253                              <1> ;
  8254                              <1> ; ON EXIT:	DI = DRIVE #
  8255                              <1> ;		ZF = 0 : DISK CHANGE LINE INACTIVE
  8256                              <1> ;		ZF = 1 : DISK CHANGE LINE ACTIVE
  8257                              <1> ;		AX,CX,DX DESTROYED
  8258                              <1> ;-------------------------------------------------------------------------------
  8259                              <1> READ_DSKCHNG:
  8260 00002809 E8A2FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON THE MOTOR IF OFF
  8261 0000280E 66BAF703            <1> 	MOV	DX,03F7H		; ADDRESS DIGITAL INPUT REGISTER
  8262 00002812 EC                  <1> 	IN	AL,DX			; INPUT DIGITAL INPUT REGISTER
  8263 00002813 A880                <1> 	TEST	AL,DSK_CHG		; CHECK FOR DISK CHANGE LINE ACTIVE
  8264 00002815 C3                  <1> 	RETn				; RETURN TO CALLER WITH ZERO FLAG SET
  8265                              <1> 
  8266                              <1> ;-------------------------------------------------------------------------------
  8267                              <1> ; DRIVE_DET
  8268                              <1> ;	DETERMINES WHETHER DRIVE IS 80 OR 40 TRACKS AND
  8269                              <1> ;	UPDATES STATE INFORMATION ACCORDINGLY.
  8270                              <1> ; ON ENTRY:	DI = DRIVE #
  8271                              <1> ;-------------------------------------------------------------------------------
  8272                              <1> DRIVE_DET:
  8273 00002816 E895FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON MOTOR IF NOT ALREADY ON
  8274 0000281B E80AFFFFFF          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  8275 00002820 7251                <1> 	JC	short DD_BAC		; ASSUME NO DRIVE PRESENT
  8276 00002822 B530                <1> 	MOV	CH,TRK_SLAP		; SEEK TO TRACK 48
  8277 00002824 E882FEFFFF          <1> 	CALL	SEEK
  8278 00002829 7248                <1> 	JC	short DD_BAC		; ERROR NO DRIVE
  8279 0000282B B50B                <1> 	MOV	CH,QUIET_SEEK+1		; SEEK TO TRACK 10
  8280                              <1> SK_GIN:
  8281 0000282D FECD                <1> 	DEC	CH			; DECREMENT TO NEXT TRACK
  8282 0000282F 6651                <1> 	PUSH	CX			; SAVE TRACK
  8283 00002831 E875FEFFFF          <1> 	CALL	SEEK
  8284 00002836 723C                <1> 	JC	short POP_BAC		; POP AND RETURN
  8285 00002838 B8[74280000]        <1> 	MOV	eAX, POP_BAC		; LOAD NEC OUTPUT ERROR ADDRESS
  8286 0000283D 50                  <1> 	PUSH	eAX
  8287 0000283E B404                <1> 	MOV	AH,SENSE_DRV_ST		; SENSE DRIVE STATUS COMMAND BYTE
  8288 00002840 E82CFEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  8289 00002845 6689F8              <1> 	MOV	AX,DI			; AL = DRIVE
  8290 00002848 88C4                <1> 	MOV	AH,AL			; AH = DRIVE
  8291 0000284A E822FEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  8292 0000284F E85AFFFFFF          <1> 	CALL	RESULTS			; GO GET STATUS
  8293 00002854 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  8294 00002855 6659                <1> 	POP	CX			; RESTORE TRACK
  8295 00002857 F605[75BE0000]10    <1> 	TEST	byte [NEC_STATUS], HOME	; TRACK 0 ?
  8296 0000285E 74CD                <1> 	JZ	short SK_GIN		; GO TILL TRACK 0
  8297 00002860 08ED                <1> 	OR	CH,CH			; IS HOME AT TRACK 0
  8298 00002862 7408                <1> 	JZ	short IS_80		; MUST BE 80 TRACK DRIVE
  8299                              <1> 
  8300                              <1> ;	DRIVE IS A 360; SET DRIVE TO DETERMINED;
  8301                              <1> ;	SET MEDIA TO DETERMINED AT RATE 250.
  8302                              <1> 
  8303 00002864 808F[81BE0000]94    <1> 	OR	byte [DSK_STATE+eDI], DRV_DET+MED_DET+RATE_250
  8304 0000286B C3                  <1> 	RETn				; ALL INFORMATION SET
  8305                              <1> IS_80:
  8306 0000286C 808F[81BE0000]01    <1> 	OR	byte [DSK_STATE+eDI], TRK_CAPA ; SETUP 80 TRACK CAPABILITY
  8307                              <1> DD_BAC:
  8308 00002873 C3                  <1> 	RETn
  8309                              <1> POP_BAC:
  8310 00002874 6659                <1> 	POP	CX			; THROW AWAY
  8311 00002876 C3                  <1> 	RETn
  8312                              <1> 
  8313                              <1> fdc_int:  
  8314                              <1> 	  ; 30/07/2015	
  8315                              <1> 	  ; 16/02/2015
  8316                              <1> ;int_0Eh: ; 11/12/2014
  8317                              <1> 
  8318                              <1> ;--- HARDWARE INT 0EH -- ( IRQ LEVEL  6 ) --------------------------------------
  8319                              <1> ; DISK_INT
  8320                              <1> ;	THIS ROUTINE HANDLES THE DISKETTE INTERRUPT.
  8321                              <1> ;
  8322                              <1> ; ON EXIT:	THE INTERRUPT FLAG IS SET IN @SEEK_STATUS.
  8323                              <1> ;-------------------------------------------------------------------------------
  8324                              <1> DISK_INT_1:
  8325                              <1> 
  8326 00002877 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER
  8327 00002879 1E                  <1> 	push	ds
  8328 0000287A 66B81000            <1> 	mov	ax, KDATA
  8329 0000287E 8ED8                <1> 	mov 	ds, ax
  8330 00002880 800D[71BE0000]80    <1>         OR      byte [SEEK_STATUS], INT_FLAG ; TURN ON INTERRUPT OCCURRED
  8331 00002887 B020                <1> 	MOV     AL,EOI                  ; END OF INTERRUPT MARKER
  8332 00002889 E620                <1> 	OUT	INTA00,AL		; INTERRUPT CONTROL PORT
  8333 0000288B 1F                  <1> 	pop	ds
  8334 0000288C 6658                <1> 	POP	AX			; RECOVER REGISTER
  8335 0000288E CF                  <1> 	IRET				; RETURN FROM INTERRUPT
  8336                              <1> 
  8337                              <1> ;-------------------------------------------------------------------------------
  8338                              <1> ; DSKETTE_SETUP
  8339                              <1> ;	THIS ROUTINE DOES A PRELIMINARY CHECK TO SEE WHAT TYPE OF
  8340                              <1> ;	DISKETTE DRIVES ARE ATTACH TO THE SYSTEM.
  8341                              <1> ;-------------------------------------------------------------------------------
  8342                              <1> DSKETTE_SETUP:
  8343                              <1> 	;PUSH	AX			; SAVE REGISTERS
  8344                              <1> 	;PUSH	BX
  8345                              <1> 	;PUSH	CX
  8346 0000288F 52                  <1> 	PUSH	eDX
  8347                              <1> 	;PUSH	DI
  8348                              <1> 	;;PUSH	DS
  8349                              <1> 	; 14/12/2014
  8350                              <1> 	;mov	word [DISK_POINTER], MD_TBL6
  8351                              <1> 	;mov	[DISK_POINTER+2], cs
  8352                              <1> 	;
  8353                              <1> 	;OR	byte [RTC_WAIT_FLAG], 1	; NO RTC WAIT, FORCE USE OF LOOP
  8354 00002890 31FF                <1> 	XOR	eDI,eDI			; INITIALIZE DRIVE POINTER
  8355 00002892 66C705[81BE0000]00- <1> 	MOV	WORD [DSK_STATE],0	; INITIALIZE STATES
  8356 0000289A 00                  <1>
  8357 0000289B 8025[7CBE0000]33    <1> 	AND	byte [LASTRATE],~(STRT_MSK+SEND_MSK) ; CLEAR START & SEND
  8358 000028A2 800D[7CBE0000]C0    <1> 	OR	byte [LASTRATE],SEND_MSK ; INITIALIZE SENT TO IMPOSSIBLE
  8359 000028A9 C605[71BE0000]00    <1> 	MOV	byte [SEEK_STATUS],0	; INDICATE RECALIBRATE NEEDED
  8360 000028B0 C605[73BE0000]00    <1> 	MOV	byte [MOTOR_COUNT],0	; INITIALIZE MOTOR COUNT
  8361 000028B7 C605[72BE0000]00    <1> 	MOV	byte [MOTOR_STATUS],0	; INITIALIZE DRIVES TO OFF STATE
  8362 000028BE C605[74BE0000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; NO ERRORS
  8363                              <1> 	;
  8364                              <1> 	; 28/02/2015
  8365                              <1> 	;mov	word [cfd], 100h 
  8366 000028C5 E85FF2FFFF          <1> 	call	DSK_RESET
  8367 000028CA 5A                  <1> 	pop	edx
  8368 000028CB C3                  <1> 	retn
  8369                              <1> 
  8370                              <1> ;SUP0:
  8371                              <1> ;	CALL	DRIVE_DET		; DETERMINE DRIVE
  8372                              <1> ;	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  8373                              <1> ;	; 02/01/2015
  8374                              <1> ;	;INC	DI			; POINT TO NEXT DRIVE
  8375                              <1> ;	;CMP	DI,MAX_DRV		; SEE IF DONE
  8376                              <1> ;	;JNZ	short SUP0		; REPEAT FOR EACH ORIVE
  8377                              <1> ;       cmp     byte [fd1_type], 0	
  8378                              <1> ;	jna	short sup1
  8379                              <1> ;	or	di, di
  8380                              <1> ;	jnz	short sup1
  8381                              <1> ;	inc	di
  8382                              <1> ;       jmp     short SUP0
  8383                              <1> ;sup1:
  8384                              <1> ;	MOV	byte [SEEK_STATUS],0	; FORCE RECALIBRATE
  8385                              <1> ;	;AND	byte [RTC_WAIT_FLAG],0FEH ; ALLOW FOR RTC WAIT
  8386                              <1> ;	CALL	SETUP_END		; VARIOUS CLEANUPS
  8387                              <1> ;	;;POP	DS			; RESTORE CALLERS REGISTERS
  8388                              <1> ;	;POP	DI
  8389                              <1> ;	POP	eDX
  8390                              <1> ;	;POP	CX
  8391                              <1> ;	;POP	BX
  8392                              <1> ;	;POP	AX
  8393                              <1> ;	RETn
  8394                              <1> 
  8395                              <1> ;//////////////////////////////////////////////////////
  8396                              <1> ;; END OF DISKETTE I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8397                              <1> ;
  8398                              <1> 
  8399                              <1> int13h: ; 21/02/2015
  8400 000028CC 9C                  <1> 	pushfd
  8401 000028CD 0E                  <1> 	push 	cs
  8402 000028CE E858000000          <1> 	call 	DISK_IO
  8403 000028D3 C3                  <1> 	retn
  8404                              <1> 
  8405                              <1> ;;;;;; DISK I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 21/02/2015 ;;;
  8406                              <1> ;/////////////////////////////////////////////////////////////////////
  8407                              <1> 
  8408                              <1> ; DISK I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  8409                              <1> ; 18/02/2016
  8410                              <1> ; 17/02/2016
  8411                              <1> ; 23/02/2015
  8412                              <1> ; 21/02/2015 (unix386.s)
  8413                              <1> ; 22/12/2014 - 14/02/2015 (dsectrm2.s)
  8414                              <1> ;
  8415                              <1> ; Original Source Code:
  8416                              <1> ; DISK ----- 09/25/85 FIXED DISK BIOS
  8417                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  8418                              <1> ;
  8419                              <1> ; Modifications: by reference of AWARD BIOS 1999 (D1A0622) 
  8420                              <1> ;		 Source Code - ATORGS.ASM, AHDSK.ASM
  8421                              <1> ;
  8422                              <1> 
  8423                              <1> 
  8424                              <1> ;The wait for controller to be not busy is 10 seconds.
  8425                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  8426                              <1> ;;WAIT_HDU_CTLR_BUSY_LO	equ	1615h		
  8427                              <1> ;;WAIT_HDU_CTLR_BUSY_HI	equ	  05h
  8428                              <1> WAIT_HDU_CTRL_BUSY_LH	equ	51615h	 ;21/02/2015		
  8429                              <1> 
  8430                              <1> ;The wait for controller to issue completion interrupt is 10 seconds.
  8431                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  8432                              <1> ;;WAIT_HDU_INT_LO	equ	1615h
  8433                              <1> ;;WAIT_HDU_INT_HI	equ	  05h
  8434                              <1> WAIT_HDU_INT_LH		equ	51615h	; 21/02/2015
  8435                              <1> 
  8436                              <1> ;The wait for Data request on read and write longs is
  8437                              <1> ;2000 us. (?)
  8438                              <1> ;;WAIT_HDU_DRQ_LO	equ	1000	; 03E8h
  8439                              <1> ;;WAIT_HDU_DRQ_HI	equ	0
  8440                              <1> WAIT_HDU_DRQ_LH		equ	1000	; 21/02/2015
  8441                              <1> 
  8442                              <1> ; Port 61h (PORT_B)
  8443                              <1> SYS1		equ	61h	; PORT_B  (diskette.inc)
  8444                              <1> 
  8445                              <1> ; 23/12/2014
  8446                              <1> %define CMD_BLOCK       eBP-8  ; 21/02/2015
  8447                              <1> 
  8448                              <1> 
  8449                              <1> ;--- INT 13H -------------------------------------------------------------------
  8450                              <1> ;									       :
  8451                              <1> ; FIXED DISK I/O INTERFACE						       :
  8452                              <1> ;									       :
  8453                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO 5 1/4" FIXED DISKS THROUGH           :
  8454                              <1> ;	THE IBM FIXED DISK CONTROLLER.					       :
  8455                              <1> ;									       :
  8456                              <1> ;	THE  BIOS  ROUTINES  ARE  MEANT  TO  BE  ACCESSED  THROUGH	       :
  8457                              <1> ;	SOFTWARE  INTERRUPTS  ONLY.    ANY  ADDRESSES  PRESENT	IN	       :
  8458                              <1> ;	THESE  LISTINGS  ARE  INCLUDED	 ONLY	FOR  COMPLETENESS,	       :
  8459                              <1> ;	NOT  FOR  REFERENCE.  APPLICATIONS   WHICH  REFERENCE  ANY	       :
  8460                              <1> ;	ABSOLUTE  ADDRESSES  WITHIN  THE  CODE	SEGMENTS  OF  BIOS	       :
  8461                              <1> ;	VIOLATE  THE  STRUCTURE  AND  DESIGN  OF  BIOS. 		       :
  8462                              <1> ;									       :
  8463                              <1> ;------------------------------------------------------------------------------:
  8464                              <1> ;									       :
  8465                              <1> ; INPUT  (AH)= HEX COMMAND VALUE					       :
  8466                              <1> ;									       :
  8467                              <1> ;	(AH)= 00H  RESET DISK (DL = 80H,81H) / DISKETTE 		       :
  8468                              <1> ;	(AH)= 01H  READ THE STATUS OF THE LAST DISK OPERATION INTO (AL)        :
  8469                              <1> ;		    NOTE: DL < 80H - DISKETTE				       :
  8470                              <1> ;			  DL > 80H - DISK				       :
  8471                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY 		       :
  8472                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY		       :
  8473                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS				       :
  8474                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK				       :
  8475                              <1> ;	(AH)= 06H  UNUSED						       :
  8476                              <1> ;	(AH)= 07H  UNUSED						       :
  8477                              <1> ;	(AH)= 08H  RETURN THE CURRENT DRIVE PARAMETERS			       :
  8478                              <1> ;	(AH)= 09H  INITIALIZE DRIVE PAIR CHARACTERISTICS		       :
  8479                              <1> ;		    INTERRUPT 41 POINTS TO DATA BLOCK FOR DRIVE 0	       :
  8480                              <1> ;		    INTERRUPT 46 POINTS TO DATA BLOCK FOR DRIVE 1	       :
  8481                              <1> ;	(AH)= 0AH  READ LONG						       :
  8482                              <1> ;	(AH)= 0BH  WRITE LONG  (READ & WRITE LONG ENCOMPASS 512 + 4 BYTES ECC) :
  8483                              <1> ;	(AH)= 0CH  SEEK 						       :
  8484                              <1> ;	(AH)= 0DH  ALTERNATE DISK RESET (SEE DL)			       :
  8485                              <1> ;	(AH)= 0EH  UNUSED						       :
  8486                              <1> ;	(AH)= 0FH  UNUSED						       :
  8487                              <1> ;	(AH)= 10H  TEST DRIVE READY					       :
  8488                              <1> ;	(AH)= 11H  RECALIBRATE						       :
  8489                              <1> ;	(AH)= 12H  UNUSED						       :
  8490                              <1> ;	(AH)= 13H  UNUSED						       :
  8491                              <1> ;	(AH)= 14H  CONTROLLER INTERNAL DIAGNOSTIC			       :
  8492                              <1> ;	(AH)= 15H  READ DASD TYPE					       :
  8493                              <1> ;									       :
  8494                              <1> ;-------------------------------------------------------------------------------
  8495                              <1> ;									       :
  8496                              <1> ;	REGISTERS USED FOR FIXED DISK OPERATIONS			       :
  8497                              <1> ;									       :
  8498                              <1> ;		(DL)	-  DRIVE NUMBER     (80H-81H FOR DISK. VALUE CHECKED)  :
  8499                              <1> ;		(DH)	-  HEAD NUMBER	    (0-15 ALLOWED, NOT VALUE CHECKED)  :
  8500                              <1> ;		(CH)	-  CYLINDER NUMBER  (0-1023, NOT VALUE CHECKED)(SEE CL):
  8501                              <1> ;		(CL)	-  SECTOR NUMBER    (1-17, NOT VALUE CHECKED)	       :
  8502                              <1> ;									       :
  8503                              <1> ;			   NOTE: HIGH 2 BITS OF CYLINDER NUMBER ARE PLACED     :
  8504                              <1> ;				 IN THE HIGH 2 BITS OF THE CL REGISTER	       :
  8505                              <1> ;				 (10 BITS TOTAL)			       :
  8506                              <1> ;									       :
  8507                              <1> ;		(AL)	-  NUMBER OF SECTORS (MAXIMUM POSSIBLE RANGE 1-80H,    :
  8508                              <1> ;					      FOR READ/WRITE LONG 1-79H)       :
  8509                              <1> ;									       :
  8510                              <1> ;		(ES:BX) -  ADDRESS OF BUFFER FOR READS AND WRITES,	       :
  8511                              <1> ;			   (NOT REQUIRED FOR VERIFY)			       :
  8512                              <1> ;									       :
  8513                              <1> ;		FORMAT (AH=5) ES:BX POINTS TO A 512 BYTE BUFFER. THE FIRST     :
  8514                              <1> ;			   2*(SECTORS/TRACK) BYTES CONTAIN F,N FOR EACH SECTOR.:
  8515                              <1> ;			   F = 00H FOR A GOOD SECTOR			       :
  8516                              <1> ;			       80H FOR A BAD SECTOR			       :
  8517                              <1> ;			   N = SECTOR NUMBER				       :
  8518                              <1> ;			   FOR AN INTERLEAVE OF 2 AND 17 SECTORS/TRACK	       :
  8519                              <1> ;			   THE TABLE SHOULD BE: 			       :
  8520                              <1> ;									       :
  8521                              <1> ;		   DB	   00H,01H,00H,0AH,00H,02H,00H,0BH,00H,03H,00H,0CH     :
  8522                              <1> ;		   DB	   00H,04H,00H,0DH,00H,05H,00H,0EH,00H,06H,00H,0FH     :
  8523                              <1> ;		   DB	   00H,07H,00H,10H,00H,08H,00H,11H,00H,09H	       :
  8524                              <1> ;									       :
  8525                              <1> ;-------------------------------------------------------------------------------
  8526                              <1> 
  8527                              <1> ;-------------------------------------------------------------------------------
  8528                              <1> ; OUTPUT								       :
  8529                              <1> ;	AH = STATUS OF CURRENT OPERATION				       :
  8530                              <1> ;	     STATUS BITS ARE DEFINED IN THE EQUATES BELOW		       :
  8531                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN)			       :
  8532                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)			       :
  8533                              <1> ;									       :
  8534                              <1> ;	NOTE:	ERROR 11H  INDICATES THAT THE DATA READ HAD A RECOVERABLE      :
  8535                              <1> ;		ERROR WHICH WAS CORRECTED BY THE ECC ALGORITHM.  THE DATA      :
  8536                              <1> ;		IS PROBABLY GOOD,   HOWEVER THE BIOS ROUTINE INDICATES AN      :
  8537                              <1> ;		ERROR TO ALLOW THE CONTROLLING PROGRAM A CHANCE TO DECIDE      :
  8538                              <1> ;		FOR ITSELF.  THE  ERROR  MAY  NOT  RECUR  IF  THE DATA IS      :
  8539                              <1> ;		REWRITTEN.						       :
  8540                              <1> ;									       :
  8541                              <1> ;	IF DRIVE PARAMETERS WERE REQUESTED (DL >= 80H), 		       :
  8542                              <1> ;	   INPUT:							       :
  8543                              <1> ;	     (DL) = DRIVE NUMBER					       :
  8544                              <1> ;	   OUTPUT:							       :
  8545                              <1> ;	     (DL) = NUMBER OF CONSECUTIVE ACKNOWLEDGING DRIVES ATTACHED (1-2)  :
  8546                              <1> ;		    (CONTROLLER CARD ZERO TALLY ONLY)			       :
  8547                              <1> ;	     (DH) = MAXIMUM USEABLE VALUE FOR HEAD NUMBER		       :
  8548                              <1> ;	     (CH) = MAXIMUM USEABLE VALUE FOR CYLINDER NUMBER		       :
  8549                              <1> ;	     (CL) = MAXIMUM USEABLE VALUE FOR SECTOR NUMBER		       :
  8550                              <1> ;		    AND CYLINDER NUMBER HIGH BITS			       :
  8551                              <1> ;									       :
  8552                              <1> ;	IF READ DASD TYPE WAS REQUESTED,				       :
  8553                              <1> ;									       :
  8554                              <1> ;	AH = 0 - NOT PRESENT						       :
  8555                              <1> ;	     1 - DISKETTE - NO CHANGE LINE AVAILABLE			       :
  8556                              <1> ;	     2 - DISKETTE - CHANGE LINE AVAILABLE			       :
  8557                              <1> ;	     3 - FIXED DISK						       :
  8558                              <1> ;									       :
  8559                              <1> ;	CX,DX = NUMBER OF 512 BYTE BLOCKS WHEN AH = 3			       :
  8560                              <1> ;									       :
  8561                              <1> ;	REGISTERS WILL BE PRESERVED EXCEPT WHEN THEY ARE USED TO RETURN        :
  8562                              <1> ;	INFORMATION.							       :
  8563                              <1> ;									       :
  8564                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISK CODE, THE APPROPRIATE        :
  8565                              <1> ;		ACTION IS TO RESET THE DISK, THEN RETRY THE OPERATION.	       :
  8566                              <1> ;									       :
  8567                              <1> ;-------------------------------------------------------------------------------
  8568                              <1> 
  8569                              <1> SENSE_FAIL	EQU	0FFH		; NOT IMPLEMENTED
  8570                              <1> NO_ERR		EQU	0E0H		; STATUS ERROR/ERROR REGISTER=0
  8571                              <1> WRITE_FAULT	EQU	0CCH		; WRITE FAULT ON SELECTED DRIVE
  8572                              <1> UNDEF_ERR	EQU	0BBH		; UNDEFINED ERROR OCCURRED
  8573                              <1> NOT_RDY 	EQU	0AAH		; DRIVE NOT READY
  8574                              <1> TIME_OUT	EQU	80H		; ATTACHMENT FAILED TO RESPOND
  8575                              <1> BAD_SEEK	EQU	40H		; SEEK OPERATION FAILED
  8576                              <1> BAD_CNTLR	EQU	20H		; CONTROLLER HAS FAILED
  8577                              <1> DATA_CORRECTED	EQU	11H		; ECC CORRECTED DATA ERROR
  8578                              <1> BAD_ECC 	EQU	10H		; BAD ECC ON DISK READ
  8579                              <1> BAD_TRACK	EQU	0BH		; NOT IMPLEMENTED
  8580                              <1> BAD_SECTOR	EQU	0AH		; BAD SECTOR FLAG DETECTED
  8581                              <1> ;DMA_BOUNDARY	EQU	09H		; DATA EXTENDS TOO FAR
  8582                              <1> INIT_FAIL	EQU	07H		; DRIVE PARAMETER ACTIVITY FAILED
  8583                              <1> BAD_RESET	EQU	05H		; RESET FAILED
  8584                              <1> ;RECORD_NOT_FND	EQU	04H		; REQUESTED SECTOR NOT FOUND
  8585                              <1> ;BAD_ADDR_MARK	EQU	02H		; ADDRESS MARK NOT FOUND
  8586                              <1> ;BAD_CMD 	EQU	01H		; BAD COMMAND PASSED TO DISK I/O
  8587                              <1> 
  8588                              <1> ;--------------------------------------------------------
  8589                              <1> ;							:
  8590                              <1> ; FIXED DISK PARAMETER TABLE				:
  8591                              <1> ;  -  THE TABLE IS COMPOSED OF A BLOCK DEFINED AS:	:
  8592                              <1> ;							:
  8593                              <1> ;  +0	(1 WORD) - MAXIMUM NUMBER OF CYLINDERS		:
  8594                              <1> ;  +2	(1 BYTE) - MAXIMUM NUMBER OF HEADS		:
  8595                              <1> ;  +3	(1 WORD) - NOT USED/SEE PC-XT			:
  8596                              <1> ;  +5	(1 WORD) - STARTING WRITE PRECOMPENSATION CYL	:
  8597                              <1> ;  +7	(1 BYTE) - MAXIMUM ECC DATA BURST LENGTH	:
  8598                              <1> ;  +8	(1 BYTE) - CONTROL BYTE 			:
  8599                              <1> ;		   BIT	  7 DISABLE RETRIES -OR-	:
  8600                              <1> ;		   BIT	  6 DISABLE RETRIES		:
  8601                              <1> ;		   BIT	  3 MORE THAN 8 HEADS		:
  8602                              <1> ;  +9	(3 BYTES)- NOT USED/SEE PC-XT			:
  8603                              <1> ; +12	(1 WORD) - LANDING ZONE 			:
  8604                              <1> ; +14	(1 BYTE) - NUMBER OF SECTORS/TRACK		:
  8605                              <1> ; +15	(1 BYTE) - RESERVED FOR FUTURE USE		:
  8606                              <1> ;							:
  8607                              <1> ;	 - TO DYNAMICALLY DEFINE A SET OF PARAMETERS	:
  8608                              <1> ;	   BUILD A TABLE FOR UP TO 15 TYPES AND PLACE	:
  8609                              <1> ;	   THE CORRESPONDING VECTOR INTO INTERRUPT 41	:
  8610                              <1> ;	   FOR DRIVE 0 AND INTERRUPT 46 FOR DRIVE 1.	:
  8611                              <1> ;							:
  8612                              <1> ;--------------------------------------------------------
  8613                              <1> 
  8614                              <1> ;--------------------------------------------------------
  8615                              <1> ;							:
  8616                              <1> ; HARDWARE SPECIFIC VALUES				:
  8617                              <1> ;							:
  8618                              <1> ;  -  CONTROLLER I/O PORT				:
  8619                              <1> ;							:
  8620                              <1> ;     > WHEN READ FROM: 				:
  8621                              <1> ;	HF_PORT+0 - READ DATA (FROM CONTROLLER TO CPU)	:
  8622                              <1> ;	HF_PORT+1 - GET ERROR REGISTER			:
  8623                              <1> ;	HF_PORT+2 - GET SECTOR COUNT			:
  8624                              <1> ;	HF_PORT+3 - GET SECTOR NUMBER			:
  8625                              <1> ;	HF_PORT+4 - GET CYLINDER LOW			:
  8626                              <1> ;	HF_PORT+5 - GET CYLINDER HIGH (2 BITS)		:
  8627                              <1> ;	HF_PORT+6 - GET SIZE/DRIVE/HEAD 		:
  8628                              <1> ;	HF_PORT+7 - GET STATUS REGISTER 		:
  8629                              <1> ;							:
  8630                              <1> ;     > WHEN WRITTEN TO:				:
  8631                              <1> ;	HF_PORT+0 - WRITE DATA (FROM CPU TO CONTROLLER) :
  8632                              <1> ;	HF_PORT+1 - SET PRECOMPENSATION CYLINDER	:
  8633                              <1> ;	HF_PORT+2 - SET SECTOR COUNT			:
  8634                              <1> ;	HF_PORT+3 - SET SECTOR NUMBER			:
  8635                              <1> ;	HF_PORT+4 - SET CYLINDER LOW			:
  8636                              <1> ;	HF_PORT+5 - SET CYLINDER HIGH (2 BITS)		:
  8637                              <1> ;	HF_PORT+6 - SET SIZE/DRIVE/HEAD 		:
  8638                              <1> ;	HF_PORT+7 - SET COMMAND REGISTER		:
  8639                              <1> ;							:
  8640                              <1> ;--------------------------------------------------------
  8641                              <1> 
  8642                              <1> ;HF_PORT 	EQU	01F0H	; DISK PORT
  8643                              <1> ;HF1_PORT	equ	0170h	
  8644                              <1> ;HF_REG_PORT	EQU	03F6H
  8645                              <1> ;HF1_REG_PORT	equ	0376h
  8646                              <1> 
  8647                              <1> HDC1_BASEPORT	equ	1F0h
  8648                              <1> HDC2_BASEPORT	equ	170h		
  8649                              <1> 
  8650                              <1> align 2
  8651                              <1> 
  8652                              <1> ;-----		STATUS REGISTER
  8653                              <1> 
  8654                              <1> ST_ERROR	EQU	00000001B	;
  8655                              <1> ST_INDEX	EQU	00000010B	;
  8656                              <1> ST_CORRCTD	EQU	00000100B	; ECC CORRECTION SUCCESSFUL
  8657                              <1> ST_DRQ		EQU	00001000B	;
  8658                              <1> ST_SEEK_COMPL	EQU	00010000B	; SEEK COMPLETE
  8659                              <1> ST_WRT_FLT	EQU	00100000B	; WRITE FAULT
  8660                              <1> ST_READY	EQU	01000000B	;
  8661                              <1> ST_BUSY 	EQU	10000000B	;
  8662                              <1> 
  8663                              <1> ;-----		ERROR REGISTER
  8664                              <1> 
  8665                              <1> ERR_DAM 	EQU	00000001B	; DATA ADDRESS MARK NOT FOUND
  8666                              <1> ERR_TRK_0	EQU	00000010B	; TRACK 0 NOT FOUND ON RECAL
  8667                              <1> ERR_ABORT	EQU	00000100B	; ABORTED COMMAND
  8668                              <1> ;		EQU	00001000B	; NOT USED
  8669                              <1> ERR_ID		EQU	00010000B	; ID NOT FOUND
  8670                              <1> ;		EQU	00100000B	; NOT USED
  8671                              <1> ERR_DATA_ECC	EQU	01000000B
  8672                              <1> ERR_BAD_BLOCK	EQU	10000000B
  8673                              <1> 
  8674                              <1> 
  8675                              <1> RECAL_CMD	EQU	00010000B	; DRIVE RECAL	(10H)
  8676                              <1> READ_CMD	EQU	00100000B	;	READ	(20H)
  8677                              <1> WRITE_CMD	EQU	00110000B	;	WRITE	(30H)
  8678                              <1> VERIFY_CMD	EQU	01000000B	;	VERIFY	(40H)
  8679                              <1> FMTTRK_CMD	EQU	01010000B	; FORMAT TRACK	(50H)
  8680                              <1> INIT_CMD	EQU	01100000B	;   INITIALIZE	(60H)
  8681                              <1> SEEK_CMD	EQU	01110000B	;	SEEK	(70H)
  8682                              <1> DIAG_CMD	EQU	10010000B	; DIAGNOSTIC	(90H)
  8683                              <1> SET_PARM_CMD	EQU	10010001B	; DRIVE PARMS	(91H)
  8684                              <1> NO_RETRIES	EQU	00000001B	; CHD MODIFIER	(01H)
  8685                              <1> ECC_MODE	EQU	00000010B	; CMD MODIFIER	(02H)
  8686                              <1> BUFFER_MODE	EQU	00001000B	; CMD MODIFIER	(08H)
  8687                              <1> 
  8688                              <1> ;MAX_FILE	EQU	2
  8689                              <1> ;S_MAX_FILE	EQU	2
  8690                              <1> MAX_FILE	equ	4		; 22/12/2014
  8691                              <1> S_MAX_FILE	equ	4		; 22/12/2014
  8692                              <1> 
  8693                              <1> DELAY_1 	EQU	25H		; DELAY FOR OPERATION COMPLETE
  8694                              <1> DELAY_2 	EQU	0600H		; DELAY FOR READY
  8695                              <1> DELAY_3 	EQU	0100H		; DELAY FOR DATA REQUEST
  8696                              <1> 
  8697                              <1> HF_FAIL 	EQU	08H		; CMOS FLAG IN BYTE 0EH
  8698                              <1> 
  8699                              <1> ;-----		COMMAND BLOCK REFERENCE
  8700                              <1> 
  8701                              <1> ;CMD_BLOCK      EQU     BP-8            ; @CMD_BLOCK REFERENCES BLOCK HEAD IN SS
  8702                              <1> 					;  (BP) POINTS TO COMMAND BLOCK TAIL
  8703                              <1> 					;	AS DEFINED BY THE "ENTER" PARMS
  8704                              <1> ; 19/12/2014
  8705                              <1> ORG_VECTOR	equ	4*13h		; INT 13h vector
  8706                              <1> DISK_VECTOR	equ	4*40h		; INT 40h vector (for floppy disks)
  8707                              <1> ;HDISK_INT	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  8708                              <1> ;HDISK_INT1	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  8709                              <1> ;HDISK_INT2	equ	4*77h		; Secondary HDC - Hardware interrupt (IRQ15)
  8710                              <1> ;HF_TBL_VEC	equ	4*41h		; Pointer to 1st fixed disk parameter table
  8711                              <1> ;HF1_TBL_VEC	equ	4*46h		; Pointer to 2nd fixed disk parameter table
  8712                              <1> 
  8713                              <1> align 2
  8714                              <1> 
  8715                              <1> ;----------------------------------------------------------------
  8716                              <1> ; FIXED DISK I/O SETUP						:
  8717                              <1> ;								:
  8718                              <1> ;  -  ESTABLISH TRANSFER VECTORS FOR THE FIXED DISK		:
  8719                              <1> ;  -  PERFORM POWER ON DIAGNOSTICS				:
  8720                              <1> ;     SHOULD AN ERROR OCCUR A "1701" MESSAGE IS DISPLAYED       :
  8721                              <1> ;								:
  8722                              <1> ;----------------------------------------------------------------
  8723                              <1> 
  8724                              <1> DISK_SETUP:
  8725                              <1> 	;CLI
  8726                              <1> 	;;MOV	AX,ABS0 			; GET ABSOLUTE SEGMENT
  8727                              <1> 	;xor	ax,ax
  8728                              <1> 	;MOV	DS,AX				; SET SEGMENT REGISTER
  8729                              <1> 	;MOV	AX, [ORG_VECTOR] 		; GET DISKETTE VECTOR
  8730                              <1> 	;MOV	[DISK_VECTOR],AX		;  INTO INT 40H
  8731                              <1> 	;MOV	AX, [ORG_VECTOR+2]
  8732                              <1> 	;MOV	[DISK_VECTOR+2],AX
  8733                              <1> 	;MOV	word [ORG_VECTOR],DISK_IO	; FIXED DISK HANDLER
  8734                              <1> 	;MOV	[ORG_VECTOR+2],CS
  8735                              <1> 	; 1st controller (primary master, slave)   - IRQ 14
  8736                              <1> 	;;MOV	word [HDISK_INT],HD_INT		; FIXED DISK INTERRUPT
  8737                              <1> 	;mov	word [HDISK_INT1],HD_INT	;
  8738                              <1> 	;;MOV	[HDISK_INT+2],CS
  8739                              <1> 	;mov	[HDISK_INT1+2],CS
  8740                              <1> 	; 2nd controller (secondary master, slave) - IRQ 15
  8741                              <1> 	;mov	word [HDISK_INT2],HD1_INT	;
  8742                              <1> 	;mov	[HDISK_INT2+2],CS
  8743                              <1> 	;
  8744                              <1> 	;;MOV	word [HF_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80
  8745                              <1> 	;;MOV	word [HF_TBL_VEC+2],DPT_SEGM
  8746                              <1> 	;;MOV	word [HF1_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81
  8747                              <1> 	;;MOV	word [HF1_TBL_VEC+2],DPT_SEGM
  8748                              <1> 	;push	cs
  8749                              <1> 	;pop	ds
  8750                              <1> 	;mov	word [HDPM_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80h
  8751                              <1> 	;mov	word [HDPM_TBL_VEC+2],DPT_SEGM
  8752 000028D4 C705[8CBE0000]0000- <1> 	mov 	dword [HDPM_TBL_VEC], (DPT_SEGM*16)+HD0_DPT
  8753 000028DC 0900                <1>
  8754                              <1> 	;mov	word [HDPS_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81h
  8755                              <1> 	;mov	word [HDPS_TBL_VEC+2],DPT_SEGM
  8756 000028DE C705[90BE0000]2000- <1> 	mov 	dword [HDPS_TBL_VEC], (DPT_SEGM*16)+HD1_DPT
  8757 000028E6 0900                <1>
  8758                              <1> 	;mov	word [HDSM_TBL_VEC],HD2_DPT	; PARM TABLE DRIVE 82h
  8759                              <1> 	;mov	word [HDSM_TBL_VEC+2],DPT_SEGM
  8760 000028E8 C705[94BE0000]4000- <1> 	mov 	dword [HDSM_TBL_VEC], (DPT_SEGM*16)+HD2_DPT
  8761 000028F0 0900                <1>
  8762                              <1> 	;mov	word [HDSS_TBL_VEC],HD3_DPT	; PARM TABLE DRIVE 83h
  8763                              <1> 	;mov	word [HDSS_TBL_VEC+2],DPT_SEGM
  8764 000028F2 C705[98BE0000]6000- <1> 	mov 	dword [HDSS_TBL_VEC], (DPT_SEGM*16)+HD3_DPT
  8765 000028FA 0900                <1>
  8766                              <1> 	;
  8767                              <1> 	;;IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  8768                              <1> 	;;;AND	AL,0BFH
  8769                              <1> 	;;and	al, 3Fh			; enable IRQ 14 and IRQ 15
  8770                              <1> 	;;;JMP	$+2
  8771                              <1> 	;;IODELAY
  8772                              <1> 	;;OUT	INTB01,AL
  8773                              <1> 	;;IODELAY
  8774                              <1> 	;;IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  8775                              <1> 	;;AND	AL,0FBH 		;  SECOND CHIP
  8776                              <1> 	;;;JMP	$+2
  8777                              <1> 	;;IODELAY
  8778                              <1> 	;;OUT	INTA01,AL
  8779                              <1> 	;
  8780                              <1> 	;STI
  8781                              <1> 	;;PUSH	DS			; MOVE ABS0 POINTER TO
  8782                              <1> 	;;POP	ES			; EXTRA SEGMENT POINTER
  8783                              <1> 	;;;CALL	DDS			; ESTABLISH DATA SEGMENT
  8784                              <1> 	;;MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  8785                              <1> 	;;MOV	byte [HF_NUM],0		; ZERO NUMBER OF FIXED DISKS
  8786                              <1> 	;;MOV	byte [CONTROL_BYTE],0
  8787                              <1> 	;;MOV	byte [PORT_OFF],0	; ZERO CARD OFFSET
  8788                              <1> 	; 20/12/2014 - private code by Erdogan Tan
  8789                              <1> 		      ; (out of original PC-AT, PC-XT BIOS code)
  8790                              <1> 	;mov	si, hd0_type
  8791 000028FC BE[C0B80000]        <1> 	mov	esi, hd0_type
  8792                              <1> 	;mov	cx, 4
  8793 00002901 B904000000          <1> 	mov	ecx, 4
  8794                              <1> hde_l:
  8795 00002906 AC                  <1> 	lodsb
  8796 00002907 3C80                <1> 	cmp	al, 80h			; 8?h = existing
  8797 00002909 7206                <1> 	jb	short _L4
  8798 0000290B FE05[88BE0000]      <1> 	inc	byte [HF_NUM]		; + 1 hard (fixed) disk drives
  8799                              <1> _L4: ; 26/02/2015
  8800 00002911 E2F3                <1> 	loop	hde_l	
  8801                              <1> ;_L4:					; 0 <= [HF_NUM] =< 4
  8802                              <1> ;L4:
  8803                              <1> 	; 
  8804                              <1> 	;; 31/12/2014 - cancel controller diagnostics here
  8805                              <1> 	;;;mov 	cx, 3  ; 26/12/2014 (Award BIOS 1999)
  8806                              <1> 	;;mov 	cl, 3
  8807                              <1> 	;;
  8808                              <1> 	;;MOV	DL,80H			; CHECK THE CONTROLLER
  8809                              <1> ;;hdc_dl:
  8810                              <1> 	;;MOV	AH,14H			; USE CONTROLLER DIAGNOSTIC COMMAND
  8811                              <1> 	;;INT	13H			; CALL BIOS WITH DIAGNOSTIC COMMAND
  8812                              <1> 	;;;JC	short CTL_ERRX		; DISPLAY ERROR MESSAGE IF BAD RETURN
  8813                              <1> 	;;;jc	short POD_DONE ;22/12/2014
  8814                              <1> 	;;jnc	short hdc_reset0
  8815                              <1> 	;;loop	hdc_dl
  8816                              <1> 	;;; 27/12/2014
  8817                              <1> 	;;stc
  8818                              <1> 	;;retn
  8819                              <1> 	;
  8820                              <1> ;;hdc_reset0:
  8821                              <1> 	; 18/01/2015
  8822 00002913 8A0D[88BE0000]      <1> 	mov	cl, [HF_NUM]
  8823 00002919 20C9                <1> 	and	cl, cl
  8824 0000291B 740D                <1> 	jz	short POD_DONE
  8825                              <1> 	;
  8826 0000291D B27F                <1> 	mov	dl, 7Fh
  8827                              <1> hdc_reset1:
  8828 0000291F FEC2                <1> 	inc	dl
  8829                              <1> 	;; 31/12/2015
  8830                              <1> 	;;push	dx
  8831                              <1> 	;;push	cx
  8832                              <1> 	;;push	ds
  8833                              <1> 	;;sub	ax, ax
  8834                              <1> 	;;mov	ds, ax
  8835                              <1> 	;;MOV	AX, [TIMER_LOW]		; GET START TIMER COUNTS
  8836                              <1> 	;;pop	ds
  8837                              <1> 	;;MOV	BX,AX
  8838                              <1> 	;;ADD	AX,6*182		; 60 SECONDS* 18.2
  8839                              <1> 	;;MOV	CX,AX
  8840                              <1> 	;;mov	word [wait_count], 0	; 22/12/2014 (reset wait counter)
  8841                              <1> 	;;
  8842                              <1> 	;; 31/12/2014 - cancel HD_RESET_1
  8843                              <1> 	;;CALL	HD_RESET_1		; SET UP DRIVE 0, (1,2,3)
  8844                              <1> 	;;pop	cx
  8845                              <1> 	;;pop	dx
  8846                              <1> 	;;
  8847                              <1> 	; 18/01/2015
  8848 00002921 B40D                <1> 	mov	ah, 0Dh ; ALTERNATE RESET
  8849                              <1> 	;int	13h
  8850 00002923 E8A4FFFFFF          <1> 	call	int13h
  8851 00002928 E2F5                <1> 	loop	hdc_reset1
  8852                              <1> POD_DONE:
  8853 0000292A C3                  <1> 	RETn
  8854                              <1> 
  8855                              <1> ;;-----	POD_ERROR
  8856                              <1> 
  8857                              <1> ;;CTL_ERRX:
  8858                              <1> ;	;MOV	SI,OFFSET F1782 	; CONTROLLER ERROR
  8859                              <1> ;	;CALL	SET_FAIL		; DO NOT IPL FROM DISK
  8860                              <1> ;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  8861                              <1> ;	;JMP	short POD_DONE
  8862                              <1> 
  8863                              <1> ;;HD_RESET_1:
  8864                              <1> ;;	;PUSH	BX			; SAVE TIMER LIMITS
  8865                              <1> ;;	;PUSH	CX
  8866                              <1> ;;RES_1: MOV	AH,09H			; SET DRIVE PARAMETERS
  8867                              <1> ;;	INT	13H
  8868                              <1> ;;	JC	short RES_2
  8869                              <1> ;;	MOV	AH,11H			; RECALIBRATE DRIVE
  8870                              <1> ;;	INT	13H
  8871                              <1> ;;	JNC	short RES_CK		; DRIVE OK
  8872                              <1> ;;RES_2: ;CALL	POD_TCHK		; CHECK TIME OUT
  8873                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  8874                              <1> ;;					; (30 seconds)		
  8875                              <1> ;;	;cmc
  8876                              <1> ;;	;JNC	short RES_1
  8877                              <1> ;;	jb	short RES_1
  8878                              <1> ;;;RES_FL: ;MOV	SI,OFFSET F1781 	; INDICATE DISK 1 FAILURE;
  8879                              <1> ;;	;TEST	DL,1
  8880                              <1> ;;	;JNZ	RES_E1
  8881                              <1> ;;	;MOV	SI,OFFSET F1780 	; INDICATE DISK 0 FAILURE
  8882                              <1> ;;	;CALL	SET_FAIL		; DO NOT TRY TO IPL DISK 0
  8883                              <1> ;;	;JMP	SHORT RES_E1
  8884                              <1> ;;RES_ER: ; 22/12/2014
  8885                              <1> ;;RES_OK:
  8886                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  8887                              <1> ;;	;POP	BX
  8888                              <1> ;;	RETn
  8889                              <1> ;;
  8890                              <1> ;;RES_RS: MOV	AH,00H			; RESET THE DRIVE
  8891                              <1> ;;	INT	13H
  8892                              <1> ;;RES_CK: MOV	AH,08H			; GET MAX CYLINDER,HEAD,SECTOR
  8893                              <1> ;;	MOV	BL,DL			; SAVE DRIVE CODE
  8894                              <1> ;;	INT	13H
  8895                              <1> ;;	JC	short RES_ER
  8896                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE MAX CYLINDER, SECTOR
  8897                              <1> ;;	MOV	DL,BL			; RESTORE DRIVE CODE
  8898                              <1> ;;RES_3: MOV	AX,0401H		; VERIFY THE LAST SECTOR
  8899                              <1> ;;	INT	13H
  8900                              <1> ;;	JNC	short RES_OK		; VERIFY OK
  8901                              <1> ;;	CMP	AH,BAD_SECTOR		; OK ALSO IF JUST ID READ
  8902                              <1> ;;	JE	short RES_OK
  8903                              <1> ;;	CMP	AH,DATA_CORRECTED
  8904                              <1> ;;	JE	short RES_OK
  8905                              <1> ;;	CMP	AH,BAD_ECC
  8906                              <1> ;;	JE	short RES_OK
  8907                              <1> ;;	;CALL	POD_TCHK		; CHECK FOR TIME OUT
  8908                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  8909                              <1> ;;					; (60 seconds)		
  8910                              <1> ;;	cmc
  8911                              <1> ;;	JC	short RES_ER		; FAILED
  8912                              <1> ;;	MOV	CX,[NEC_STATUS] 	; GET SECTOR ADDRESS, AND CYLINDER
  8913                              <1> ;;	MOV	AL,CL			; SEPARATE OUT SECTOR NUMBER
  8914                              <1> ;;	AND	AL,3FH
  8915                              <1> ;;	DEC	AL			; TRY PREVIOUS ONE
  8916                              <1> ;;	JZ	short RES_RS		; WE'VE TRIED ALL SECTORS ON TRACK
  8917                              <1> ;;	AND	CL,0C0H 		; KEEP CYLINDER BITS
  8918                              <1> ;;	OR	CL,AL			; MERGE SECTOR WITH CYLINDER BITS
  8919                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE CYLINDER, NEW SECTOR NUMBER
  8920                              <1> ;;	JMP	short RES_3		; TRY AGAIN
  8921                              <1> ;;;RES_ER: MOV	SI,OFFSET F1791 	; INDICATE DISK 1 ERROR
  8922                              <1> ;;	;TEST	DL,1
  8923                              <1> ;;	;JNZ	short RES_E1
  8924                              <1> ;;	;MOV	SI,OFFSET F1790 	; INDICATE DISK 0 ERROR
  8925                              <1> ;;;RES_E1:
  8926                              <1> ;;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  8927                              <1> ;;;RES_OK:
  8928                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  8929                              <1> ;;	;POP	BX
  8930                              <1> ;;	;RETn
  8931                              <1> ;
  8932                              <1> ;;SET_FAIL:
  8933                              <1> ;	;MOV	AX,X*(CMOS_DIAG+NMI)	; GET CMOS ERROR BYTE
  8934                              <1> ;	;CALL	CMOS_READ
  8935                              <1> ;	;OR	AL,HF_FAIL		; SET DO NOT IPL FROM DISK FLAG
  8936                              <1> ;	;XCHG	AH,AL			; SAVE IT
  8937                              <1> ;	;CALL	CMOS_WRITE		; PUT IT OUT
  8938                              <1> ;	;RETn
  8939                              <1> ;
  8940                              <1> ;;POD_TCHK:				; CHECK FOR 30 SECOND TIME OUT
  8941                              <1> ;	;POP	AX			; SAVE RETURN
  8942                              <1> ;	;POP	CX			; GET TIME OUT LIMITS
  8943                              <1> ;	;POP	BX
  8944                              <1> ;	;PUSH	BX			; AND SAVE THEM AGAIN
  8945                              <1> ;	;PUSH	CX
  8946                              <1> ;	;PUSH	AX
  8947                              <1> ;	;push	ds
  8948                              <1> ;	;xor	ax, ax
  8949                              <1> ;	;mov	ds, ax			; RESTORE RETURN
  8950                              <1> ;	;MOV	AX, [TIMER_LOW]		; AX = CURRENT TIME
  8951                              <1> ;	;				; BX = START TIME
  8952                              <1> ;	;				; CX = END TIME
  8953                              <1> ;	;pop	ds
  8954                              <1> ;	;CMP	BX,CX
  8955                              <1> ;	;JB	short TCHK1		; START < END
  8956                              <1> ;	;CMP	BX,AX
  8957                              <1> ;	;JB	short TCHKG		; END < START < CURRENT
  8958                              <1> ;	;JMP	SHORT TCHK2		; END, CURRENT < START
  8959                              <1> ;;TCHK1: CMP	AX,BX
  8960                              <1> ;;	JB	short TCHKNG		; CURRENT < START < END
  8961                              <1> ;;TCHK2: CMP	AX,CX
  8962                              <1> ;;	JB	short TCHKG		; START < CURRENT < END
  8963                              <1> ;;					; OR CURRENT < END < START
  8964                              <1> ;;TCHKNG: STC				; CARRY SET INDICATES TIME OUT
  8965                              <1> ;;	RETn
  8966                              <1> ;;TCHKG: CLC				; INDICATE STILL TIME
  8967                              <1> ;;	RETn
  8968                              <1> ;;
  8969                              <1> ;;int_13h:
  8970                              <1> 
  8971                              <1> ;----------------------------------------
  8972                              <1> ;	FIXED DISK BIOS ENTRY POINT	:
  8973                              <1> ;----------------------------------------
  8974                              <1> 
  8975                              <1> DISK_IO:
  8976 0000292B 80FA80              <1> 	CMP	DL,80H			; TEST FOR FIXED DISK DRIVE
  8977                              <1> 	;JAE	short A1		; YES, HANDLE HERE
  8978                              <1> 	;;;INT	40H			; DISKETTE HANDLER
  8979                              <1> 	;;call	int40h
  8980 0000292E 0F8225F1FFFF        <1> 	jb	DISKETTE_IO_1
  8981                              <1> ;RET_2:
  8982                              <1> 	;RETf	2			; BACK TO CALLER
  8983                              <1> ;	retf	4
  8984                              <1> A1:
  8985 00002934 FB                  <1> 	STI				; ENABLE INTERRUPTS
  8986                              <1> 	;; 04/01/2015
  8987                              <1> 	;;OR	AH,AH
  8988                              <1> 	;;JNZ	short A2
  8989                              <1> 	;;INT	40H			; RESET NEC WHEN AH=0
  8990                              <1> 	;;SUB	AH,AH
  8991 00002935 80FA83              <1> 	CMP	DL,(80H + S_MAX_FILE - 1)
  8992 00002938 772C                <1> 	JA	short RET_2
  8993                              <1> 	; 18/01/2015
  8994 0000293A 08E4                <1> 	or	ah,ah
  8995 0000293C 742B                <1> 	jz	short A4
  8996 0000293E 80FC0D              <1> 	cmp	ah, 0Dh	; Alternate reset
  8997 00002941 7504                <1> 	jne	short A2
  8998 00002943 28E4                <1> 	sub	ah,ah	; Reset
  8999 00002945 EB22                <1> 	jmp	short A4
  9000                              <1> A2:
  9001 00002947 80FC08              <1> 	CMP	AH,08H			; GET PARAMETERS IS A SPECIAL CASE
  9002                              <1> 	;JNZ	short A3
  9003                              <1>         ;JMP    GET_PARM_N
  9004 0000294A 0F841C030000        <1> 	je	GET_PARM_N
  9005 00002950 80FC15              <1> A3:	CMP	AH,15H			; READ DASD TYPE IS ALSO
  9006                              <1> 	;JNZ	short A4
  9007                              <1>         ;JMP    READ_DASD_TYPE
  9008 00002953 0F84C7020000        <1>         je      READ_DASD_TYPE
  9009                              <1> 	; 02/02/2015
  9010 00002959 80FC1D              <1> 	cmp	ah, 1Dh			;(Temporary for Retro UNIX 386 v1)
  9011                              <1> 	; 12/01/2015
  9012 0000295C F5                  <1> 	cmc
  9013 0000295D 730A                <1> 	jnc	short A4
  9014                              <1> 	; 30/01/2015
  9015                              <1> 	;mov     byte [CS:DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  9016 0000295F C605[87BE0000]01    <1>         mov     byte [DISK_STATUS1], BAD_CMD
  9017                              <1> 	;jmp	short RET_2
  9018                              <1> RET_2:
  9019 00002966 CA0400              <1> 	retf	4
  9020                              <1> A4:					; SAVE REGISTERS DURING OPERATION
  9021 00002969 C8080000            <1> 	ENTER	8,0			; SAVE (BP) AND MAKE ROOM FOR @CMD_BLOCK
  9022 0000296D 53                  <1> 	PUSH	eBX			;  IN THE STACK, THE COMMAND BLOCK IS:
  9023 0000296E 51                  <1> 	PUSH	eCX			;   @CMD_BLOCK == BYTE PTR [BP]-8
  9024 0000296F 52                  <1> 	PUSH	eDX
  9025 00002970 1E                  <1> 	PUSH	DS
  9026 00002971 06                  <1> 	PUSH	ES
  9027 00002972 56                  <1> 	PUSH	eSI
  9028 00002973 57                  <1> 	PUSH	eDI
  9029                              <1> 	;;04/01/2015
  9030                              <1> 	;;OR	AH,AH			; CHECK FOR RESET
  9031                              <1> 	;;JNZ	short A5
  9032                              <1> 	;;MOV	DL,80H			; FORCE DRIVE 80 FOR RESET
  9033                              <1> ;;A5:	
  9034                              <1> 	;push	cs
  9035                              <1> 	;pop	ds
  9036                              <1> 	; 21/02/2015
  9037 00002974 6650                <1> 	push	ax
  9038 00002976 66B81000            <1> 	mov	ax, KDATA
  9039 0000297A 8ED8                <1> 	mov	ds, ax
  9040 0000297C 8EC0                <1> 	mov	es, ax	
  9041 0000297E 6658                <1> 	pop	ax
  9042 00002980 E889000000          <1> 	CALL	DISK_IO_CONT		; PERFORM THE OPERATION
  9043                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  9044 00002985 8A25[87BE0000]      <1> 	MOV	AH,[DISK_STATUS1]	; GET STATUS FROM OPERATION
  9045 0000298B 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  9046 0000298E F5                  <1> 	CMC				; SUCCESS OR FAILURE
  9047 0000298F 5F                  <1> 	POP	eDI			; RESTORE REGISTERS
  9048 00002990 5E                  <1> 	POP	eSI
  9049 00002991 07                  <1>         POP     ES
  9050 00002992 1F                  <1>         POP     DS
  9051 00002993 5A                  <1> 	POP	eDX
  9052 00002994 59                  <1> 	POP	eCX
  9053 00002995 5B                  <1> 	POP	eBX
  9054 00002996 C9                  <1> 	LEAVE				; ADJUST (SP) AND RESTORE (BP)
  9055                              <1> 	;RETf	2			; THROW AWAY SAVED FLAGS
  9056 00002997 CA0400              <1> 	retf	4
  9057                              <1> 
  9058                              <1> ; 21/02/2015
  9059                              <1> ;       dw --> dd
  9060                              <1> D1:					; FUNCTION TRANSFER TABLE
  9061 0000299A [5C2B0000]          <1> 	dd	DISK_RESET		; 000H
  9062 0000299E [D32B0000]          <1> 	dd	RETURN_STATUS		; 001H
  9063 000029A2 [E02B0000]          <1> 	dd	DISK_READ		; 002H
  9064 000029A6 [E92B0000]          <1> 	dd	DISK_WRITE		; 003H
  9065 000029AA [F22B0000]          <1> 	dd	DISK_VERF		; 004H
  9066 000029AE [0A2C0000]          <1> 	dd	FMT_TRK 		; 005H
  9067 000029B2 [522B0000]          <1> 	dd	BAD_COMMAND		; 006H	FORMAT BAD SECTORS
  9068 000029B6 [522B0000]          <1> 	dd	BAD_COMMAND		; 007H	FORMAT DRIVE
  9069 000029BA [522B0000]          <1> 	dd	BAD_COMMAND		; 008H	RETURN PARAMETERS
  9070 000029BE [D12C0000]          <1> 	dd	INIT_DRV		; 009H
  9071 000029C2 [302D0000]          <1> 	dd	RD_LONG 		; 00AH
  9072 000029C6 [392D0000]          <1> 	dd	WR_LONG 		; 00BH
  9073 000029CA [422D0000]          <1> 	dd	DISK_SEEK		; 00CH
  9074 000029CE [5C2B0000]          <1> 	dd	DISK_RESET		; 00DH
  9075 000029D2 [522B0000]          <1> 	dd	BAD_COMMAND		; 00EH	READ BUFFER
  9076 000029D6 [522B0000]          <1> 	dd	BAD_COMMAND		; 00FH	WRITE BUFFER
  9077 000029DA [6A2D0000]          <1> 	dd	TST_RDY 		; 010H
  9078 000029DE [8E2D0000]          <1> 	dd	HDISK_RECAL		; 011H
  9079 000029E2 [522B0000]          <1> 	dd	BAD_COMMAND		; 012H	MEMORY DIAGNOSTIC
  9080 000029E6 [522B0000]          <1> 	dd	BAD_COMMAND		; 013H	DRIVE DIAGNOSTIC
  9081 000029EA [C42D0000]          <1> 	dd	CTLR_DIAGNOSTIC 	; 014H	CONTROLLER DIAGNOSTIC
  9082                              <1> 	; 02/02/2015 (Temporary - Retro UNIX 386 v1 - DISK I/O test)
  9083 000029EE [522B0000]          <1> 	dd	BAD_COMMAND		; 015h
  9084 000029F2 [522B0000]          <1> 	dd	BAD_COMMAND		; 016h
  9085 000029F6 [522B0000]          <1> 	dd	BAD_COMMAND		; 017h
  9086 000029FA [522B0000]          <1> 	dd	BAD_COMMAND		; 018h
  9087 000029FE [522B0000]          <1> 	dd	BAD_COMMAND		; 019h
  9088 00002A02 [522B0000]          <1> 	dd	BAD_COMMAND		; 01Ah
  9089 00002A06 [E02B0000]          <1> 	dd	DISK_READ		; 01Bh ; LBA read
  9090 00002A0A [E92B0000]          <1> 	dd	DISK_WRITE		; 01Ch ; LBA write
  9091                              <1> D1L     EQU    $ - D1
  9092                              <1> 
  9093                              <1> DISK_IO_CONT:
  9094                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  9095 00002A0E 80FC01              <1> 	CMP	AH,01H			; RETURN STATUS
  9096                              <1> 	;;JNZ	short SU0
  9097                              <1>         ;;JMP    RETURN_STATUS
  9098 00002A11 0F84BC010000        <1> 	je	RETURN_STATUS
  9099                              <1> SU0:
  9100 00002A17 C605[87BE0000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  9101                              <1> 	;;PUSH	BX			; SAVE DATA ADDRESS
  9102                              <1> 	;mov	si, bx ;; 14/02/2015
  9103 00002A1E 89DE                <1> 	mov	esi, ebx ; 21/02/2015
  9104 00002A20 8A1D[88BE0000]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  9105                              <1> 	;; 04/01/2015
  9106                              <1> 	;;PUSH	AX
  9107 00002A26 80E27F              <1> 	AND	DL,7FH			; GET DRIVE AS 0 OR 1
  9108                              <1> 					; (get drive number as 0 to 3)
  9109 00002A29 38D3                <1> 	CMP	BL,DL
  9110                              <1>         ;;JBE   BAD_COMMAND_POP         ; INVALID DRIVE
  9111 00002A2B 0F8621010000        <1>         jbe     BAD_COMMAND ;; 14/02/2015
  9112                              <1>         ;
  9113                              <1> 	;;03/01/2015
  9114 00002A31 29DB                <1> 	sub	ebx, ebx
  9115 00002A33 88D3                <1> 	mov	bl, dl
  9116                              <1> 	;sub	bh, bh
  9117 00002A35 883D[9CBE0000]      <1> 	mov	[LBAMode], bh 	; 0
  9118                              <1> 	;;test	byte [bx+hd0_type], 1	; LBA ready ?
  9119                              <1> 	;test	byte [ebx+hd0_type], 1
  9120                              <1> 	;jz	short su1		; no
  9121                              <1> 	;inc	byte [LBAMode]
  9122                              <1> ;su1:
  9123                              <1> 	; 21/02/2015 (32 bit modification)
  9124                              <1> 	;04/01/2015
  9125 00002A3B 6650                <1> 	push	ax ; ***
  9126                              <1> 	;PUSH	ES ; **
  9127 00002A3D 6652                <1> 	PUSH	DX ; *
  9128 00002A3F 6650                <1> 	push	ax
  9129 00002A41 E864060000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS
  9130                              <1> 	; 02/02/2015
  9131                              <1> 	;mov	ax, [ES:BX+16] ; I/O port base address (1F0h, 170h)
  9132 00002A46 668B4310            <1> 	mov	ax, [ebx+16]
  9133 00002A4A 66A3[B4B80000]      <1> 	mov	[HF_PORT], ax
  9134                              <1> 	;mov	dx, [ES:BX+18] ; control port address (3F6h, 376h)
  9135 00002A50 668B5312            <1> 	mov	dx, [ebx+18]
  9136 00002A54 668915[B6B80000]    <1> 	mov	[HF_REG_PORT], dx
  9137                              <1> 	;mov	al, [ES:BX+20] ; head register upper nibble (A0h,B0h,E0h,F0h)
  9138 00002A5B 8A4314              <1> 	mov	al, [ebx+20]
  9139                              <1> 	; 23/02/2015
  9140 00002A5E A840                <1> 	test	al, 40h	 ; LBA bit (bit 6)
  9141 00002A60 7406                <1> 	jz 	short su1
  9142 00002A62 FE05[9CBE0000]      <1> 	inc	byte [LBAMode] ; 1 
  9143                              <1> su1: 	 
  9144 00002A68 C0E804              <1> 	shr 	al, 4
  9145 00002A6B 2401                <1> 	and	al, 1			
  9146 00002A6D A2[B8B80000]        <1> 	mov	[hf_m_s], al 
  9147                              <1> 	;
  9148                              <1> 	; 03/01/2015
  9149                              <1> 	;MOV	AL,byte [ES:BX+8]	; GET CONTROL BYTE MODIFIER
  9150 00002A72 8A4308              <1> 	mov	al, [ebx+8]
  9151                              <1> 	;MOV	DX,[HF_REG_PORT]	; Device Control register	
  9152 00002A75 EE                  <1> 	OUT	DX,AL			; SET EXTRA HEAD OPTION
  9153                              <1> 					; Control Byte:  (= 08h, here)
  9154                              <1> 					; bit 0 - 0
  9155                              <1> 					; bit 1 - nIEN (1 = disable irq)
  9156                              <1> 					; bit 2 - SRST (software RESET)
  9157                              <1> 					; bit 3 - use extra heads (8 to 15)
  9158                              <1> 					;         -always set to 1-	
  9159                              <1> 					; (bits 3 to 7 are reserved
  9160                              <1> 					;          for ATA devices)
  9161 00002A76 8A25[89BE0000]      <1> 	MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  9162 00002A7C 80E4C0              <1> 	AND	AH,0C0H 		; CONTROL BYTE
  9163 00002A7F 08C4                <1> 	OR	AH,AL
  9164 00002A81 8825[89BE0000]      <1> 	MOV	[CONTROL_BYTE],AH	
  9165                              <1> 	; 04/01/2015
  9166 00002A87 6658                <1> 	pop	ax
  9167 00002A89 665A                <1> 	pop	dx ; * ;; 14/02/2015
  9168 00002A8B 20E4                <1> 	and	ah, ah	; Reset function ?
  9169 00002A8D 7507                <1> 	jnz	short su2
  9170                              <1> 	;;pop	dx ; * ;; 14/02/2015
  9171                              <1> 	;pop	es ; **
  9172 00002A8F 6658                <1> 	pop	ax ; ***
  9173                              <1> 	;;pop	bx
  9174 00002A91 E9C6000000          <1>         jmp     DISK_RESET
  9175                              <1> su2:
  9176 00002A96 803D[9CBE0000]00    <1> 	cmp	byte [LBAMode], 0
  9177 00002A9D 7661                <1> 	jna	short su3
  9178                              <1> 	;
  9179                              <1> 	; 02/02/2015 (LBA read/write function calls)
  9180 00002A9F 80FC1B              <1> 	cmp	ah, 1Bh
  9181 00002AA2 720B                <1> 	jb	short lbarw1
  9182 00002AA4 80FC1C              <1> 	cmp	ah, 1Ch
  9183 00002AA7 775C                <1> 	ja 	short invldfnc
  9184                              <1> 	;;pop	dx ; * ; 14/02/2015
  9185                              <1> 	;mov	ax, cx ; Lower word of LBA address (bits 0-15)
  9186 00002AA9 89C8                <1> 	mov	eax, ecx ; LBA address (21/02/2015)
  9187                              <1> 	;; 14/02/2015
  9188 00002AAB 88D1                <1> 	mov	cl, dl ; 14/02/2015
  9189                              <1> 	;;mov	dx, bx
  9190                              <1> 	;mov	dx, si ; higher word of LBA address (bits 16-23)
  9191                              <1> 	;;mov	bx, di
  9192                              <1> 	;mov	si, di ; Buffer offset
  9193 00002AAD EB31                <1> 	jmp	short lbarw2
  9194                              <1> lbarw1:
  9195                              <1> 	; convert CHS to LBA
  9196                              <1> 	;
  9197                              <1> 	; LBA calculation - AWARD BIOS - 1999 - AHDSK.ASM
  9198                              <1> 	; LBA = "# of Heads" * Sectors/Track * Cylinder + Head * Sectors/Track
  9199                              <1> 	;	+ Sector - 1
  9200 00002AAF 6652                <1> 	push	dx ; * ;; 14/02/2015
  9201                              <1> 	;xor	dh, dh
  9202 00002AB1 31D2                <1> 	xor	edx, edx
  9203                              <1> 	;mov	dl, [ES:BX+14]	; sectors per track (logical)
  9204 00002AB3 8A530E              <1> 	mov	dl, [ebx+14]
  9205                              <1> 	;xor	ah, ah
  9206 00002AB6 31C0                <1> 	xor	eax, eax
  9207                              <1> 	;mov	al, [ES:BX+2]	; heads (logical) 	
  9208 00002AB8 8A4302              <1> 	mov	al, [ebx+2]
  9209 00002ABB FEC8                <1> 	dec	al
  9210 00002ABD 6640                <1> 	inc	ax		; 0 =  256
  9211 00002ABF 66F7E2              <1> 	mul 	dx
  9212                              <1> 		; AX = # of Heads" * Sectors/Track
  9213 00002AC2 6689CA              <1> 	mov	dx, cx
  9214                              <1> 	;and	cx, 3Fh	 ; sector  (1 to 63)
  9215 00002AC5 83E13F              <1> 	and	ecx, 3fh
  9216 00002AC8 86D6                <1> 	xchg	dl, dh
  9217 00002ACA C0EE06              <1> 	shr	dh, 6
  9218                              <1> 		; DX = cylinder (0 to 1023)
  9219                              <1> 	;mul 	dx
  9220                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder
  9221 00002ACD F7E2                <1> 	mul	edx
  9222 00002ACF FEC9                <1> 	dec	cl  ; sector - 1
  9223                              <1> 	;add	ax, cx
  9224                              <1> 	;adc	dx, 0
  9225                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder + Sector -1
  9226 00002AD1 01C8                <1> 	add	eax, ecx
  9227 00002AD3 6659                <1> 	pop	cx ; * ; ch = head, cl = drive number (zero based)
  9228                              <1> 	;push	dx
  9229                              <1> 	;push	ax
  9230 00002AD5 50                  <1> 	push	eax
  9231                              <1> 	;mov	al, [ES:BX+14]	; sectors per track (logical)	
  9232 00002AD6 8A430E              <1> 	mov	al, [ebx+14]
  9233 00002AD9 F6E5                <1> 	mul	ch
  9234                              <1> 		;  AX = Head * Sectors/Track
  9235 00002ADB 6699                <1>         cwd
  9236                              <1> 	;pop	dx
  9237 00002ADD 5A                  <1> 	pop	edx
  9238                              <1> 	;add	ax, dx
  9239                              <1> 	;pop	dx
  9240                              <1> 	;adc	dx, 0 ; add carry bit
  9241 00002ADE 01D0                <1> 	add	eax, edx
  9242                              <1> lbarw2:
  9243 00002AE0 29D2                <1> 	sub	edx, edx ; 21/02/2015
  9244 00002AE2 88CA                <1> 	mov	dl, cl ; 21/02/2015
  9245 00002AE4 C645F800            <1>         mov     byte [CMD_BLOCK], 0 ; Features Register
  9246                              <1> 				; NOTE: Features register (1F1h, 171h)
  9247                              <1> 				; is not used for ATA device R/W functions. 
  9248                              <1> 				; It is old/obsolete 'write precompensation'
  9249                              <1> 				; register and error register
  9250                              <1> 				; for old ATA/IDE devices.
  9251                              <1> 	; 18/01/2014
  9252                              <1> 	;mov	ch, [hf_m_s]	; Drive 0 (master) or 1 (slave)
  9253 00002AE8 8A0D[B8B80000]      <1> 	mov	cl, [hf_m_s]
  9254                              <1> 	;shl	ch, 4		; bit 4 (drive bit)
  9255                              <1> 	;or	ch, 0E0h	; bit 5 = 1
  9256                              <1> 				; bit 6 = 1 = LBA mode
  9257                              <1> 				; bit 7 = 1
  9258 00002AEE 80C90E              <1> 	or	cl, 0Eh ; 1110b
  9259                              <1> 	;and	dh, 0Fh		; LBA byte 4 (bits 24 to 27)
  9260 00002AF1 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh
  9261 00002AF6 C1E11C              <1> 	shl	ecx, 28 ; 21/02/2015
  9262                              <1> 	;or	dh, ch
  9263 00002AF9 09C8                <1> 	or	eax, ecx	
  9264                              <1> 	;;mov	[CMD_BLOCK+2], al ; LBA byte 1 (bits 0 to 7)
  9265                              <1> 				  ; (Sector Number Register)
  9266                              <1> 	;;mov	[CMD_BLOCK+3], ah ; LBA byte 2 (bits 8 to 15)
  9267                              <1> 				  ; (Cylinder Low Register)
  9268                              <1> 	;mov	[CMD_BLOCK+2], ax ; LBA byte 1, 2
  9269                              <1> 	;mov	[CMD_BLOCK+4], dl ; LBA byte 3 (bits 16 to 23)
  9270                              <1> 				  ; (Cylinder High Register)
  9271                              <1> 	;;mov	[CMD_BLOCK+5], dh ; LBA byte 4 (bits 24 to 27)
  9272                              <1> 				  ; (Drive/Head Register)
  9273                              <1> 	
  9274                              <1> 	;mov	[CMD_BLOCK+4], dx ; LBA byte 4, LBA & DEV select bits
  9275 00002AFB 8945FA              <1> 	mov	[CMD_BLOCK+2], eax ; 21/02/2015
  9276                              <1> 	;14/02/2015
  9277                              <1> 	;mov	dl, cl ; Drive number (INIT_DRV)		
  9278 00002AFE EB38                <1> 	jmp	short su4
  9279                              <1> su3:
  9280                              <1> 	; 02/02/2015 
  9281                              <1> 	; (Temporary functions 1Bh & 1Ch are not valid for CHS mode) 
  9282 00002B00 80FC14              <1> 	cmp 	ah, 14h
  9283 00002B03 7604                <1> 	jna 	short chsfnc
  9284                              <1> invldfnc:
  9285                              <1>         ; 14/02/2015  
  9286                              <1> 	;pop	es ; **
  9287 00002B05 6658                <1>         pop     ax ; ***
  9288                              <1>         ;jmp     short BAD_COMMAND_POP
  9289 00002B07 EB49                <1>         jmp     short BAD_COMMAND
  9290                              <1> chsfnc:	
  9291                              <1> 	;MOV	AX,[ES:BX+5]		; GET WRITE PRE-COMPENSATION CYLINDER
  9292 00002B09 668B4305            <1> 	mov	ax, [ebx+5]
  9293 00002B0D 66C1E802            <1> 	SHR	AX,2
  9294 00002B11 8845F8              <1> 	MOV	[CMD_BLOCK],AL
  9295                              <1> 	;;MOV	AL,[ES:BX+8]		; GET CONTROL BYTE MODIFIER
  9296                              <1> 	;;PUSH	DX
  9297                              <1> 	;;MOV	DX,[HF_REG_PORT]
  9298                              <1> 	;;OUT	DX,AL			; SET EXTRA HEAD OPTION
  9299                              <1> 	;;POP	DX ; * 
  9300                              <1> 	;;POP	ES ; **
  9301                              <1> 	;;MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  9302                              <1> 	;;AND	AH,0C0H 		; CONTROL BYTE	
  9303                              <1> 	;;OR	AH,AL
  9304                              <1> 	;;MOV	[CONTROL_BYTE],AH
  9305                              <1> 	;
  9306 00002B14 88C8                <1> 	MOV	AL,CL			; GET SECTOR NUMBER
  9307 00002B16 243F                <1> 	AND	AL,3FH
  9308 00002B18 8845FA              <1> 	MOV	[CMD_BLOCK+2],AL
  9309 00002B1B 886DFB              <1> 	MOV	[CMD_BLOCK+3],CH 	; GET CYLINDER NUMBER
  9310 00002B1E 88C8                <1> 	MOV	AL,CL
  9311 00002B20 C0E806              <1> 	SHR	AL,6
  9312 00002B23 8845FC              <1> 	MOV	[CMD_BLOCK+4],AL 	; CYLINDER HIGH ORDER 2 BITS
  9313                              <1> 	;;05/01/2015
  9314                              <1> 	;;MOV	AL,DL			; DRIVE NUMBER
  9315 00002B26 A0[B8B80000]        <1> 	mov	al, [hf_m_s]
  9316 00002B2B C0E004              <1> 	SHL	AL,4
  9317 00002B2E 80E60F              <1> 	AND	DH,0FH			; HEAD NUMBER
  9318 00002B31 08F0                <1> 	OR	AL,DH
  9319                              <1> 	;OR	AL,80H or 20H
  9320 00002B33 0CA0                <1> 	OR	AL,80h+20h		; ECC AND 512 BYTE SECTORS
  9321 00002B35 8845FD              <1> 	MOV	[CMD_BLOCK+5],AL 	; ECC/SIZE/DRIVE/HEAD
  9322                              <1> su4:
  9323                              <1> 	;POP	ES ; **
  9324                              <1>         ;; 14/02/2015
  9325                              <1>         ;;POP   AX
  9326                              <1>         ;;MOV   [CMD_BLOCK+1],AL        ; SECTOR COUNT
  9327                              <1>         ;;PUSH  AX
  9328                              <1>         ;;MOV   AL,AH                   ; GET INTO LOW BYTE
  9329                              <1>         ;;XOR   AH,AH                   ; ZERO HIGH BYTE
  9330                              <1>         ;;SAL   AX,1                    ; *2 FOR TABLE LOOKUP
  9331 00002B38 6658                <1>         pop     ax ; ***
  9332 00002B3A 8845F9              <1>         mov     [CMD_BLOCK+1], al
  9333 00002B3D 29DB                <1>         sub	ebx, ebx
  9334 00002B3F 88E3                <1> 	mov     bl, ah
  9335                              <1>         ;xor     bh, bh
  9336                              <1>         ;sal     bx, 1
  9337 00002B41 66C1E302            <1>         sal	bx, 2	; 32 bit offset (21/02/2015)
  9338                              <1> 	;;MOV   SI,AX                   ; PUT INTO SI FOR BRANCH
  9339                              <1>         ;;CMP   AX,D1L                  ; TEST WITHIN RANGE
  9340                              <1>         ;;JNB   short BAD_COMMAND_POP
  9341                              <1>         ;cmp     bx, D1L
  9342 00002B45 83FB74              <1> 	cmp	ebx, D1L
  9343 00002B48 7308                <1> 	jnb	short BAD_COMMAND
  9344                              <1>         ;xchg    bx, si
  9345 00002B4A 87DE                <1>         xchg	ebx, esi
  9346                              <1> 	;;;POP	AX			; RESTORE AX
  9347                              <1> 	;;;POP	BX			; AND DATA ADDRESS
  9348                              <1> 	
  9349                              <1> 	;;PUSH	CX
  9350                              <1> 	;;PUSH	AX			; ADJUST ES:BX
  9351                              <1> 	;MOV	CX,BX			; GET 3 HIGH ORDER NIBBLES OF BX
  9352                              <1> 	;SHR	CX,4
  9353                              <1> 	;MOV	AX,ES
  9354                              <1> 	;ADD	AX,CX
  9355                              <1> 	;MOV	ES,AX
  9356                              <1> 	;AND	BX,000FH		; ES:BX CHANGED TO ES:000X
  9357                              <1> 	;;POP	AX
  9358                              <1> 	;;POP	CX
  9359                              <1> 	;;JMP	word [CS:SI+D1]
  9360                              <1> 	;jmp	word [SI+D1]
  9361 00002B4C FFA6[9A290000]      <1> 	jmp	dword [esi+D1]
  9362                              <1> ;;BAD_COMMAND_POP:
  9363                              <1> ;;	POP	AX
  9364                              <1> ;;	POP	BX
  9365                              <1> BAD_COMMAND:
  9366 00002B52 C605[87BE0000]01    <1>         MOV     byte [DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  9367 00002B59 B000                <1> 	MOV	AL,0
  9368 00002B5B C3                  <1> 	RETn
  9369                              <1> 
  9370                              <1> ;----------------------------------------
  9371                              <1> ;	RESET THE DISK SYSTEM  (AH=00H) :
  9372                              <1> ;----------------------------------------
  9373                              <1> 
  9374                              <1> ; 18-1-2015 : one controller reset (not other one)
  9375                              <1> 
  9376                              <1> DISK_RESET:
  9377 00002B5C FA                  <1> 	CLI
  9378 00002B5D E4A1                <1> 	IN	AL,INTB01		; GET THE MASK REGISTER
  9379                              <1> 	;JMP	$+2
  9380                              <1> 	IODELAY
  9381 00002B5F EB00                <2>  jmp short $+2
  9382 00002B61 EB00                <2>  jmp short $+2
  9383                              <1> 	;AND	AL,0BFH 		; ENABLE FIXED DISK INTERRUPT
  9384 00002B63 243F                <1> 	and	al,3Fh			; 22/12/2014 (IRQ 14 & IRQ 15)
  9385 00002B65 E6A1                <1> 	OUT	INTB01,AL
  9386 00002B67 FB                  <1> 	STI				; START INTERRUPTS
  9387                              <1> 	; 14/02/2015
  9388 00002B68 6689D7              <1> 	mov	di, dx	
  9389                              <1> 	; 04/01/2015
  9390                              <1> 	;xor	di,di
  9391                              <1> drst0:
  9392 00002B6B B004                <1> 	MOV	AL,04H  ; bit 2 - SRST 
  9393                              <1> 	;MOV	DX,HF_REG_PORT
  9394 00002B6D 668B15[B6B80000]    <1> 	MOV	DX,[HF_REG_PORT]
  9395 00002B74 EE                  <1> 	OUT	DX,AL			; RESET
  9396                              <1> ;	MOV	CX,10			; DELAY COUNT
  9397                              <1> ;DRD:	DEC	CX
  9398                              <1> ;	JNZ	short DRD		; WAIT 4.8 MICRO-SEC
  9399                              <1> 	;mov	cx,2			; wait for 30 micro seconds	
  9400 00002B75 B902000000          <1>         mov	ecx, 2 ; 21/02/2015
  9401 00002B7A E871EDFFFF          <1> 	call    WAITF                   ; (Award Bios 1999 - WAIT_REFRESH,
  9402                              <1>                                         ; 40 micro seconds)
  9403 00002B7F A0[89BE0000]        <1> 	mov	al,[CONTROL_BYTE]
  9404 00002B84 240F                <1> 	AND	AL,0FH			; SET HEAD OPTION
  9405 00002B86 EE                  <1> 	OUT	DX,AL			; TURN RESET OFF
  9406 00002B87 E814040000          <1> 	CALL	NOT_BUSY
  9407 00002B8C 7515                <1> 	JNZ	short DRERR		; TIME OUT ON RESET
  9408 00002B8E 668B15[B4B80000]    <1> 	MOV	DX,[HF_PORT]
  9409 00002B95 FEC2                <1> 	inc	dl  ; HF_PORT+1
  9410                              <1> 	; 02/01/2015 - Award BIOS 1999 - AHDSK.ASM
  9411                              <1>         ;mov     cl, 10
  9412 00002B97 B90A000000          <1>         mov     ecx, 10 ; 21/02/2015 
  9413                              <1> drst1:
  9414 00002B9C EC                  <1> 	IN	AL,DX			; GET RESET STATUS
  9415 00002B9D 3C01                <1> 	CMP	AL,1
  9416                              <1> 	; 04/01/2015
  9417 00002B9F 740A                <1> 	jz	short drst2
  9418                              <1> 	;JNZ	short DRERR		; BAD RESET STATUS
  9419                              <1>         	; Drive/Head Register - bit 4
  9420 00002BA1 E2F9                <1> 	loop	drst1
  9421                              <1> DRERR:	
  9422 00002BA3 C605[87BE0000]05    <1> 	MOV	byte [DISK_STATUS1],BAD_RESET ; CARD FAILED
  9423 00002BAA C3                  <1> 	RETn
  9424                              <1> drst2:
  9425                              <1> 	; 14/02/2015
  9426 00002BAB 6689FA              <1> 	mov	dx,di
  9427                              <1> ;drst3:
  9428                              <1> ;	; 05/01/2015
  9429                              <1> ;	shl 	di,1
  9430                              <1> ;	; 04/01/2015
  9431                              <1> ;	mov	ax,[di+hd_cports]
  9432                              <1> ;	cmp	ax,[HF_REG_PORT]
  9433                              <1> ;	je	short drst4
  9434                              <1> ;	mov	[HF_REG_PORT], ax
  9435                              <1> ;	; 03/01/2015
  9436                              <1> ;	mov	ax,[di+hd_ports]
  9437                              <1> ;       mov     [HF_PORT], ax
  9438                              <1> ;	; 05/01/2014
  9439                              <1> ;	shr	di,1
  9440                              <1> ;	; 04/01/2015
  9441                              <1> ;	jmp	short drst0	; reset other controller
  9442                              <1> ;drst4:
  9443                              <1> ;	; 05/01/2015
  9444                              <1> ;	shr	di,1
  9445                              <1> ;	mov	al,[di+hd_dregs]
  9446                              <1> ;	and	al,10h ; bit 4 only
  9447                              <1> ;	shr	al,4 ; bit 4  -> bit 0
  9448                              <1> ;	mov	[hf_m_s], al ; (0 = master, 1 = slave)
  9449                              <1> 	;
  9450 00002BAE A0[B8B80000]        <1> 	mov	al, [hf_m_s] ; 18/01/2015
  9451 00002BB3 A801                <1> 	test	al,1
  9452                              <1> ;	jnz	short drst6
  9453 00002BB5 7516                <1>         jnz     short drst4
  9454 00002BB7 8065FDEF            <1> 	AND     byte [CMD_BLOCK+5],0EFH ; SET TO DRIVE 0
  9455                              <1> ;drst5:
  9456                              <1> drst3:
  9457 00002BBB E811010000          <1> 	CALL	INIT_DRV		; SET MAX HEADS
  9458                              <1> 	;mov	dx,di
  9459 00002BC0 E8C9010000          <1> 	CALL	HDISK_RECAL		; RECAL TO RESET SEEK SPEED
  9460                              <1> 	; 04/01/2014
  9461                              <1> ;	inc	di
  9462                              <1> ;	mov	dx,di
  9463                              <1> ;	cmp	dl,[HF_NUM]
  9464                              <1> ;	jb	short drst3
  9465                              <1> ;DRE:
  9466 00002BC5 C605[87BE0000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; IGNORE ANY SET UP ERRORS
  9467 00002BCC C3                  <1> 	RETn
  9468                              <1> ;drst6:
  9469                              <1> drst4:		; Drive/Head Register - bit 4
  9470 00002BCD 804DFD10            <1> 	OR      byte [CMD_BLOCK+5],010H ; SET TO DRIVE 1     
  9471                              <1>         ;jmp    short drst5
  9472 00002BD1 EBE8                <1>         jmp     short drst3
  9473                              <1> 
  9474                              <1> ;----------------------------------------
  9475                              <1> ;	DISK STATUS ROUTINE  (AH = 01H) :
  9476                              <1> ;----------------------------------------
  9477                              <1> 
  9478                              <1> RETURN_STATUS:
  9479 00002BD3 A0[87BE0000]        <1> 	MOV	AL,[DISK_STATUS1]	; OBTAIN PREVIOUS STATUS
  9480 00002BD8 C605[87BE0000]00    <1>         MOV     byte [DISK_STATUS1],0   ; RESET STATUS
  9481 00002BDF C3                  <1> 	RETn
  9482                              <1> 
  9483                              <1> ;----------------------------------------
  9484                              <1> ;	DISK READ ROUTINE    (AH = 02H) :
  9485                              <1> ;----------------------------------------
  9486                              <1> 
  9487                              <1> DISK_READ:
  9488 00002BE0 C645FE20            <1> 	MOV	byte [CMD_BLOCK+6],READ_CMD
  9489 00002BE4 E930020000          <1>         JMP     COMMANDI
  9490                              <1> 
  9491                              <1> ;----------------------------------------
  9492                              <1> ;	DISK WRITE ROUTINE   (AH = 03H) :
  9493                              <1> ;----------------------------------------
  9494                              <1> 
  9495                              <1> DISK_WRITE:
  9496 00002BE9 C645FE30            <1> 	MOV	byte [CMD_BLOCK+6],WRITE_CMD
  9497 00002BED E982020000          <1>         JMP     COMMANDO
  9498                              <1> 
  9499                              <1> ;----------------------------------------
  9500                              <1> ;	DISK VERIFY	     (AH = 04H) :
  9501                              <1> ;----------------------------------------
  9502                              <1> 
  9503                              <1> DISK_VERF:
  9504 00002BF2 C645FE40            <1> 	MOV	byte [CMD_BLOCK+6],VERIFY_CMD
  9505 00002BF6 E8F0020000          <1> 	CALL	COMMAND
  9506 00002BFB 750C                <1> 	JNZ	short VERF_EXIT		; CONTROLLER STILL BUSY
  9507 00002BFD E862030000          <1> 	CALL	_WAIT			; (Original: CALL WAIT)	
  9508 00002C02 7505                <1> 	JNZ	short VERF_EXIT		; TIME OUT
  9509 00002C04 E8EF030000          <1> 	CALL	CHECK_STATUS
  9510                              <1> VERF_EXIT:
  9511 00002C09 C3                  <1> 	RETn
  9512                              <1> 
  9513                              <1> ;----------------------------------------
  9514                              <1> ;	FORMATTING	     (AH = 05H) :
  9515                              <1> ;----------------------------------------
  9516                              <1> 
  9517                              <1> FMT_TRK:				; FORMAT TRACK	(AH = 005H)
  9518 00002C0A C645FE50            <1> 	MOV	byte [CMD_BLOCK+6],FMTTRK_CMD
  9519                              <1> 	;PUSH	ES
  9520                              <1> 	;PUSH	BX
  9521 00002C0E 53                  <1> 	push	ebx
  9522 00002C0F E896040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS ADDRESS
  9523                              <1> 	;MOV	AL,[ES:BX+14]		; GET SECTORS/TRACK
  9524 00002C14 8A430E              <1> 	mov	al, [ebx+14]
  9525 00002C17 8845F9              <1> 	MOV	[CMD_BLOCK+1],AL 	; SET SECTOR COUNT IN COMMAND
  9526 00002C1A 5B                  <1> 	pop	ebx
  9527                              <1> 	;POP	BX
  9528                              <1> 	;POP	ES
  9529 00002C1B E95B020000          <1>         JMP     CMD_OF                  ; GO EXECUTE THE COMMAND
  9530                              <1> 
  9531                              <1> ;----------------------------------------
  9532                              <1> ;	READ DASD TYPE	     (AH = 15H) :
  9533                              <1> ;----------------------------------------
  9534                              <1> 
  9535                              <1> READ_DASD_TYPE:
  9536                              <1> READ_D_T:				; GET DRIVE PARAMETERS
  9537 00002C20 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  9538                              <1> 	;PUSH	ES
  9539 00002C21 53                  <1> 	PUSH	eBX
  9540                              <1> 	;CALL	DDS			; ESTABLISH ADDRESSING
  9541                              <1> 	;push	cs
  9542                              <1> 	;pop	ds
  9543 00002C22 66BB1000            <1>         mov	bx, KDATA
  9544 00002C26 8EDB                <1> 	mov	ds, bx
  9545                              <1> 	;mov	es, bx
  9546 00002C28 C605[87BE0000]00    <1> 	MOV     byte [DISK_STATUS1],0
  9547 00002C2F 8A1D[88BE0000]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  9548 00002C35 80E27F              <1> 	AND	DL,7FH			; GET DRIVE NUMBER
  9549 00002C38 38D3                <1> 	CMP	BL,DL
  9550 00002C3A 7625                <1> 	JBE	short RDT_NOT_PRESENT 	; RETURN DRIVE NOT PRESENT
  9551 00002C3C E869040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETER ADDRESS
  9552                              <1> 	;MOV	AL,[ES:BX+2]		; HEADS
  9553 00002C41 8A4302              <1> 	mov	al, [ebx+2]
  9554                              <1> 	;MOV	CL,[ES:BX+14]
  9555 00002C44 8A4B0E              <1> 	mov	cl, [ebx+14]
  9556 00002C47 F6E9                <1> 	IMUL	CL			; * NUMBER OF SECTORS
  9557                              <1> 	;MOV	CX,[ES:BX]		; MAX NUMBER OF CYLINDERS
  9558 00002C49 668B0B              <1> 	mov	cx ,[ebx]
  9559                              <1> 	;
  9560                              <1> 	; 02/01/2015 
  9561                              <1> 	; ** leave the last cylinder as reserved for diagnostics **
  9562                              <1> 	; (Also in Award BIOS - 1999, AHDSK.ASM, FUN15 -> sub ax, 1)
  9563 00002C4C 6649                <1> 	DEC	CX			; LEAVE ONE FOR DIAGNOSTICS
  9564                              <1> 	;
  9565 00002C4E 66F7E9              <1> 	IMUL	CX			; NUMBER OF SECTORS
  9566 00002C51 6689D1              <1> 	MOV	CX,DX			; HIGH ORDER HALF
  9567 00002C54 6689C2              <1> 	MOV	DX,AX			; LOW ORDER HALF
  9568                              <1> 	;SUB	AX,AX
  9569 00002C57 28C0                <1> 	sub	al, al
  9570 00002C59 B403                <1> 	MOV	AH,03H			; INDICATE FIXED DISK
  9571 00002C5B 5B                  <1> RDT2:	POP	eBX			; RESTORE REGISTERS
  9572                              <1> 	;POP	ES
  9573 00002C5C 1F                  <1> 	POP	DS
  9574 00002C5D F8                  <1> 	CLC				; CLEAR CARRY
  9575                              <1> 	;RETf	2
  9576 00002C5E CA0400              <1> 	retf	4
  9577                              <1> RDT_NOT_PRESENT:
  9578 00002C61 6629C0              <1> 	SUB	AX,AX			; DRIVE NOT PRESENT RETURN
  9579 00002C64 6689C1              <1> 	MOV	CX,AX			; ZERO BLOCK COUNT
  9580 00002C67 6689C2              <1> 	MOV	DX,AX
  9581 00002C6A EBEF                <1> 	JMP	short RDT2
  9582                              <1> 
  9583                              <1> ;----------------------------------------
  9584                              <1> ;	GET PARAMETERS	     (AH = 08H) :
  9585                              <1> ;----------------------------------------
  9586                              <1> 
  9587                              <1> GET_PARM_N:
  9588                              <1> ;GET_PARM:				; GET DRIVE PARAMETERS
  9589 00002C6C 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  9590                              <1> 	;PUSH	ES
  9591 00002C6D 53                  <1> 	PUSH	eBX
  9592                              <1> 	;MOV	AX,ABS0 		; ESTABLISH ADDRESSING
  9593                              <1> 	;MOV	DS,AX
  9594                              <1> 	;TEST	DL,1			; CHECK FOR DRIVE 1
  9595                              <1> 	;JZ	short G0
  9596                              <1> 	;LES	BX,@HF1_TBL_VEC
  9597                              <1> 	;JMP	SHORT G1
  9598                              <1> ;G0:	LES	BX,@HF_TBL_VEC
  9599                              <1> ;G1:
  9600                              <1> 	;CALL	DDS			; ESTABLISH SEGMENT
  9601                              <1> 	; 22/12/2014
  9602                              <1> 	;push	cs
  9603                              <1> 	;pop	ds
  9604 00002C6E 66BB1000            <1> 	mov	bx, KDATA
  9605 00002C72 8EDB                <1> 	mov	ds, bx
  9606                              <1> 	;mov	es, bx
  9607                              <1> 	;
  9608 00002C74 80EA80              <1> 	SUB	DL,80H
  9609 00002C77 80FA04              <1> 	CMP	DL,MAX_FILE		; TEST WITHIN RANGE
  9610 00002C7A 7341                <1> 	JAE	short G4
  9611                              <1> 	;
  9612 00002C7C 31DB                <1> 	xor	ebx, ebx ; 21/02/2015
  9613                              <1> 	; 22/12/2014
  9614 00002C7E 88D3                <1> 	mov	bl, dl
  9615                              <1> 	;xor	bh, bh  
  9616 00002C80 C0E302              <1> 	shl	bl, 2			; convert index to offset
  9617                              <1> 	;add	bx, HF_TBL_VEC
  9618 00002C83 81C3[8CBE0000]      <1> 	add	ebx, HF_TBL_VEC
  9619                              <1> 	;mov	ax, [bx+2]
  9620                              <1> 	;mov	es, ax			; dpt segment
  9621                              <1> 	;mov	bx, [bx]		; dpt offset
  9622 00002C89 8B1B                <1> 	mov	ebx, [ebx] ; 32 bit offset	
  9623                              <1> 
  9624 00002C8B C605[87BE0000]00    <1> 	MOV	byte [DISK_STATUS1],0
  9625                              <1>         ;MOV     AX,[ES:BX]              ; MAX NUMBER OF CYLINDERS
  9626 00002C92 668B03              <1> 	mov	ax, [ebx]
  9627                              <1> 	;;SUB	AX,2			; ADJUST FOR 0-N
  9628 00002C95 6648                <1> 	dec	ax			; max. cylinder number
  9629 00002C97 88C5                <1> 	MOV	CH,AL
  9630 00002C99 66250003            <1> 	AND	AX,0300H		; HIGH TWO BITS OF CYLINDER
  9631 00002C9D 66D1E8              <1> 	SHR	AX,1
  9632 00002CA0 66D1E8              <1> 	SHR	AX,1
  9633                              <1> 	;OR	AL,[ES:BX+14]		; SECTORS
  9634 00002CA3 0A430E              <1> 	or	al, [ebx+14]
  9635 00002CA6 88C1                <1> 	MOV	CL,AL
  9636                              <1> 	;MOV	DH,[ES:BX+2]		; HEADS
  9637 00002CA8 8A7302              <1> 	mov	dh, [ebx+2]
  9638 00002CAB FECE                <1> 	DEC	DH			; 0-N RANGE
  9639 00002CAD 8A15[88BE0000]      <1> 	MOV	DL,[HF_NUM]		; DRIVE COUNT
  9640 00002CB3 6629C0              <1> 	SUB	AX,AX
  9641                              <1>         ;27/12/2014 
  9642                              <1> 	; ES:DI = Address of disk parameter table from BIOS
  9643                              <1> 	;(Programmer's Guide to the AMIBIOS - 1993)
  9644                              <1> 	;mov	di, bx			; HDPT offset
  9645 00002CB6 89DF                <1> 	mov	edi, ebx
  9646                              <1> G5:
  9647 00002CB8 5B                  <1> 	POP	eBX			; RESTORE REGISTERS
  9648                              <1> 	;POP	ES
  9649 00002CB9 1F                  <1> 	POP	DS
  9650                              <1> 	;RETf	2
  9651 00002CBA CA0400              <1> 	retf	4
  9652                              <1> G4:
  9653 00002CBD C605[87BE0000]07    <1> 	MOV     byte [DISK_STATUS1],INIT_FAIL ; OPERATION FAILED
  9654 00002CC4 B407                <1> 	MOV	AH,INIT_FAIL
  9655 00002CC6 28C0                <1> 	SUB	AL,AL
  9656 00002CC8 6629D2              <1> 	SUB	DX,DX
  9657 00002CCB 6629C9              <1> 	SUB	CX,CX
  9658 00002CCE F9                  <1> 	STC				; SET ERROR FLAG
  9659 00002CCF EBE7                <1> 	JMP	short G5
  9660                              <1> 
  9661                              <1> ;----------------------------------------
  9662                              <1> ;	INITIALIZE DRIVE     (AH = 09H) :
  9663                              <1> ;----------------------------------------
  9664                              <1> 	; 03/01/2015
  9665                              <1> 	; According to ATA-ATAPI specification v2.0 to v5.0
  9666                              <1> 	; logical sector per logical track
  9667                              <1> 	; and logical heads - 1 would be set but
  9668                              <1> 	; it is seen as it will be good
  9669                              <1> 	; if physical parameters will be set here
  9670                              <1> 	; because, number of heads <= 16.
  9671                              <1> 	; (logical heads usually more than 16)
  9672                              <1> 	; NOTE: ATA logical parameters (software C, H, S)
  9673                              <1> 	;	== INT 13h physical parameters
  9674                              <1> 
  9675                              <1> ;INIT_DRV:
  9676                              <1> ;	MOV	byte [CMD_BLOCK+6],SET_PARM_CMD
  9677                              <1> ;	CALL	GET_VEC 		; ES:BX -> PARAMETER BLOCK
  9678                              <1> ;	MOV	AL,[ES:BX+2]		; GET NUMBER OF HEADS
  9679                              <1> ;	DEC	AL			; CONVERT TO 0-INDEX
  9680                              <1> ;	MOV	AH,[CMD_BLOCK+5] 	; GET SDH REGISTER
  9681                              <1> ;	AND	AH,0F0H 		; CHANGE HEAD NUMBER
  9682                              <1> ;	OR	AH,AL			; TO MAX HEAD
  9683                              <1> ;	MOV	[CMD_BLOCK+5],AH
  9684                              <1> ;	MOV	AL,[ES:BX+14]		; MAX SECTOR NUMBER
  9685                              <1> ;	MOV	[CMD_BLOCK+1],AL
  9686                              <1> ;	SUB	AX,AX
  9687                              <1> ;	MOV	[CMD_BLOCK+3],AL 	; ZERO FLAGS
  9688                              <1> ;	CALL	COMMAND 		; TELL CONTROLLER
  9689                              <1> ;	JNZ	short INIT_EXIT		; CONTROLLER BUSY ERROR
  9690                              <1> ;	CALL	NOT_BUSY		; WAIT FOR IT TO BE DONE
  9691                              <1> ;	JNZ	short INIT_EXIT		; TIME OUT
  9692                              <1> ;	CALL	CHECK_STATUS
  9693                              <1> ;INIT_EXIT:
  9694                              <1> ;	RETn
  9695                              <1> 
  9696                              <1> ; 04/01/2015
  9697                              <1> ; 02/01/2015 - Derived from from AWARD BIOS 1999
  9698                              <1> ;				 AHDSK.ASM - INIT_DRIVE
  9699                              <1> INIT_DRV:
  9700                              <1> 	;xor	ah,ah
  9701 00002CD1 31C0                <1> 	xor	eax, eax ; 21/02/2015
  9702 00002CD3 B00B                <1> 	mov	al,11 ; Physical heads from translated HDPT
  9703 00002CD5 3825[9CBE0000]      <1>         cmp     [LBAMode], ah   ; 0
  9704 00002CDB 7702                <1> 	ja	short idrv0
  9705 00002CDD B002                <1> 	mov	al,2  ; Physical heads from standard HDPT
  9706                              <1> idrv0:
  9707                              <1> 	; DL = drive number (0 based)
  9708 00002CDF E8C6030000          <1> 	call	GET_VEC
  9709                              <1> 	;push	bx
  9710 00002CE4 53                  <1> 	push	ebx ; 21/02/2015
  9711                              <1> 	;add	bx,ax
  9712 00002CE5 01C3                <1> 	add	ebx, eax
  9713                              <1> 	;; 05/01/2015
  9714 00002CE7 8A25[B8B80000]      <1> 	mov	ah, [hf_m_s] ; drive number (0= master, 1= slave)
  9715                              <1> 	;;and 	ah,1 
  9716 00002CED C0E404              <1> 	shl	ah,4
  9717 00002CF0 80CCA0              <1> 	or	ah,0A0h  ; Drive/Head register - 10100000b (A0h)	
  9718                              <1> 	;mov	al,[es:bx]
  9719 00002CF3 8A03                <1> 	mov	al, [ebx] ; 21/02/2015
  9720 00002CF5 FEC8                <1> 	dec	al	 ; last head number 
  9721                              <1> 	;and	al,0Fh
  9722 00002CF7 08E0                <1> 	or	al,ah	 ; lower 4 bits for head number
  9723                              <1> 	;
  9724 00002CF9 C645FE91            <1> 	mov	byte [CMD_BLOCK+6],SET_PARM_CMD
  9725 00002CFD 8845FD              <1> 	mov	[CMD_BLOCK+5],al
  9726                              <1> 	;pop	bx
  9727 00002D00 5B                  <1> 	pop	ebx
  9728 00002D01 29C0                <1> 	sub	eax, eax ; 21/02/2015
  9729 00002D03 B004                <1> 	mov	al,4 ; Physical sec per track from translated HDPT
  9730 00002D05 803D[9CBE0000]00    <1> 	cmp	byte [LBAMode], 0
  9731 00002D0C 7702                <1> 	ja	short idrv1
  9732 00002D0E B00E                <1> 	mov	al,14 ; Physical sec per track from standard HDPT
  9733                              <1> idrv1:
  9734                              <1> 	;xor	ah,ah
  9735                              <1> 	;add	bx,ax
  9736 00002D10 01C3                <1> 	add	ebx, eax ; 21/02/2015
  9737                              <1> 	;mov	al,[es:bx]
  9738                              <1> 			; sector number
  9739 00002D12 8A03                <1> 	mov	al, [ebx]
  9740 00002D14 8845F9              <1> 	mov	[CMD_BLOCK+1],al
  9741 00002D17 28C0                <1> 	sub	al,al
  9742 00002D19 8845FB              <1> 	mov	[CMD_BLOCK+3],al  ; ZERO FLAGS
  9743 00002D1C E8CA010000          <1> 	call	COMMAND 	  ; TELL CONTROLLER
  9744 00002D21 750C                <1> 	jnz	short INIT_EXIT	  ; CONTROLLER BUSY ERROR
  9745 00002D23 E878020000          <1> 	call	NOT_BUSY	  ; WAIT FOR IT TO BE DONE
  9746 00002D28 7505                <1> 	jnz	short INIT_EXIT	  ; TIME OUT
  9747 00002D2A E8C9020000          <1> 	call	CHECK_STATUS
  9748                              <1> INIT_EXIT:
  9749 00002D2F C3                  <1> 	RETn
  9750                              <1> 
  9751                              <1> ;----------------------------------------
  9752                              <1> ;	READ LONG	     (AH = 0AH) :
  9753                              <1> ;----------------------------------------
  9754                              <1> 
  9755                              <1> RD_LONG:
  9756                              <1> 	;MOV	@CMD_BLOCK+6,READ_CMD OR ECC_MODE
  9757 00002D30 C645FE22            <1>         mov     byte [CMD_BLOCK+6],READ_CMD + ECC_MODE 
  9758 00002D34 E9E0000000          <1>         JMP     COMMANDI
  9759                              <1> 
  9760                              <1> ;----------------------------------------
  9761                              <1> ;	WRITE LONG	     (AH = 0BH) :
  9762                              <1> ;----------------------------------------
  9763                              <1> 
  9764                              <1> WR_LONG:
  9765                              <1> 	;MOV	@CMD_BLOCK+6,WRITE_CMD OR ECC_MODE
  9766 00002D39 C645FE32            <1>         MOV     byte [CMD_BLOCK+6],WRITE_CMD + ECC_MODE
  9767 00002D3D E932010000          <1>         JMP     COMMANDO
  9768                              <1> 
  9769                              <1> ;----------------------------------------
  9770                              <1> ;	SEEK		     (AH = 0CH) :
  9771                              <1> ;----------------------------------------
  9772                              <1> 
  9773                              <1> DISK_SEEK:
  9774 00002D42 C645FE70            <1>         MOV     byte [CMD_BLOCK+6],SEEK_CMD
  9775 00002D46 E8A0010000          <1> 	CALL	COMMAND
  9776 00002D4B 751C                <1> 	JNZ	short DS_EXIT 		; CONTROLLER BUSY ERROR
  9777 00002D4D E812020000          <1> 	CALL	_WAIT
  9778 00002D52 7515                <1>         JNZ     DS_EXIT                 ; TIME OUT ON SEEK
  9779 00002D54 E89F020000          <1> 	CALL	CHECK_STATUS
  9780 00002D59 803D[87BE0000]40    <1>         CMP     byte [DISK_STATUS1],BAD_SEEK
  9781 00002D60 7507                <1> 	JNE	short DS_EXIT
  9782 00002D62 C605[87BE0000]00    <1>         MOV     byte [DISK_STATUS1],0
  9783                              <1> DS_EXIT:
  9784 00002D69 C3                  <1> 	RETn
  9785                              <1> 
  9786                              <1> ;----------------------------------------
  9787                              <1> ;	TEST DISK READY      (AH = 10H) :
  9788                              <1> ;----------------------------------------
  9789                              <1> 
  9790                              <1> TST_RDY:				; WAIT FOR CONTROLLER
  9791 00002D6A E831020000          <1> 	CALL	NOT_BUSY
  9792 00002D6F 751C                <1> 	JNZ	short TR_EX
  9793 00002D71 8A45FD              <1> 	MOV	AL,[CMD_BLOCK+5] 	; SELECT DRIVE
  9794 00002D74 668B15[B4B80000]    <1> 	MOV	DX,[HF_PORT]
  9795 00002D7B 80C206              <1> 	add	dl,6
  9796 00002D7E EE                  <1> 	OUT	DX,AL
  9797 00002D7F E88C020000          <1> 	CALL	CHECK_ST		; CHECK STATUS ONLY
  9798 00002D84 7507                <1> 	JNZ	short TR_EX
  9799 00002D86 C605[87BE0000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; WIPE OUT DATA CORRECTED ERROR
  9800                              <1> TR_EX:	
  9801 00002D8D C3                  <1> 	RETn
  9802                              <1> 
  9803                              <1> ;----------------------------------------
  9804                              <1> ;	RECALIBRATE	     (AH = 11H) :
  9805                              <1> ;----------------------------------------
  9806                              <1> 
  9807                              <1> HDISK_RECAL:
  9808 00002D8E C645FE10            <1>         MOV     byte [CMD_BLOCK+6],RECAL_CMD ; 10h, 16
  9809 00002D92 E854010000          <1> 	CALL	COMMAND 		; START THE OPERATION
  9810 00002D97 7523                <1> 	JNZ	short RECAL_EXIT	; ERROR
  9811 00002D99 E8C6010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION
  9812 00002D9E 7407                <1> 	JZ	short RECAL_X 		; TIME OUT ONE OK ?
  9813 00002DA0 E8BF010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION LONGER
  9814 00002DA5 7515                <1> 	JNZ	short RECAL_EXIT	; TIME OUT TWO TIMES IS ERROR
  9815                              <1> RECAL_X:
  9816 00002DA7 E84C020000          <1> 	CALL	CHECK_STATUS
  9817 00002DAC 803D[87BE0000]40    <1> 	CMP	byte [DISK_STATUS1],BAD_SEEK ; SEEK NOT COMPLETE
  9818 00002DB3 7507                <1> 	JNE	short RECAL_EXIT	; IS OK
  9819 00002DB5 C605[87BE0000]00    <1> 	MOV	byte [DISK_STATUS1],0
  9820                              <1> RECAL_EXIT:
  9821 00002DBC 803D[87BE0000]00    <1>         CMP     byte [DISK_STATUS1],0
  9822 00002DC3 C3                  <1> 	RETn
  9823                              <1> 
  9824                              <1> ;----------------------------------------
  9825                              <1> ;      CONTROLLER DIAGNOSTIC (AH = 14H) :
  9826                              <1> ;----------------------------------------
  9827                              <1> 
  9828                              <1> CTLR_DIAGNOSTIC:
  9829 00002DC4 FA                  <1>         CLI                             ; DISABLE INTERRUPTS WHILE CHANGING MASK
  9830 00002DC5 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  9831                              <1> 	;AND	AL,0BFH
  9832 00002DC7 243F                <1> 	and	al, 3Fh			; enable IRQ 14 & IRQ 15
  9833                              <1> 	;JMP	$+2
  9834                              <1> 	IODELAY
  9835 00002DC9 EB00                <2>  jmp short $+2
  9836 00002DCB EB00                <2>  jmp short $+2
  9837 00002DCD E6A1                <1> 	OUT	INTB01,AL
  9838                              <1> 	IODELAY
  9839 00002DCF EB00                <2>  jmp short $+2
  9840 00002DD1 EB00                <2>  jmp short $+2
  9841 00002DD3 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  9842 00002DD5 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
  9843                              <1> 	;JMP	$+2
  9844                              <1> 	IODELAY
  9845 00002DD7 EB00                <2>  jmp short $+2
  9846 00002DD9 EB00                <2>  jmp short $+2
  9847 00002DDB E621                <1> 	OUT	INTA01,AL
  9848 00002DDD FB                  <1> 	STI
  9849 00002DDE E8BD010000          <1> 	CALL	NOT_BUSY		; WAIT FOR CARD
  9850 00002DE3 752B                <1> 	JNZ	short CD_ERR		; BAD CARD
  9851                              <1> 	;MOV	DX, HF_PORT+7
  9852 00002DE5 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
  9853 00002DEC 80C207              <1> 	add	dl, 7
  9854 00002DEF B090                <1> 	MOV	AL,DIAG_CMD		; START DIAGNOSE
  9855 00002DF1 EE                  <1> 	OUT	DX,AL
  9856 00002DF2 E8A9010000          <1> 	CALL	NOT_BUSY		; WAIT FOR IT TO COMPLETE
  9857 00002DF7 B480                <1> 	MOV	AH,TIME_OUT
  9858 00002DF9 7517                <1> 	JNZ	short CD_EXIT 		; TIME OUT ON DIAGNOSTIC
  9859                              <1> 	;MOV	DX,HF_PORT+1		; GET ERROR REGISTER
  9860 00002DFB 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
  9861 00002E02 FEC2                <1> 	inc	dl
  9862 00002E04 EC                  <1> 	IN	AL,DX
  9863 00002E05 A2[7EBE0000]        <1> 	MOV	[HF_ERROR],AL		; SAVE IT
  9864 00002E0A B400                <1> 	MOV	AH,0
  9865 00002E0C 3C01                <1> 	CMP	AL,1			; CHECK FOR ALL OK
  9866 00002E0E 7402                <1> 	JE	SHORT CD_EXIT
  9867 00002E10 B420                <1> CD_ERR: MOV	AH,BAD_CNTLR
  9868                              <1> CD_EXIT:
  9869 00002E12 8825[87BE0000]      <1> 	MOV	[DISK_STATUS1],AH
  9870 00002E18 C3                  <1> 	RETn
  9871                              <1> 
  9872                              <1> ;----------------------------------------
  9873                              <1> ; COMMANDI				:
  9874                              <1> ;	REPEATEDLY INPUTS DATA TILL	:
  9875                              <1> ;	NSECTOR RETURNS ZERO		:
  9876                              <1> ;----------------------------------------
  9877                              <1> COMMANDI:
  9878 00002E19 E862020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  9879 00002E1E 7253                <1> 	JC	short CMD_ABORT
  9880                              <1> 	;MOV	DI,BX
  9881 00002E20 89DF                <1> 	mov	edi, ebx ; 21/02/2015
  9882 00002E22 E8C4000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  9883 00002E27 754A                <1> 	JNZ	short CMD_ABORT
  9884                              <1> CMD_I1:
  9885 00002E29 E836010000          <1> 	CALL	_WAIT			; WAIT FOR DATA REQUEST INTERRUPT
  9886 00002E2E 7543                <1> 	JNZ	short TM_OUT		; TIME OUT
  9887                              <1> cmd_i1x: ; 18/02/2016
  9888                              <1> 	;MOV	CX,256			; SECTOR SIZE IN WORDS
  9889 00002E30 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015	
  9890                              <1> 	;MOV	DX,HF_PORT
  9891 00002E35 668B15[B4B80000]    <1> 	mov	dx,[HF_PORT]
  9892 00002E3C FA                  <1> 	CLI
  9893 00002E3D FC                  <1> 	CLD
  9894 00002E3E F3666D              <1> 	REP	INSW			; GET THE SECTOR
  9895 00002E41 FB                  <1> 	STI
  9896 00002E42 F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL INPUT
  9897 00002E46 7419                <1> 	JZ	short CMD_I3
  9898 00002E48 E880010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9899 00002E4D 7224                <1> 	JC	short TM_OUT
  9900                              <1> 	;MOV	DX,HF_PORT
  9901 00002E4F 668B15[B4B80000]    <1> 	mov	dx,[HF_PORT]
  9902                              <1> 	;MOV	CX,4			; GET ECC BYTES
  9903 00002E56 B904000000          <1> 	mov 	ecx, 4 ; mov cx, 4 
  9904 00002E5B EC                  <1> CMD_I2: IN	AL,DX
  9905                              <1> 	;MOV	[ES:DI],AL		; GO SLOW FOR BOARD
  9906 00002E5C 8807                <1> 	mov 	[edi], al ; 21/02/2015
  9907 00002E5E 47                  <1> 	INC	eDI
  9908 00002E5F E2FA                <1> 	LOOP	CMD_I2
  9909                              <1> CMD_I3: 
  9910                              <1> 	; wait for 400 ns
  9911 00002E61 80C207              <1> 	add 	dl, 7
  9912 00002E64 EC                  <1> 	in	al, dx
  9913 00002E65 EC                  <1> 	in	al, dx
  9914 00002E66 EC                  <1> 	in	al, dx
  9915                              <1> 	;
  9916 00002E67 E88C010000          <1> 	CALL	CHECK_STATUS
  9917 00002E6C 7505                <1> 	JNZ	short CMD_ABORT		; ERROR RETURNED
  9918 00002E6E FE4DF9              <1> 	DEC	byte [CMD_BLOCK+1]	; CHECK FOR MORE
  9919                              <1> 	;JNZ	SHORT CMD_I1
  9920 00002E71 75BD                <1> 	jnz	short cmd_i1x ; 18/02/2016
  9921                              <1> CMD_ABORT:
  9922 00002E73 C3                  <1> TM_OUT: RETn
  9923                              <1> 
  9924                              <1> ;----------------------------------------
  9925                              <1> ; COMMANDO				:
  9926                              <1> ;	REPEATEDLY OUTPUTS DATA TILL	:
  9927                              <1> ;	NSECTOR RETURNS ZERO		:
  9928                              <1> ;----------------------------------------
  9929                              <1> COMMANDO:
  9930 00002E74 E807020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  9931 00002E79 72F8                <1> 	JC	short CMD_ABORT
  9932 00002E7B 89DE                <1> CMD_OF: MOV	eSI,eBX ; 21/02/2015
  9933 00002E7D E869000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  9934 00002E82 75EF                <1> 	JNZ	short CMD_ABORT
  9935 00002E84 E844010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9936 00002E89 72E8                <1> 	JC	short TM_OUT			; TOO LONG
  9937                              <1> CMD_O1: ;PUSH	DS
  9938                              <1> 	;PUSH	ES			; MOVE ES TO DS
  9939                              <1> 	;POP	DS
  9940                              <1> 	;MOV	CX,256			; PUT THE DATA OUT TO THE CARD
  9941                              <1> 	;MOV	DX,HF_PORT
  9942                              <1> 	; 01/02/2015
  9943 00002E8B 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
  9944                              <1> 	;push	es
  9945                              <1> 	;pop	ds
  9946                              <1> 	;mov	cx, 256
  9947 00002E92 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015
  9948 00002E97 FA                  <1> 	CLI
  9949 00002E98 FC                  <1> 	CLD
  9950 00002E99 F3666F              <1> 	REP	OUTSW
  9951 00002E9C FB                  <1> 	STI
  9952                              <1> 	;POP	DS			; RESTORE DS
  9953 00002E9D F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL OUTPUT
  9954 00002EA1 7419                <1> 	JZ	short CMD_O3
  9955 00002EA3 E825010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9956 00002EA8 72C9                <1> 	JC	short TM_OUT
  9957                              <1> 	;MOV	DX,HF_PORT
  9958 00002EAA 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
  9959                              <1> 	;MOV	CX,4			; OUTPUT THE ECC BYTES
  9960 00002EB1 B904000000          <1> 	mov	ecx, 4  ; mov cx, 4
  9961                              <1> CMD_O2: ;MOV	AL,[ES:SI]
  9962 00002EB6 8A06                <1> 	mov	al, [esi]
  9963 00002EB8 EE                  <1> 	OUT	DX,AL
  9964 00002EB9 46                  <1> 	INC	eSI
  9965 00002EBA E2FA                <1> 	LOOP	CMD_O2
  9966                              <1> CMD_O3:
  9967 00002EBC E8A3000000          <1> 	CALL	_WAIT			; WAIT FOR SECTOR COMPLETE INTERRUPT
  9968 00002EC1 75B0                <1> 	JNZ	short TM_OUT		; ERROR RETURNED
  9969 00002EC3 E830010000          <1> 	CALL	CHECK_STATUS
  9970 00002EC8 75A9                <1> 	JNZ	short CMD_ABORT
  9971 00002ECA F605[7DBE0000]08    <1> 	TEST	byte [HF_STATUS],ST_DRQ	; CHECK FOR MORE
  9972 00002ED1 75B8                <1> 	JNZ	SHORT CMD_O1
  9973                              <1> 	;MOV	DX,HF_PORT+2		; CHECK RESIDUAL SECTOR COUNT
  9974 00002ED3 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
  9975                              <1> 	;add	dl, 2
  9976 00002EDA FEC2                <1> 	inc	dl
  9977 00002EDC FEC2                <1> 	inc	dl
  9978 00002EDE EC                  <1> 	IN	AL,DX			;
  9979 00002EDF A8FF                <1> 	TEST	AL,0FFH 		;
  9980 00002EE1 7407                <1> 	JZ	short CMD_O4			; COUNT = 0  OK
  9981 00002EE3 C605[87BE0000]BB    <1> 	MOV	byte [DISK_STATUS1],UNDEF_ERR 
  9982                              <1> 					; OPERATION ABORTED - PARTIAL TRANSFER
  9983                              <1> CMD_O4:
  9984 00002EEA C3                  <1> 	RETn
  9985                              <1> 
  9986                              <1> ;--------------------------------------------------------
  9987                              <1> ; COMMAND						:
  9988                              <1> ;	THIS ROUTINE OUTPUTS THE COMMAND BLOCK		:
  9989                              <1> ; OUTPUT						:
  9990                              <1> ;	BL = STATUS					:
  9991                              <1> ;	BH = ERROR REGISTER				:
  9992                              <1> ;--------------------------------------------------------
  9993                              <1> 
  9994                              <1> COMMAND:
  9995 00002EEB 53                  <1> 	PUSH	eBX			; WAIT FOR SEEK COMPLETE AND READY
  9996                              <1> 	;;MOV	CX,DELAY_2		; SET INITIAL DELAY BEFORE TEST
  9997                              <1> COMMAND1:
  9998                              <1> 	;;PUSH	CX			; SAVE LOOP COUNT
  9999 00002EEC E879FEFFFF          <1> 	CALL	TST_RDY 		; CHECK DRIVE READY
 10000                              <1> 	;;POP	CX
 10001 00002EF1 7419                <1> 	JZ	short COMMAND2		; DRIVE IS READY
 10002 00002EF3 803D[87BE0000]80    <1>         CMP     byte [DISK_STATUS1],TIME_OUT ; TST_RDY TIMED OUT--GIVE UP
 10003                              <1> 	;JZ	short CMD_TIMEOUT
 10004                              <1> 	;;LOOP	COMMAND1		; KEEP TRYING FOR A WHILE
 10005                              <1> 	;JMP	SHORT COMMAND4		; ITS NOT GOING TO GET READY
 10006 00002EFA 7507                <1> 	jne	short COMMAND4
 10007                              <1> CMD_TIMEOUT:
 10008 00002EFC C605[87BE0000]20    <1> 	MOV	byte [DISK_STATUS1],BAD_CNTLR
 10009                              <1> COMMAND4:
 10010 00002F03 5B                  <1> 	POP	eBX
 10011 00002F04 803D[87BE0000]00    <1>         CMP     byte [DISK_STATUS1],0   ; SET CONDITION CODE FOR CALLER
 10012 00002F0B C3                  <1> 	RETn
 10013                              <1> COMMAND2:
 10014 00002F0C 5B                  <1> 	POP	eBX
 10015 00002F0D 57                  <1> 	PUSH	eDI
 10016 00002F0E C605[7FBE0000]00    <1> 	MOV	byte [HF_INT_FLAG],0	; RESET INTERRUPT FLAG
 10017 00002F15 FA                  <1> 	CLI				; INHIBIT INTERRUPTS WHILE CHANGING MASK
 10018 00002F16 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
 10019                              <1> 	;AND	AL,0BFH
 10020 00002F18 243F                <1> 	and	al, 3Fh			; Enable IRQ 14 & 15
 10021                              <1> 	;JMP	$+2
 10022                              <1> 	IODELAY
 10023 00002F1A EB00                <2>  jmp short $+2
 10024 00002F1C EB00                <2>  jmp short $+2
 10025 00002F1E E6A1                <1> 	OUT	INTB01,AL
 10026 00002F20 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
 10027 00002F22 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
 10028                              <1> 	;JMP	$+2
 10029                              <1> 	IODELAY
 10030 00002F24 EB00                <2>  jmp short $+2
 10031 00002F26 EB00                <2>  jmp short $+2
 10032 00002F28 E621                <1> 	OUT	INTA01,AL
 10033 00002F2A FB                  <1> 	STI
 10034 00002F2B 31FF                <1> 	XOR	eDI,eDI			; INDEX THE COMMAND TABLE
 10035                              <1> 	;MOV	DX,HF_PORT+1		; DISK ADDRESS
 10036 00002F2D 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
 10037 00002F34 FEC2                <1> 	inc	dl
 10038 00002F36 F605[89BE0000]C0    <1> 	TEST	byte [CONTROL_BYTE],0C0H ; CHECK FOR RETRY SUPPRESSION
 10039 00002F3D 7411                <1> 	JZ	short COMMAND3
 10040 00002F3F 8A45FE              <1> 	MOV	AL, [CMD_BLOCK+6] 	; YES-GET OPERATION CODE
 10041 00002F42 24F0                <1> 	AND	AL,0F0H 		; GET RID OF MODIFIERS
 10042 00002F44 3C20                <1> 	CMP	AL,20H			; 20H-40H IS READ, WRITE, VERIFY
 10043 00002F46 7208                <1> 	JB	short COMMAND3
 10044 00002F48 3C40                <1> 	CMP	AL,40H
 10045 00002F4A 7704                <1> 	JA	short COMMAND3
 10046 00002F4C 804DFE01            <1> 	OR	byte [CMD_BLOCK+6],NO_RETRIES 
 10047                              <1> 					; VALID OPERATION FOR RETRY SUPPRESS
 10048                              <1> COMMAND3:
 10049 00002F50 8A443DF8            <1> 	MOV	AL,[CMD_BLOCK+eDI]	; GET THE COMMAND STRING BYTE
 10050 00002F54 EE                  <1> 	OUT	DX,AL			; GIVE IT TO CONTROLLER
 10051                              <1> 	IODELAY
 10052 00002F55 EB00                <2>  jmp short $+2
 10053 00002F57 EB00                <2>  jmp short $+2
 10054 00002F59 47                  <1> 	INC	eDI			; NEXT BYTE IN COMMAND BLOCK
 10055 00002F5A 6642                <1> 	INC	DX			; NEXT DISK ADAPTER REGISTER
 10056 00002F5C 6683FF07            <1> 	cmp	di, 7	; 1/1/2015	; ALL DONE?
 10057 00002F60 75EE                <1> 	JNZ	short COMMAND3		; NO--GO DO NEXT ONE
 10058 00002F62 5F                  <1> 	POP	eDI
 10059 00002F63 C3                  <1> 	RETn				; ZERO FLAG IS SET
 10060                              <1> 
 10061                              <1> ;CMD_TIMEOUT:
 10062                              <1> ;	MOV	byte [DISK_STATUS1],BAD_CNTLR
 10063                              <1> ;COMMAND4:
 10064                              <1> ;	POP	BX
 10065                              <1> ;	CMP	[DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10066                              <1> ;	RETn
 10067                              <1> 
 10068                              <1> ;----------------------------------------
 10069                              <1> ;	WAIT FOR INTERRUPT		:
 10070                              <1> ;----------------------------------------
 10071                              <1> ;WAIT:
 10072                              <1> _WAIT:
 10073 00002F64 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
 10074                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
 10075                              <1> 	;CLC
 10076                              <1> 	;MOV	AX,9000H		; DEVICE WAIT INTERRUPT
 10077                              <1> 	;INT	15H
 10078                              <1> 	;JC	WT2			; DEVICE TIMED OUT
 10079                              <1> 	;MOV	BL,DELAY_1		; SET DELAY COUNT
 10080                              <1> 
 10081                              <1> 	;mov	bl, WAIT_HDU_INT_HI
 10082                              <1> 	;; 21/02/2015
 10083                              <1> 	;;mov	bl, WAIT_HDU_INT_HI + 1
 10084                              <1> 	;;mov	cx, WAIT_HDU_INT_LO
 10085 00002F65 B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH
 10086                              <1> 					; (AWARD BIOS -> WAIT_FOR_MEM)
 10087                              <1> ;-----	WAIT LOOP
 10088                              <1> 
 10089                              <1> WT1:	
 10090                              <1> 	;TEST	byte [HF_INT_FLAG],80H	; TEST FOR INTERRUPT
 10091 00002F6A F605[7FBE0000]C0    <1> 	test 	byte [HF_INT_FLAG],0C0h
 10092                              <1> 	;LOOPZ	WT1
 10093 00002F71 7517                <1> 	JNZ	short WT3		; INTERRUPT--LETS GO
 10094                              <1> 	;DEC	BL
 10095                              <1> 	;JNZ	short WT1		; KEEP TRYING FOR A WHILE
 10096                              <1> 
 10097                              <1> WT1_hi:
 10098 00002F73 E461                <1> 	in	al, SYS1 ; 61h (PORT_B)	; wait for lo to hi
 10099 00002F75 A810                <1> 	test	al, 10h			; transition on memory
 10100 00002F77 75FA                <1> 	jnz	short WT1_hi		; refresh.
 10101                              <1> WT1_lo:
 10102 00002F79 E461                <1> 	in	al, SYS1 		; 061h (PORT_B)	
 10103 00002F7B A810                <1> 	test	al, 10h			
 10104 00002F7D 74FA                <1> 	jz	short WT1_lo
 10105 00002F7F E2E9                <1> 	loop	WT1
 10106                              <1> 	;;or	bl, bl
 10107                              <1> 	;;jz	short WT2	
 10108                              <1> 	;;dec	bl
 10109                              <1> 	;;jmp	short WT1
 10110                              <1> 	;dec	bl
 10111                              <1> 	;jnz	short WT1	
 10112                              <1> 
 10113 00002F81 C605[87BE0000]80    <1> WT2:	MOV	byte [DISK_STATUS1],TIME_OUT ; REPORT TIME OUT ERROR
 10114 00002F88 EB0E                <1> 	JMP	SHORT WT4
 10115 00002F8A C605[87BE0000]00    <1> WT3:	MOV	byte [DISK_STATUS1],0
 10116 00002F91 C605[7FBE0000]00    <1> 	MOV	byte [HF_INT_FLAG],0
 10117 00002F98 803D[87BE0000]00    <1> WT4:	CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10118 00002F9F C3                  <1> 	RETn
 10119                              <1> 
 10120                              <1> ;----------------------------------------
 10121                              <1> ;	WAIT FOR CONTROLLER NOT BUSY	:
 10122                              <1> ;----------------------------------------
 10123                              <1> NOT_BUSY:
 10124 00002FA0 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
 10125                              <1> 	;PUSH	eBX
 10126                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
 10127 00002FA1 668B15[B4B80000]    <1> 	mov	DX, [HF_PORT]
 10128 00002FA8 80C207              <1> 	add	dl, 7			; Status port (HF_PORT+7)
 10129                              <1> 	;MOV	BL,DELAY_1
 10130                              <1> 					; wait for 10 seconds
 10131                              <1> 	;mov 	cx, WAIT_HDU_INT_LO	; 1615h
 10132                              <1> 	;;mov 	bl, WAIT_HDU_INT_HI	;   05h
 10133                              <1> 	;mov	bl, WAIT_HDU_INT_HI + 1
 10134 00002FAB B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH  ; 21/02/2015
 10135                              <1> 	;
 10136                              <1> ;;      mov     byte [wait_count], 0    ; Reset wait counter
 10137                              <1> NB1:	
 10138 00002FB0 EC                  <1> 	IN	AL,DX			; CHECK STATUS
 10139                              <1> 	;TEST	AL,ST_BUSY
 10140 00002FB1 2480                <1> 	and	al, ST_BUSY
 10141                              <1> 	;LOOPNZ	NB1
 10142 00002FB3 7410                <1> 	JZ	short NB2		; NOT BUSY--LETS GO
 10143                              <1> 	;DEC	BL			
 10144                              <1> 	;JNZ	short NB1		; KEEP TRYING FOR A WHILE
 10145                              <1> 
 10146 00002FB5 E461                <1> NB1_hi: IN	AL,SYS1			; wait for hi to lo
 10147 00002FB7 A810                <1> 	TEST	AL,010H			; transition on memory
 10148 00002FB9 75FA                <1> 	JNZ	SHORT NB1_hi		; refresh.
 10149 00002FBB E461                <1> NB1_lo: IN	AL,SYS1
 10150 00002FBD A810                <1> 	TEST	AL,010H
 10151 00002FBF 74FA                <1> 	JZ	short NB1_lo
 10152 00002FC1 E2ED                <1> 	LOOP	NB1
 10153                              <1> 	;dec	bl
 10154                              <1> 	;jnz	short NB1
 10155                              <1> 	;
 10156                              <1> ;;      cmp     byte [wait_count], 182  ; 10 seconds (182 timer ticks)
 10157                              <1> ;;	jb	short NB1
 10158                              <1> 	;
 10159                              <1> 	;MOV	[DISK_STATUS1],TIME_OUT	; REPORT TIME OUT ERROR
 10160                              <1> 	;JMP	SHORT NB3
 10161 00002FC3 B080                <1> 	mov	al, TIME_OUT
 10162                              <1> NB2:	
 10163                              <1> 	;MOV	byte [DISK_STATUS1],0
 10164                              <1> ;NB3:	
 10165                              <1> 	;POP	eBX
 10166 00002FC5 A2[87BE0000]        <1> 	mov	[DISK_STATUS1], al	;;; will be set after return
 10167                              <1> 	;CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10168 00002FCA 08C0                <1> 	or	al, al			; (zf = 0 --> timeout)
 10169 00002FCC C3                  <1> 	RETn
 10170                              <1> 
 10171                              <1> ;----------------------------------------
 10172                              <1> ;	WAIT FOR DATA REQUEST		:
 10173                              <1> ;----------------------------------------
 10174                              <1> WAIT_DRQ:
 10175                              <1> 	;MOV	CX,DELAY_3
 10176                              <1> 	;MOV	DX,HF_PORT+7
 10177 00002FCD 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
 10178 00002FD4 80C207              <1> 	add	dl, 7
 10179                              <1> 	;;MOV	bl, WAIT_HDU_DRQ_HI	; 0
 10180                              <1> 	;MOV	cx, WAIT_HDU_DRQ_LO	; 1000 (30 milli seconds)
 10181                              <1> 					; (but it is written as 2000
 10182                              <1> 					; micro seconds in ATORGS.ASM file
 10183                              <1> 					; of Award Bios - 1999, D1A0622)
 10184 00002FD7 B9E8030000          <1> 	mov 	ecx, WAIT_HDU_DRQ_LH ; 21/02/2015 
 10185 00002FDC EC                  <1> WQ_1:	IN	AL,DX			; GET STATUS
 10186 00002FDD A808                <1> 	TEST	AL,ST_DRQ		; WAIT FOR DRQ
 10187 00002FDF 7516                <1> 	JNZ	short WQ_OK
 10188                              <1> 	;LOOP	WQ_1			; KEEP TRYING FOR A SHORT WHILE
 10189                              <1> WQ_hi:	
 10190 00002FE1 E461                <1> 	IN	AL,SYS1			; wait for hi to lo
 10191 00002FE3 A810                <1> 	TEST	AL,010H			; transition on memory
 10192 00002FE5 75FA                <1> 	JNZ	SHORT WQ_hi		; refresh.
 10193 00002FE7 E461                <1> WQ_lo:  IN      AL,SYS1
 10194 00002FE9 A810                <1> 	TEST	AL,010H
 10195 00002FEB 74FA                <1> 	JZ	SHORT WQ_lo
 10196 00002FED E2ED                <1> 	LOOP	WQ_1
 10197                              <1> 
 10198 00002FEF C605[87BE0000]80    <1>         MOV     byte [DISK_STATUS1],TIME_OUT ; ERROR
 10199 00002FF6 F9                  <1> 	STC
 10200                              <1> WQ_OK:
 10201 00002FF7 C3                  <1> 	RETn
 10202                              <1> ;WQ_OK:	;CLC
 10203                              <1> ;	RETn
 10204                              <1> 
 10205                              <1> ;----------------------------------------
 10206                              <1> ;	CHECK FIXED DISK STATUS 	:
 10207                              <1> ;----------------------------------------
 10208                              <1> CHECK_STATUS:
 10209 00002FF8 E813000000          <1> 	CALL	CHECK_ST		; CHECK THE STATUS BYTE
 10210 00002FFD 7509                <1> 	JNZ	short CHECK_S1		; AN ERROR WAS FOUND
 10211 00002FFF A801                <1> 	TEST	AL,ST_ERROR		; WERE THERE ANY OTHER ERRORS
 10212 00003001 7405                <1> 	JZ	short CHECK_S1		; NO ERROR REPORTED
 10213 00003003 E849000000          <1> 	CALL	CHECK_ER		; ERROR REPORTED
 10214                              <1> CHECK_S1:
 10215 00003008 803D[87BE0000]00    <1> 	CMP	byte [DISK_STATUS1],0 	; SET STATUS FOR CALLER
 10216 0000300F C3                  <1> 	RETn
 10217                              <1> 
 10218                              <1> ;----------------------------------------
 10219                              <1> ;	CHECK FIXED DISK STATUS BYTE	:
 10220                              <1> ;----------------------------------------
 10221                              <1> CHECK_ST:
 10222                              <1> 	;MOV	DX,HF_PORT+7		; GET THE STATUS
 10223 00003010 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]
 10224 00003017 80C207              <1> 	add	dl, 7
 10225                              <1> 	
 10226                              <1> 	; 17/02/2016
 10227                              <1> 	;(http://wiki.osdev.org/ATA_PIO_Mode)
 10228                              <1> 	;"delay 400ns to allow drive to set new values of BSY and DRQ"
 10229 0000301A EC                  <1> 	IN	AL,DX
 10230                              <1> 	;in	al, dx ; 100ns
 10231                              <1> 	;in	al, dx ; 100ns
 10232                              <1>  	;in	al, dx ; 100ns
 10233                              <1> 	NEWIODELAY ; 18/02/2016 (AWARD BIOS - 1999, 'CKST' in AHSDK.ASM)
 10234 0000301B E6EB                <2>  out 0ebh,al
 10235                              <1> 	;
 10236 0000301D A2[7DBE0000]        <1> 	MOV	[HF_STATUS],AL
 10237 00003022 B400                <1> 	MOV	AH,0
 10238 00003024 A880                <1> 	TEST	AL,ST_BUSY		; IF STILL BUSY
 10239 00003026 751A                <1> 	JNZ	short CKST_EXIT		;  REPORT OK
 10240 00003028 B4CC                <1> 	MOV	AH,WRITE_FAULT
 10241 0000302A A820                <1> 	TEST	AL,ST_WRT_FLT		; CHECK FOR WRITE FAULT
 10242 0000302C 7514                <1> 	JNZ	short CKST_EXIT
 10243 0000302E B4AA                <1> 	MOV	AH,NOT_RDY
 10244 00003030 A840                <1> 	TEST	AL,ST_READY		; CHECK FOR NOT READY
 10245 00003032 740E                <1> 	JZ	short CKST_EXIT
 10246 00003034 B440                <1> 	MOV	AH,BAD_SEEK
 10247 00003036 A810                <1> 	TEST	AL,ST_SEEK_COMPL	; CHECK FOR SEEK NOT COMPLETE
 10248 00003038 7408                <1> 	JZ	short CKST_EXIT
 10249 0000303A B411                <1> 	MOV	AH,DATA_CORRECTED
 10250 0000303C A804                <1> 	TEST	AL,ST_CORRCTD		; CHECK FOR CORRECTED ECC
 10251 0000303E 7502                <1> 	JNZ	short CKST_EXIT
 10252 00003040 B400                <1> 	MOV	AH,0
 10253                              <1> CKST_EXIT:
 10254 00003042 8825[87BE0000]      <1> 	MOV	[DISK_STATUS1],AH	; SET ERROR FLAG
 10255 00003048 80FC11              <1> 	CMP	AH,DATA_CORRECTED	; KEEP GOING WITH DATA CORRECTED
 10256 0000304B 7403                <1> 	JZ	short CKST_EX1
 10257 0000304D 80FC00              <1> 	CMP	AH,0
 10258                              <1> CKST_EX1:
 10259 00003050 C3                  <1> 	RETn
 10260                              <1> 
 10261                              <1> ;----------------------------------------
 10262                              <1> ;	CHECK FIXED DISK ERROR REGISTER :
 10263                              <1> ;----------------------------------------
 10264                              <1> CHECK_ER:
 10265                              <1> 	;MOV	DX, HF_PORT+1		; GET THE ERROR REGISTER
 10266 00003051 668B15[B4B80000]    <1> 	mov	dx, [HF_PORT]		;
 10267 00003058 FEC2                <1> 	inc	dl
 10268 0000305A EC                  <1> 	IN	AL,DX
 10269 0000305B A2[7EBE0000]        <1> 	MOV	[HF_ERROR],AL
 10270 00003060 53                  <1> 	PUSH	eBX ; 21/02/2015
 10271 00003061 B908000000          <1> 	MOV	eCX,8			; TEST ALL 8 BITS
 10272 00003066 D0E0                <1> CK1:	SHL	AL,1			; MOVE NEXT ERROR BIT TO CARRY
 10273 00003068 7202                <1> 	JC	short CK2		; FOUND THE ERROR
 10274 0000306A E2FA                <1> 	LOOP	CK1			; KEEP TRYING
 10275 0000306C BB[A8B80000]        <1> CK2:	MOV	eBX, ERR_TBL		; COMPUTE ADDRESS OF
 10276 00003071 01CB                <1> 	ADD	eBX,eCX			; ERROR CODE
 10277                              <1> 	;;MOV	AH,BYTE [CS:BX]		; GET ERROR CODE
 10278                              <1> 	;mov	ah, [bx]
 10279 00003073 8A23                <1> 	mov	ah, [ebx] ; 21/02/2015	
 10280 00003075 8825[87BE0000]      <1> CKEX:	MOV	[DISK_STATUS1],AH	; SAVE ERROR CODE
 10281 0000307B 5B                  <1> 	POP	eBX
 10282 0000307C 80FC00              <1> 	CMP	AH,0
 10283 0000307F C3                  <1> 	RETn
 10284                              <1> 
 10285                              <1> ;--------------------------------------------------------
 10286                              <1> ; CHECK_DMA						:
 10287                              <1> ;  -CHECK ES:BX AND # SECTORS TO MAKE SURE THAT IT WILL :
 10288                              <1> ;   FIT WITHOUT SEGMENT OVERFLOW.			:
 10289                              <1> ;  -ES:BX HAS BEEN REVISED TO THE FORMAT SSSS:000X	:
 10290                              <1> ;  -OK IF # SECTORS < 80H (7FH IF LONG READ OR WRITE)	:
 10291                              <1> ;  -OK IF # SECTORS = 80H (7FH) AND BX <= 00H (04H)	:
 10292                              <1> ;  -ERROR OTHERWISE					:
 10293                              <1> ;--------------------------------------------------------
 10294                              <1> CHECK_DMA:
 10295 00003080 6650                <1> 	PUSH	AX			; SAVE REGISTERS
 10296 00003082 66B80080            <1> 	MOV	AX,8000H		; AH = MAX # SECTORS AL = MAX OFFSET
 10297 00003086 F645FE02            <1>         TEST    byte [CMD_BLOCK+6],ECC_MODE
 10298 0000308A 7404                <1> 	JZ	short CKD1
 10299 0000308C 66B8047F            <1> 	MOV	AX,7F04H		; ECC IS 4 MORE BYTES
 10300 00003090 3A65F9              <1> CKD1:	CMP	AH, [CMD_BLOCK+1] 	; NUMBER OF SECTORS
 10301 00003093 7706                <1> 	JA	short CKDOK		; IT WILL FIT
 10302 00003095 7208                <1> 	JB	short CKDERR		; TOO MANY
 10303 00003097 38D8                <1> 	CMP	AL,BL			; CHECK OFFSET ON MAX SECTORS
 10304 00003099 7204                <1> 	JB	short CKDERR		; ERROR
 10305 0000309B F8                  <1> CKDOK:	CLC				; CLEAR CARRY
 10306 0000309C 6658                <1> 	POP	AX
 10307 0000309E C3                  <1> 	RETn				; NORMAL RETURN
 10308 0000309F F9                  <1> CKDERR: STC				; INDICATE ERROR
 10309 000030A0 C605[87BE0000]09    <1>         MOV     byte [DISK_STATUS1],DMA_BOUNDARY
 10310 000030A7 6658                <1> 	POP	AX
 10311 000030A9 C3                  <1> 	RETn
 10312                              <1> 
 10313                              <1> ;----------------------------------------
 10314                              <1> ;	SET UP ES:BX-> DISK PARMS	:
 10315                              <1> ;----------------------------------------
 10316                              <1> 					
 10317                              <1> ; INPUT -> DL = 0 based drive number
 10318                              <1> ; OUTPUT -> ES:BX = disk parameter table address
 10319                              <1> 
 10320                              <1> GET_VEC:
 10321                              <1> 	;SUB	AX,AX			; GET DISK PARAMETER ADDRESS
 10322                              <1> 	;MOV	ES,AX
 10323                              <1> 	;TEST	DL,1
 10324                              <1> 	;JZ	short GV_0
 10325                              <1> ;	LES	BX,[HF1_TBL_VEC] 	; ES:BX -> DRIVE PARAMETERS
 10326                              <1> ;	JMP	SHORT GV_EXIT
 10327                              <1> ;GV_0:
 10328                              <1> ;	LES	BX,[HF_TBL_VEC]		; ES:BX -> DRIVE PARAMETERS
 10329                              <1> ;
 10330                              <1> 	;xor	bh, bh
 10331 000030AA 31DB                <1> 	xor	ebx, ebx
 10332 000030AC 88D3                <1> 	mov	bl, dl
 10333                              <1> 	;;02/01/2015
 10334                              <1> 	;;shl	bl, 1			; port address offset
 10335                              <1> 	;;mov	ax, [bx+hd_ports]	; Base port address (1F0h, 170h)
 10336                              <1> 	;;shl	bl, 1			; dpt pointer offset
 10337 000030AE C0E302              <1> 	shl	bl, 2	;;
 10338                              <1> 	;add	bx, HF_TBL_VEC		; Disk parameter table pointer
 10339 000030B1 81C3[8CBE0000]      <1> 	add	ebx, HF_TBL_VEC ; 21/02/2015
 10340                              <1> 	;push	word [bx+2]		; dpt segment
 10341                              <1> 	;pop	es
 10342                              <1> 	;mov	bx, [bx]		; dpt offset
 10343 000030B7 8B1B                <1> 	mov	ebx, [ebx]		
 10344                              <1> ;GV_EXIT:
 10345 000030B9 C3                  <1> 	RETn
 10346                              <1> 
 10347                              <1> hdc1_int: ; 21/02/2015
 10348                              <1> ;--- HARDWARE INT 76H -- ( IRQ LEVEL  14 ) ----------------------
 10349                              <1> ;								:
 10350                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
 10351                              <1> ;								:
 10352                              <1> ;----------------------------------------------------------------
 10353                              <1> 
 10354                              <1> ; 22/12/2014
 10355                              <1> ; IBM PC-XT Model 286 System BIOS Source Code - DISK.ASM (HD_INT)
 10356                              <1> ;	 '11/15/85'
 10357                              <1> ; AWARD BIOS 1999 (D1A0622) 
 10358                              <1> ;	Source Code - ATORGS.ASM (INT_HDISK, INT_HDISK1)
 10359                              <1> 
 10360                              <1> ;int_76h:
 10361                              <1> HD_INT:
 10362 000030BA 6650                <1> 	PUSH	AX
 10363 000030BC 1E                  <1> 	PUSH	DS
 10364                              <1> 	;CALL	DDS
 10365                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
 10366 000030BD 66B81000            <1> 	mov	ax, KDATA
 10367 000030C1 8ED8                <1> 	mov 	ds, ax
 10368                              <1> 	;
 10369                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
 10370                              <1>         ;mov     byte [CS:HF_INT_FLAG], 0FFh
 10371 000030C3 C605[7FBE0000]FF    <1> 	mov	byte [HF_INT_FLAG], 0FFh
 10372                              <1> 	;
 10373 000030CA 6652                <1> 	push	dx
 10374 000030CC 66BAF701            <1> 	mov	dx, HDC1_BASEPORT+7	; Status Register (1F7h)
 10375                              <1> 					; Clear Controller
 10376                              <1> Clear_IRQ1415:				; (Award BIOS - 1999)
 10377 000030D0 EC                  <1> 	in	al, dx			;
 10378 000030D1 665A                <1> 	pop	dx
 10379                              <1> 	NEWIODELAY
 10380 000030D3 E6EB                <2>  out 0ebh,al
 10381                              <1> 	;
 10382 000030D5 B020                <1> 	MOV	AL,EOI			; NON-SPECIFIC END OF INTERRUPT
 10383 000030D7 E6A0                <1> 	OUT	INTB00,AL		; FOR CONTROLLER #2
 10384                              <1> 	;JMP	$+2			; WAIT
 10385                              <1> 	NEWIODELAY
 10386 000030D9 E6EB                <2>  out 0ebh,al
 10387 000030DB E620                <1> 	OUT	INTA00,AL		; FOR CONTROLLER #1
 10388 000030DD 1F                  <1> 	POP	DS
 10389                              <1> 	;STI				; RE-ENABLE INTERRUPTS
 10390                              <1> 	;MOV	AX,9100H		; DEVICE POST
 10391                              <1> 	;INT	15H			;  INTERRUPT
 10392                              <1> irq15_iret: ; 25/02/2015
 10393 000030DE 6658                <1> 	POP	AX
 10394 000030E0 CF                  <1> 	IRETd				; RETURN FROM INTERRUPT
 10395                              <1> 
 10396                              <1> hdc2_int: ; 21/02/2015
 10397                              <1> ;++++ HARDWARE INT 77H ++ ( IRQ LEVEL  15 ) +++++++++++++++++++++
 10398                              <1> ;								:
 10399                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
 10400                              <1> ;								:
 10401                              <1> ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 10402                              <1> 
 10403                              <1> ;int_77h:
 10404                              <1> HD1_INT:
 10405 000030E1 6650                <1> 	PUSH	AX
 10406                              <1> 	; Check if that is a spurious IRQ (from slave PIC)
 10407                              <1> 	; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
 10408 000030E3 B00B                <1> 	mov	al, 0Bh  ; In-Service Register
 10409 000030E5 E6A0                <1> 	out	0A0h, al
 10410 000030E7 EB00                <1>         jmp short $+2
 10411 000030E9 EB00                <1> 	jmp short $+2
 10412 000030EB E4A0                <1> 	in	al, 0A0h
 10413 000030ED 2480                <1> 	and 	al, 80h ; bit 7 (is it real IRQ 15 or fake?)
 10414 000030EF 74ED                <1> 	jz	short irq15_iret ; Fake (spurious)IRQ, do not send EOI)
 10415                              <1> 	;
 10416 000030F1 1E                  <1> 	PUSH	DS
 10417                              <1> 	;CALL	DDS
 10418                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
 10419 000030F2 66B81000            <1> 	mov	ax, KDATA
 10420 000030F6 8ED8                <1> 	mov 	ds, ax
 10421                              <1> 	;
 10422                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
 10423                              <1>         ;or      byte [CS:HF_INT_FLAG],0C0h 
 10424 000030F8 800D[7FBE0000]C0    <1> 	or	byte [HF_INT_FLAG], 0C0h
 10425                              <1> 	;
 10426 000030FF 6652                <1> 	push	dx
 10427 00003101 66BA7701            <1> 	mov	dx, HDC2_BASEPORT+7	; Status Register (177h)
 10428                              <1> 					; Clear Controller (Award BIOS 1999)
 10429 00003105 EBC9                <1> 	jmp	short Clear_IRQ1415
 10430                              <1> 
 10431                              <1> 
 10432                              <1> ;%include 'diskdata.inc' ; 11/03/2015
 10433                              <1> ;%include 'diskbss.inc' ; 11/03/2015
 10434                              <1> 
 10435                              <1> 
 10436                              <1> ;////////////////////////////////////////////////////////////////////
 10437                              <1> ;; END OF DISK I/O SYTEM ///
 10438                                  %include 'memory.s'  ; 09/03/2015
 10439                              <1> ; ****************************************************************************
 10440                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - memory.s
 10441                              <1> ; ----------------------------------------------------------------------------
 10442                              <1> ; Last Update: 14/03/2016
 10443                              <1> ; ----------------------------------------------------------------------------
 10444                              <1> ; Beginning: 24/01/2016
 10445                              <1> ; ----------------------------------------------------------------------------
 10446                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 10447                              <1> ; ----------------------------------------------------------------------------
 10448                              <1> ; Turkish Rational DOS
 10449                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 10450                              <1> ;
 10451                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 10452                              <1> ; memory.inc (18/10/2015)
 10453                              <1> ; ****************************************************************************
 10454                              <1> 
 10455                              <1> ; MEMORY.ASM - Retro UNIX 386 v1 MEMORY MANAGEMENT FUNCTIONS (PROCEDURES)
 10456                              <1> ; Retro UNIX 386 v1 Kernel (unix386.s, v0.2.0.14) - MEMORY.INC
 10457                              <1> ; Last Modification: 18/10/2015
 10458                              <1> 
 10459                              <1> ; ///////// MEMORY MANAGEMENT FUNCTIONS (PROCEDURES) ///////////////
 10460                              <1> 
 10461                              <1> ;;04/11/2014 (unix386.s)	
 10462                              <1> ;PDE_A_PRESENT	equ	1		; Present flag for PDE
 10463                              <1> ;PDE_A_WRITE	equ 	2		; Writable (write permission) flag
 10464                              <1> ;PDE_A_USER	equ	4		; User (non-system/kernel) page flag
 10465                              <1> ;;
 10466                              <1> ;PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
 10467                              <1> ;PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
 10468                              <1> ;PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
 10469                              <1> ;PTE_A_ACCESS   equ	32		; Accessed flag (bit 5) ; 09/03/2015
 10470                              <1> 
 10471                              <1> ; 27/04/2015
 10472                              <1> ; 09/03/2015
 10473                              <1> PAGE_SIZE 	equ 4096		; page size in bytes
 10474                              <1> PAGE_SHIFT 	equ 12			; page table shift count
 10475                              <1> PAGE_D_SHIFT 	equ 22	; 12 + 10	; page directory shift count
 10476                              <1> PAGE_OFF	equ 0FFFh		; 12 bit byte offset in page frame
 10477                              <1> PTE_MASK 	equ 03FFh		; page table entry mask
 10478                              <1> PTE_DUPLICATED  equ 200h		; duplicated page sign (AVL bit 0)
 10479                              <1> PDE_A_CLEAR	equ 0F000h		; to clear PDE attribute bits
 10480                              <1> PTE_A_CLEAR	equ 0F000h		; to clear PTE attribute bits
 10481                              <1> LOGIC_SECT_SIZE equ 512			; logical sector size
 10482                              <1> ERR_MAJOR_PF	equ 0E0h		; major error: page fault
 10483                              <1> ERR_MINOR_IM	equ 1			; insufficient (out of) memory
 10484                              <1> ERR_MINOR_DSK	equ 2			; disk read/write error
 10485                              <1> ERR_MINOR_PV	equ 3			; protection violation
 10486                              <1> SWP_DISK_READ_ERR equ 4
 10487                              <1> SWP_DISK_NOT_PRESENT_ERR equ 5
 10488                              <1> SWP_SECTOR_NOT_PRESENT_ERR equ 6
 10489                              <1> SWP_NO_FREE_SPACE_ERR equ 7
 10490                              <1> SWP_DISK_WRITE_ERR equ 8
 10491                              <1> SWP_NO_PAGE_TO_SWAP_ERR equ 9
 10492                              <1> PTE_A_ACCESS_BIT equ 5  ; Bit 5 (accessed flag)        
 10493                              <1> SECTOR_SHIFT    equ 3   ; sector shift (to convert page block number)
 10494                              <1> 
 10495                              <1> ;
 10496                              <1> ;; Retro Unix 386 v1 - paging method/principles
 10497                              <1> ;;
 10498                              <1> ;; 10/10/2014
 10499                              <1> ;; RETRO UNIX 386 v1 - PAGING METHOD/PRINCIPLES
 10500                              <1> ;;
 10501                              <1> ;; KERNEL PAGE MAP: 1 to 1 physical memory page map
 10502                              <1> ;;	(virtual address = physical address)
 10503                              <1> ;; KERNEL PAGE TABLES:
 10504                              <1> ;;	Kernel page directory and all page tables are
 10505                              <1> ;;	on memory as initialized, as equal to physical memory
 10506                              <1> ;;	layout. Kernel pages can/must not be swapped out/in.
 10507                              <1> ;;
 10508                              <1> ;;	what for: User pages may be swapped out, when accessing
 10509                              <1> ;;	a page in kernel/system mode, if it would be swapped out,
 10510                              <1> ;;	kernel would have to swap it in! But it is also may be
 10511                              <1> ;;	in use by a user process. (In system/kernel mode
 10512                              <1> ;;	kernel can access all memory pages even if they are
 10513                              <1> ;;	reserved/allocated for user processes. Swap out/in would
 10514                              <1> ;;	cause conflicts.) 
 10515                              <1> ;;	
 10516                              <1> ;;	As result of these conditions,
 10517                              <1> ;;	all kernel pages must be initialized as equal to 
 10518                              <1> ;;	physical layout for preventing page faults. 
 10519                              <1> ;;	Also, calling "allocate page" procedure after
 10520                              <1> ;;	a page fault can cause another page fault (double fault)
 10521                              <1> ;;	if all kernel page tables would not be initialized.
 10522                              <1> ;;
 10523                              <1> ;;	[first_page] = Beginning of users space, as offset to 
 10524                              <1> ;;	memory allocation table. (double word aligned)
 10525                              <1> ;;
 10526                              <1> ;;	[next_page] = first/next free space to be searched
 10527                              <1> ;;	as offset to memory allocation table. (dw aligned)
 10528                              <1> ;;
 10529                              <1> ;;	[last_page] = End of memory (users space), as offset
 10530                              <1> ;;	to memory allocation table. (double word aligned)
 10531                              <1> ;;
 10532                              <1> ;; USER PAGE TABLES:
 10533                              <1> ;;	Demand paging (& 'copy on write' allocation method) ...
 10534                              <1> ;;		'ready only' marked copies of the 
 10535                              <1> ;;		parent process's page table entries (for
 10536                              <1> ;;		same physical memory).
 10537                              <1> ;;		(A page will be copied to a new page after
 10538                              <1> ;;		 if it causes R/W page fault.)
 10539                              <1> ;;
 10540                              <1> ;;	Every user process has own (different)
 10541                              <1> ;;	page directory and page tables.	
 10542                              <1> ;;
 10543                              <1> ;;	Code starts at virtual address 0, always.
 10544                              <1> ;;	(Initial value of EIP is 0 in user mode.)
 10545                              <1> ;;	(Programs can be written/developed as simple
 10546                              <1> ;;	 flat memory programs.)
 10547                              <1> ;;
 10548                              <1> ;; MEMORY ALLOCATION STRATEGY:
 10549                              <1> ;;	Memory page will be allocated by kernel only 
 10550                              <1> ;;		(in kernel/system mode only).
 10551                              <1> ;;	* After a
 10552                              <1> ;;	  - 'not present' page fault
 10553                              <1> ;;	  - 'writing attempt on read only page' page fault 	 	
 10554                              <1> ;;	* For loading (opening, reading) a file or disk/drive
 10555                              <1> ;;	* As responce to 'allocate additional memory blocks' 
 10556                              <1> ;;	  request by running process.
 10557                              <1> ;;	* While creating a process, allocating a new buffer,
 10558                              <1> ;;	  new page tables etc.
 10559                              <1> ;;
 10560                              <1> ;;	At first,
 10561                              <1> ;;	- 'allocate page' procedure will be called;
 10562                              <1> ;,	   if it will return with a valid (>0) physical address
 10563                              <1> ;;	   (that means the relevant M.A.T. bit has been RESET)	
 10564                              <1> ;;	   relevant memory page/block will be cleared (zeroed).
 10565                              <1> ;;	- 'allocate page' will be called for allocating page
 10566                              <1> ;;	   directory, page table and running space (data/code).
 10567                              <1> ;;	- every successful 'allocate page' call will decrease
 10568                              <1> ;;	  'free_pages' count (pointer).
 10569                              <1> ;;	- 'out of (insufficient) memory error' will be returned
 10570                              <1> ;;	  if 'free_pages' points to a ZERO.
 10571                              <1> ;;	- swapping out and swapping in (if it is not a new page)
 10572                              <1> ;;	  procedures will be called as responce to 'out of memory'
 10573                              <1> ;;	  error except errors caused by attribute conflicts.
 10574                              <1> ;;	 (swapper functions)	 
 10575                              <1> ;;					
 10576                              <1> ;;	At second,
 10577                              <1> ;;	- page directory entry will be updated then page table
 10578                              <1> ;;	  entry will be updated.		
 10579                              <1> ;;
 10580                              <1> ;; MEMORY ALLOCATION TABLE FORMAT:
 10581                              <1> ;;	- M.A.T. has a size according to available memory as
 10582                              <1> ;;	  follows:
 10583                              <1> ;;		  - 1 (allocation) bit per 1 page (4096 bytes)
 10584                              <1> ;;		  - a bit with value of 0 means allocated page
 10585                              <1> ;;		  - a bit with value of 1 means a free page
 10586                              <1> ;,	- 'free_pages' pointer holds count of free pages
 10587                              <1> ;;	  depending on M.A.T.
 10588                              <1> ;;		(NOTE: Free page count will not be checked
 10589                              <1> ;;		again -on M.A.T.- after initialization. 
 10590                              <1> ;;		Kernel will trust on initial count.)
 10591                              <1> ;,	- 'free_pages' count will be decreased by allocation
 10592                              <1> ;;	  and it will be increased by deallocation procedures.
 10593                              <1> ;;	
 10594                              <1> ;;	- Available memory will be calculated during
 10595                              <1> ;;	  the kernel's initialization stage (in real mode).
 10596                              <1> ;;	  Memory allocation table and kernel page tables 
 10597                              <1> ;;	  will be formatted/sized as result of available
 10598                              <1> ;;	  memory calculation before paging is enabled.
 10599                              <1> ;;
 10600                              <1> ;; For 4GB Available/Present Memory: (max. possible memory size)
 10601                              <1> ;;	- Memory Allocation Table size will be 128 KB.
 10602                              <1> ;;	- Memory allocation for kernel page directory size 
 10603                              <1> ;;	  is always 4 KB. (in addition to total allocation size
 10604                              <1> ;;	  for page tables)
 10605                              <1> ;;	- Memory allocation for kernel page tables (1024 tables)
 10606                              <1> ;;	  is 4 MB (1024*4*1024 bytes).
 10607                              <1> ;;	- User (available) space will be started 
 10608                              <1> ;;	  at 6th MB of the memory (after 1MB+4MB).
 10609                              <1> ;;	- The first 640 KB is for kernel's itself plus
 10610                              <1> ;;	  memory allocation table and kernel's page directory
 10611                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
 10612                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
 10613                              <1> ;; 	  for buffers.
 10614                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
 10615                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
 10616                              <1> ;;	- Kernel page tables start at 100000h (2nd MB)
 10617                              <1> ;;
 10618                              <1> ;; For 1GB Available Memory:
 10619                              <1> ;;	- Memory Allocation Table size will be 32 KB.
 10620                              <1> ;;	- Memory allocation for kernel page directory size 
 10621                              <1> ;;	  is always 4 KB. (in addition to total allocation size
 10622                              <1> ;;	  for page tables)
 10623                              <1> ;;	- Memory allocation for kernel page tables (256 tables)
 10624                              <1> ;;	  is 1 MB (256*4*1024 bytes).
 10625                              <1> ;;	- User (available) space will be started 
 10626                              <1> ;;	  at 3th MB of the memory (after 1MB+1MB).
 10627                              <1> ;;	- The first 640 KB is for kernel's itself plus
 10628                              <1> ;;	  memory allocation table and kernel's page directory
 10629                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
 10630                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
 10631                              <1> ;; 	  for buffers.
 10632                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
 10633                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
 10634                              <1> ;;	- Kernel page tables start at 100000h (2nd MB).	
 10635                              <1> ;;
 10636                              <1> ;;
 10637                              <1> 
 10638                              <1> 
 10639                              <1> ;;************************************************************************************
 10640                              <1> ;; 
 10641                              <1> ;; RETRO UNIX 386 v1 - Paging (Method for Copy On Write paging principle)
 10642                              <1> ;; DEMAND PAGING - PARENT&CHILD PAGE TABLE DUPLICATION PRINCIPLES (23/04/2015)
 10643                              <1> 
 10644                              <1> ;; Main factor: "sys fork" system call 
 10645                              <1> ;;	
 10646                              <1> ;; 		FORK
 10647                              <1> ;;                      |----> parent - duplicated PTEs, read only pages
 10648                              <1> ;;  writable pages ---->|
 10649                              <1> ;;                      |----> child - duplicated PTEs, read only pages
 10650                              <1> ;; 
 10651                              <1> ;; AVL bit (0) of Page Table Entry is used as duplication sign 
 10652                              <1> ;; 
 10653                              <1> ;; AVL Bit 0 [PTE Bit 9] = 'Duplicated PTE belongs to child' sign/flag (if it is set)
 10654                              <1> ;; Note: Dirty bit (PTE bit 6) may be used instead of AVL bit 0 (PTE bit 9)
 10655                              <1> ;;       -while R/W bit is 0-. 
 10656                              <1> ;; 
 10657                              <1> ;; Duplicate page tables with writable pages (the 1st sys fork in the process):
 10658                              <1> ;; # Parent's Page Table Entries are updated to point same pages as read only, 
 10659                              <1> ;;   as duplicated PTE bit  -AVL bit 0, PTE bit 9- are reset/clear.
 10660                              <1> ;; # Then Parent's Page Table is copied to Child's Page Table.
 10661                              <1> ;; # Child's Page Table Entries are updated as duplicated child bit
 10662                              <1> ;;   -AVL bit 0, PTE bit 9- is set.	  
 10663                              <1> ;; 
 10664                              <1> ;; Duplicate page tables with read only pages (several sys fork system calls):
 10665                              <1> ;; # Parent's read only pages are copied to new child pages. 
 10666                              <1> ;;   Parent's PTE attributes are not changed.
 10667                              <1> ;;   (Because, there is another parent-child fork before this fork! We must not
 10668                              <1> ;;    destroy/mix previous fork result).
 10669                              <1> ;; # Child's Page Table Entries (which are corresponding to Parent's 
 10670                              <1> ;;   read only pages) are set as writable (while duplicated PTE bit is clear). 
 10671                              <1> ;; # Parent's PTEs with writable page attribute are updated to point same pages 
 10672                              <1> ;;   as read only, (while) duplicated PTE bit is reset (clear).
 10673                              <1> ;; # Parent's Page Table Entries (with writable page attribute) are duplicated 
 10674                              <1> ;;   as Child's Page Table Entries without copying actual page.
 10675                              <1> ;; # Child 's Page Table Entries (which are corresponding to Parent's writable 
 10676                              <1> ;;   pages) are updated as duplicated PTE bit (AVL bit 0, PTE bit 9- is set.
 10677                              <1> ;; 
 10678                              <1> ;; !? WHAT FOR (duplication after duplication):
 10679                              <1> ;; In UNIX method for sys fork (a typical 'fork' application in /etc/init)
 10680                              <1> ;; program/executable code continues from specified location as child process, 
 10681                              <1> ;; returns back previous code location as parent process, every child after 
 10682                              <1> ;; every sys fork uses last image of code and data just prior the fork.
 10683                              <1> ;; Even if the parent code changes data, the child will not see the changed data 
 10684                              <1> ;; after the fork. In Retro UNIX 8086 v1, parent's process segment (32KB)
 10685                              <1> ;; was copied to child's process segment (all of code and data) according to
 10686                              <1> ;; original UNIX v1 which copies all of parent process code and data -core- 
 10687                              <1> ;; to child space -core- but swaps that core image -of child- on to disk.
 10688                              <1> ;; If I (Erdogan Tan) would use a method of to copy parent's core
 10689                              <1> ;; (complete running image of parent process) to the child process; 
 10690                              <1> ;; for big sizes, i would force Retro UNIX 386 v1 to spend many memory pages 
 10691                              <1> ;; and times only for a sys fork. (It would excessive reservation for sys fork,
 10692                              <1> ;; because sys fork usually is prior to sys exec; sys exec always establishes
 10693                              <1> ;; a new/fresh core -running space-, by clearing all code/data content). 
 10694                              <1> ;; 'Read Only' page flag ensures page fault handler is needed only for a few write
 10695                              <1> ;; attempts between sys fork and sys exec, not more... (I say so by thinking 
 10696                              <1> ;; of "/etc/init" content, specially.) sys exec will clear page tables and
 10697                              <1> ;; new/fresh pages will be used to load and run new executable/program.
 10698                              <1> ;; That is what for i have preferred "copy on write", "duplication" method
 10699                              <1> ;; for sharing same read only pages between parent and child processes.
 10700                              <1> ;; That is a pitty i have to use new private flag (AVL bit 0, "duplicated PTE 
 10701                              <1> ;; belongs to child" sign) for cooperation on duplicated pages between a parent 
 10702                              <1> ;; and it's child processes; otherwise parent process would destroy data belongs
 10703                              <1> ;; to its child or vice versa; or some pages would remain unclaimed 
 10704                              <1> ;; -deallocation problem-.
 10705                              <1> ;; Note: to prevent conflicts, read only pages must not be swapped out... 
 10706                              <1> ;; 
 10707                              <1> ;; WHEN PARENT TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
 10708                              <1> ;; # Page fault handler will do those:
 10709                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
 10710                              <1> ;;   - If it is reset/clear, there is a child uses same page.
 10711                              <1> ;;   - Parent's read only page -previous page- is copied to a new writable page. 
 10712                              <1> ;;   - Parent's PTE is updated as writable page, as unique page (AVL=0)
 10713                              <1> ;;   - (Page fault handler whill check this PTE later, if child process causes to
 10714                              <1> ;;     page fault due to write attempt on read only page. Of course, the previous 
 10715                              <1> ;;     read only page will be converted to writable and unique page which belongs
 10716                              <1> ;;     to child process.)	
 10717                              <1> ;; WHEN CHILD TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
 10718                              <1> ;; # Page fault handler will do those:
 10719                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
 10720                              <1> ;;   - If it is set, there is a parent uses -or was using- same page.
 10721                              <1> ;;   - Same PTE address within parent's page table is checked if it has same page
 10722                              <1> ;;     address or not. 
 10723                              <1> ;;   - If parent's PTE has same address, child will continue with a new writable page.
 10724                              <1> ;;     Parent's PTE will point to same (previous) page as writable, unique (AVL=0).	
 10725                              <1> ;;   - If parent's PTE has different address, child will continue with it's 
 10726                              <1> ;;     own/same page but read only flag (0) will be changed to writable flag (1) and
 10727                              <1> ;;     'duplicated PTE (belongs to child)' flag/sign will be cleared/reset. 	  	
 10728                              <1> ;; 
 10729                              <1> ;; NOTE: When a child process is terminated, read only flags of parent's page tables
 10730                              <1> ;;       will be set as writable (and unique) in case of child process was using 
 10731                              <1> ;;       same pages with duplicated child PTE sign... Depending on sys fork and 
 10732                              <1> ;;       duplication method details, it is not possible multiple child processes
 10733                              <1> ;;       were using same page with duplicated PTEs.
 10734                              <1> ;; 
 10735                              <1> ;;************************************************************************************   
 10736                              <1> 
 10737                              <1> ;; 08/10/2014
 10738                              <1> ;; 11/09/2014 - Retro UNIX 386 v1 PAGING (further) draft
 10739                              <1> ;;		by Erdogan Tan (Based on KolibriOS 'memory.inc')
 10740                              <1> 
 10741                              <1> ;; 'allocate_page' code is derived and modified from KolibriOS
 10742                              <1> ;; 'alloc_page' procedure in 'memory.inc' 
 10743                              <1> ;; (25/08/2014, Revision: 5057) file 
 10744                              <1> ;; by KolibriOS Team (2004-2012)
 10745                              <1> 
 10746                              <1> allocate_page:
 10747                              <1> 	; 01/07/2015
 10748                              <1> 	; 05/05/2015
 10749                              <1> 	; 30/04/2015
 10750                              <1> 	; 16/10/2014
 10751                              <1> 	; 08/10/2014
 10752                              <1> 	; 09/09/2014 (Retro UNIX 386 v1 - beginning)
 10753                              <1> 	;
 10754                              <1> 	; INPUT -> none
 10755                              <1> 	;
 10756                              <1> 	; OUTPUT ->
 10757                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 10758                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is RESET)
 10759                              <1> 	;
 10760                              <1> 	;	CF = 1 and EAX = 0 
 10761                              <1> 	; 		   if there is not a free page to be allocated	
 10762                              <1> 	;
 10763                              <1> 	; Modified Registers -> none (except EAX)
 10764                              <1> 	;
 10765 00003107 A1[F0BD0000]        <1> 	mov	eax, [free_pages]
 10766 0000310C 21C0                <1> 	and	eax, eax
 10767 0000310E 7438                <1> 	jz	short out_of_memory
 10768                              <1> 	;
 10769 00003110 53                  <1> 	push	ebx
 10770 00003111 51                  <1> 	push	ecx
 10771                              <1> 	;
 10772 00003112 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table offset
 10773 00003117 89D9                <1> 	mov	ecx, ebx
 10774                              <1>  				     ; NOTE: 32 (first_page) is initial
 10775                              <1> 				     ; value of [next_page].
 10776                              <1> 				     ; It points to the first available
 10777                              <1> 				     ; page block for users (ring 3) ...	
 10778                              <1> 				     ; (MAT offset 32 = 1024/32)	
 10779                              <1> 				     ; (at the of the first 4 MB)		
 10780 00003119 031D[F4BD0000]      <1> 	add	ebx, [next_page] ; Free page searching starts from here
 10781                              <1> 				 ; next_free_page >> 5
 10782 0000311F 030D[F8BD0000]      <1> 	add	ecx, [last_page] ; Free page searching ends here
 10783                              <1> 				 ; (total_pages - 1) >> 5
 10784                              <1> al_p_scan:
 10785 00003125 39CB                <1> 	cmp	ebx, ecx
 10786 00003127 770A                <1> 	ja	short al_p_notfound
 10787                              <1> 	;
 10788                              <1> 	; 01/07/2015
 10789                              <1> 	; AMD64 Architecture Programmers Manual
 10790                              <1> 	; Volume 3:
 10791                              <1> 	; General-Purpose and System Instructions
 10792                              <1> 	;
 10793                              <1> 	; BSF - Bit Scan Forward
 10794                              <1> 	;
 10795                              <1> 	;   Searches the value in a register or a memory location
 10796                              <1> 	;   (second operand) for the least-significant set bit. 
 10797                              <1> 	;   If a set bit is found, the instruction clears the zero flag (ZF)
 10798                              <1> 	;   and stores the index of the least-significant set bit in a destination
 10799                              <1> 	;   register (first operand). If the second operand contains 0, 
 10800                              <1> 	;   the instruction sets ZF to 1 and does not change the contents of the 
 10801                              <1> 	;   destination register. The bit index is an unsigned offset from bit 0 
 10802                              <1> 	;   of the searched value
 10803                              <1> 	;
 10804 00003129 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
 10805                              <1> 			   ; Clear ZF if a bit is found set (1) and 
 10806                              <1> 			   ; loads the destination with an index to
 10807                              <1> 			   ; first set bit. (0 -> 31) 
 10808                              <1> 			   ; Sets ZF to 1 if no bits are found set.
 10809 0000312C 7525                <1> 	jnz	short al_p_found ; ZF = 0 -> a free page has been found
 10810                              <1> 			 ;
 10811                              <1> 			 ; NOTE:  a Memory Allocation Table bit 
 10812                              <1> 			 ;	  with value of 1 means 
 10813                              <1> 			 ;	  the corresponding page is free 
 10814                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
 10815 0000312E 83C304              <1> 	add	ebx, 4
 10816                              <1> 			 ; We return back for searching next page block
 10817                              <1> 			 ; NOTE: [free_pages] is not ZERO; so, 
 10818                              <1> 			 ;	 we always will find at least 1 free page here.
 10819 00003131 EBF2                <1>         jmp     short al_p_scan
 10820                              <1> 	;
 10821                              <1> al_p_notfound:
 10822 00003133 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
 10823 00003139 890D[F4BD0000]      <1> 	mov	[next_page], ecx ; next/first free page = last page 
 10824                              <1> 				 ; (deallocate_page procedure will change it)
 10825 0000313F 31C0                <1> 	xor	eax, eax
 10826 00003141 A3[F0BD0000]        <1> 	mov	[free_pages], eax ; 0
 10827 00003146 59                  <1> 	pop	ecx
 10828 00003147 5B                  <1> 	pop	ebx
 10829                              <1> 	;
 10830                              <1> out_of_memory:
 10831 00003148 E857040000          <1> 	call	swap_out
 10832 0000314D 7325                <1> 	jnc	short al_p_ok  ; [free_pages] = 0, re-allocation by swap_out
 10833                              <1> 	;
 10834 0000314F 29C0                <1> 	sub 	eax, eax ; 0
 10835 00003151 F9                  <1> 	stc
 10836 00003152 C3                  <1> 	retn
 10837                              <1> 
 10838                              <1> al_p_found:
 10839 00003153 89D9                <1> 	mov	ecx, ebx
 10840 00003155 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
 10841 0000315B 890D[F4BD0000]      <1> 	mov	[next_page], ecx ; Set first free page searching start
 10842                              <1> 				 ; address/offset (to the next)
 10843 00003161 FF0D[F0BD0000]      <1>         dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
 10844                              <1> 	;
 10845 00003167 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 10846                              <1> 				 ; is copied into the Carry Flag and then cleared
 10847                              <1> 				 ; in the destination.
 10848                              <1> 				 ;
 10849                              <1> 				 ; Reset the bit which is corresponding to the 
 10850                              <1> 				 ; (just) allocated page.
 10851                              <1> 	; 01/07/2015 (4*8 = 32, 1 allocation byte = 8 pages)	
 10852 0000316A C1E103              <1> 	shl	ecx, 3		 ; (page block offset * 32) + page index
 10853 0000316D 01C8                <1> 	add	eax, ecx	 ; = page number
 10854 0000316F C1E00C              <1> 	shl	eax, 12		 ; physical address of the page (flat/real value)
 10855                              <1> 	; EAX = physical address of memory page
 10856                              <1> 	;
 10857                              <1> 	; NOTE: The relevant page directory and page table entry will be updated
 10858                              <1> 	;       according to this EAX value...
 10859 00003172 59                  <1> 	pop	ecx
 10860 00003173 5B                  <1> 	pop	ebx
 10861                              <1> al_p_ok:
 10862 00003174 C3                  <1> 	retn
 10863                              <1> 
 10864                              <1> 
 10865                              <1> make_page_dir:
 10866                              <1> 	; 18/04/2015
 10867                              <1> 	; 12/04/2015
 10868                              <1> 	; 23/10/2014
 10869                              <1> 	; 16/10/2014
 10870                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10871                              <1> 	;
 10872                              <1> 	; INPUT ->
 10873                              <1> 	;	none
 10874                              <1> 	; OUTPUT ->
 10875                              <1> 	;	(EAX = 0)
 10876                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10877                              <1> 	;	cf = 0 ->
 10878                              <1> 	;	u.pgdir = page directory (physical) address of the current
 10879                              <1> 	;		  process/user.
 10880                              <1> 	;
 10881                              <1> 	; Modified Registers -> EAX
 10882                              <1> 	;
 10883 00003175 E88DFFFFFF          <1> 	call	allocate_page
 10884 0000317A 7216                <1> 	jc	short mkpd_error
 10885                              <1> 	;
 10886 0000317C A3[99CE0000]        <1> 	mov	[u.pgdir], eax    ; Page dir address for current user/process
 10887                              <1> 				  ; (Physical address)
 10888                              <1> clear_page:
 10889                              <1> 	; 18/04/2015
 10890                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10891                              <1> 	;
 10892                              <1> 	; INPUT ->
 10893                              <1> 	;	EAX = physical address of the page
 10894                              <1> 	; OUTPUT ->
 10895                              <1> 	;	all bytes of the page will be cleared
 10896                              <1> 	;
 10897                              <1> 	; Modified Registers -> none
 10898                              <1> 	;
 10899 00003181 57                  <1> 	push	edi
 10900 00003182 51                  <1> 	push	ecx
 10901 00003183 50                  <1> 	push	eax
 10902 00003184 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
 10903 00003189 89C7                <1> 	mov	edi, eax
 10904 0000318B 31C0                <1> 	xor	eax, eax
 10905 0000318D F3AB                <1> 	rep	stosd
 10906 0000318F 58                  <1> 	pop	eax
 10907 00003190 59                  <1> 	pop	ecx
 10908 00003191 5F                  <1> 	pop	edi
 10909                              <1> mkpd_error:
 10910                              <1> mkpt_error:
 10911 00003192 C3                  <1> 	retn
 10912                              <1> 
 10913                              <1> make_page_table:
 10914                              <1> 	; 23/06/2015
 10915                              <1> 	; 18/04/2015
 10916                              <1> 	; 12/04/2015
 10917                              <1> 	; 16/10/2014
 10918                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10919                              <1> 	;
 10920                              <1> 	; INPUT ->
 10921                              <1> 	;	EBX = virtual (linear) address
 10922                              <1> 	;	ECX = page table attributes (lower 12 bits)
 10923                              <1> 	;	      (higher 20 bits must be ZERO)
 10924                              <1> 	;	      (bit 0 must be 1)	 
 10925                              <1> 	;	u.pgdir = page directory (physical) address
 10926                              <1> 	; OUTPUT ->
 10927                              <1> 	;	EDX = Page directory entry address
 10928                              <1> 	;	EAX = Page table address
 10929                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10930                              <1> 	;	cf = 0 -> page table address in the PDE (EDX)
 10931                              <1> 	;
 10932                              <1> 	; Modified Registers -> EAX, EDX
 10933                              <1> 	;
 10934 00003193 E86FFFFFFF          <1> 	call	allocate_page
 10935 00003198 72F8                <1> 	jc	short mkpt_error
 10936 0000319A E811000000          <1> 	call	set_pde	
 10937 0000319F EBE0                <1> 	jmp	short clear_page
 10938                              <1> 
 10939                              <1> make_page:
 10940                              <1> 	; 24/07/2015
 10941                              <1> 	; 23/06/2015 ; (Retro UNIX 386 v1 - beginning)
 10942                              <1> 	;
 10943                              <1> 	; INPUT ->
 10944                              <1> 	;	EBX = virtual (linear) address
 10945                              <1> 	;	ECX = page attributes (lower 12 bits)
 10946                              <1> 	;	      (higher 20 bits must be ZERO)
 10947                              <1> 	;	      (bit 0 must be 1)	 
 10948                              <1> 	;	u.pgdir = page directory (physical) address
 10949                              <1> 	; OUTPUT ->
 10950                              <1> 	;	EBX = Virtual address
 10951                              <1> 	;	(EDX = PTE value)
 10952                              <1> 	;	EAX = Physical address
 10953                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10954                              <1> 	;
 10955                              <1> 	; Modified Registers -> EAX, EDX
 10956                              <1> 	;
 10957 000031A1 E861FFFFFF          <1> 	call	allocate_page
 10958 000031A6 7207                <1> 	jc	short mkp_err
 10959 000031A8 E821000000          <1> 	call	set_pte	
 10960 000031AD 73D2                <1> 	jnc	short clear_page ; 18/04/2015
 10961                              <1> mkp_err:
 10962 000031AF C3                  <1> 	retn
 10963                              <1> 
 10964                              <1> 
 10965                              <1> set_pde:	; Set page directory entry (PDE)
 10966                              <1> 	; 20/07/2015
 10967                              <1> 	; 18/04/2015
 10968                              <1> 	; 12/04/2015
 10969                              <1> 	; 23/10/2014
 10970                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10971                              <1> 	;
 10972                              <1> 	; INPUT ->
 10973                              <1> 	;	EAX = physical address
 10974                              <1> 	;	      (use present value if EAX = 0)
 10975                              <1> 	;	EBX = virtual (linear) address
 10976                              <1> 	;	ECX = page table attributes (lower 12 bits)
 10977                              <1> 	;	      (higher 20 bits must be ZERO)
 10978                              <1> 	;	      (bit 0 must be 1)	 
 10979                              <1> 	;	u.pgdir = page directory (physical) address
 10980                              <1> 	; OUTPUT ->
 10981                              <1> 	;	EDX = PDE address
 10982                              <1> 	;	EAX = page table address (physical)
 10983                              <1> 	;	;(CF=1 -> Invalid page address)
 10984                              <1> 	;
 10985                              <1> 	; Modified Registers -> EDX
 10986                              <1> 	;
 10987 000031B0 89DA                <1> 	mov	edx, ebx
 10988 000031B2 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22
 10989 000031B5 C1E202              <1> 	shl	edx, 2 ; offset to page directory (1024*4)
 10990 000031B8 0315[99CE0000]      <1> 	add	edx, [u.pgdir]
 10991                              <1> 	;
 10992 000031BE 21C0                <1> 	and	eax, eax
 10993 000031C0 7506                <1> 	jnz	short spde_1
 10994                              <1> 	;
 10995 000031C2 8B02                <1> 	mov	eax, [edx]  ; old PDE value
 10996                              <1> 	;test	al, 1
 10997                              <1> 	;jz	short spde_2
 10998 000031C4 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h  ; clear lower 12 bits
 10999                              <1> spde_1:
 11000                              <1> 	;and	cx, 0FFFh
 11001 000031C8 8902                <1> 	mov	[edx], eax
 11002 000031CA 66090A              <1> 	or	[edx], cx
 11003 000031CD C3                  <1> 	retn
 11004                              <1> ;spde_2: ; error
 11005                              <1> ;	stc
 11006                              <1> ;	retn
 11007                              <1> 
 11008                              <1> set_pte:	; Set page table entry (PTE)
 11009                              <1> 	; 24/07/2015
 11010                              <1> 	; 20/07/2015
 11011                              <1> 	; 23/06/2015
 11012                              <1> 	; 18/04/2015
 11013                              <1> 	; 12/04/2015
 11014                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11015                              <1> 	;
 11016                              <1> 	; INPUT ->
 11017                              <1> 	;	EAX = physical page address
 11018                              <1> 	;	      (use present value if EAX = 0)
 11019                              <1> 	;	EBX = virtual (linear) address
 11020                              <1> 	;	ECX = page attributes (lower 12 bits)
 11021                              <1> 	;	      (higher 20 bits must be ZERO)
 11022                              <1> 	;	      (bit 0 must be 1)	 
 11023                              <1> 	;	u.pgdir = page directory (physical) address
 11024                              <1> 	; OUTPUT ->
 11025                              <1> 	;	EAX = physical page address
 11026                              <1> 	;	(EDX = PTE value)
 11027                              <1> 	;	EBX = virtual address
 11028                              <1> 	;
 11029                              <1> 	;	CF = 1 -> error
 11030                              <1> 	;
 11031                              <1> 	; Modified Registers -> EAX, EDX
 11032                              <1> 	;
 11033 000031CE 50                  <1> 	push	eax
 11034 000031CF A1[99CE0000]        <1> 	mov	eax, [u.pgdir] ; 20/07/2015
 11035 000031D4 E837000000          <1> 	call 	get_pde
 11036                              <1> 		; EDX = PDE address
 11037                              <1> 		; EAX = PDE value
 11038 000031D9 5A                  <1> 	pop	edx ; physical page address
 11039 000031DA 722A                <1> 	jc	short spte_err ; PDE not present
 11040                              <1> 	;
 11041 000031DC 53                  <1> 	push	ebx ; 24/07/2015
 11042 000031DD 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11043                              <1> 			    ; EDX = PT address (physical)	
 11044 000031E1 C1EB0C              <1> 	shr	ebx, PAGE_SHIFT ; 12
 11045 000031E4 81E3FF030000        <1> 	and	ebx, PTE_MASK	; 03FFh
 11046                              <1> 			 ; clear higher 10 bits (PD bits)
 11047 000031EA C1E302              <1> 	shl	ebx, 2   ; offset to page table (1024*4)
 11048 000031ED 01C3                <1> 	add	ebx, eax
 11049                              <1> 	;
 11050 000031EF 8B03                <1> 	mov	eax, [ebx] ; Old PTE value
 11051 000031F1 A801                <1> 	test	al, 1
 11052 000031F3 740C                <1> 	jz	short spte_0
 11053 000031F5 09D2                <1> 	or	edx, edx
 11054 000031F7 750F                <1> 	jnz	short spte_1
 11055 000031F9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11056 000031FD 89C2                <1> 	mov	edx, eax
 11057 000031FF EB09                <1> 	jmp	short spte_2	
 11058                              <1> spte_0:
 11059                              <1> 	; If this PTE contains a swap (disk) address,
 11060                              <1> 	; it can be updated by using 'swap_in' procedure
 11061                              <1> 	; only!
 11062 00003201 21C0                <1> 	and	eax, eax
 11063 00003203 7403                <1> 	jz	short spte_1
 11064                              <1> 	; 24/07/2015
 11065                              <1> 	; swapped page ! (on disk)
 11066 00003205 5B                  <1> 	pop	ebx
 11067                              <1> spte_err:
 11068 00003206 F9                  <1> 	stc
 11069 00003207 C3                  <1> 	retn
 11070                              <1> spte_1: 
 11071 00003208 89D0                <1> 	mov	eax, edx
 11072                              <1> spte_2:
 11073 0000320A 09CA                <1> 	or	edx, ecx
 11074                              <1> 	; 23/06/2015
 11075 0000320C 8913                <1> 	mov	[ebx], edx ; PTE value in EDX
 11076                              <1> 	; 24/07/2015
 11077 0000320E 5B                  <1> 	pop	ebx
 11078 0000320F C3                  <1> 	retn
 11079                              <1> 
 11080                              <1> get_pde:	; Get present value of the relevant PDE
 11081                              <1> 	; 20/07/2015
 11082                              <1> 	; 18/04/2015
 11083                              <1> 	; 12/04/2015
 11084                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11085                              <1> 	;
 11086                              <1> 	; INPUT ->
 11087                              <1> 	;	EBX = virtual (linear) address
 11088                              <1> 	;	EAX = page directory (physical) address
 11089                              <1> 	; OUTPUT ->
 11090                              <1> 	;	EDX = Page directory entry address
 11091                              <1> 	;	EAX = Page directory entry value
 11092                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
 11093                              <1> 	; Modified Registers -> EDX, EAX
 11094                              <1> 	;
 11095 00003210 89DA                <1> 	mov	edx, ebx
 11096 00003212 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22  (12+10)
 11097 00003215 C1E202              <1> 	shl 	edx, 2 ; offset to page directory (1024*4)
 11098 00003218 01C2                <1> 	add	edx, eax ; page directory address (physical)
 11099 0000321A 8B02                <1> 	mov	eax, [edx]
 11100 0000321C A801                <1> 	test	al, PDE_A_PRESENT ; page table is present or not !
 11101 0000321E 751F                <1> 	jnz	short gpte_retn
 11102 00003220 F9                  <1> 	stc
 11103                              <1> gpde_retn:	
 11104 00003221 C3                  <1> 	retn
 11105                              <1> 
 11106                              <1> get_pte:
 11107                              <1> 		; Get present value of the relevant PTE
 11108                              <1> 	; 29/07/2015
 11109                              <1> 	; 20/07/2015
 11110                              <1> 	; 18/04/2015
 11111                              <1> 	; 12/04/2015
 11112                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11113                              <1> 	;
 11114                              <1> 	; INPUT ->
 11115                              <1> 	;	EBX = virtual (linear) address
 11116                              <1> 	;	EAX = page directory (physical) address
 11117                              <1> 	; OUTPUT ->
 11118                              <1> 	;	EDX = Page table entry address (if CF=0)
 11119                              <1> 	;	      Page directory entry address (if CF=1)
 11120                              <1> 	;            (Bit 0 value is 0 if PT is not present)
 11121                              <1> 	;	EAX = Page table entry value (page address)
 11122                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
 11123                              <1> 	; Modified Registers -> EAX, EDX
 11124                              <1> 	;
 11125 00003222 E8E9FFFFFF          <1> 	call 	get_pde
 11126 00003227 72F8                <1> 	jc	short gpde_retn	; page table is not present
 11127                              <1> 	;jnc	short gpte_1
 11128                              <1> 	;retn
 11129                              <1> ;gpte_1:
 11130 00003229 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11131 0000322D 89DA                <1> 	mov	edx, ebx
 11132 0000322F C1EA0C              <1> 	shr	edx, PAGE_SHIFT ; 12
 11133 00003232 81E2FF030000        <1> 	and	edx, PTE_MASK	; 03FFh
 11134                              <1> 			 ; clear higher 10 bits (PD bits)
 11135 00003238 C1E202              <1> 	shl	edx, 2 ; offset from start of page table (1024*4)
 11136 0000323B 01C2                <1> 	add	edx, eax
 11137 0000323D 8B02                <1> 	mov	eax, [edx]
 11138                              <1> gpte_retn:
 11139 0000323F C3                  <1> 	retn
 11140                              <1> 
 11141                              <1> deallocate_page_dir:
 11142                              <1> 	; 15/09/2015
 11143                              <1> 	; 05/08/2015
 11144                              <1> 	; 30/04/2015
 11145                              <1> 	; 28/04/2015
 11146                              <1> 	; 17/10/2014
 11147                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11148                              <1> 	;
 11149                              <1> 	; INPUT ->
 11150                              <1> 	;	EAX = PHYSICAL ADDRESS OF THE PAGE DIRECTORY (CHILD)
 11151                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
 11152                              <1> 	; OUTPUT ->
 11153                              <1> 	;	All of page tables in the page directory
 11154                              <1> 	;	and page dir's itself will be deallocated
 11155                              <1> 	;	except 'read only' duplicated pages (will be converted
 11156                              <1> 	;	to writable pages).
 11157                              <1> 	;
 11158                              <1> 	; Modified Registers -> EAX
 11159                              <1> 	;
 11160                              <1> 	;
 11161 00003240 56                  <1> 	push	esi
 11162 00003241 51                  <1> 	push	ecx
 11163 00003242 50                  <1> 	push	eax
 11164 00003243 89C6                <1> 	mov	esi, eax 
 11165 00003245 31C9                <1> 	xor	ecx, ecx
 11166                              <1> 	; The 1st PDE points to Kernel Page Table 0 (the 1st 4MB),
 11167                              <1> 	; it must not be deallocated
 11168 00003247 890E                <1> 	mov	[esi], ecx ; 0 ; clear PDE 0
 11169                              <1> dapd_0:
 11170 00003249 AD                  <1> 	lodsd
 11171 0000324A A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
 11172 0000324C 7409                <1> 	jz	short dapd_1	
 11173 0000324E 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
 11174 00003252 E812000000          <1> 	call	deallocate_page_table			
 11175                              <1> dapd_1:
 11176 00003257 41                  <1> 	inc	ecx ; page directory entry index
 11177 00003258 81F900040000        <1> 	cmp	ecx, PAGE_SIZE / 4 ; 1024
 11178 0000325E 72E9                <1> 	jb	short dapd_0
 11179                              <1> dapd_2:
 11180 00003260 58                  <1> 	pop	eax
 11181 00003261 E879000000          <1> 	call	deallocate_page	; deallocate the page dir's itself
 11182 00003266 59                  <1> 	pop	ecx
 11183 00003267 5E                  <1> 	pop	esi
 11184 00003268 C3                  <1> 	retn
 11185                              <1> 
 11186                              <1> deallocate_page_table:
 11187                              <1> 	; 19/09/2015
 11188                              <1> 	; 15/09/2015
 11189                              <1> 	; 05/08/2015
 11190                              <1> 	; 30/04/2015
 11191                              <1> 	; 28/04/2015
 11192                              <1> 	; 24/10/2014
 11193                              <1> 	; 23/10/2014
 11194                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11195                              <1> 	;
 11196                              <1> 	; INPUT ->
 11197                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE PAGE TABLE
 11198                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
 11199                              <1> 	;	(ECX = page directory entry index)
 11200                              <1> 	; OUTPUT ->
 11201                              <1> 	;	All of pages in the page table and page table's itself
 11202                              <1> 	;	will be deallocated except 'read only' duplicated pages
 11203                              <1> 	;	(will be converted to writable pages).
 11204                              <1> 	;
 11205                              <1> 	; Modified Registers -> EAX
 11206                              <1> 	;
 11207 00003269 56                  <1> 	push	esi
 11208 0000326A 57                  <1> 	push	edi
 11209 0000326B 52                  <1> 	push	edx
 11210 0000326C 50                  <1> 	push	eax ; *
 11211 0000326D 89C6                <1> 	mov	esi, eax 
 11212 0000326F 31FF                <1> 	xor	edi, edi ; 0
 11213                              <1> dapt_0:
 11214 00003271 AD                  <1> 	lodsd
 11215 00003272 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
 11216 00003274 7441                <1> 	jz	short dapt_1
 11217                              <1> 	;
 11218 00003276 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
 11219                              <1> 				  ; (must be 1)
 11220 00003278 754C                <1> 	jnz	short dapt_3
 11221                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
 11222 0000327A 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
 11223                              <1> 				   ; as child's page ?
 11224 0000327E 744B                <1> 	jz	short dapt_4 ; Clear PTE but don't deallocate the page!
 11225                              <1> 	; check the parent's PTE value is read only & same page or not.. 
 11226                              <1> 	; ECX = page directory entry index (0-1023)
 11227 00003280 53                  <1> 	push	ebx
 11228 00003281 51                  <1> 	push	ecx
 11229 00003282 66C1E102            <1> 	shl	cx, 2 ; *4 
 11230 00003286 01CB                <1> 	add	ebx, ecx ; PDE offset (for the parent)
 11231 00003288 8B0B                <1> 	mov	ecx, [ebx]
 11232 0000328A F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
 11233 0000328D 7435                <1> 	jz	short dapt_2	; parent process does not use this page
 11234 0000328F 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
 11235                              <1> 	; EDI = page table entry index (0-1023)
 11236 00003294 89FA                <1> 	mov	edx, edi 
 11237 00003296 66C1E202            <1> 	shl	dx, 2 ; *4 
 11238 0000329A 01CA                <1> 	add	edx, ecx ; PTE offset (for the parent)
 11239 0000329C 8B1A                <1> 	mov	ebx, [edx]
 11240 0000329E F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
 11241 000032A1 7421                <1> 	jz	short dapt_2	; parent process does not use this page
 11242 000032A3 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
 11243 000032A7 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
 11244 000032AC 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
 11245 000032AE 7514                <1> 	jne	short dapt_2	; not same page
 11246                              <1> 				; deallocate the child's page
 11247 000032B0 800A02              <1>         or      byte [edx], PTE_A_WRITE ; convert to writable page (parent)
 11248 000032B3 59                  <1> 	pop	ecx
 11249 000032B4 5B                  <1> 	pop	ebx
 11250 000032B5 EB14                <1> 	jmp	short dapt_4
 11251                              <1> dapt_1:
 11252 000032B7 09C0                <1> 	or	eax, eax	; swapped page ?
 11253 000032B9 7417                <1> 	jz	short dapt_5	; no
 11254                              <1> 				; yes
 11255 000032BB D1E8                <1> 	shr	eax, 1
 11256 000032BD E848040000          <1> 	call	unlink_swap_block ; Deallocate swapped page block
 11257                              <1> 				  ; on the swap disk (or in file)
 11258 000032C2 EB0E                <1> 	jmp	short dapt_5
 11259                              <1> dapt_2:
 11260 000032C4 59                  <1> 	pop	ecx
 11261 000032C5 5B                  <1> 	pop	ebx
 11262                              <1> dapt_3:	
 11263                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
 11264 000032C6 E814000000          <1> 	call	deallocate_page
 11265                              <1> dapt_4:
 11266 000032CB C746FC00000000      <1> 	mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
 11267                              <1> dapt_5:
 11268 000032D2 47                  <1> 	inc	edi ; page table entry index
 11269 000032D3 81FF00040000        <1> 	cmp	edi, PAGE_SIZE / 4 ; 1024
 11270 000032D9 7296                <1> 	jb	short dapt_0
 11271                              <1> 	;
 11272 000032DB 58                  <1> 	pop	eax ; *
 11273 000032DC 5A                  <1> 	pop	edx
 11274 000032DD 5F                  <1> 	pop	edi	
 11275 000032DE 5E                  <1> 	pop	esi
 11276                              <1> 	;
 11277                              <1> 	;call	deallocate_page	; deallocate the page table's itself
 11278                              <1> 	;retn
 11279                              <1> 
 11280                              <1> deallocate_page:
 11281                              <1> 	; 15/09/2015
 11282                              <1> 	; 28/04/2015
 11283                              <1> 	; 10/03/2015
 11284                              <1> 	; 17/10/2014
 11285                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11286                              <1> 	;
 11287                              <1> 	; INPUT -> 
 11288                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 11289                              <1> 	; OUTPUT ->
 11290                              <1> 	;	[free_pages] is increased
 11291                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is SET)
 11292                              <1> 	;	CF = 1 if the page is already deallocated
 11293                              <1> 	; 	       (or not allocated) before.  
 11294                              <1> 	;
 11295                              <1> 	; Modified Registers -> EAX
 11296                              <1> 	;
 11297 000032DF 53                  <1> 	push	ebx
 11298 000032E0 52                  <1> 	push	edx
 11299                              <1> 	;
 11300 000032E1 C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; shift physical address to 
 11301                              <1> 				     ; 12 bits right
 11302                              <1> 				     ; to get page number
 11303 000032E4 89C2                <1> 	mov	edx, eax
 11304                              <1> 	; 15/09/2015
 11305 000032E6 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
 11306                              <1> 				     ; (1 allocation bit = 1 page)
 11307                              <1> 				     ; (1 allocation bytes = 8 pages)
 11308 000032E9 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 11309                              <1> 				     ; (to get 32 bit position)			
 11310                              <1> 	;
 11311 000032EC BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address
 11312 000032F1 01D3                <1> 	add	ebx, edx
 11313 000032F3 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
 11314                              <1> 				     ; (allocation bit position)	 
 11315 000032F6 3B15[F4BD0000]      <1> 	cmp 	edx, [next_page]     ; is the new free page address lower
 11316                              <1> 				     ; than the address in 'next_page' ?
 11317                              <1> 				     ; (next/first free page value)		
 11318 000032FC 7306                <1> 	jnb	short dap_1	     ; no	
 11319 000032FE 8915[F4BD0000]      <1> 	mov	[next_page], edx     ; yes
 11320                              <1> dap_1:
 11321 00003304 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
 11322                              <1> 				     ; set relevant bit to 1.
 11323                              <1> 				     ; set CF to the previous bit value	
 11324                              <1> 	;cmc			     ; complement carry flag	
 11325                              <1> 	;jc	short dap_2	     ; do not increase free_pages count
 11326                              <1> 				     ; if the page is already deallocated
 11327                              <1> 				     ; before.	
 11328 00003307 FF05[F0BD0000]      <1>         inc     dword [free_pages]
 11329                              <1> dap_2:
 11330 0000330D 5A                  <1> 	pop	edx
 11331 0000330E 5B                  <1> 	pop	ebx
 11332 0000330F C3                  <1> 	retn
 11333                              <1> 
 11334                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 11335                              <1> ;;                                                              ;;
 11336                              <1> ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
 11337                              <1> ;; Distributed under terms of the GNU General Public License    ;;
 11338                              <1> ;;                                                              ;;
 11339                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 11340                              <1> 
 11341                              <1> ;;$Revision: 5057 $
 11342                              <1> 
 11343                              <1> 
 11344                              <1> ;;align 4
 11345                              <1> ;;proc alloc_page
 11346                              <1> 
 11347                              <1> ;;        pushfd
 11348                              <1> ;;        cli
 11349                              <1> ;;        push    ebx
 11350                              <1> ;;;//-
 11351                              <1> ;;        cmp     [pg_data.pages_free], 1
 11352                              <1> ;;        jle     .out_of_memory
 11353                              <1> ;;;//-
 11354                              <1> ;;
 11355                              <1> ;;        mov     ebx, [page_start]
 11356                              <1> ;;        mov     ecx, [page_end]
 11357                              <1> ;;.l1:
 11358                              <1> ;;        bsf     eax, [ebx];
 11359                              <1> ;;        jnz     .found
 11360                              <1> ;;        add     ebx, 4
 11361                              <1> ;;        cmp     ebx, ecx
 11362                              <1> ;;        jb      .l1
 11363                              <1> ;;        pop     ebx
 11364                              <1> ;;        popfd
 11365                              <1> ;;        xor     eax, eax
 11366                              <1> ;;        ret
 11367                              <1> ;;.found:
 11368                              <1> ;;;//-
 11369                              <1> ;;        dec     [pg_data.pages_free]
 11370                              <1> ;;        jz      .out_of_memory
 11371                              <1> ;;;//-
 11372                              <1> ;;        btr     [ebx], eax
 11373                              <1> ;;        mov     [page_start], ebx
 11374                              <1> ;;        sub     ebx, sys_pgmap
 11375                              <1> ;;        lea     eax, [eax+ebx*8]
 11376                              <1> ;;        shl     eax, 12
 11377                              <1> ;;;//-       dec [pg_data.pages_free]
 11378                              <1> ;;        pop     ebx
 11379                              <1> ;;        popfd
 11380                              <1> ;;        ret
 11381                              <1> ;;;//-
 11382                              <1> ;;.out_of_memory:
 11383                              <1> ;;        mov     [pg_data.pages_free], 1
 11384                              <1> ;;        xor     eax, eax
 11385                              <1> ;;        pop     ebx
 11386                              <1> ;;        popfd
 11387                              <1> ;;        ret
 11388                              <1> ;;;//-
 11389                              <1> ;;endp
 11390                              <1> 
 11391                              <1> duplicate_page_dir:
 11392                              <1> 	; 21/09/2015
 11393                              <1> 	; 31/08/2015
 11394                              <1> 	; 20/07/2015
 11395                              <1> 	; 28/04/2015
 11396                              <1> 	; 27/04/2015
 11397                              <1> 	; 18/04/2015
 11398                              <1> 	; 12/04/2015
 11399                              <1> 	; 18/10/2014
 11400                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
 11401                              <1> 	;
 11402                              <1> 	; INPUT -> 
 11403                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
 11404                              <1> 	;		    page directory.
 11405                              <1> 	; OUTPUT ->
 11406                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
 11407                              <1> 	;	       page directory.
 11408                              <1> 	;	(New page directory with new page table entries.)
 11409                              <1> 	;	(New page tables with read only copies of the parent's
 11410                              <1> 	;	pages.)
 11411                              <1> 	;	EAX = 0 -> Error (CF = 1)
 11412                              <1> 	;
 11413                              <1> 	; Modified Registers -> none (except EAX)
 11414                              <1> 	;
 11415 00003310 E8F2FDFFFF          <1> 	call	allocate_page
 11416 00003315 723E                <1> 	jc	short dpd_err
 11417                              <1> 	;
 11418 00003317 55                  <1> 	push	ebp ; 20/07/2015
 11419 00003318 56                  <1> 	push	esi
 11420 00003319 57                  <1> 	push	edi
 11421 0000331A 53                  <1> 	push	ebx
 11422 0000331B 51                  <1> 	push	ecx
 11423 0000331C 8B35[99CE0000]      <1> 	mov	esi, [u.pgdir]
 11424 00003322 89C7                <1> 	mov	edi, eax
 11425 00003324 50                  <1> 	push	eax ; save child's page directory address
 11426                              <1> 	; 31/08/2015
 11427                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
 11428                              <1> 	; (use same system space for all user page tables) 
 11429 00003325 A5                  <1> 	movsd
 11430 00003326 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
 11431 0000332B B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
 11432                              <1> dpd_0:	
 11433 00003330 AD                  <1> 	lodsd
 11434                              <1> 	;or	eax, eax
 11435                              <1>         ;jnz     short dpd_1
 11436 00003331 A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
 11437 00003333 7508                <1> 	jnz	short dpd_1
 11438                              <1>  	; 20/07/2015 (virtual address at the end of the page table)	
 11439 00003335 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
 11440 0000333B EB0F                <1> 	jmp	short dpd_2
 11441                              <1> dpd_1:	
 11442 0000333D 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
 11443 00003341 89C3                <1> 	mov	ebx, eax
 11444                              <1> 	; EBX = Parent's page table address
 11445 00003343 E81F000000          <1> 	call	duplicate_page_table
 11446 00003348 720C                <1> 	jc	short dpd_p_err
 11447                              <1> 	; EAX = Child's page table address
 11448 0000334A 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
 11449                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
 11450                              <1> 			 ; (present, writable, user)
 11451                              <1> dpd_2:
 11452 0000334C AB                  <1> 	stosd
 11453 0000334D E2E1                <1> 	loop	dpd_0
 11454                              <1> 	;
 11455 0000334F 58                  <1> 	pop	eax  ; restore child's page directory address
 11456                              <1> dpd_3:
 11457 00003350 59                  <1> 	pop	ecx
 11458 00003351 5B                  <1> 	pop	ebx
 11459 00003352 5F                  <1> 	pop	edi
 11460 00003353 5E                  <1> 	pop	esi
 11461 00003354 5D                  <1> 	pop	ebp ; 20/07/2015
 11462                              <1> dpd_err:
 11463 00003355 C3                  <1> 	retn
 11464                              <1> dpd_p_err:
 11465                              <1> 	; release the allocated pages missing (recover free space)
 11466 00003356 58                  <1> 	pop	eax  ; the new page directory address (physical)
 11467 00003357 8B1D[99CE0000]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
 11468 0000335D E8DEFEFFFF          <1> 	call 	deallocate_page_dir
 11469 00003362 29C0                <1> 	sub	eax, eax ; 0
 11470 00003364 F9                  <1> 	stc
 11471 00003365 EBE9                <1> 	jmp	short dpd_3	
 11472                              <1> 
 11473                              <1> duplicate_page_table:
 11474                              <1> 	; 21/09/2015
 11475                              <1> 	; 20/07/2015
 11476                              <1> 	; 05/05/2015
 11477                              <1> 	; 28/04/2015
 11478                              <1> 	; 27/04/2015
 11479                              <1> 	; 18/04/2015
 11480                              <1> 	; 18/10/2014
 11481                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
 11482                              <1> 	;
 11483                              <1> 	; INPUT -> 
 11484                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
 11485                              <1> 	;	EBP = page table entry index (from 'duplicate_page_dir')
 11486                              <1> 	; OUTPUT ->
 11487                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
 11488                              <1> 	;	      (with 'read only' attribute of page table entries)
 11489                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
 11490                              <1> 	;	CF = 1 -> error 
 11491                              <1> 	;
 11492                              <1> 	; Modified Registers -> EBP (except EAX)
 11493                              <1> 	;
 11494 00003367 E89BFDFFFF          <1> 	call	allocate_page
 11495 0000336C 726A                <1> 	jc	short dpt_err
 11496                              <1> 	;
 11497 0000336E 50                  <1> 	push	eax ; *
 11498 0000336F 56                  <1> 	push	esi
 11499 00003370 57                  <1> 	push	edi
 11500 00003371 52                  <1> 	push	edx
 11501 00003372 51                  <1> 	push	ecx
 11502                              <1> 	;
 11503 00003373 89DE                <1> 	mov	esi, ebx
 11504 00003375 89C7                <1> 	mov	edi, eax
 11505 00003377 89C2                <1> 	mov	edx, eax
 11506 00003379 81C200100000        <1> 	add	edx, PAGE_SIZE 	
 11507                              <1> dpt_0:
 11508 0000337F AD                  <1> 	lodsd
 11509 00003380 21C0                <1> 	and	eax, eax
 11510 00003382 7444                <1> 	jz	short dpt_3
 11511 00003384 A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
 11512 00003386 7507                <1> 	jnz	short dpt_1
 11513                              <1> 	; 20/07/2015
 11514                              <1> 	; ebp = virtual (linear) address of the memory page
 11515 00003388 E887040000          <1> 	call	reload_page ; 28/04/2015
 11516 0000338D 7244                <1> 	jc	short dpt_p_err
 11517                              <1> dpt_1:
 11518                              <1> 	; 21/09/2015
 11519 0000338F 89C1                <1> 	mov	ecx, eax
 11520 00003391 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 11521 00003395 F6C102              <1> 	test	cl, PTE_A_WRITE ; writable page ?
 11522 00003398 7525                <1> 	jnz	short dpt_2
 11523                              <1> 	; Read only (parent) page
 11524                              <1> 	; 	- there is a third process which uses this page -
 11525                              <1> 	; Allocate a new page for the child process
 11526 0000339A E868FDFFFF          <1> 	call	allocate_page
 11527 0000339F 7232                <1> 	jc	short dpt_p_err
 11528 000033A1 57                  <1> 	push	edi
 11529 000033A2 56                  <1> 	push	esi
 11530 000033A3 89CE                <1> 	mov	esi, ecx
 11531 000033A5 89C7                <1> 	mov	edi, eax
 11532 000033A7 B900040000          <1> 	mov	ecx, PAGE_SIZE/4
 11533 000033AC F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
 11534 000033AE 5E                  <1> 	pop	esi
 11535 000033AF 5F                  <1> 	pop	edi
 11536                              <1> 	; 
 11537 000033B0 53                  <1> 	push	ebx
 11538 000033B1 50                  <1> 	push	eax
 11539                              <1> 	; 20/07/2015
 11540 000033B2 89EB                <1> 	mov	ebx, ebp
 11541                              <1> 	; ebx = virtual address of the memory page
 11542 000033B4 E80B030000          <1> 	call	add_to_swap_queue
 11543 000033B9 58                  <1> 	pop	eax
 11544 000033BA 5B                  <1> 	pop	ebx
 11545                              <1> 	; 21/09/2015
 11546 000033BB 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
 11547                              <1> 		; user + writable + present page
 11548 000033BD EB09                <1> 	jmp	short dpt_3
 11549                              <1> dpt_2:
 11550                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
 11551 000033BF 0C05                <1> 	or	al, PTE_A_USER+PTE_A_PRESENT 
 11552                              <1> 		    ; (read only page!)
 11553 000033C1 8946FC              <1> 	mov	[esi-4], eax ; update parent's PTE
 11554 000033C4 660D0002            <1> 	or      ax, PTE_DUPLICATED  ; (read only page & duplicated PTE!)
 11555                              <1> dpt_3:
 11556 000033C8 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
 11557                              <1> 	;
 11558 000033C9 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
 11559                              <1> 	;
 11560 000033CF 39D7                <1> 	cmp	edi, edx
 11561 000033D1 72AC                <1> 	jb	short dpt_0
 11562                              <1> dpt_p_err:
 11563 000033D3 59                  <1> 	pop	ecx
 11564 000033D4 5A                  <1> 	pop	edx
 11565 000033D5 5F                  <1> 	pop	edi
 11566 000033D6 5E                  <1> 	pop	esi
 11567 000033D7 58                  <1> 	pop	eax ; *
 11568                              <1> dpt_err:
 11569 000033D8 C3                  <1> 	retn
 11570                              <1> 
 11571                              <1> page_fault_handler:	; CPU EXCEPTION 0Eh (14) : Page Fault !
 11572                              <1> 	; 21/09/2015
 11573                              <1> 	; 19/09/2015
 11574                              <1> 	; 17/09/2015
 11575                              <1> 	; 28/08/2015
 11576                              <1> 	; 20/07/2015
 11577                              <1> 	; 28/06/2015
 11578                              <1> 	; 03/05/2015
 11579                              <1> 	; 30/04/2015
 11580                              <1> 	; 18/04/2015
 11581                              <1> 	; 12/04/2015
 11582                              <1> 	; 30/10/2014
 11583                              <1> 	; 11/09/2014
 11584                              <1> 	; 10/09/2014 (Retro UNIX 386 v1 - beginning)
 11585                              <1> 	;
 11586                              <1> 	; Note: This is not an interrupt/exception handler.
 11587                              <1> 	;	This is a 'page fault remedy' subroutine 
 11588                              <1> 	;	which will be called by standard/uniform
 11589                              <1> 	;	exception handler.
 11590                              <1> 	;
 11591                              <1> 	; INPUT -> 
 11592                              <1> 	;	[error_code] = 32 bit ERROR CODE (lower 5 bits are valid)
 11593                              <1> 	;
 11594                              <1> 	;	cr2 = the virtual (linear) address 
 11595                              <1> 	;	      which has caused to page fault (19/09/2015)
 11596                              <1> 	;
 11597                              <1> 	; OUTPUT ->
 11598                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
 11599                              <1> 	;	EAX = 0 -> no error
 11600                              <1> 	;	EAX > 0 -> error code in EAX (also CF = 1)
 11601                              <1> 	;
 11602                              <1> 	; Modified Registers -> none (except EAX)
 11603                              <1> 	;	
 11604                              <1>         ;
 11605                              <1>         ; ERROR CODE:
 11606                              <1> 	;	 31  .....	4   3	2   1	0
 11607                              <1> 	;	+---+-- --+---+---+---+---+---+---+
 11608                              <1> 	;	|   Reserved  | I | R | U | W | P |
 11609                              <1> 	;	+---+-- --+---+---+---+---+---+---+
 11610                              <1> 	;
 11611                              <1> 	; P : PRESENT -	When set, the page fault was caused by 
 11612                              <1>     	;		a page-protection violation. When not set,
 11613                              <1> 	;		it was caused by a non-present page.
 11614                              <1> 	; W : WRITE   -	When set, the page fault was caused by
 11615                              <1> 	;		a page write. When not set, it was caused
 11616                              <1> 	;		by a page read.
 11617                              <1> 	; U : USER    -	When set, the page fault was caused 
 11618                              <1> 	;		while CPL = 3. 
 11619                              <1> 	;		This does not necessarily mean that
 11620                              <1> 	;		the page fault was a privilege violation.
 11621                              <1> 	; R : RESERVD -	When set, the page fault was caused by
 11622                              <1> 	;     WRITE	reading a 1 in a reserved field.
 11623                              <1> 	; I : INSTRUC -	When set, the page fault was caused by
 11624                              <1> 	;     FETCH	an instruction fetch
 11625                              <1> 	;
 11626                              <1> 	;; x86 (32 bit) VIRTUAL ADDRESS TRANSLATION
 11627                              <1> 	;  31               22                  12 11                    0
 11628                              <1> 	; +-------------------+-------------------+-----------------------+
 11629                              <1>        	; | PAGE DIR. ENTRY # | PAGE TAB. ENTRY # |        OFFSET         |
 11630                              <1>        	; +-------------------+-------------------+-----------------------+
 11631                              <1> 	;
 11632                              <1> 
 11633                              <1> 	;; CR3 REGISTER (Control Register 3)
 11634                              <1> 	;  31                                   12             5 4 3 2   0
 11635                              <1> 	; +---------------------------------------+-------------+---+-----+
 11636                              <1>       	; |                                       |  		|P|P|     |
 11637                              <1>       	; |   PAGE DIRECTORY TABLE BASE ADDRESS   |  reserved	|C|W|rsvrd|
 11638                              <1>       	; |                                       | 		|D|T|     |
 11639                              <1>    	; +---------------------------------------+-------------+---+-----+
 11640                              <1> 	;
 11641                              <1> 	;	PWT    - WRITE THROUGH
 11642                              <1> 	;	PCD    - CACHE DISABLE		
 11643                              <1> 	;
 11644                              <1> 	;
 11645                              <1> 	;; x86 PAGE DIRECTORY ENTRY (4 KByte Page)
 11646                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11647                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11648                              <1>       	; |                                       |     | | | | |P|P|U|R| |
 11649                              <1>       	; |     PAGE TABLE BASE ADDRESS 31..12    | AVL |G|0|D|A|C|W|/|/|P|
 11650                              <1>       	; |                                       |     | | | | |D|T|S|W| |
 11651                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11652                              <1> 	;
 11653                              <1>         ;       P      - PRESENT
 11654                              <1>         ;       R/W    - READ/WRITE
 11655                              <1>         ;       U/S    - USER/SUPERVISOR
 11656                              <1> 	;	PWT    - WRITE THROUGH
 11657                              <1> 	;	PCD    - CACHE DISABLE	
 11658                              <1> 	;	A      - ACCESSED	
 11659                              <1>         ;       D      - DIRTY (IGNORED)
 11660                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
 11661                              <1> 	;	G      - GLOBAL	(IGNORED) 
 11662                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11663                              <1> 	;
 11664                              <1> 	;
 11665                              <1> 	;; x86 PAGE TABLE ENTRY (4 KByte Page)
 11666                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11667                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11668                              <1>       	; |                                       |     | |P| | |P|P|U|R| |
 11669                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |G|A|D|A|C|W|/|/|P|
 11670                              <1>       	; |                                       |     | |T| | |D|T|S|W| |
 11671                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11672                              <1> 	;
 11673                              <1>         ;       P      - PRESENT
 11674                              <1>         ;       R/W    - READ/WRITE
 11675                              <1>         ;       U/S    - USER/SUPERVISOR
 11676                              <1> 	;	PWT    - WRITE THROUGH
 11677                              <1> 	;	PCD    - CACHE DISABLE	
 11678                              <1> 	;	A      - ACCESSED	
 11679                              <1>         ;       D      - DIRTY
 11680                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
 11681                              <1> 	;	G      - GLOBAL	 
 11682                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11683                              <1> 	;
 11684                              <1> 	;
 11685                              <1> 	;; 80386 PAGE TABLE ENTRY (4 KByte Page)
 11686                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11687                              <1> 	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
 11688                              <1>       	; |                                       |     | | | | | | |U|R| |
 11689                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |0|0|D|A|0|0|/|/|P|
 11690                              <1>       	; |                                       |     | | | | | | |S|W| |
 11691                              <1>       	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
 11692                              <1> 	;
 11693                              <1>         ;       P      - PRESENT
 11694                              <1>         ;       R/W    - READ/WRITE
 11695                              <1>         ;       U/S    - USER/SUPERVISOR
 11696                              <1>         ;       D      - DIRTY
 11697                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11698                              <1> 	;
 11699                              <1>         ;       NOTE: 0 INDICATES INTEL RESERVED. DO NOT DEFINE.
 11700                              <1> 	;
 11701                              <1> 	;
 11702                              <1> 	;; Invalid Page Table Entry
 11703                              <1> 	; 31                                                           1 0
 11704                              <1>       	; +-------------------------------------------------------------+-+
 11705                              <1>       	; |                                                             | |
 11706                              <1>       	; |                          AVAILABLE                          |0|
 11707                              <1>       	; |                                                             | |
 11708                              <1>       	; +-------------------------------------------------------------+-+
 11709                              <1> 	;
 11710                              <1> 
 11711 000033D9 53                  <1> 	push	ebx
 11712 000033DA 52                  <1> 	push	edx
 11713 000033DB 51                  <1> 	push	ecx
 11714                              <1> 	;
 11715                              <1> 	; 21/09/2015 (debugging)
 11716 000033DC FF05[A9CE0000]      <1> 	inc	dword [u.pfcount] ; page fault count for running process
 11717 000033E2 FF05[14DB0000]      <1> 	inc	dword [PF_Count] ; total page fault count	
 11718                              <1> 	; 28/06/2015
 11719                              <1> 	;mov	edx, [error_code] ; Lower 5 bits are valid
 11720 000033E8 8A15[0CDB0000]      <1> 	mov	dl, [error_code]
 11721                              <1> 	;
 11722 000033EE F6C201              <1> 	test	dl, 1	; page fault was caused by a non-present page
 11723                              <1> 			; sign
 11724 000033F1 7422                <1> 	jz	short pfh_alloc_np
 11725                              <1> 	; 
 11726                              <1> 	; If it is not a 'write on read only page' type page fault
 11727                              <1> 	; major page fault error with minor reason must be returned without 
 11728                              <1> 	; fixing the problem. 'sys_exit with error' will be needed
 11729                              <1> 	; after return here!
 11730                              <1> 	; Page fault will be remedied, by copying page contents
 11731                              <1> 	; to newly allocated page with write permission;
 11732                              <1> 	; sys_fork -> sys_exec -> copy on write, demand paging method is 
 11733                              <1> 	; used for working with minimum possible memory usage. 
 11734                              <1> 	; sys_fork will duplicate page directory and tables of parent  
 11735                              <1> 	; process with 'read only' flag. If the child process attempts to
 11736                              <1> 	; write on these read only pages, page fault will be directed here
 11737                              <1> 	; for allocating a new page with same data/content. 
 11738                              <1> 	;
 11739                              <1> 	; IMPORTANT : Retro UNIX 386 v1 (and SINGLIX and TR-DOS)
 11740                              <1> 	; will not force to separate CODE and DATA space 
 11741                              <1> 	; in a process/program... 
 11742                              <1> 	; CODE segment/section may contain DATA!
 11743                              <1> 	; It is flat, smoth and simplest programming method already as in 
 11744                              <1> 	; Retro UNIX 8086 v1 and MS-DOS programs.
 11745                              <1> 	;	
 11746 000033F3 F6C202              <1> 	test	dl, 2	; page fault was caused by a page write
 11747                              <1> 			; sign
 11748 000033F6 0F84AB000000        <1>         jz      pfh_p_err
 11749                              <1> 	; 31/08/2015
 11750 000033FC F6C204              <1> 	test	dl, 4	; page fault was caused while CPL = 3 (user mode)
 11751                              <1> 			; sign.  (U+W+P = 4+2+1 = 7)
 11752 000033FF 0F84A2000000        <1>         jz	pfh_pv_err
 11753                              <1> 	;
 11754                              <1> 	; make a new page and copy the parent's page content
 11755                              <1> 	; as the child's new page content
 11756                              <1> 	;
 11757 00003405 0F20D3              <1> 	mov	ebx, cr2 ; CR2 contains the linear address 
 11758                              <1> 			 ; which has caused to page fault
 11759 00003408 E8A2000000          <1> 	call 	copy_page
 11760 0000340D 0F828D000000        <1>         jc      pfh_im_err ; insufficient memory
 11761                              <1> 	;
 11762 00003413 EB7D                <1>         jmp     pfh_cpp_ok
 11763                              <1> 	;
 11764                              <1> pfh_alloc_np:
 11765 00003415 E8EDFCFFFF          <1> 	call	allocate_page	; (allocate a new page)
 11766 0000341A 0F8280000000        <1>         jc      pfh_im_err	; 'insufficient memory' error
 11767                              <1> pfh_chk_cpl:
 11768                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 11769                              <1> 		; (Lower 12 bits are ZERO, because 
 11770                              <1> 		;	the address is on a page boundary)
 11771 00003420 80E204              <1> 	and	dl, 4	; CPL = 3 ?
 11772 00003423 7505                <1> 	jnz	short pfh_um
 11773                              <1> 			; Page fault handler for kernel/system mode (CPL=0)		
 11774 00003425 0F20DB              <1> 	mov	ebx, cr3 ; CR3 (Control Register 3) contains physical address
 11775                              <1> 			 ; of the current/active page directory
 11776                              <1> 			 ; (Always kernel/system mode page directory, here!)
 11777                              <1> 			 ; Note: Lower 12 bits are 0. (page boundary)
 11778 00003428 EB06                <1> 	jmp	short pfh_get_pde
 11779                              <1> 	;
 11780                              <1> pfh_um:			; Page fault handler for user/appl. mode (CPL=3)
 11781 0000342A 8B1D[99CE0000]      <1>  	mov	ebx, [u.pgdir] ; Page directory of current/active process
 11782                              <1> 			; Physical address of the USER's page directory
 11783                              <1> 			; Note: Lower 12 bits are 0. (page boundary)
 11784                              <1> pfh_get_pde:
 11785 00003430 80CA03              <1> 	or	dl, 3	; USER + WRITE + PRESENT or SYSTEM + WRITE + PRESENT
 11786 00003433 0F20D1              <1> 	mov	ecx, cr2 ; CR2 contains the virtual address 
 11787                              <1> 			 ; which has been caused to page fault
 11788                              <1> 			 ;
 11789 00003436 C1E914              <1> 	shr	ecx, 20	 ; shift 20 bits right
 11790 00003439 80E1FC              <1> 	and	cl, 0FCh ; mask lower 2 bits to get PDE offset		
 11791                              <1> 	;
 11792 0000343C 01CB                <1> 	add	ebx, ecx ; now, EBX points to the relevant page dir entry 
 11793 0000343E 8B0B                <1> 	mov	ecx, [ebx] ; physical (base) address of the page table 	
 11794 00003440 F6C101              <1> 	test	cl, 1	 ; check bit 0 is set (1) or not (0).
 11795 00003443 740B                <1> 	jz	short pfh_set_pde ; Page directory entry is not valid,
 11796                              <1> 			  	  ; set/validate page directory entry
 11797 00003445 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
 11798 0000344A 89CB                <1> 	mov	ebx, ecx ; Physical address of the page table
 11799 0000344C 89C1                <1> 	mov	ecx, eax ; new page address (physical) 	
 11800 0000344E EB16                <1> 	jmp	short pfh_get_pte
 11801                              <1> pfh_set_pde:
 11802                              <1> 	;; NOTE: Page directories and page tables never be swapped out!
 11803                              <1> 	;;	 (So, we know this PDE is empty or invalid)
 11804                              <1> 	;
 11805 00003450 08D0                <1> 	or	al, dl	 ; lower 3 bits are used as U/S, R/W, P flags
 11806 00003452 8903                <1> 	mov	[ebx], eax ; Let's put the new page directory entry here !
 11807 00003454 30C0                <1> 	xor	al, al	 ; clear lower (3..8) bits
 11808 00003456 89C3                <1> 	mov	ebx, eax
 11809 00003458 E8AAFCFFFF          <1> 	call	allocate_page	 ; (allocate a new page)
 11810 0000345D 7241                <1> 	jc	short pfh_im_err   ; 'insufficient memory' error
 11811                              <1> pfh_spde_1:
 11812                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 11813 0000345F 89C1                <1> 	mov	ecx, eax
 11814 00003461 E81BFDFFFF          <1> 	call	clear_page ; Clear page content
 11815                              <1> pfh_get_pte:
 11816 00003466 0F20D0              <1> 	mov	eax, cr2 ; virtual address
 11817                              <1> 			 ; which has been caused to page fault
 11818 00003469 89C7                <1> 	mov	edi, eax ; 20/07/2015
 11819 0000346B C1E80C              <1> 	shr	eax, 12	 ; shift 12 bit right to get 
 11820                              <1> 			 ; higher 20 bits of the page fault address 
 11821 0000346E 25FF030000          <1> 	and	eax, 3FFh ; mask PDE# bits, the result is PTE# (0 to 1023)
 11822 00003473 C1E002              <1> 	shl	eax, 2	; shift 2 bits left to get PTE offset
 11823 00003476 01C3                <1> 	add	ebx, eax ; now, EBX points to the relevant page table entry 
 11824 00003478 8B03                <1> 	mov	eax, [ebx] ; get previous value of pte
 11825                              <1> 		; bit 0 of EAX is always 0 (otherwise we would not be here)
 11826 0000347A 21C0                <1> 	and	eax, eax
 11827 0000347C 7410                <1> 	jz	short pfh_gpte_1
 11828                              <1> 	; 20/07/2015
 11829 0000347E 87D9                <1> 	xchg	ebx, ecx ; new page address (physical)
 11830 00003480 55                  <1> 	push	ebp ; 20/07/2015
 11831 00003481 0F20D5              <1> 	mov	ebp, cr2
 11832                              <1> 		; ECX = physical address of the page table entry
 11833                              <1> 		; EBX = Memory page address (physical!)
 11834                              <1> 		; EAX = Swap disk (offset) address
 11835                              <1> 		; EBP = virtual address (page fault address)
 11836 00003484 E8B7000000          <1> 	call	swap_in
 11837 00003489 5D                  <1> 	pop	ebp
 11838 0000348A 7210                <1> 	jc      short pfh_err_retn
 11839 0000348C 87CB                <1> 	xchg	ecx, ebx
 11840                              <1> 		; EBX = physical address of the page table entry
 11841                              <1> 		; ECX = new page
 11842                              <1> pfh_gpte_1:
 11843 0000348E 08D1                <1> 	or	cl, dl	; lower 3 bits are used as U/S, R/W, P flags
 11844 00003490 890B                <1> 	mov	[ebx], ecx ; Let's put the new page table entry here !
 11845                              <1> pfh_cpp_ok:
 11846                              <1> 	; 20/07/2015
 11847 00003492 0F20D3              <1> 	mov	ebx, cr2
 11848 00003495 E82A020000          <1> 	call 	add_to_swap_queue
 11849                              <1> 	;
 11850                              <1> 	; The new PTE (which contains the new page) will be added to 
 11851                              <1> 	; the swap queue, here. 
 11852                              <1> 	; (Later, if memory will become insufficient, 
 11853                              <1> 	; one page will be swapped out which is at the head of 
 11854                              <1> 	; the swap queue by using FIFO and access check methods.)
 11855                              <1> 	;
 11856 0000349A 31C0                <1> 	xor	eax, eax  ; 0
 11857                              <1> 	;
 11858                              <1> pfh_err_retn:
 11859 0000349C 59                  <1> 	pop	ecx
 11860 0000349D 5A                  <1> 	pop	edx
 11861 0000349E 5B                  <1> 	pop	ebx
 11862 0000349F C3                  <1> 	retn 
 11863                              <1> 	
 11864                              <1> pfh_im_err:
 11865 000034A0 B8E1000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_IM ; Error code in AX
 11866                              <1> 			; Major (Primary) Error: Page Fault
 11867                              <1> 			; Minor (Secondary) Error: Insufficient Memory !
 11868 000034A5 EBF5                <1> 	jmp	short pfh_err_retn
 11869                              <1> 
 11870                              <1> 
 11871                              <1> pfh_p_err: ; 09/03/2015
 11872                              <1> pfh_pv_err:
 11873                              <1> 	; Page fault was caused by a protection-violation
 11874 000034A7 B8E3000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_PV ; Error code in AX
 11875                              <1> 			; Major (Primary) Error: Page Fault
 11876                              <1> 			; Minor (Secondary) Error: Protection violation !
 11877 000034AC F9                  <1> 	stc
 11878 000034AD EBED                <1> 	jmp	short pfh_err_retn
 11879                              <1> 
 11880                              <1> copy_page:
 11881                              <1> 	; 22/09/2015
 11882                              <1> 	; 21/09/2015
 11883                              <1> 	; 19/09/2015
 11884                              <1> 	; 07/09/2015
 11885                              <1> 	; 31/08/2015
 11886                              <1> 	; 20/07/2015
 11887                              <1> 	; 05/05/2015
 11888                              <1> 	; 03/05/2015
 11889                              <1> 	; 18/04/2015
 11890                              <1> 	; 12/04/2015
 11891                              <1> 	; 30/10/2014
 11892                              <1> 	; 18/10/2014 (Retro UNIX 386 v1 - beginning)
 11893                              <1> 	;
 11894                              <1> 	; INPUT -> 
 11895                              <1> 	;	EBX = Virtual (linear) address of source page
 11896                              <1> 	;	     (Page fault address)
 11897                              <1> 	; OUTPUT ->
 11898                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 11899                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
 11900                              <1> 	;	EAX = 0 (CF = 1) 
 11901                              <1> 	;		if there is not a free page to be allocated
 11902                              <1> 	;	(page content of the source page will be copied
 11903                              <1> 	;	onto the target/new page) 	
 11904                              <1> 	;
 11905                              <1> 	; Modified Registers -> ecx, ebx (except EAX)
 11906                              <1> 	;	
 11907 000034AF 56                  <1> 	push	esi
 11908 000034B0 57                  <1> 	push	edi
 11909                              <1> 	;push	ebx
 11910                              <1> 	;push	ecx
 11911 000034B1 31F6                <1> 	xor 	esi, esi
 11912 000034B3 C1EB0C              <1> 	shr	ebx, 12 ; shift 12 bits right to get PDE & PTE numbers
 11913 000034B6 89D9                <1> 	mov	ecx, ebx ; save page fault address (as 12 bit shifted)
 11914 000034B8 C1EB08              <1> 	shr	ebx, 8	 ; shift 8 bits right and then
 11915 000034BB 80E3FC              <1> 	and	bl, 0FCh ; mask lower 2 bits to get PDE offset	
 11916 000034BE 89DF                <1> 	mov 	edi, ebx ; save it for the parent of current process
 11917 000034C0 031D[99CE0000]      <1> 	add	ebx, [u.pgdir] ; EBX points to the relevant page dir entry 
 11918 000034C6 8B03                <1> 	mov	eax, [ebx] ; physical (base) address of the page table
 11919 000034C8 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits 	
 11920 000034CC 89CB                <1> 	mov	ebx, ecx   ; (restore higher 20 bits of page fault address)
 11921 000034CE 81E3FF030000        <1> 	and	ebx, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
 11922 000034D4 66C1E302            <1> 	shl	bx, 2	   ; shift 2 bits left to get PTE offset
 11923 000034D8 01C3                <1> 	add	ebx, eax   ; EBX points to the relevant page table entry 
 11924                              <1> 	; 07/09/2015
 11925 000034DA 66F7030002          <1>         test    word [ebx], PTE_DUPLICATED ; (Does current process share this
 11926                              <1> 				     ; read only page as a child process?)	
 11927 000034DF 7509                <1> 	jnz	short cpp_0 ; yes
 11928 000034E1 8B0B                <1> 	mov	ecx, [ebx] ; PTE value
 11929 000034E3 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h  ; clear page attributes
 11930 000034E8 EB32                <1> 	jmp	short cpp_1
 11931                              <1> cpp_0:
 11932 000034EA 89FE                <1> 	mov	esi, edi
 11933 000034EC 0335[9DCE0000]      <1> 	add	esi, [u.ppgdir] ; the parent's page directory entry
 11934 000034F2 8B06                <1> 	mov	eax, [esi] ; physical (base) address of the page table
 11935 000034F4 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 11936 000034F8 89CE                <1> 	mov	esi, ecx   ; (restore higher 20 bits of page fault address)	
 11937 000034FA 81E6FF030000        <1> 	and	esi, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
 11938 00003500 66C1E602            <1> 	shl	si, 2	   ; shift 2 bits left to get PTE offset
 11939 00003504 01C6                <1> 	add	esi, eax   ; EDX points to the relevant page table entry  	
 11940 00003506 8B0E                <1> 	mov	ecx, [esi] ; PTE value of the parent process
 11941                              <1> 	; 21/09/2015
 11942 00003508 8B03                <1> 	mov	eax, [ebx] ; PTE value of the child process
 11943 0000350A 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear page attributes	
 11944                              <1> 	;
 11945 0000350E F6C101              <1> 	test	cl, PTE_A_PRESENT ; is it a present/valid page ?
 11946 00003511 7424                <1> 	jz	short cpp_3 ; the parent's page is not same page  	
 11947                              <1> 	;
 11948 00003513 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h ; clear page attributes
 11949 00003518 39C8                <1> 	cmp	eax, ecx   ; Same page?	
 11950 0000351A 751B                <1> 	jne	short cpp_3 ; Parent page and child page are not same 
 11951                              <1> 			    ; Convert child's page to writable page
 11952                              <1> cpp_1:
 11953 0000351C E8E6FBFFFF          <1> 	call	allocate_page
 11954 00003521 721A                <1> 	jc	short cpp_4 ; 'insufficient memory' error
 11955 00003523 21F6                <1> 	and	esi, esi    ; check ESI is valid or not
 11956 00003525 7405                <1> 	jz	short cpp_2
 11957                              <1> 		; Convert read only page to writable page 
 11958                              <1> 		;(for the parent of the current process)
 11959                              <1> 	;and	word [esi], PTE_A_CLEAR ; 0F000h
 11960                              <1> 	; 22/09/2015
 11961 00003527 890E                <1> 	mov	[esi], ecx
 11962 00003529 800E07              <1> 	or	byte [esi], PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER
 11963                              <1> 				 ; 1+2+4 = 7
 11964                              <1> cpp_2:
 11965 0000352C 89C7                <1> 	mov	edi, eax ; new page address of the child process
 11966                              <1> 	; 07/09/2015
 11967 0000352E 89CE                <1> 	mov	esi, ecx ; the page address of the parent process
 11968 00003530 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
 11969 00003535 F3A5                <1> 	rep	movsd ; 31/08/2015
 11970                              <1> cpp_3:		
 11971 00003537 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 1+2+4 = 7
 11972 00003539 8903                <1> 	mov	[ebx], eax ; Update PTE
 11973 0000353B 28C0                <1> 	sub	al, al ; clear attributes
 11974                              <1> cpp_4:
 11975                              <1> 	;pop	ecx
 11976                              <1> 	;pop	ebx
 11977 0000353D 5F                  <1> 	pop	edi
 11978 0000353E 5E                  <1> 	pop	esi
 11979 0000353F C3                  <1> 	retn
 11980                              <1> 
 11981                              <1> ;; 28/04/2015
 11982                              <1> ;; 24/10/2014
 11983                              <1> ;; 21/10/2014 (Retro UNIX 386 v1 - beginning)
 11984                              <1> ;; SWAP_PAGE_QUEUE (4096 bytes)
 11985                              <1> ;;
 11986                              <1> ;;   0000   0001   0002   0003   ....   1020   1021   1022   1023	
 11987                              <1> ;; +------+------+------+------+-    -+------+------+------+------+
 11988                              <1> ;; |  pg1 |  pg2 |  pg3 |  pg4 | .... |pg1021|pg1022|pg1023|pg1024|
 11989                              <1> ;; +------+------+------+------+-    -+------+------+------+------+    
 11990                              <1> ;;
 11991                              <1> ;; [swpq_last] = 0 to 4096 (step 4) -> the last position on the queue
 11992                              <1> ;;
 11993                              <1> ;; Method:
 11994                              <1> ;;	Swap page queue is a list of allocated pages with physical
 11995                              <1> ;;	addresses (system mode virtual adresses = physical addresses).
 11996                              <1> ;;	It is used for 'swap_in' and 'swap_out' procedures.
 11997                              <1> ;;	When a new page is being allocated, swap queue is updated
 11998                              <1> ;;	by 'swap_queue_shift' procedure, header of the queue (offset 0)
 11999                              <1> ;;	is checked for 'accessed' flag. If the 1st page on the queue
 12000                              <1> ;;	is 'accessed' or 'read only', it is dropped from the list;
 12001                              <1> ;;	other pages from the 2nd to the last (in [swpq_last]) shifted
 12002                              <1> ;; 	to head then the 2nd page becomes the 1st and '[swpq_last]' 
 12003                              <1> ;;	offset value becomes it's previous offset value - 4.
 12004                              <1> ;;	If the 1st page of the swap page queue is not 'accessed'	
 12005                              <1> ;;	the queue/list is not shifted.
 12006                              <1> ;;	After the queue/list shift, newly allocated page is added
 12007                              <1> ;;	to the tail of the queue at the [swpq_count*4] position.
 12008                              <1> ;;	But, if [swpq_count] > 1023, the newly allocated page
 12009                              <1> ;;	will not be added to the tail of swap page queue.  		 
 12010                              <1> ;;	
 12011                              <1> ;;	During 'swap_out' procedure, swap page queue is checked for
 12012                              <1> ;;	the first non-accessed, writable page in the list, 
 12013                              <1> ;;	from the head to the tail. The list is shifted to left 
 12014                              <1> ;;	(to the head) till a non-accessed page will be found in the list.
 12015                              <1> ;;	Then, this page	is swapped out (to disk) and then it is dropped
 12016                              <1> ;;	from the list by a final swap queue shift. [swpq_count] value
 12017                              <1> ;;	is changed. If all pages on the queue' are 'accessed', 
 12018                              <1> ;;	'insufficient memory' error will be returned ('swap_out' 
 12019                              <1> ;;	procedure will be failed)...
 12020                              <1> ;;
 12021                              <1> ;;	Note: If the 1st page of the queue is an 'accessed' page,
 12022                              <1> ;;	'accessed' flag of the page will be reset (0) and that page
 12023                              <1> ;;	(PTE) will be added to the tail of the queue after
 12024                              <1> ;;	the check, if [swpq_count] < 1023. If [swpq_count] = 1024
 12025                              <1> ;;	the queue will be rotated and the PTE in the head will be
 12026                              <1> ;;	added to the tail after resetting 'accessed' bit. 
 12027                              <1> ;;
 12028                              <1> ;;
 12029                              <1> ;;	
 12030                              <1> ;; SWAP DISK/FILE (with 4096 bytes swapped page blocks)
 12031                              <1> ;;
 12032                              <1> ;;  00000000  00000004  00000008  0000000C   ...   size-8    size-4
 12033                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+
 12034                              <1> ;; |descriptr| page(1) | page(2) | page(3) | ... |page(n-1)| page(n) |
 12035                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+    
 12036                              <1> ;;
 12037                              <1> ;; [swpd_next] = the first free block address in swapped page records
 12038                              <1> ;;    		 for next free block search by 'swap_out' procedure.
 12039                              <1> ;; [swpd_size] = swap disk/file size in sectors (512 bytes)
 12040                              <1> ;;		 NOTE: max. possible swap disk size is 1024 GB
 12041                              <1> ;; 		 (entire swap space must be accessed by using
 12042                              <1> ;;		 31 bit offset address) 
 12043                              <1> ;; [swpd_free] = free block (4096 bytes) count in swap disk/file space
 12044                              <1> ;; [swpd_start] = absolute/start address of the swap disk/file
 12045                              <1> ;;		  0 for file, or beginning sector of the swap partition
 12046                              <1> ;; [swp_drv] = logical drive description table addr. of swap disk/file
 12047                              <1> ;;
 12048                              <1> ;; 					
 12049                              <1> ;; Method:
 12050                              <1> ;;	When the memory (ram) becomes insufficient, page allocation
 12051                              <1> ;;	procedure swaps out a page from memory to the swap disk 
 12052                              <1> ;;	(partition) or swap file to get a new free page at the memory.
 12053                              <1> ;;	Swapping out is performed by using swap page queue.
 12054                              <1> ;;
 12055                              <1> ;; 	Allocation block size of swap disk/file is equal to page size
 12056                              <1> ;;	(4096 bytes). Swapping address (in sectors) is recorded
 12057                              <1> ;;	into relevant page file entry as 31 bit physical (logical)
 12058                              <1> ;;	offset address as 1 bit shifted to left for present flag (0).
 12059                              <1> ;;	Swapped page address is between 1 and swap disk/file size - 4.	  
 12060                              <1> ;;	Absolute physical (logical) address of the swapped page is 
 12061                              <1> ;;	calculated by adding offset value to the swap partition's 
 12062                              <1> ;;	start address. If the swap device (disk) is a virtual disk 
 12063                              <1> ;;	or it is a file, start address of the swap disk/volume is 0, 
 12064                              <1> ;;	and offset value is equal to absolute (physical or logical)
 12065                              <1> ;;	address/position. (It has not to be ZERO if the swap partition 
 12066                              <1> ;;	is in a partitioned virtual hard disk.) 
 12067                              <1> ;;
 12068                              <1> ;;	Note: Swap addresses are always specified/declared in sectors, 
 12069                              <1> ;;	not in bytes or	in blocks/zones/clusters (4096 bytes) as unit.
 12070                              <1> ;;
 12071                              <1> ;;	Swap disk/file allocation is mapped via 'Swap Allocation Table'
 12072                              <1> ;;	at memory as similar to 'Memory Allocation Table'.
 12073                              <1> ;;
 12074                              <1> ;;	Every bit of Swap Allocation Table repsesents one swap block
 12075                              <1> ;;	(equal to page size) respectively. Bit 0 of the S.A.T. byte 0
 12076                              <1> ;;	is reserved for swap disk/file block 0 as descriptor block
 12077                              <1> ;;	(also for compatibility with PTE). If bit value is ZERO,
 12078                              <1> ;;	it means relevant (respective) block is in use, and, 
 12079                              <1> ;;	of course, if bit value is 1, it means relevant (respective)
 12080                              <1> ;;      swap disk/file block is free.
 12081                              <1> ;;	For example: bit 1 of the byte 128 repsesents block 1025 
 12082                              <1> ;;	(128*8+1) or sector (offset) 8200 on the swap disk or
 12083                              <1> ;;	byte (offset/position) 4198400 in the swap file. 
 12084                              <1> ;;	4GB swap space is represented via 128KB Swap Allocation Table.
 12085                              <1> ;;	Initial layout of Swap Allocation Table is as follows:
 12086                              <1> ;;	------------------------------------------------------------
 12087                              <1> ;;	0111111111111111111111111 .... 11111111111111111111111111111
 12088                              <1> ;;	------------------------------------------------------------
 12089                              <1> ;;	(0 is reserved block, 1s represent free blocks respectively.)
 12090                              <1> ;;	(Note: Allocation cell/unit of the table is bit, not byte)
 12091                              <1> ;;
 12092                              <1> ;;	..............................................................
 12093                              <1> ;;
 12094                              <1> ;;	'swap_out' procedure checks 'free_swap_blocks' count at first,
 12095                              <1> ;;	then it searches Swap Allocation Table if free count is not
 12096                              <1> ;;	zero. From begining the [swpd_next] dword value, the first bit 
 12097                              <1> ;;	position with value of 1 on the table is converted to swap
 12098                              <1> ;;	disk/file offset address, in sectors (not 4096 bytes block).
 12099                              <1> ;;	'ldrv_write' procedure is called with ldrv (logical drive
 12100                              <1> ;;	number of physical swap disk or virtual swap disk)
 12101                              <1> ;;	number, sector offset (not absolute sector -LBA- number),
 12102                              <1> ;;	and sector count (8, 512*8 = 4096) and buffer adress
 12103                              <1> ;;	(memory page). That will be a direct disk write procedure.
 12104                              <1> ;;	(for preventing late memory allocation, significant waiting). 
 12105                              <1> ;;	If disk write procedure returns with error or free count of 
 12106                              <1> ;;	swap blocks is ZERO, 'swap_out' procedure will return with
 12107                              <1> ;;	'insufficient memory error' (cf=1). 
 12108                              <1> ;;
 12109                              <1> ;;	(Note: Even if free swap disk/file blocks was not zero,
 12110                              <1> ;;	any disk write error will not be fixed by 'swap_out' procedure,
 12111                              <1> ;;	in other words, 'swap_out' will not check the table for other
 12112                              <1> ;;	free blocks after a disk write error. It will return to 
 12113                              <1> ;;	the caller with error (CF=1) which means swapping is failed. 
 12114                              <1> ;;
 12115                              <1> ;;	After writing the page on to swap disk/file address/sector,
 12116                              <1> ;;	'swap_out' procesure returns with that swap (offset) sector
 12117                              <1> ;;	address (cf=0). 
 12118                              <1> ;;
 12119                              <1> ;;	..............................................................
 12120                              <1> ;;
 12121                              <1> ;;	'swap_in' procedure loads addressed (relevant) swap disk or
 12122                              <1> ;;	file sectors at specified memory page. Then page allocation
 12123                              <1> ;;	procedure updates relevant page table entry with 'present' 
 12124                              <1> ;;	attribute. If swap disk or file reading fails there is nothing
 12125                              <1> ;;	to do, except to terminate the process which is the owner of
 12126                              <1> ;;	the swapped page.
 12127                              <1> ;;
 12128                              <1> ;;	'swap_in' procedure sets the relevant/respective bit value
 12129                              <1> ;;	in the Swap Allocation Table (as free block). 'swap_in' also
 12130                              <1> ;;	updates [swpd_first] pointer if it is required.
 12131                              <1> ;;
 12132                              <1> ;;	..............................................................	 
 12133                              <1> ;;
 12134                              <1> ;;	Note: If [swap_enabled] value is ZERO, that means there is not
 12135                              <1> ;;	a swap disk or swap file in use... 'swap_in' and 'swap_out'
 12136                              <1> ;;	procedures ans 'swap page que' procedures will not be active...
 12137                              <1> ;;	'Insufficient memory' error will be returned by 'swap_out'
 12138                              <1> ;;	and 'general protection fault' will be returned by 'swap_in'
 12139                              <1> ;;	procedure, if it is called mistakenly (a wrong value in a PTE).		
 12140                              <1> ;;
 12141                              <1> 
 12142                              <1> swap_in:
 12143                              <1> 	; 31/08/2015
 12144                              <1> 	; 20/07/2015
 12145                              <1> 	; 28/04/2015
 12146                              <1> 	; 18/04/2015
 12147                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12148                              <1> 	;
 12149                              <1> 	; INPUT -> 
 12150                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS OF THE MEMORY PAGE
 12151                              <1> 	;	EBP = VIRTUAL (LINEAR) ADDRESS (page fault address)
 12152                              <1> 	;	EAX = Offset Address for the swapped page on the
 12153                              <1> 	;	      swap disk or in the swap file.
 12154                              <1> 	;
 12155                              <1> 	; OUTPUT ->
 12156                              <1> 	;	EAX = 0 if loading at memory has been successful
 12157                              <1> 	;
 12158                              <1> 	;	CF = 1 -> swap disk reading error (disk/file not present
 12159                              <1> 	;		  or sector not present or drive not ready
 12160                              <1> 	;	     EAX = Error code
 12161                              <1> 	;	     [u.error] = EAX 
 12162                              <1> 	;		       = The last error code for the process
 12163                              <1> 	;		         (will be reset after returning to user)	  
 12164                              <1> 	;
 12165                              <1> 	; Modified Registers -> EAX
 12166                              <1> 	;
 12167                              <1> 
 12168 00003540 833D[F7DA0000]00    <1>         cmp     dword [swp_drv], 0
 12169 00003547 7648                <1> 	jna	short swpin_dnp_err
 12170                              <1> 
 12171 00003549 3B05[FBDA0000]      <1> 	cmp	eax, [swpd_size]
 12172 0000354F 734C                <1> 	jnb	short swpin_snp_err
 12173                              <1> 
 12174 00003551 56                  <1> 	push	esi
 12175 00003552 53                  <1> 	push	ebx
 12176 00003553 51                  <1> 	push	ecx
 12177 00003554 8B35[F7DA0000]      <1> 	mov	esi, [swp_drv]	
 12178 0000355A B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
 12179                              <1> 		; Note: Even if corresponding physical disk's sector 
 12180                              <1> 		; size different than 512 bytes, logical disk sector
 12181                              <1> 		; size is 512 bytes and disk reading procedure
 12182                              <1> 		; will be performed for reading 4096 bytes
 12183                              <1> 		; (2*2048, 8*512). 
 12184                              <1> 	; ESI = Logical disk description table address
 12185                              <1> 	; EBX = Memory page (buffer) address (physical!)
 12186                              <1> 	; EAX = Sector adress (offset address, logical sector number)
 12187                              <1> 	; ECX = Sector count ; 8 sectors
 12188 0000355F 50                  <1> 	push	eax
 12189 00003560 E833020000          <1> 	call	logical_disk_read
 12190 00003565 58                  <1> 	pop	eax
 12191 00003566 730C                <1> 	jnc	short swpin_read_ok
 12192                              <1> 	;
 12193 00003568 B804000000          <1> 	mov	eax, SWP_DISK_READ_ERR ; drive not ready or read error
 12194 0000356D A3[95CE0000]        <1> 	mov	[u.error], eax
 12195 00003572 EB19                <1> 	jmp	short swpin_retn
 12196                              <1> 	;
 12197                              <1> swpin_read_ok:
 12198                              <1> 	; EAX = Offset address (logical sector number)
 12199 00003574 E891010000          <1> 	call	unlink_swap_block  ; Deallocate swap block	
 12200                              <1> 	;
 12201                              <1> 	; EBX = Memory page (buffer) address (physical!)
 12202                              <1> 	; 20/07/2015
 12203 00003579 89EB                <1> 	mov	ebx, ebp ; virtual address (page fault address)
 12204 0000357B 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
 12205 00003580 8A1D[8FCE0000]      <1> 	mov	bl, [u.uno] ; current process number
 12206                              <1> 	; EBX = Virtual address & process number combination
 12207 00003586 E89E000000          <1> 	call	swap_queue_shift
 12208 0000358B 29C0                <1> 	sub	eax, eax  ; 0 ; Error Code = 0  (no error)
 12209                              <1> 	;
 12210                              <1> swpin_retn:
 12211 0000358D 59                  <1> 	pop	ecx
 12212 0000358E 5B                  <1> 	pop	ebx
 12213 0000358F 5E                  <1> 	pop	esi
 12214 00003590 C3                  <1> 	retn
 12215                              <1> 
 12216                              <1> swpin_dnp_err:
 12217 00003591 B805000000          <1> 	mov	eax, SWP_DISK_NOT_PRESENT_ERR
 12218                              <1> swpin_err_retn:
 12219 00003596 A3[95CE0000]        <1> 	mov	[u.error], eax
 12220 0000359B F9                  <1> 	stc
 12221 0000359C C3                  <1> 	retn
 12222                              <1> 
 12223                              <1> swpin_snp_err:
 12224 0000359D B806000000          <1> 	mov	eax, SWP_SECTOR_NOT_PRESENT_ERR
 12225 000035A2 EBF2                <1> 	jmp	short swpin_err_retn
 12226                              <1> 
 12227                              <1> swap_out:
 12228                              <1> 	; 31/08/2015
 12229                              <1> 	; 05/05/2015
 12230                              <1> 	; 30/04/2015
 12231                              <1> 	; 28/04/2015
 12232                              <1> 	; 18/04/2015
 12233                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12234                              <1> 	;
 12235                              <1> 	; INPUT -> 
 12236                              <1> 	;	none
 12237                              <1> 	;
 12238                              <1> 	; OUTPUT ->
 12239                              <1> 	;	EAX = Physical page address (which is swapped out
 12240                              <1> 	;	      for allocating a new page)
 12241                              <1> 	;	CF = 1 -> swap disk writing error (disk/file not present
 12242                              <1> 	;		  or sector not present or drive not ready
 12243                              <1> 	;	     EAX = Error code
 12244                              <1> 	;	     [u.error] = EAX 
 12245                              <1> 	;		       = The last error code for the process
 12246                              <1> 	;		         (will be reset after returning to user)	  
 12247                              <1> 	;
 12248                              <1> 	; Modified Registers -> non (except EAX)
 12249                              <1> 	;
 12250 000035A4 66833D[F5DA0000]01  <1> 	cmp 	word [swpq_count], 1
 12251 000035AC 7274                <1>         jc      short swpout_im_err ; 'insufficient memory'
 12252                              <1> 
 12253                              <1>         ;cmp     dword [swp_drv], 1
 12254                              <1> 	;jc	short swpout_dnp_err ; 'swap disk/file not present'
 12255                              <1> 
 12256 000035AE 833D[FFDA0000]01    <1>         cmp     dword [swpd_free], 1
 12257 000035B5 7258                <1> 	jc	short swpout_nfspc_err ; 'no free space on swap disk'
 12258                              <1> 
 12259 000035B7 53                  <1> 	push	ebx
 12260                              <1> swpout_1:
 12261 000035B8 31DB                <1> 	xor	ebx, ebx
 12262 000035BA E86A000000          <1> 	call	swap_queue_shift
 12263 000035BF 21C0                <1> 	and	eax, eax	; entry count (before shifting)
 12264 000035C1 7457                <1> 	jz	short swpout_npts_err  ; There is no any PTE in
 12265                              <1> 				       ; the swap queue
 12266 000035C3 BB00E00800          <1> 	mov	ebx, swap_queue	       ; Addres of the head of 
 12267                              <1> 				       ; the swap queue		
 12268 000035C8 8B03                <1> 	mov	eax, [ebx]	       ; The PTE in the queue head	
 12269                              <1> 
 12270                              <1> 	;test	al, PTE_A_PRESENT      ; bit 0 = 1
 12271                              <1> 	;jz	short swpout_1	       ; non-present page already
 12272                              <1> 				       ; must not be in the queue
 12273                              <1> 
 12274                              <1> 	;test	al, PTE_A_WRITE	       ; bit 1 = 0
 12275                              <1> 	;jz	short swpout_1 	       ; read only page (must not be
 12276                              <1> 				       ; swapped out)
 12277                              <1> 	
 12278 000035CA A820                <1> 	test	al, PTE_A_ACCESS       ; bit 5 = 1 (Accessed)
 12279 000035CC 75EA                <1> 	jnz	short swpout_1 	       ; accessed page (must not be
 12280                              <1> 				       ; swapped out, at this stage)
 12281                              <1> 	;
 12282 000035CE 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 12283                              <1> 	;
 12284 000035D2 52                  <1> 	push	edx
 12285 000035D3 89DA                <1> 	mov	edx, ebx	       ; Page table entry address	
 12286 000035D5 89C3                <1> 	mov	ebx, eax	       ; Buffer (Page) Address				
 12287                              <1> 	;
 12288 000035D7 E861010000          <1> 	call	link_swap_block
 12289 000035DC 7304                <1> 	jnc	short swpout_2	       ; It may not be needed here	
 12290 000035DE 5A                  <1> 	pop	edx		       ; because [swpd_free] value	
 12291 000035DF 5B                  <1> 	pop	ebx
 12292 000035E0 EB2D                <1> 	jmp	short swpout_nfspc_err ; was checked at the beginging. 	
 12293                              <1> swpout_2:	
 12294 000035E2 56                  <1> 	push	esi
 12295 000035E3 51                  <1> 	push	ecx
 12296 000035E4 50                  <1> 	push	eax ; sector address
 12297 000035E5 8B35[F7DA0000]      <1> 	mov	esi, [swp_drv]	
 12298 000035EB B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
 12299                              <1> 		; Note: Even if corresponding physical disk's sector 
 12300                              <1> 		; size different than 512 bytes, logical disk sector
 12301                              <1> 		; size is 512 bytes and disk writing procedure
 12302                              <1> 		; will be performed for writing 4096 bytes
 12303                              <1> 		; (2*2048, 8*512). 
 12304                              <1> 	; ESI = Logical disk description table address
 12305                              <1> 	; EBX = Buffer address
 12306                              <1> 	; EAX = Sector adress (offset address, logical sector number)
 12307                              <1> 	; ECX = Sector count ; 8 sectors
 12308 000035F0 E8A4010000          <1> 	call	logical_disk_write
 12309 000035F5 59                  <1> 	pop	ecx ; sector address	
 12310 000035F6 730C                <1> 	jnc	short swpout_write_ok
 12311                              <1> 	;
 12312                              <1> 	;; call	unlink_swap_block ; this block must be left as 'in use'
 12313                              <1> swpout_dw_err:
 12314 000035F8 B808000000          <1> 	mov	eax, SWP_DISK_WRITE_ERR ; drive not ready or write error
 12315 000035FD A3[95CE0000]        <1> 	mov	[u.error], eax
 12316 00003602 EB06                <1> 	jmp	short swpout_retn
 12317                              <1> 	;
 12318                              <1> swpout_write_ok:
 12319                              <1> 	; EBX = Buffer (page) address
 12320                              <1> 	; EDX = Page Table entry address
 12321                              <1> 	; ECX = Swap disk sector (file block) address (31 bit)
 12322 00003604 D1E1                <1> 	shl 	ecx, 1  ; 31 bit sector address from bit 1 to bit 31 
 12323 00003606 890A                <1> 	mov 	[edx], ecx 
 12324                              <1> 		; bit 0 = 0 (swapped page)
 12325 00003608 89D8                <1> 	mov	eax, ebx
 12326                              <1> swpout_retn:
 12327 0000360A 59                  <1> 	pop	ecx
 12328 0000360B 5E                  <1> 	pop	esi
 12329 0000360C 5A                  <1> 	pop	edx
 12330 0000360D 5B                  <1> 	pop	ebx
 12331 0000360E C3                  <1> 	retn
 12332                              <1> 
 12333                              <1> ; Note: Swap_queue will not be updated in 'swap_out' procedure
 12334                              <1> ;	after the page is swapped out. (the PTE at the queue head
 12335                              <1> ;	-with 'non-present' attribute- will be dropped from the
 12336                              <1> ;	the queue in next 'swap_out' or in next 'swap_queue_shift'.
 12337                              <1> 	
 12338                              <1> ;swpout_dnp_err:
 12339                              <1> ;	mov	eax, SWP_DISK_NOT_PRESENT_ERR ; disk not present
 12340                              <1> ;	jmp	short swpout_err_retn
 12341                              <1> swpout_nfspc_err:
 12342 0000360F B807000000          <1> 	mov	eax, SWP_NO_FREE_SPACE_ERR ; no free space
 12343                              <1> swpout_err_retn:
 12344 00003614 A3[95CE0000]        <1> 	mov	[u.error], eax
 12345                              <1> 	;stc
 12346 00003619 C3                  <1> 	retn
 12347                              <1> swpout_npts_err:
 12348 0000361A B809000000          <1> 	mov	eax, SWP_NO_PAGE_TO_SWAP_ERR
 12349 0000361F 5B                  <1> 	pop	ebx
 12350 00003620 EBF2                <1> 	jmp	short swpout_err_retn
 12351                              <1> swpout_im_err:
 12352 00003622 B801000000          <1> 	mov	eax, ERR_MINOR_IM ; insufficient (out of) memory
 12353 00003627 EBEB                <1> 	jmp	short swpout_err_retn
 12354                              <1> 
 12355                              <1> swap_queue_shift:
 12356                              <1> 	; 20/07/2015
 12357                              <1> 	; 28/04/2015
 12358                              <1> 	; 18/04/2015
 12359                              <1> 	; 23/10/2014 (Retro UNIX 386 v1 - beginning)
 12360                              <1> 	;
 12361                              <1> 	; INPUT ->
 12362                              <1> 	;	EBX = Virtual (linear) address (bit 12 to 31) 
 12363                              <1> 	;	      and process number combination (bit 0 to 11)
 12364                              <1> 	;	EBX = 0 -> shift/drop from the head (offset 0)
 12365                              <1> 	; OUTPUT ->
 12366                              <1> 	;	If EBX input > 0 
 12367                              <1> 	;	    the queue will be shifted 4 bytes (dword),
 12368                              <1> 	; 	    from the tail to the head, up to entry offset
 12369                              <1> 	; 	    which points to EBX input value or nothing
 12370                              <1> 	;	    to do if EBX value is not found in the queue.
 12371                              <1> 	;	    (The entry -with EBX value- will be removed
 12372                              <1> 	;	     from the queue if it is found.)	
 12373                              <1> 	;	If EBX input = 0
 12374                              <1> 	;	    the queue will be shifted 4 bytes (dword),
 12375                              <1> 	; 	    from the tail to the head, if the PTE address
 12376                              <1> 	;	    in head of the queue is marked as "accessed"
 12377                              <1> 	;	    or it is marked as "non present".
 12378                              <1> 	;	    (If "accessed" flag of the PTE -in the head-
 12379                              <1> 	; 	    is set -to 1-, it will be reset -to 0- and then, 
 12380                              <1> 	;	    the queue will be rotated -without dropping
 12381                              <1> 	; 	    the PTE from the queue-, for 4 bytes on head
 12382                              <1> 	; 	    to tail direction. The PTE in the head will be
 12383                              <1> 	;	    moved in the tail, other PTEs will be shifted on
 12384                              <1> 	;	    head direction.)	
 12385                              <1> 	;
 12386                              <1> 	;	EAX = [swpq_count] (before the shifting)
 12387                              <1> 	;	    (EAX = 0 -> next 'swap_out' stage 
 12388                              <1> 	; 	     is not applicable)	
 12389                              <1> 	;
 12390                              <1> 	; Modified Registers -> EAX
 12391                              <1> 	;
 12392 00003629 0FB705[F5DA0000]    <1> 	movzx   eax, word [swpq_count]  ; Max. 1024
 12393 00003630 6621C0              <1> 	and	ax, ax
 12394 00003633 7433                <1> 	jz	short swpqs_retn
 12395 00003635 57                  <1> 	push	edi
 12396 00003636 56                  <1> 	push	esi
 12397 00003637 53                  <1> 	push	ebx
 12398 00003638 51                  <1> 	push	ecx
 12399 00003639 50                  <1> 	push	eax
 12400 0000363A BE00E00800          <1> 	mov	esi, swap_queue
 12401 0000363F 89C1                <1> 	mov	ecx, eax
 12402 00003641 09DB                <1> 	or	ebx, ebx
 12403 00003643 7424                <1> 	jz	short swpqs_7
 12404                              <1> swpqs_1:
 12405 00003645 AD                  <1> 	lodsd
 12406 00003646 39D8                <1> 	cmp	eax, ebx
 12407 00003648 7404                <1> 	je	short swpqs_2
 12408 0000364A E2F9                <1> 	loop	swpqs_1
 12409 0000364C EB15                <1> 	jmp	short swpqs_6
 12410                              <1> swpqs_2:
 12411 0000364E 89F7                <1> 	mov	edi, esi
 12412 00003650 83EF04              <1> 	sub 	edi, 4
 12413                              <1> swpqs_3:
 12414 00003653 66FF0D[F5DA0000]    <1> 	dec	word [swpq_count]
 12415 0000365A 7403                <1> 	jz	short swpqs_5
 12416                              <1> swpqs_4:
 12417 0000365C 49                  <1> 	dec 	ecx
 12418 0000365D F3A5                <1> 	rep	movsd	; shift up (to the head)
 12419                              <1> swpqs_5:
 12420 0000365F 31C0                <1> 	xor	eax, eax
 12421 00003661 8907                <1> 	mov	[edi], eax
 12422                              <1> swpqs_6:
 12423 00003663 58                  <1> 	pop	eax
 12424 00003664 59                  <1> 	pop	ecx
 12425 00003665 5B                  <1> 	pop	ebx
 12426 00003666 5E                  <1> 	pop	esi
 12427 00003667 5F                  <1> 	pop	edi
 12428                              <1> swpqs_retn:
 12429 00003668 C3                  <1> 	retn		
 12430                              <1> swpqs_7:
 12431 00003669 89F7                <1> 	mov	edi, esi ; head
 12432 0000366B AD                  <1> 	lodsd
 12433                              <1> 	; 20/07/2015
 12434 0000366C 89C3                <1> 	mov	ebx, eax
 12435 0000366E 81E300F0FFFF        <1> 	and	ebx, ~PAGE_OFF ; ~0FFFh 
 12436                              <1> 		      ; ebx = virtual address (at page boundary)	
 12437 00003674 25FF0F0000          <1> 	and	eax, PAGE_OFF ; 0FFFh
 12438                              <1> 		      ; ax = process number (1 to 4095)
 12439 00003679 3A05[8FCE0000]      <1> 	cmp	al, [u.uno]
 12440                              <1> 		; Max. 16 (nproc) processes for Retro UNIX 386 v1
 12441 0000367F 7507                <1> 	jne	short swpqs_8
 12442 00003681 A1[99CE0000]        <1> 	mov	eax, [u.pgdir]
 12443 00003686 EB16                <1> 	jmp	short swpqs_9
 12444                              <1> swpqs_8:
 12445                              <1> 	;shl	ax, 2
 12446 00003688 C0E002              <1> 	shl	al, 2
 12447 0000368B 8B80[D2CB0000]      <1> 	mov 	eax, [eax+p.upage-4]
 12448 00003691 09C0                <1> 	or	eax, eax
 12449 00003693 74BE                <1> 	jz	short swpqs_3 ; invalid upage
 12450 00003695 83C061              <1> 	add	eax, u.pgdir - user
 12451                              <1> 			 ; u.pgdir value for the process
 12452                              <1> 			 ; is in [eax]
 12453 00003698 8B00                <1> 	mov	eax, [eax]
 12454 0000369A 21C0                <1> 	and	eax, eax
 12455 0000369C 74B5                <1> 	jz	short swpqs_3 ; invalid page directory
 12456                              <1> swpqs_9:
 12457 0000369E 52                  <1> 	push	edx
 12458                              <1> 	; eax = page directory
 12459                              <1> 	; ebx = virtual address
 12460 0000369F E87EFBFFFF          <1> 	call	get_pte
 12461 000036A4 89D3                <1> 	mov	ebx, edx ; PTE address
 12462 000036A6 5A                  <1> 	pop	edx
 12463 000036A7 72AA                <1> 	jc	short swpqs_3 ; empty PDE
 12464                              <1> 	; EAX = PTE value
 12465 000036A9 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0 = 1
 12466 000036AB 74A6                <1> 	jz	short swpqs_3 ; Drop non-present page
 12467                              <1> 			      ; from the queue (head)
 12468 000036AD A802                <1> 	test	al, PTE_A_WRITE	  ; bit 1 = 0
 12469 000036AF 74A2                <1> 	jz	short swpqs_3 ; Drop read only page
 12470                              <1> 			      ; from the queue (head) 	
 12471                              <1> 	;test	al, PTE_A_ACCESS  ; bit 5 = 1 (Accessed)
 12472                              <1> 	;jz	short swpqs_6 ; present
 12473                              <1> 			      ; non-accessed page
 12474 000036B1 0FBAF005            <1>         btr     eax, PTE_A_ACCESS_BIT ; reset 'accessed' bit
 12475 000036B5 73AC                <1> 	jnc	short swpqs_6  ; non-accessed page
 12476 000036B7 8903                <1> 	mov	[ebx], eax     ; save changed attribute
 12477                              <1> 	;
 12478                              <1> 	; Rotation (head -> tail)
 12479 000036B9 49                  <1> 	dec	ecx     ; entry count -> last entry number		
 12480 000036BA 74A7                <1> 	jz	short swpqs_6
 12481                              <1> 		; esi = head + 4
 12482                              <1> 		; edi = head
 12483 000036BC 8B07                <1> 	mov	eax, [edi] ; 20/07/2015
 12484 000036BE F3A5                <1> 	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
 12485 000036C0 8907                <1> 	mov	[edi], eax ; head -> tail ; [k] = [1] 		
 12486 000036C2 EB9F                <1> 	jmp	short swpqs_6
 12487                              <1> 
 12488                              <1> add_to_swap_queue:
 12489                              <1> ; temporary - 16/09/2015
 12490 000036C4 C3                  <1> retn
 12491                              <1> 	; 20/07/2015
 12492                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12493                              <1> 	;
 12494                              <1> 	; Adds new page to swap queue
 12495                              <1> 	; (page directories and page tables must not be added
 12496                              <1> 	; to swap queue)	
 12497                              <1> 	;
 12498                              <1> 	; INPUT ->
 12499                              <1> 	;	EBX = Virtual address (for current process, [u.uno])
 12500                              <1> 	;
 12501                              <1> 	; OUTPUT ->
 12502                              <1> 	;	EAX = [swpq_count]
 12503                              <1> 	;	      (after the PTE has been added)
 12504                              <1> 	;	EAX = 0 -> Swap queue is full, (1024 entries)
 12505                              <1> 	;	      the pte could not be added.
 12506                              <1> 	;
 12507                              <1> 	; Modified Registers -> EAX
 12508                              <1> 	;
 12509 000036C5 53                  <1> 	push	ebx
 12510 000036C6 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
 12511 000036CB 8A1D[8FCE0000]      <1> 	mov	bl, [u.uno] ; current process number
 12512 000036D1 E853FFFFFF          <1> 	call	swap_queue_shift ; drop from the queue if
 12513                              <1> 				 ; it is already in the queue
 12514                              <1> 		; Then add it to the tail of the queue
 12515 000036D6 0FB705[F5DA0000]    <1> 	movzx	eax, word [swpq_count]
 12516 000036DD 663D0004            <1> 	cmp	ax, 1024
 12517 000036E1 7205                <1> 	jb	short atsq_1
 12518 000036E3 6629C0              <1> 	sub	ax, ax
 12519 000036E6 5B                  <1> 	pop	ebx
 12520 000036E7 C3                  <1> 	retn
 12521                              <1> atsq_1:
 12522 000036E8 56                  <1> 	push	esi
 12523 000036E9 BE00E00800          <1> 	mov	esi, swap_queue
 12524 000036EE 6621C0              <1> 	and	ax, ax
 12525 000036F1 740A                <1> 	jz	short atsq_2
 12526 000036F3 66C1E002            <1> 	shl	ax, 2	; convert to offset
 12527 000036F7 01C6                <1> 	add	esi, eax
 12528 000036F9 66C1E802            <1> 	shr	ax, 2
 12529                              <1> atsq_2:
 12530 000036FD 6640                <1> 	inc	ax
 12531 000036FF 891E                <1> 	mov	[esi], ebx ; Virtual address + [u.uno] combination
 12532 00003701 66A3[F5DA0000]      <1> 	mov	[swpq_count], ax
 12533 00003707 5E                  <1> 	pop	esi
 12534 00003708 5B                  <1> 	pop	ebx
 12535 00003709 C3                  <1> 	retn
 12536                              <1> 
 12537                              <1> unlink_swap_block:
 12538                              <1> 	; 15/09/2015
 12539                              <1> 	; 30/04/2015
 12540                              <1> 	; 18/04/2015
 12541                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12542                              <1> 	;
 12543                              <1> 	; INPUT -> 
 12544                              <1> 	;	EAX = swap disk/file offset address
 12545                              <1> 	;	      (bit 1 to bit 31)
 12546                              <1> 	; OUTPUT ->
 12547                              <1> 	;	[swpd_free] is increased
 12548                              <1> 	;	(corresponding SWAP DISK ALLOC. TABLE bit is SET)
 12549                              <1> 	;
 12550                              <1> 	; Modified Registers -> EAX
 12551                              <1> 	;
 12552 0000370A 53                  <1> 	push	ebx
 12553 0000370B 52                  <1> 	push	edx
 12554                              <1> 	;
 12555 0000370C C1E804              <1> 	shr	eax, SECTOR_SHIFT+1  ;3+1 ; shift sector address to 
 12556                              <1> 				     ; 3 bits right
 12557                              <1> 				     ; to get swap block/page number
 12558 0000370F 89C2                <1> 	mov	edx, eax
 12559                              <1> 	; 15/09/2015
 12560 00003711 C1EA03              <1> 	shr	edx, 3		     ; to get offset to S.A.T.
 12561                              <1> 				     ; (1 allocation bit = 1 page)
 12562                              <1> 				     ; (1 allocation bytes = 8 pages)
 12563 00003714 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 12564                              <1> 				     ; (to get 32 bit position)			
 12565                              <1> 	;
 12566 00003717 BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table address
 12567 0000371C 01D3                <1> 	add	ebx, edx
 12568 0000371E 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
 12569                              <1> 				     ; (allocation bit position)	 
 12570 00003721 3B05[03DB0000]      <1> 	cmp 	eax, [swpd_next]     ; is the new free block addr. lower
 12571                              <1> 				     ; than the address in 'swpd_next' ?
 12572                              <1> 				     ; (next/first free block value)		
 12573 00003727 7305                <1> 	jnb	short uswpbl_1	     ; no	
 12574 00003729 A3[03DB0000]        <1> 	mov	[swpd_next], eax     ; yes	
 12575                              <1> uswpbl_1:
 12576 0000372E 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate block
 12577                              <1> 				     ; set relevant bit to 1.
 12578                              <1> 				     ; set CF to the previous bit value	
 12579 00003731 F5                  <1> 	cmc			     ; complement carry flag	
 12580 00003732 7206                <1> 	jc	short uswpbl_2	     ; do not increase swfd_free count
 12581                              <1> 				     ; if the block is already deallocated
 12582                              <1> 				     ; before.	
 12583 00003734 FF05[FFDA0000]      <1>         inc     dword [swpd_free]
 12584                              <1> uswpbl_2:
 12585 0000373A 5A                  <1> 	pop	edx
 12586 0000373B 5B                  <1> 	pop	ebx
 12587 0000373C C3                  <1> 	retn
 12588                              <1> 
 12589                              <1> link_swap_block:
 12590                              <1> 	; 01/07/2015
 12591                              <1> 	; 18/04/2015
 12592                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12593                              <1> 	;
 12594                              <1> 	; INPUT -> none
 12595                              <1> 	;
 12596                              <1> 	; OUTPUT ->
 12597                              <1> 	;	EAX = OFFSET ADDRESS OF THE ALLOCATED BLOCK (4096 bytes)
 12598                              <1> 	;	      in sectors (corresponding 
 12599                              <1> 	;	      SWAP DISK ALLOCATION TABLE bit is RESET)
 12600                              <1> 	;
 12601                              <1> 	;	CF = 1 and EAX = 0 
 12602                              <1> 	; 		   if there is not a free block to be allocated	
 12603                              <1> 	;
 12604                              <1> 	; Modified Registers -> none (except EAX)
 12605                              <1> 	;
 12606                              <1> 
 12607                              <1> 	;mov	eax, [swpd_free]
 12608                              <1> 	;and	eax, eax
 12609                              <1> 	;jz	short out_of_swpspc
 12610                              <1> 	;
 12611 0000373D 53                  <1> 	push	ebx
 12612 0000373E 51                  <1> 	push	ecx
 12613                              <1> 	;
 12614 0000373F BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table offset
 12615 00003744 89D9                <1> 	mov	ecx, ebx
 12616 00003746 031D[03DB0000]      <1> 	add	ebx, [swpd_next] ; Free block searching starts from here
 12617                              <1> 				 ; next_free_swap_block >> 5
 12618 0000374C 030D[07DB0000]      <1> 	add	ecx, [swpd_last] ; Free block searching ends here
 12619                              <1> 				 ; (total_swap_blocks - 1) >> 5
 12620                              <1> lswbl_scan:
 12621 00003752 39CB                <1> 	cmp	ebx, ecx
 12622 00003754 770A                <1> 	ja	short lswbl_notfound
 12623                              <1> 	;
 12624 00003756 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
 12625                              <1> 			   ; Clears ZF if a bit is found set (1) and 
 12626                              <1> 			   ; loads the destination with an index to
 12627                              <1> 			   ; first set bit. (0 -> 31) 
 12628                              <1> 			   ; Sets ZF to 1 if no bits are found set.
 12629                              <1> 	; 01/07/2015
 12630 00003759 751C                <1> 	jnz	short lswbl_found ; ZF = 0 -> a free block has been found
 12631                              <1> 			 ;
 12632                              <1> 			 ; NOTE:  a Swap Disk Allocation Table bit 
 12633                              <1> 			 ;	  with value of 1 means 
 12634                              <1> 			 ;	  the corresponding page is free 
 12635                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
 12636 0000375B 83C304              <1> 	add	ebx, 4
 12637                              <1> 			 ; We return back for searching next page block
 12638                              <1> 			 ; NOTE: [swpd_free] is not ZERO; so, 
 12639                              <1> 			 ;	 we always will find at least 1 free block here.
 12640 0000375E EBF2                <1> 	jmp    	short lswbl_scan
 12641                              <1> 	;
 12642                              <1> lswbl_notfound:	
 12643 00003760 81E900000D00        <1> 	sub	ecx, swap_alloc_table
 12644 00003766 890D[03DB0000]      <1> 	mov	[swpd_next], ecx ; next/first free page = last page 
 12645                              <1> 				 ; (unlink_swap_block procedure will change it)
 12646 0000376C 31C0                <1> 	xor	eax, eax
 12647 0000376E A3[FFDA0000]        <1> 	mov	[swpd_free], eax
 12648 00003773 F9                  <1> 	stc
 12649                              <1> lswbl_ok:
 12650 00003774 59                  <1> 	pop	ecx
 12651 00003775 5B                  <1> 	pop	ebx
 12652 00003776 C3                  <1> 	retn
 12653                              <1> 	;
 12654                              <1> ;out_of_swpspc:
 12655                              <1> ;	stc
 12656                              <1> ;	retn
 12657                              <1> 
 12658                              <1> lswbl_found:
 12659 00003777 89D9                <1> 	mov	ecx, ebx
 12660 00003779 81E900000D00        <1> 	sub	ecx, swap_alloc_table
 12661 0000377F 890D[03DB0000]      <1> 	mov	[swpd_next], ecx ; Set first free block searching start
 12662                              <1> 				 ; address/offset (to the next)
 12663 00003785 FF0D[FFDA0000]      <1>         dec     dword [swpd_free] ; 1 block has been allocated (X = X-1) 
 12664                              <1> 	;
 12665 0000378B 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 12666                              <1> 				 ; is copied into the Carry Flag and then cleared
 12667                              <1> 				 ; in the destination.
 12668                              <1> 				 ;
 12669                              <1> 				 ; Reset the bit which is corresponding to the 
 12670                              <1> 				 ; (just) allocated block.
 12671 0000378E C1E105              <1> 	shl	ecx, 5		 ; (block offset * 32) + block index
 12672 00003791 01C8                <1> 	add	eax, ecx	 ; = block number
 12673 00003793 C1E003              <1> 	shl	eax, SECTOR_SHIFT ; 3, sector (offset) address of the block
 12674                              <1> 				 ; 1 block =  8 sectors
 12675                              <1> 	;
 12676                              <1> 	; EAX = offset address of swap disk/file sector (beginning of the block)
 12677                              <1> 	;
 12678                              <1> 	; NOTE: The relevant page table entry will be updated
 12679                              <1> 	;       according to this EAX value...
 12680                              <1> 	;
 12681 00003796 EBDC                <1> 	jmp	short lswbl_ok
 12682                              <1> 
 12683                              <1> logical_disk_read:
 12684                              <1> 	; 20/07/2015
 12685                              <1> 	; 09/03/2015 (temporary code here)
 12686                              <1> 	;
 12687                              <1> 	; INPUT ->
 12688                              <1> 	; 	ESI = Logical disk description table address
 12689                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
 12690                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
 12691                              <1> 	; 	ECX = Sector count
 12692                              <1> 	;
 12693                              <1> 	;
 12694 00003798 C3                  <1> 	retn
 12695                              <1> 
 12696                              <1> logical_disk_write:
 12697                              <1> 	; 20/07/2015
 12698                              <1> 	; 09/03/2015 (temporary code here)
 12699                              <1> 	;
 12700                              <1> 	; INPUT ->
 12701                              <1> 	; 	ESI = Logical disk description table address
 12702                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
 12703                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
 12704                              <1> 	; 	ECX = Sector count
 12705                              <1> 	;
 12706 00003799 C3                  <1> 	retn
 12707                              <1> 
 12708                              <1> get_physical_addr:
 12709                              <1> 	; 18/10/2015
 12710                              <1> 	; 29/07/2015
 12711                              <1> 	; 20/07/2015
 12712                              <1> 	; 04/06/2015
 12713                              <1> 	; 20/05/2015
 12714                              <1> 	; 28/04/2015
 12715                              <1> 	; 18/04/2015
 12716                              <1> 	; Get physical address
 12717                              <1> 	;     (allocates a new page for user if it is not present)
 12718                              <1> 	;	
 12719                              <1> 	; (This subroutine is needed for mapping user's virtual 
 12720                              <1> 	; (buffer) address to physical address (of the buffer).)
 12721                              <1> 	; ('sys write', 'sys read' system calls...)
 12722                              <1> 	;
 12723                              <1> 	; INPUT ->
 12724                              <1> 	;	EBX = virtual address
 12725                              <1> 	;	u.pgdir = page directory (physical) address
 12726                              <1> 	;
 12727                              <1> 	; OUTPUT ->
 12728                              <1> 	;	EAX = physical address 
 12729                              <1> 	;	EBX = linear address	
 12730                              <1> 	;	EDX = physical address of the page frame
 12731                              <1> 	;	      (with attribute bits)
 12732                              <1> 	;	ECX = byte count within the page frame
 12733                              <1> 	;
 12734                              <1> 	; Modified Registers -> EAX, EBX, ECX, EDX
 12735                              <1> 	;
 12736 0000379A 81C300004000        <1> 	add	ebx, CORE ; 18/10/2015
 12737                              <1> 	;
 12738 000037A0 A1[99CE0000]        <1> 	mov	eax, [u.pgdir]
 12739 000037A5 E878FAFFFF          <1> 	call	get_pte
 12740                              <1> 		; EDX = Page table entry address (if CF=0)
 12741                              <1> 	        ;       Page directory entry address (if CF=1)
 12742                              <1> 		;       (Bit 0 value is 0 if PT is not present)
 12743                              <1> 		; EAX = Page table entry value (page address)
 12744                              <1> 		;	CF = 1 -> PDE not present or invalid ? 
 12745 000037AA 731C                <1> 	jnc	short gpa_1
 12746                              <1> 	;
 12747 000037AC E856F9FFFF          <1> 	call	allocate_page
 12748 000037B1 725B                <1> 	jc	short gpa_im_err  ; 'insufficient memory' error
 12749                              <1> gpa_0:
 12750 000037B3 E8C9F9FFFF          <1> 	call 	clear_page
 12751                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 12752 000037B8 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
 12753                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
 12754                              <1> 			   ; (user, writable, present page)	
 12755 000037BA 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
 12756 000037BC A1[99CE0000]        <1> 	mov	eax, [u.pgdir]	
 12757 000037C1 E85CFAFFFF          <1> 	call	get_pte
 12758 000037C6 7246                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
 12759                              <1> gpa_1:
 12760                              <1> 	; EAX = PTE value, EDX = PTE address
 12761 000037C8 A801                <1> 	test 	al, PTE_A_PRESENT
 12762 000037CA 751A                <1> 	jnz	short gpa_3
 12763 000037CC 09C0                <1> 	or	eax, eax
 12764 000037CE 7430                <1> 	jz	short gpa_4  ; Allocate a new page
 12765                              <1> 	; 20/07/2015
 12766 000037D0 55                  <1> 	push	ebp
 12767 000037D1 89DD                <1> 	mov	ebp, ebx ; virtual (linear) address
 12768                              <1> 	; reload swapped page
 12769 000037D3 E83C000000          <1> 	call	reload_page ; 28/04/2015
 12770 000037D8 5D                  <1> 	pop	ebp
 12771 000037D9 7224                <1> 	jc	short gpa_retn
 12772                              <1> gpa_2:
 12773                              <1> 	; 20/07/2015
 12774                              <1> 	; 20/05/2015
 12775                              <1> 	; add this page to swap queue
 12776 000037DB 50                  <1> 	push	eax 
 12777                              <1> 	; EBX = virtual address
 12778 000037DC E8E3FEFFFF          <1> 	call 	add_to_swap_queue
 12779 000037E1 58                  <1> 	pop	eax
 12780                              <1> 		; PTE address in EDX
 12781                              <1> 		; virtual address in EBX
 12782                              <1> 	; EAX = memory page address
 12783 000037E2 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_USER + PTE_A_WRITE
 12784                              <1> 				  ; present flag, bit 0 = 1
 12785                              <1> 				  ; user flag, bit 2 = 1	
 12786                              <1> 				  ; writable flag, bit 1 = 1
 12787 000037E4 8902                <1> 	mov	[edx], eax  ; Update PTE value
 12788                              <1> gpa_3:
 12789                              <1> 	; 18/10/2015
 12790 000037E6 89D9                <1> 	mov	ecx, ebx
 12791 000037E8 81E1FF0F0000        <1> 	and	ecx, PAGE_OFF
 12792 000037EE 89C2                <1> 	mov 	edx, eax
 12793 000037F0 662500F0            <1> 	and	ax, PTE_A_CLEAR
 12794 000037F4 01C8                <1> 	add	eax, ecx
 12795 000037F6 F7D9                <1> 	neg	ecx ; 1 -> -1 (0FFFFFFFFh), 4095 (0FFFh) -> -4095
 12796 000037F8 81C100100000        <1> 	add	ecx, PAGE_SIZE
 12797 000037FE F8                  <1> 	clc
 12798                              <1> gpa_retn:
 12799 000037FF C3                  <1> 	retn	
 12800                              <1> gpa_4:	
 12801 00003800 E802F9FFFF          <1> 	call	allocate_page
 12802 00003805 7207                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
 12803 00003807 E875F9FFFF          <1> 	call	clear_page
 12804 0000380C EBCD                <1> 	jmp	short gpa_2
 12805                              <1> 
 12806                              <1> gpa_im_err:	
 12807 0000380E B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
 12808                              <1> 				  ; Major error = 0 (No protection fault)	
 12809 00003813 C3                  <1> 	retn
 12810                              <1> 
 12811                              <1> reload_page:
 12812                              <1> 	; 20/07/2015
 12813                              <1> 	; 28/04/2015 (Retro UNIX 386 v1 - beginning)
 12814                              <1> 	;
 12815                              <1> 	; Reload (Restore) swapped page at memory
 12816                              <1> 	;
 12817                              <1> 	; INPUT -> 
 12818                              <1> 	;	EBP = Virtual (linear) memory address
 12819                              <1> 	;	EAX = PTE value (swap disk sector address)
 12820                              <1> 	;	(Swap disk sector address = bit 1 to bit 31 of EAX)	
 12821                              <1> 	; OUTPUT ->
 12822                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF RELOADED PAGE
 12823                              <1> 	;
 12824                              <1> 	;	CF = 1 and EAX = error code
 12825                              <1> 	;
 12826                              <1> 	; Modified Registers -> none (except EAX)
 12827                              <1> 	;
 12828 00003814 D1E8                <1> 	shr	eax, 1   ; Convert PTE value to swap disk address 
 12829 00003816 53                  <1> 	push	ebx      ;
 12830 00003817 89C3                <1> 	mov	ebx, eax ; Swap disk (offset) address	
 12831 00003819 E8E9F8FFFF          <1> 	call	allocate_page
 12832 0000381E 720C                <1> 	jc	short rlp_im_err
 12833 00003820 93                  <1> 	xchg 	eax, ebx	
 12834                              <1> 	; EBX = Physical memory (page) address
 12835                              <1> 	; EAX = Swap disk (offset) address
 12836                              <1> 	; EBP = Virtual (linear) memory address
 12837 00003821 E81AFDFFFF          <1> 	call	swap_in
 12838 00003826 720B                <1> 	jc	short rlp_swp_err  ; (swap disk/file read error)
 12839 00003828 89D8                <1> 	mov	eax, ebx	
 12840                              <1> rlp_retn:
 12841 0000382A 5B                  <1> 	pop	ebx
 12842 0000382B C3                  <1> 	retn
 12843                              <1> 	
 12844                              <1> rlp_im_err:	
 12845 0000382C B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
 12846                              <1> 				  ; Major error = 0 (No protection fault)	
 12847 00003831 EBF7                <1> 	jmp	short rlp_retn
 12848                              <1> 
 12849                              <1> rlp_swp_err:
 12850 00003833 B804000000          <1> 	mov 	eax, SWP_DISK_READ_ERR ; Swap disk read error !
 12851 00003838 EBF0                <1> 	jmp	short rlp_retn
 12852                              <1> 
 12853                              <1> 
 12854                              <1> copy_page_dir:
 12855                              <1> 	; 19/09/2015
 12856                              <1> 	; temporary - 07/09/2015
 12857                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
 12858                              <1> 	;
 12859                              <1> 	; INPUT -> 
 12860                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
 12861                              <1> 	;		    page directory.
 12862                              <1> 	; OUTPUT ->
 12863                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
 12864                              <1> 	;	       page directory.
 12865                              <1> 	;	(New page directory with new page table entries.)
 12866                              <1> 	;	(New page tables with read only copies of the parent's
 12867                              <1> 	;	pages.)
 12868                              <1> 	;	EAX = 0 -> Error (CF = 1)
 12869                              <1> 	;
 12870                              <1> 	; Modified Registers -> none (except EAX)
 12871                              <1> 	;
 12872 0000383A E8C8F8FFFF          <1> 	call	allocate_page
 12873 0000383F 723E                <1> 	jc	short cpd_err
 12874                              <1> 	;
 12875 00003841 55                  <1> 	push	ebp ; 20/07/2015
 12876 00003842 56                  <1> 	push	esi
 12877 00003843 57                  <1> 	push	edi
 12878 00003844 53                  <1> 	push	ebx
 12879 00003845 51                  <1> 	push	ecx
 12880 00003846 8B35[99CE0000]      <1> 	mov	esi, [u.pgdir]
 12881 0000384C 89C7                <1> 	mov	edi, eax
 12882 0000384E 50                  <1> 	push	eax ; save child's page directory address
 12883                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
 12884                              <1> 	; (use same system space for all user page tables) 
 12885 0000384F A5                  <1> 	movsd
 12886 00003850 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
 12887 00003855 B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
 12888                              <1> cpd_0:	
 12889 0000385A AD                  <1> 	lodsd
 12890                              <1> 	;or	eax, eax
 12891                              <1>         ;jnz     short cpd_1
 12892 0000385B A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
 12893 0000385D 7508                <1> 	jnz	short cpd_1
 12894                              <1>  	; (virtual address at the end of the page table)	
 12895 0000385F 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
 12896 00003865 EB0F                <1> 	jmp	short cpd_2
 12897                              <1> cpd_1:	
 12898 00003867 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
 12899 0000386B 89C3                <1> 	mov	ebx, eax
 12900                              <1> 	; EBX = Parent's page table address
 12901 0000386D E81F000000          <1> 	call	copy_page_table
 12902 00003872 720C                <1> 	jc	short cpd_p_err
 12903                              <1> 	; EAX = Child's page table address
 12904 00003874 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
 12905                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
 12906                              <1> 			 ; (present, writable, user)
 12907                              <1> cpd_2:
 12908 00003876 AB                  <1> 	stosd
 12909 00003877 E2E1                <1> 	loop	cpd_0
 12910                              <1> 	;
 12911 00003879 58                  <1> 	pop	eax  ; restore child's page directory address
 12912                              <1> cpd_3:
 12913 0000387A 59                  <1> 	pop	ecx
 12914 0000387B 5B                  <1> 	pop	ebx
 12915 0000387C 5F                  <1> 	pop	edi
 12916 0000387D 5E                  <1> 	pop	esi
 12917 0000387E 5D                  <1> 	pop	ebp
 12918                              <1> cpd_err:
 12919 0000387F C3                  <1> 	retn
 12920                              <1> cpd_p_err:
 12921                              <1> 	; release the allocated pages missing (recover free space)
 12922 00003880 58                  <1> 	pop	eax  ; the new page directory address (physical)
 12923 00003881 8B1D[99CE0000]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
 12924 00003887 E8B4F9FFFF          <1> 	call 	deallocate_page_dir
 12925 0000388C 29C0                <1> 	sub	eax, eax ; 0
 12926 0000388E F9                  <1> 	stc
 12927 0000388F EBE9                <1> 	jmp	short cpd_3	
 12928                              <1> 
 12929                              <1> copy_page_table:
 12930                              <1> 	; 19/09/2015
 12931                              <1> 	; temporary - 07/09/2015
 12932                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
 12933                              <1> 	;
 12934                              <1> 	; INPUT -> 
 12935                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
 12936                              <1> 	;	EBP = page table entry index (from 'copy_page_dir')
 12937                              <1> 	; OUTPUT ->
 12938                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
 12939                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
 12940                              <1> 	;	CF = 1 -> error 
 12941                              <1> 	;
 12942                              <1> 	; Modified Registers -> EBP (except EAX)
 12943                              <1> 	;
 12944 00003891 E871F8FFFF          <1> 	call	allocate_page
 12945 00003896 725A                <1> 	jc	short cpt_err
 12946                              <1> 	;
 12947 00003898 50                  <1> 	push	eax ; *
 12948                              <1> 	;push 	ebx
 12949 00003899 56                  <1> 	push	esi
 12950 0000389A 57                  <1> 	push	edi
 12951 0000389B 52                  <1> 	push	edx
 12952 0000389C 51                  <1> 	push	ecx
 12953                              <1> 	;
 12954 0000389D 89DE                <1> 	mov	esi, ebx
 12955 0000389F 89C7                <1> 	mov	edi, eax
 12956 000038A1 89C2                <1> 	mov	edx, eax
 12957 000038A3 81C200100000        <1> 	add	edx, PAGE_SIZE 	
 12958                              <1> cpt_0:
 12959 000038A9 AD                  <1> 	lodsd
 12960 000038AA A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
 12961 000038AC 750B                <1> 	jnz	short cpt_1
 12962 000038AE 21C0                <1> 	and	eax, eax
 12963 000038B0 7430                <1> 	jz	short cpt_2
 12964                              <1> 	; ebp = virtual (linear) address of the memory page
 12965 000038B2 E85DFFFFFF          <1> 	call	reload_page ; 28/04/2015
 12966 000038B7 7234                <1> 	jc	short cpt_p_err
 12967                              <1> cpt_1:
 12968 000038B9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 12969 000038BD 89C1                <1> 	mov	ecx, eax
 12970                              <1> 	; Allocate a new page for the child process
 12971 000038BF E843F8FFFF          <1> 	call	allocate_page
 12972 000038C4 7227                <1> 	jc	short cpt_p_err
 12973 000038C6 57                  <1> 	push	edi
 12974 000038C7 56                  <1> 	push	esi
 12975 000038C8 89CE                <1> 	mov	esi, ecx
 12976 000038CA 89C7                <1> 	mov	edi, eax
 12977 000038CC B900040000          <1> 	mov	ecx, PAGE_SIZE/4
 12978 000038D1 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
 12979 000038D3 5E                  <1> 	pop	esi
 12980 000038D4 5F                  <1> 	pop	edi
 12981                              <1> 	; 
 12982 000038D5 53                  <1> 	push	ebx
 12983 000038D6 50                  <1> 	push	eax
 12984 000038D7 89EB                <1> 	mov	ebx, ebp
 12985                              <1> 	; ebx = virtual address of the memory page
 12986 000038D9 E8E6FDFFFF          <1> 	call	add_to_swap_queue
 12987 000038DE 58                  <1> 	pop	eax
 12988 000038DF 5B                  <1> 	pop	ebx
 12989                              <1> 	;
 12990                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
 12991 000038E0 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
 12992                              <1> cpt_2:
 12993 000038E2 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
 12994                              <1> 	;
 12995 000038E3 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
 12996                              <1> 	;
 12997 000038E9 39D7                <1> 	cmp	edi, edx
 12998 000038EB 72BC                <1> 	jb	short cpt_0
 12999                              <1> cpt_p_err:
 13000 000038ED 59                  <1> 	pop	ecx
 13001 000038EE 5A                  <1> 	pop	edx
 13002 000038EF 5F                  <1> 	pop	edi
 13003 000038F0 5E                  <1> 	pop	esi
 13004                              <1> 	;pop	ebx
 13005 000038F1 58                  <1> 	pop	eax ; *
 13006                              <1> cpt_err:
 13007 000038F2 C3                  <1> 	retn
 13008                              <1> 
 13009                              <1> 
 13010                              <1> allocate_memory_block:
 13011                              <1> 	; 14/03/2016
 13012                              <1> 	; 13/03/2016
 13013                              <1> 	; 12/03/2016 (TRDOS 386 = TRDOS v2.0)
 13014                              <1> 	; Allocating contiguous memory pages (in the kernel's memory space)
 13015                              <1> 	;
 13016                              <1> 	; INPUT -> 
 13017                              <1> 	;	EAX = Beginning address (physical)
 13018                              <1> 	;	EAX = 0 -> Allocate memory block from the first proper aperture	
 13019                              <1> 	;	ECX = Number of bytes to be allocated
 13020                              <1> 	;
 13021                              <1> 	; OUTPUT ->
 13022                              <1> 	; 	1) cf = 0 -> successful
 13023                              <1> 	;	EAX = Beginning (physical) address of the allocated memory block
 13024                              <1> 	;	ECX = Number of allocated bytes (rounded up to page borders) 
 13025                              <1> 	;	2) cf = 1 -> unsuccessful
 13026                              <1> 	;	 2.1) If EAX > 0 -> 
 13027                              <1> 	;	      (Number of requested pages is more than # of free pages
 13028                              <1> 	;	       but contiguous free pages -the aperture- is not enough!)	   	
 13029                              <1> 	;	      EAX = Beginning address of available aperture
 13030                              <1> 	;		    (one of all aperture with max. aperture size/length)		
 13031                              <1> 	;	      ECX = Size of available aperture (memory block) in bytes
 13032                              <1> 	;	 2.2) If EAX = 0 -> Out of memory error 
 13033                              <1> 	;	            (number of free pages is less than requested number)
 13034                              <1> 	;	      ECX = Total number of free bytes (free pages * 4096) 
 13035                              <1> 	;		    (It is not number of contiguous free bytes)	
 13036                              <1> 	;
 13037                              <1> 	; (Modified Registers -> EAX, ECX)
 13038                              <1> 	;
 13039                              <1> 	; PURPOSE: Loading a file at memory for copying or running etc.
 13040                              <1> 	; If this procedure returns with cf is set, ECX contains maximum
 13041                              <1> 	; available space and EAX contains the beginning address of it.
 13042                              <1> 	; If EAX has zero, ECX contains total number of free bytes.
 13043                              <1> 	; If requested block has been successfully allocated (by rounding up to
 13044                              <1> 	; the last page border), it must be deallocated later by using
 13045                              <1> 	; 'dealloacate_memory_block' procedure.    
 13046                              <1> 
 13047 000038F3 52                  <1> 	push	edx ; *
 13048 000038F4 BAFF0F0000          <1> 	mov	edx, PAGE_SIZE - 1   ; 4095
 13049 000038F9 01D1                <1> 	add	ecx, edx
 13050 000038FB 01D0                <1> 	add	eax, edx
 13051 000038FD C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
 13052                              <1> 
 13053                              <1> 	; ECX = number of contiguous pages to be allocated
 13054 00003900 8B15[F0BD0000]      <1> 	mov	edx, [free_pages]
 13055 00003906 39D1                <1> 	cmp	ecx, edx
 13056 00003908 7775                <1> 	ja	short amb_6
 13057                              <1> 
 13058 0000390A C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; 12
 13059                              <1> 
 13060 0000390D 89C2                <1> 	mov	edx, eax 	     ; page number
 13061 0000390F C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
 13062                              <1> 				     ; (1 allocation bit = 1 page)
 13063                              <1> 				     ; (1 allocation bytes = 8 pages)
 13064 00003912 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 13065                              <1> 				     ; (to get 32 bit position)	
 13066 00003915 53                  <1> 	push	ebx ; **
 13067                              <1> amb_0:
 13068 00003916 890D[A2CA0000]      <1> 	mov	[mem_ipg_count], ecx ; initial (reset) value of page count
 13069 0000391C 890D[A6CA0000]      <1> 	mov	[mem_pg_count], ecx
 13070 00003922 31C9                <1> 	xor	ecx, ecx ; 0
 13071 00003924 890D[AACA0000]      <1> 	mov	[mem_aperture], ecx ; 0
 13072 0000392A 890D[AECA0000]      <1> 	mov	[mem_max_aperture], ecx ; 0
 13073                              <1> 	
 13074 00003930 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address
 13075 00003935 3B15[F4BD0000]      <1> 	cmp	edx, [next_page]     ; is the beginning page address higher
 13076                              <1> 				     ; than the address in 'last_page' ?
 13077                              <1> 				     ; (the first/next free page of user space)		
 13078 0000393B 7208                <1> 	jb	short amb_1
 13079 0000393D 3B15[F8BD0000]      <1> 	cmp 	edx, [last_page]     ; is the beginning page address higher
 13080                              <1> 				     ; than the address in 'last_page' ?
 13081                              <1> 				     ; (end of the memory)		
 13082 00003943 7606                <1> 	jna	short amb_2	     ; no	
 13083                              <1> amb_1:
 13084 00003945 8B15[F4BD0000]      <1> 	mov	edx, [next_page]     ; yes (reset to the first page of user space)
 13085                              <1> amb_2:
 13086 0000394B 01D3                <1> 	add	ebx, edx
 13087                              <1> 
 13088 0000394D A3[B2CA0000]        <1> 	mov	[mem_pg_pos], eax    ; beginning page no (for curr. mem. aperture)
 13089 00003952 A3[B6CA0000]        <1>  	mov	[mem_max_pg_pos], eax ; beginning page no for max. mem. aperture
 13090                              <1> 
 13091 00003957 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
 13092                              <1> 				     ; (allocation bit position)	 
 13093 0000395A 744B                <1> 	jz	short amb_10
 13094                              <1> amb_3:
 13095 0000395C 8B13                <1> 	mov	edx, [ebx]
 13096 0000395E 88C1                <1> 	mov	cl, al ; 0 to 31
 13097 00003960 D3EA                <1> 	shr	edx, cl
 13098 00003962 89D0                <1> 	mov	eax, edx
 13099                              <1> amb_4:
 13100 00003964 D1E8                <1> 	shr	eax, 1 ; (***)
 13101 00003966 7321                <1> 	jnc	short amb_7
 13102 00003968 FF05[AACA0000]      <1> 	inc	dword [mem_aperture]
 13103 0000396E FF0D[A6CA0000]      <1> 	dec	dword [mem_pg_count]
 13104 00003974 7478                <1> 	jz	short amb_15
 13105                              <1> amb_5:
 13106 00003976 80F91F              <1> 	cmp	cl, 31
 13107 00003979 7317                <1> 	jnb	short amb_8
 13108 0000397B FEC1                <1> 	inc	cl
 13109 0000397D EBE5                <1> 	jmp	short amb_4
 13110                              <1> 
 13111                              <1> amb_6:	; out_of_memory
 13112 0000397F 31C0                <1> 	xor	eax, eax ; 0
 13113 00003981 89D1                <1> 	mov	ecx, edx ; free pages
 13114 00003983 C1E10C              <1> 	shl	ecx, PAGE_SHIFT
 13115 00003986 5A                  <1> 	pop	edx ; *
 13116 00003987 F9                  <1> 	stc
 13117 00003988 C3                  <1> 	retn
 13118                              <1> amb_7:
 13119 00003989 50                  <1> 	push	eax ; (***) allocation bits (in shifted status)
 13120 0000398A E8E7000000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
 13121 0000398F 58                  <1> 	pop	eax ; (***)
 13122 00003990 EBE4                <1> 	jmp	amb_5
 13123                              <1> amb_8:
 13124 00003992 28C9                <1> 	sub	cl, cl ; 0
 13125                              <1> amb_9:
 13126 00003994 89DA                <1> 	mov	edx, ebx
 13127 00003996 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL
 13128 0000399C 3B15[F8BD0000]      <1> 	cmp	edx, [last_page]
 13129 000039A2 7336                <1> 	jnb	short amb_14 ; contiguous pages not enough
 13130 000039A4 83C304              <1> 	add	ebx, 4
 13131                              <1> amb_10:
 13132 000039A7 8B03                <1> 	mov	eax, [ebx]
 13133 000039A9 21C0                <1> 	and 	eax, eax
 13134 000039AB 7406                <1>         jz      short amb_11 ; there is not a free page bit in this alloc dword
 13135 000039AD 40                  <1> 	inc	eax ; 0FFFFFFFFh -> 0
 13136 000039AE 740A                <1> 	jz	short amb_12 ; all of bits are set (32 free pages)
 13137 000039B0 48                  <1> 	dec	eax
 13138 000039B1 EBB1                <1> 	jmp	short amb_4
 13139                              <1> amb_11:
 13140 000039B3 E8BE000000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
 13141 000039B8 EBDA                <1> 	jmp	short amb_9	
 13142                              <1> amb_12:
 13143 000039BA B120                <1> 	mov	cl, 32
 13144 000039BC 390D[A6CA0000]      <1> 	cmp	[mem_pg_count], ecx ; 32
 13145 000039C2 7306                <1> 	jnb	short amb_13
 13146 000039C4 8B0D[A6CA0000]      <1> 	mov	ecx, [mem_pg_count]
 13147                              <1> amb_13:
 13148 000039CA 010D[AACA0000]      <1> 	add	[mem_aperture], ecx
 13149 000039D0 290D[A6CA0000]      <1> 	sub	[mem_pg_count], ecx
 13150 000039D6 7616                <1> 	jna	short amb_15
 13151 000039D8 EBB8                <1> 	jmp	short amb_8
 13152                              <1> amb_14:
 13153 000039DA A1[B6CA0000]        <1> 	mov	eax, [mem_max_pg_pos] ; begin address of max. mem aperture	
 13154 000039DF 8B0D[AECA0000]      <1> 	mov	ecx, [mem_max_aperture] ; max. (largest) memory aperture
 13155 000039E5 C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
 13156 000039E8 C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
 13157 000039EB F9                  <1> 	stc
 13158 000039EC EB7D                <1> 	jmp	short amb_25
 13159                              <1> 
 13160                              <1> amb_15: ; OK !
 13161 000039EE A1[B2CA0000]        <1> 	mov	eax, [mem_pg_pos]   ; Beginning address as page number
 13162 000039F3 8B0D[AACA0000]      <1> 	mov	ecx, [mem_aperture]  ; Free contiguous page count
 13163                              <1> amb_16:
 13164                              <1> 	; allocate contiguous memory pages (via memory allocation table bits)
 13165 000039F9 89C2                <1> 	mov	edx, eax
 13166 000039FB C1EA05              <1> 	shr	edx, 5 ; 32 pages in one allocation dword (32 bits)
 13167 000039FE BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
 13168 00003A03 01D3                <1> 	add	ebx, edx
 13169 00003A05 83E01F              <1> 	and	eax, 1Fh ; 31
 13170 00003A08 29C1                <1> 	sub	ecx, eax
 13171 00003A0A 51                  <1> 	push	ecx ; ***
 13172 00003A0B B920000000          <1> 	mov	ecx, 32
 13173 00003A10 28C1                <1> 	sub	cl, al
 13174                              <1> amb_17:		
 13175 00003A12 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 13176                              <1> 				 ; is copied into the Carry Flag and then cleared
 13177                              <1> 				 ; in the destination.
 13178 00003A15 FF0D[F0BD0000]      <1> 	dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
 13179 00003A1B 49                  <1> 	dec	ecx
 13180 00003A1C 7404                <1> 	jz	short amb_18
 13181 00003A1E FEC0                <1> 	inc	al
 13182 00003A20 EBF0                <1> 	jmp	short amb_17
 13183                              <1> amb_18:	
 13184 00003A22 59                  <1> 	pop	ecx ; ***
 13185 00003A23 21C9                <1> 	and	ecx, ecx ; 0 ?
 13186 00003A25 742B                <1> 	jz	short amb_22	
 13187                              <1> amb_19:
 13188 00003A27 B020                <1> 	mov	al, 32
 13189 00003A29 39C1                <1> 	cmp	ecx, eax ; 32
 13190 00003A2B 7218                <1> 	jb	short amb_20
 13191 00003A2D 2905[F0BD0000]      <1> 	sub	[free_pages], eax ; [free_pages] = [free_pages] - 32
 13192 00003A33 01C2                <1> 	add	edx, eax ; 4 bytes =  32 bits
 13193 00003A35 29C1                <1> 	sub	ecx, eax ; 32
 13194 00003A37 B004                <1> 	mov	al, 4  
 13195 00003A39 7415                <1> 	jz	short amb_21	
 13196 00003A3B 01C3                <1> 	add	ebx, eax
 13197 00003A3D 01C2                <1> 	add	edx, eax
 13198 00003A3F 28C0                <1> 	sub	al, al ; 0
 13199 00003A41 8903                <1> 	mov	[ebx], eax ; 0 ; reset 32 bits
 13200 00003A43 EBE2                <1> 	jmp	short amb_19
 13201                              <1> amb_20:
 13202 00003A45 B004                <1> 	mov	al, 4
 13203 00003A47 01C3                <1> 	add	ebx, eax ; 4
 13204 00003A49 01C2                <1> 	add	edx, eax ; 4
 13205                              <1> 	; ECX < 32
 13206 00003A4B 28C0                <1> 	sub	al, al ; 0
 13207 00003A4D 50                  <1> 	push	eax ; 0 ***
 13208 00003A4E EBC2                <1> 	jmp	short amb_17	
 13209                              <1> amb_21:
 13210 00003A50 01C2                <1> 	add	edx, eax ; 4
 13211                              <1> amb_22:
 13212 00003A52 3B15[F4BD0000]      <1> 	cmp	edx, [next_page]
 13213 00003A58 7600                <1> 	jna	short amb_23
 13214                              <1> amb_23:
 13215 00003A5A 8915[F4BD0000]      <1> 	mov	[next_page], edx	
 13216                              <1> amb_24:
 13217 00003A60 A1[B2CA0000]        <1> 	mov	eax, [mem_pg_pos]   ; Beginning address as page number
 13218 00003A65 8B0D[AACA0000]      <1> 	mov	ecx, [mem_aperture]  ; Free contiguous page count
 13219                              <1> amb_25:
 13220 00003A6B 9C                  <1> 	pushf
 13221 00003A6C C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
 13222 00003A6F C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
 13223 00003A72 9D                  <1> 	popf
 13224 00003A73 5B                  <1> 	pop	ebx ; **
 13225 00003A74 5A                  <1> 	pop	edx ; *
 13226 00003A75 C3                  <1> 	retn
 13227                              <1> 
 13228                              <1> amb_26:	; set maximum free memory aperture (free memory block size) 
 13229 00003A76 89DA                <1> 	mov	edx, ebx
 13230 00003A78 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL
 13231 00003A7E C1E802              <1> 	shr	eax, 2 ; page count
 13232 00003A81 01CA                <1> 	add	edx, ecx ; current page number (last free page + 1)
 13233                              <1> 	;
 13234 00003A83 A1[AACA0000]        <1> 	mov	eax, [mem_aperture]
 13235 00003A88 21C0                <1> 	and	eax, eax
 13236 00003A8A 7424                <1> 	jz	short amb_27
 13237 00003A8C C705[AACA0000]0000- <1> 	mov	dword [mem_aperture], 0
 13238 00003A94 0000                <1>
 13239 00003A96 3B05[AECA0000]      <1> 	cmp	eax, [mem_max_aperture]
 13240 00003A9C 7612                <1> 	jna	short amb_27
 13241 00003A9E A3[AECA0000]        <1> 	mov	[mem_max_aperture], eax
 13242                              <1> 	;
 13243 00003AA3 89D0                <1> 	mov	eax, edx
 13244 00003AA5 2B05[AECA0000]      <1> 	sub	eax, [mem_max_aperture] ; the last aperture size in pages
 13245                              <1> 	; EAX = Beginning page number of the max. aperture 
 13246 00003AAB A3[B6CA0000]        <1> 	mov	[mem_max_pg_pos], eax
 13247                              <1> amb_27: 
 13248 00003AB0 42                  <1> 	inc	edx	
 13249 00003AB1 8915[B2CA0000]      <1> 	mov	[mem_pg_pos], edx ; next page
 13250                              <1> 
 13251 00003AB7 A1[A2CA0000]        <1> 	mov	eax, [mem_ipg_count] ; initial (reset) value of page count
 13252 00003ABC A3[A6CA0000]        <1> 	mov	[mem_pg_count], eax
 13253                              <1> 
 13254 00003AC1 C3                  <1> 	retn
 13255                              <1> 
 13256                              <1> deallocate_memory_block:
 13257                              <1> 	; 14/03/2016 (TRDOS 386 = TRDOS v2.0)
 13258                              <1> 	; Deallocating contiguous memory pages (in the kernel's memory space)
 13259                              <1> 	;
 13260                              <1> 	; INPUT -> 
 13261                              <1> 	;	EAX = Beginning address (physical)
 13262                              <1> 	;	ECX = Number of bytes to be deallocated
 13263                              <1> 	;
 13264                              <1> 	; OUTPUT ->
 13265                              <1> 	;	Mememory Allocation Table bits will be updated
 13266                              <1> 	;	[free_pages] will be changed (increased)
 13267                              <1> 	;
 13268                              <1> 	; (Modified Registers -> EAX, ECX)
 13269                              <1> 	;
 13270                              <1> 	; PURPOSE: Unloading/Freeing a file -or an allocated memory block- 
 13271                              <1> 	; at memory after copying, running, saving, reading, writing etc.
 13272                              <1> 	;
 13273                              <1> 
 13274 00003AC2 52                  <1> 	push	edx ; *
 13275 00003AC3 53                  <1> 	push	ebx ; **
 13276                              <1> 
 13277 00003AC4 C1E80C              <1> 	shr	eax, PAGE_SHIFT	     ; 12
 13278 00003AC7 C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
 13279                              <1> 
 13280                              <1> 	; EAX = Beginning page number
 13281                              <1> 	; ECX = Number of contiguous pages to be deallocated
 13282                              <1> damb_0:
 13283                              <1> 	; deallocate contiguous memory pages (via memory allocation table bits)
 13284 00003ACA 89C2                <1> 	mov	edx, eax
 13285 00003ACC C1EA05              <1> 	shr	edx, 5 ; 32 pages in one allocation dword (32 bits)
 13286 00003ACF 3B15[F4BD0000]      <1> 	cmp	edx, [next_page] ; next free page
 13287 00003AD5 7306                <1> 	jnb	short damb_1
 13288 00003AD7 8915[F4BD0000]      <1> 	mov	[next_page], edx
 13289                              <1> damb_1:
 13290 00003ADD BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
 13291 00003AE2 01D3                <1> 	add	ebx, edx
 13292 00003AE4 83E01F              <1> 	and	eax, 1Fh ; 31
 13293 00003AE7 29C1                <1> 	sub	ecx, eax
 13294 00003AE9 51                  <1> 	push	ecx ; ***
 13295 00003AEA B920000000          <1> 	mov	ecx, 32
 13296 00003AEF 28C1                <1> 	sub	cl, al
 13297                              <1> damb_2:		
 13298 00003AF1 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
 13299                              <1> 				     ; set relevant bit to 1.
 13300                              <1> 				     ; set CF to the previous bit value	
 13301 00003AF4 FF05[F0BD0000]      <1> 	inc     dword [free_pages]   ; 1 page has been deallocated (X = X+1) 
 13302 00003AFA 49                  <1> 	dec	ecx
 13303 00003AFB 7404                <1> 	jz	short damb_3
 13304 00003AFD FEC0                <1> 	inc	al
 13305 00003AFF EBF0                <1> 	jmp	short damb_2
 13306                              <1> damb_3:	
 13307 00003B01 59                  <1> 	pop	ecx ; ***
 13308 00003B02 21C9                <1> 	and	ecx, ecx ; 0 ?
 13309 00003B04 742D                <1> 	jz	short damb_6
 13310                              <1> damb_4:
 13311 00003B06 B020                <1> 	mov	al, 32
 13312 00003B08 39C1                <1> 	cmp	ecx, eax ; 32
 13313 00003B0A 721C                <1> 	jb	short damb_5
 13314 00003B0C 0105[F0BD0000]      <1> 	add	[free_pages], eax ; [free_pages] = [free_pages] + 32
 13315 00003B12 01C2                <1> 	add	edx, eax ; 4 bytes =  32 bits
 13316 00003B14 29C1                <1> 	sub	ecx, eax ; 32
 13317 00003B16 B004                <1> 	mov	al, 4  
 13318 00003B18 7419                <1> 	jz	short damb_6	
 13319 00003B1A 01C3                <1> 	add	ebx, eax
 13320 00003B1C 01C2                <1> 	add	edx, eax
 13321 00003B1E 28C0                <1> 	sub	al, al ; 0
 13322 00003B20 C703FFFFFFFF        <1>         mov     dword [ebx], 0FFFFFFFFh ; set 32 bits
 13323 00003B26 EBDE                <1> 	jmp	short damb_4
 13324                              <1> damb_5:
 13325 00003B28 B004                <1> 	mov	al, 4
 13326 00003B2A 01C3                <1> 	add	ebx, eax ; 4
 13327 00003B2C 01C2                <1> 	add	edx, eax ; 4
 13328                              <1> 	; ECX < 32
 13329 00003B2E 28C0                <1> 	sub	al, al ; 0
 13330 00003B30 50                  <1> 	push	eax ; 0 ***
 13331 00003B31 EBBE                <1> 	jmp	short damb_2	
 13332                              <1> damb_6:
 13333 00003B33 5B                  <1> 	pop	ebx
 13334 00003B34 5A                  <1> 	pop	edx
 13335 00003B35 C3                  <1> 	retn
 13336                              <1> 
 13337                              <1> 
 13338                              <1> ; /// End Of MEMORY MANAGEMENT FUNCTIONS ///
 13339                              <1> 
 13340                              <1> ;; Data:
 13341                              <1> 
 13342                              <1> ; 09/03/2015
 13343                              <1> ;swpq_count: dw 0 ; count of pages on the swap que
 13344                              <1> ;swp_drv:    dd 0 ; logical drive description table address of the swap drive/disk
 13345                              <1> ;swpd_size:  dd 0 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
 13346                              <1> ;swpd_free:  dd 0 ; free page blocks (4096 bytes) on swap disk/drive (logical)
 13347                              <1> ;swpd_next:  dd 0 ; next free page block
 13348                              <1> ;swpd_last:  dd 0 ; last swap page block		 		
 13349                                  %include 'timer.s'   ; 17/01/2015
 13350                              <1> ; ****************************************************************************
 13351                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - timer.s
 13352                              <1> ; ----------------------------------------------------------------------------
 13353                              <1> ; Last Update: 29/01/2016
 13354                              <1> ; ----------------------------------------------------------------------------
 13355                              <1> ; Beginning: 17/01/2016
 13356                              <1> ; ----------------------------------------------------------------------------
 13357                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13358                              <1> ; ----------------------------------------------------------------------------
 13359                              <1> ; Turkish Rational DOS
 13360                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 13361                              <1> ;
 13362                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 13363                              <1> ;
 13364                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
 13365                              <1> ; ****************************************************************************
 13366                              <1> 
 13367                              <1> ; TRDOS 386  (TRDOS v2.0) Kernel - TIMER & REAL TIME CLOCK (BIOS) FUNCTIONS
 13368                              <1> 
 13369                              <1> ; IBM PC-AT BIOS Source Code ('BIOS2.ASM')
 13370                              <1> ; TITLE BIOS2 ---- 06/10/85 BIOS INTERRUPT ROUTINES
 13371                              <1> 
 13372                              <1> ;
 13373                              <1> ; ///////// TIMER (& REAL TIME CLOCK) FUNCTIONS ///////////////
 13374                              <1> 
 13375                              <1> int1Ah:
 13376                              <1> 	; 29/01/2016
 13377                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13378 00003B36 9C                  <1> 	pushfd
 13379 00003B37 0E                  <1> 	push 	cs
 13380 00003B38 E801000000          <1> 	call 	TIME_OF_DAY_1
 13381 00003B3D C3                  <1> 	retn
 13382                              <1> 
 13383                              <1> ;--- INT  1A H -- (TIME OF DAY) -------------------------------------------------
 13384                              <1> ;       THIS BIOS ROUTINE ALLOWS THE CLOCKS TO BE SET OR READ			:
 13385                              <1> ;										:
 13386                              <1> ; PARAMETERS:									:
 13387                              <1> ;     (AH) = 00H  READ THE CURRENT SETTING AND RETURN WITH,			:
 13388                              <1> ;                      (CX) = HIGH PORTION OF COUNT				:
 13389                              <1> ;                      (DX) = LOW PORTION OF COUNT				:
 13390                              <1> ;                      (AL) = 0 TIMER HAS NOT PASSED 24 HOURS SINCE LAST READ	:
 13391                              <1> ;                             1 IF ON ANOTHER DAY. (RESET TO ZERO AFTER READ)	:
 13392                              <1> ;										:
 13393                              <1> ;     (AH) = 01H  SET THE CURRENT CLOCK USING,					:
 13394                              <1> ;		     (CX) = HIGH PORTION OF COUNT				:
 13395                              <1> ;		     (DX) = LOW PORTION OF COUNT.				:
 13396                              <1> ;										:
 13397                              <1> ;               NOTE: COUNTS OCCUR AT THE RATE OF 1193180/65536 COUNTS/SECOND	:
 13398                              <1> ;                            (OR ABOUT 18.2 PER SECOND -- SEE EQUATES)		:
 13399                              <1> ;										:
 13400                              <1> ;     (AH) = 02H  READ THE REAL TIME CLOCK AND RETURN WITH,			:
 13401                              <1> ;                      (CH) = HOURS IN BCD (00-23)				:
 13402                              <1> ;                      (CL) = MINUTES IN BCD (00-59)				:
 13403                              <1> ;                      (DH) = SECONDS IN BCD (00-59)				:
 13404                              <1> ;                      (DL) = DAYLIGHT SAVINGS ENABLE (00-01)			:
 13405                              <1> ;										:
 13406                              <1> ;     (AH) = 03H  SET THE REAL TIME CLOCK USING,				:
 13407                              <1> ;                     (CH) = HOURS IN BCD (00-23)				:
 13408                              <1> ;                     (CL) = MINUTES IN BCD (00-59)				:
 13409                              <1> ;                     (DH) = SECONDS IN BCD (00-59)				:
 13410                              <1> ;                     (DL) = 01 IF DAYLIGHT SAVINGS ENABLE OPTION, ELSE 00.	:
 13411                              <1> ;										:
 13412                              <1> ;             NOTE: (DL) = 00 IF DAYLIGHT SAVINGS TIME ENABLE IS NOT ENABLED.	:
 13413                              <1> ;                   (DL) = 01 ENABLES TWO SPECIAL UPDATES THE LAST SUNDAY IN	:
 13414                              <1> ;	           APRIL   (1:59:59 --> 3:00:00 AM) AND THE LAST SUNDAY IN	:
 13415                              <1> ;                   OCTOBER (1:59:59 --> 1:00:00 AM) THE FIRST TIME.		:
 13416                              <1> ;										:
 13417                              <1> ;     (AH) = 04H  READ THE DATE FROM THE REAL TIME CLOCK AND RETURN WITH,	:
 13418                              <1> ;                      (CH) = CENTURY IN BCD (19 OR 20)				:
 13419                              <1> ;                      (CL) = YEAR IN BCD (00-99)				:
 13420                              <1> ;                      (DH) = MONTH IN BCD (01-12)				:
 13421                              <1> ;                      (DL) = DAY IN BCD (01-31).				:
 13422                              <1> ;										:
 13423                              <1> ;     (AH) = 05H  SET THE DATE INTO THE REAL TIME CLOCK USING,			:
 13424                              <1> ;                     (CH) = CENTURY IN BCD (19 OR 20)				:
 13425                              <1> ;                     (CL) = YEAR IN BCD (00-99)				:
 13426                              <1> ;                     (DH) = MONTH IN BCD (01-12)				:
 13427                              <1> ;                     (DL) = DAY IN BCD (01-31).				:
 13428                              <1> ;										:
 13429                              <1> ;     (AH) = 06H  SET THE ALARM TO INTERRUPT AT SPECIFIED TIME,			:
 13430                              <1> ;                     (CH) = HOURS IN BCD (00-23 (OR FFH))			:
 13431                              <1> ;                     (CL) = MINUTES IN BCD (00-59 (OR FFH))			:
 13432                              <1> ;                     (DH) = SECONDS IN BCD (00-59 (OR FFH))			:
 13433                              <1> ;										:
 13434                              <1> ;     (AH) = 07H  RESET THE ALARM INTERRUPT FUNCTION.				:
 13435                              <1> ;										:
 13436                              <1> ; NOTES: FOR ALL RETURNS CY= 0 FOR SUCCESSFUL OPERATION.			:
 13437                              <1> ;        FOR (AH)= 2, 4, 6 - CARRY FLAG SET IF REAL TIME CLOCK NOT OPERATING.	:
 13438                              <1> ;        FOR (AH)= 6 - CARRY FLAG SET IF ALARM ALREADY ENABLED. 		:
 13439                              <1> ;        FOR THE ALARM FUNCTION (AH = 6) THE USER MUST SUPPLY A ROUTINE AND	:
 13440                              <1> ;         INTERCEPT THE CORRECT ADDRESS IN THE VECTOR TABLE FOR INTERRUPT 4AH.	:
 13441                              <1> ;         USE 0FFH FOR ANY "DO NOT CARE" POSITION FOR INTERVAL INTERRUPTS.	:
 13442                              <1> ;        INTERRUPTS ARE DISABLED DURING DATA MODIFICATION. 			:
 13443                              <1> ;        AH & AL ARE RETURNED MODIFIED AND NOT DEFINED EXCEPT WHERE INDICATED.	:
 13444                              <1> ;--------------------------------------------------------------------------------
 13445                              <1> 
 13446                              <1> ; 29/01/2016
 13447                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13448                              <1> 
 13449                              <1> TIME_OF_DAY_1:
 13450 00003B3E FB                  <1> 	sti				; INTERRUPTS BACK ON
 13451 00003B3F 80FC08              <1> 	cmp	ah, (RTC_TBE-RTC_TB)/4	; CHECK IF COMMAND IN VALID RANGE (0-7)
 13452 00003B42 F5                  <1> 	cmc				; COMPLEMENT CARRY FOR ERROR EXIT
 13453 00003B43 721A                <1> 	jc	short TIME_9		; EXIT WITH CARRY = 1 IF NOT VALID
 13454                              <1> 
 13455 00003B45 1E                  <1> 	push	ds
 13456 00003B46 56                  <1> 	push	esi
 13457 00003B47 66BE1000            <1> 	mov	si, KDATA		; kernel data segment
 13458 00003B4B 8EDE                <1> 	mov	ds, si
 13459 00003B4D C0E402              <1> 	shl	ah, 2			; convert function to dword offset
 13460 00003B50 0FB6F4              <1> 	movzx	esi, ah			; PLACE INTO ADDRESSING REGISTER
 13461 00003B53 FA                  <1> 	cli				; NO INTERRUPTS DURING TIME FUNCTIONS
 13462 00003B54 FF96[623B0000]      <1> 	call	[esi+RTC_TB]		; VECTOR TO FUNCTION REQUESTED WITH CY=0
 13463                              <1> 					; RETURN WITH CARRY FLAG SET FOR RESULT
 13464 00003B5A FB                  <1> 	sti				; INTERRUPTS BACK ON
 13465 00003B5B B400                <1> 	mov	ah, 0			; CLEAR (AH) TO ZERO
 13466 00003B5D 5E                  <1> 	pop	esi			; RECOVER USERS REGISTER
 13467 00003B5E 1F                  <1> 	pop	ds			; RECOVER USERS SEGMENT SELECTOR
 13468                              <1> TIME_9:					; RETURN WITH CY= 0 IF NO ERROR
 13469 00003B5F CA0400              <1> 	retf	4
 13470                              <1> 					; ROUTINE VECTOR TABLE (AH)=
 13471                              <1> RTC_TB:
 13472 00003B62 [823B0000]          <1> 	dd	RTC_00			; 0 = READ CURRENT CLOCK COUNT
 13473 00003B66 [953B0000]          <1> 	dd	RTC_10			; 1 = SET CLOCK COUNT
 13474 00003B6A [A33B0000]          <1> 	dd	RTC_20			; 2 = READ THE REAL TIME CLOCK TIME
 13475 00003B6E [D23B0000]          <1> 	dd	RTC_30			; 3 = SET REAL TIME CLOCK TIME
 13476 00003B72 [143C0000]          <1> 	dd	RTC_40			; 4 = READ THE REAL TIME CLOCK DATE
 13477 00003B76 [413C0000]          <1> 	dd	RTC_50			; 5 = SET REAL TIME CLOCK DATE
 13478 00003B7A [8E3C0000]          <1> 	dd	RTC_60			; 6 = SET THE REAL TIME CLOCK ALARM
 13479 00003B7E [E13C0000]          <1> 	dd	RTC_70			; 7 = RESET ALARM
 13480                              <1> 
 13481                              <1> RTC_TBE	equ	$
 13482                              <1> 
 13483                              <1> RTC_00:				; READ TIME COUNT
 13484 00003B82 A0[70BE0000]        <1> 	mov	al, [TIMER_OFL]		; GET THE OVERFLOW FLAG
 13485 00003B87 C605[70BE0000]00    <1> 	mov	byte [TIMER_OFL], 0	; AND THEN RESET THE OVERFLOW FLAG
 13486 00003B8E 8B0D[6CBE0000]      <1>         mov     ecx, [TIMER_LH]         ; GET COUNT OF TIME
 13487 00003B94 C3                  <1> 	retn
 13488                              <1> 
 13489                              <1> RTC_10:				; SET TIME COUNT
 13490 00003B95 890D[6CBE0000]      <1>         mov     [TIMER_LH], ecx         ; SET TIME COUNT
 13491 00003B9B C605[70BE0000]00    <1> 	mov	byte [TIMER_OFL], 0	; RESET OVERFLOW FLAG
 13492 00003BA2 C3                  <1> 	retn				; RETURN WITH NO CARRY
 13493                              <1> 
 13494                              <1> RTC_20:				; GET RTC TIME
 13495 00003BA3 E8EB010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13496 00003BA8 7227                <1> 	jc	short RTC_29		; EXIT IF ERROR (CY= 1)
 13497                              <1> 
 13498 00003BAA B000                <1> 	mov	al, CMOS_SECONDS	; SET ADDRESS OF SECONDS
 13499 00003BAC E8FD010000          <1> 	call	CMOS_READ		; GET SECONDS
 13500 00003BB1 88C6                <1> 	mov	dh, al			; SAVE
 13501 00003BB3 B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13502 00003BB5 E8F4010000          <1> 	call	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
 13503 00003BBA 2401                <1> 	and	al, 00000001b		; MASK FOR VALID DSE BIT
 13504 00003BBC 88C2                <1> 	mov	dl, al			; SET [DL] TO ZERO FOR NO DSE BIT
 13505 00003BBE B002                <1> 	mov	al, CMOS_MINUTES	; SET ADDRESS OF MINUTES
 13506 00003BC0 E8E9010000          <1> 	call	CMOS_READ		; GET MINUTES
 13507 00003BC5 88C1                <1> 	mov	cl, al			; SAVE
 13508 00003BC7 B004                <1>         mov     al, CMOS_HOURS          ; SET ADDRESS OF HOURS
 13509 00003BC9 E8E0010000          <1> 	call	CMOS_READ		; GET HOURS
 13510 00003BCE 88C5                <1> 	mov	ch, al			; SAVE
 13511 00003BD0 F8                  <1> 	clc				; SET CY= 0
 13512                              <1> RTC_29:
 13513 00003BD1 C3                  <1> 	retn				; RETURN WITH RESULT IN CARRY FLAG
 13514                              <1> 
 13515                              <1> RTC_30:				; SET RTC TIME
 13516 00003BD2 E8BC010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13517 00003BD7 7305                <1> 	jnc	short RTC_35		; GO AROUND IF CLOCK OPERATING
 13518 00003BD9 E817010000          <1> 	call	RTC_STA			; ELSE TRY INITIALIZING CLOCK
 13519                              <1> RTC_35:
 13520 00003BDE 88F4                <1> 	mov	ah, dh			; GET TIME BYTE - SECONDS
 13521 00003BE0 B000                <1> 	mov	al, CMOS_SECONDS	; ADDRESS SECONDS
 13522 00003BE2 E8DF010000          <1> 	call	CMOS_WRITE		; UPDATE SECONDS
 13523 00003BE7 88CC                <1> 	mov	ah, cl			; GET TIME BYTE - MINUTES
 13524 00003BE9 B002                <1> 	mov	al, CMOS_MINUTES	; ADDRESS MINUTES
 13525 00003BEB E8D6010000          <1> 	call	CMOS_WRITE		; UPDATE MINUTES
 13526 00003BF0 88EC                <1> 	mov	ah, ch			; GET TIME BYTE - HOURS
 13527 00003BF2 B004                <1> 	mov	al, CMOS_HOURS		; ADDRESS HOURS
 13528 00003BF4 E8CD010000          <1> 	call	CMOS_WRITE		; UPDATE ADDRESS
 13529                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13530                              <1> 	;mov	ah, al
 13531 00003BF9 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13532 00003BFD E8AC010000          <1> 	call	CMOS_READ		; READ CURRENT TIME
 13533 00003C02 2462                <1> 	and	al, 01100010b		; MASK FOR VALID BIT POSITIONS
 13534 00003C04 0C02                <1> 	or	al, 00000010b		; TURN ON 24 HOUR MODE
 13535 00003C06 80E201              <1> 	and	dl, 00000001b		; USE ONLY THE DSE BIT
 13536 00003C09 08D0                <1> 	or	al, dl			; GET DAY LIGHT SAVINGS TIME BIT (OSE)
 13537 00003C0B 86E0                <1> 	xchg	ah, al			; PLACE IN WORK REGISTER AND GET ADDRESS
 13538 00003C0D E8B4010000          <1> 	call	CMOS_WRITE		; SET NEW ALARM SITS
 13539 00003C12 F8                  <1> 	clc				; SET CY= 0
 13540 00003C13 C3                  <1> 	retn				; RETURN WITH CY= 0
 13541                              <1> 
 13542                              <1> RTC_40:				; GET RTC DATE
 13543 00003C14 E87A010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13544 00003C19 7225                <1> 	jc	short RTC_49		; EXIT IF ERROR (CY= 1)
 13545                              <1> 
 13546 00003C1B B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH
 13547 00003C1D E88C010000          <1> 	call	CMOS_READ		; READ DAY OF MONTH
 13548 00003C22 88C2                <1> 	mov	dl, al			; SAVE
 13549 00003C24 B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH
 13550 00003C26 E883010000          <1> 	call	CMOS_READ		; READ MONTH
 13551 00003C2B 88C6                <1> 	mov	dh, al			; SAVE
 13552 00003C2D B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR
 13553 00003C2F E87A010000          <1> 	call	CMOS_READ		; READ YEAR
 13554 00003C34 88C1                <1> 	mov	cl, al			; SAVE
 13555 00003C36 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY LOCATION
 13556 00003C38 E871010000          <1> 	call	CMOS_READ		; GET CENTURY BYTE
 13557 00003C3D 88C5                <1> 	mov	ch, al			; SAVE
 13558 00003C3F F8                  <1> 	clc				; SET CY=0
 13559                              <1> RTC_49:
 13560 00003C40 C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAG
 13561                              <1> 
 13562                              <1> RTC_50:				; SET RTC DATE
 13563 00003C41 E84D010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13564 00003C46 7305                <1> 	jnc	short RTC_55		; GO AROUND IF NO ERROR
 13565 00003C48 E8A8000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
 13566                              <1> RTC_55:
 13567 00003C4D 66B80600            <1> 	mov	ax, CMOS_DAY_WEEK	; ADDRESS OF DAY OF WEEK BYTE
 13568 00003C51 E870010000          <1> 	call	CMOS_WRITE		; LOAD ZEROS TO DAY OF WEEK
 13569 00003C56 88D4                <1> 	mov	ah, dl			; GET DAY OF MONTH BYTE
 13570 00003C58 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH BYTE
 13571 00003C5A E867010000          <1> 	call	CMOS_WRITE		; WRITE OF DAY OF MONTH REGISTER
 13572 00003C5F 88F4                <1> 	mov	ah, dh			; GET MONTH
 13573 00003C61 B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH BYTE
 13574 00003C63 E85E010000          <1> 	call	CMOS_WRITE		; WRITE MONTH REGISTER
 13575 00003C68 88CC                <1> 	mov	ah, cl			; GET YEAR BYTE
 13576 00003C6A B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR REGISTER
 13577 00003C6C E855010000          <1> 	call	CMOS_WRITE		; WRITE YEAR REGISTER
 13578 00003C71 88EC                <1> 	mov	ah, ch			; GET CENTURY BYTE
 13579 00003C73 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY BYTE
 13580 00003C75 E84C010000          <1> 	call	CMOS_WRITE		; WRITE CENTURY LOCATION
 13581                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13582                              <1> 	;mov	ah, al
 13583 00003C7A 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13584 00003C7E E82B010000          <1> 	call	CMOS_READ		; READ WIRRENT SETTINGS
 13585 00003C83 247F                <1> 	and	al, 07Fh		; CLEAR 'SET BIT'
 13586 00003C85 86E0                <1> 	xchg	ah, al			; MOVE TO WORK REGISTER
 13587 00003C87 E83A010000          <1> 	call	CMOS_WRITE		; AND START CLOCK UPDATING
 13588 00003C8C F8                  <1> 	clc				; SET CY= 0
 13589 00003C8D C3                  <1> 	retn				; RETURN CY=0
 13590                              <1> 
 13591                              <1> RTC_60:				; SET RTC ALARM
 13592 00003C8E B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM
 13593 00003C90 E819010000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
 13594 00003C95 A820                <1> 	test	al, 20h			; CHECK FOR ALARM ALREADY ENABLED
 13595 00003C97 F9                  <1> 	stc				; SET CARRY IN CASE OF ERROR
 13596 00003C98 7542                <1> 	jnz	short RTC_69		; ERROR EXIT IF ALARM SET
 13597 00003C9A E8F4000000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13598 00003C9F 7305                <1> 	jnc	short RTC_65		; SKIP INITIALIZATION IF NO ERROR
 13599 00003CA1 E84F000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
 13600                              <1> RTC_65:	
 13601 00003CA6 88F4                <1> 	mov	ah, dh			; GET SECONDS BYTE
 13602 00003CA8 B001                <1> 	mov	al, CMOS_SEC_ALARM	; ADDRESS THE SECONDS ALARM REGISTER
 13603 00003CAA E817010000          <1> 	call	CMOS_WRITE		; INSERT SECONDS
 13604 00003CAF 88CC                <1> 	mov	ah, cl			; GET MINUTES PARAMETER
 13605 00003CB1 B003                <1> 	mov	al, CMOS_MIN_ALARM	; ADDRESS MINUTES ALARM REGISTER
 13606 00003CB3 E80E010000          <1> 	call	CMOS_WRITE		; INSERT MINUTES
 13607 00003CB8 88EC                <1> 	mov	ah, ch			; GET HOURS PARAMETER
 13608 00003CBA B005                <1> 	mov	al, CMOS_HR_ALARM	; ADDRESS HOUR ALARM REGISTER
 13609 00003CBC E805010000          <1> 	call	CMOS_WRITE		; INSERT HOURS
 13610 00003CC1 E4A1                <1> 	in	al, INTB01		; READ SECOND INTERRUPT MASK REGISTER
 13611 00003CC3 24FE                <1> 	and	al, 0FEh		; ENABLE ALARM TIMER BIT (CY= 0)
 13612 00003CC5 E6A1                <1> 	out	INTB01, al		; WRITE UPDATED MASK
 13613                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13614                              <1> 	;mov	ah, al
 13615 00003CC7 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13616 00003CCB E8DE000000          <1> 	call	CMOS_READ		; READ CURRENT ALARM REGISTER
 13617 00003CD0 247F                <1> 	and	al, 07Fh		; ENSURE SET BIT TURNED OFF
 13618 00003CD2 0C20                <1> 	or	al, 20h			; TURN ON ALARM ENABLE
 13619 00003CD4 86E0                <1> 	xchg	ah, al			; MOVE MASK TO OUTPUT REGISTER
 13620 00003CD6 E8EB000000          <1> 	call	CMOS_WRITE		; WRITE NEW ALARM MASK
 13621 00003CDB F8                  <1> 	clc				; SET CY= 0
 13622                              <1> RTC_69:
 13623 00003CDC 66B80000            <1> 	mov	ax, 0			; CLEAR AX REGISTER
 13624 00003CE0 C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAC
 13625                              <1> 
 13626                              <1> RTC_70:				; RESET ALARM
 13627                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13628                              <1> 	;mov	ah, al
 13629 00003CE1 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257	; ADDRESS ALARM REGISTER (TO BOTH AH,AL)
 13630 00003CE5 E8C4000000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
 13631 00003CEA 2457                <1> 	and	al, 57h			; TURN OFF ALARM ENABLE
 13632 00003CEC 86E0                <1> 	xchg	ah, al			; SAVE DATA AND RECOVER ADDRESS
 13633 00003CEE E8D3000000          <1> 	call	CMOS_WRITE		; RESTORE NEW VALUE
 13634 00003CF3 F8                  <1> 	clc				; SET CY= 0
 13635 00003CF4 C3                  <1> 	retn				; RETURN WITH NO CARRY
 13636                              <1> 
 13637                              <1> RTC_STA:			; INITIALIZE REAL TIME CLOCK
 13638                              <1> 	;mov	al, CMOS_REG_A		; ADDRESS REGISTER A AND LOAD DATA MASK		
 13639                              <1> 	;mov	ah, 26h
 13640 00003CF5 66B80A26            <1> 	mov	ax, (26h*100h)+CMOS_REG_A
 13641 00003CF9 E8C8000000          <1> 	call	CMOS_WRITE		; INITIALIZE STATUS REGISTER A
 13642                              <1> 	;mov	al, CMOS_REG_B		; SET "SET BIT" FOR CLOCK INITIALIZATION	
 13643                              <1> 	;mov	ah, 82h
 13644 00003CFE 66B80B82            <1> 	mov	ax, (82h*100h)+CMOS_REG_B
 13645 00003D02 E8BF000000          <1> 	call	CMOS_WRITE		; AND 24 HOUR MODE TO REGISTER B
 13646 00003D07 B00C                <1> 	mov	al, CMOS_REG_C		; ADDRESS REGISTER C
 13647 00003D09 E8A0000000          <1> 	call	CMOS_READ		; READ REGISTER C TO INITIALIZE
 13648 00003D0E B00D                <1> 	mov	al, CMOS_REG_D		; ADDRESS REGISTER D
 13649 00003D10 E899000000          <1> 	call	CMOS_READ		; READ REGISTER D TO INITIALIZE
 13650 00003D15 C3                  <1> 	retn
 13651                              <1> 
 13652                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13653                              <1> 
 13654                              <1> ;--- HARDWARE INT  70 H -- ( IRQ LEVEL  8) --------------------------------------
 13655                              <1> ; ALARM INTERRUPT HANDLER (RTC)							:
 13656                              <1> ;       THIS ROUTINE HANDLES THE PERIODIC AND ALARM INTERRUPTS FROM THE CMOS	:
 13657                              <1> ;       TIMER. INPUT FREQUENCY IS 1.024 KHZ OR APPROXIMATELY 1024 INTERRUPTS	:
 13658                              <1> ;       EVERY SECOND FOR THE PERIODIC INTERRUPT. FOR THE ALARM FUNCTION,	:
 13659                              <1> ;       THE INTERRUPT WILL OCCUR AT THE DESIGNATED TIME.			:
 13660                              <1> ;										:
 13661                              <1> ;       INTERRUPTS ARE ENABLED WHEN THE EVENT OR ALARM FUNCTION IS ACTIVATED.	:
 13662                              <1> ;       FOR THE EVENT INTERRUPT, THE HANDLER WILL DECREMENT THE WAIT COUNTER	:
 13663                              <1> ;       AND WHEN IT EXPIRES WILL SET THE DESIGNATED LOCATION TO 80H. FOR	:
 13664                              <1> ;       THE ALARM INTERRUPT. THE USER MUST PROVIDE A ROUTINE TO INTERCEPT	:
 13665                              <1> ;       THE CORRECT ADDRESS FROM THE VECTOR TABLE INVOKED BY INTERRUPT 4AH	:
 13666                              <1> ;       PRIOR TO SETTING THE REAL TIME CLOCK ALARM (INT 1AH, AH= 06H).		:
 13667                              <1> ;--------------------------------------------------------------------------------
 13668                              <1> 
 13669                              <1> RTC_INT:			; ALARM INTERRUPT
 13670 00003D16 1E                  <1> 	push	ds			; LEAVE INTERRUPTS DISABLED
 13671 00003D17 50                  <1> 	push	eax			; SAVE REGISTERS
 13672 00003D18 57                  <1> 	push	edi
 13673                              <1> RTC_I_1:				; CHECK FOR SECOND INTERRUPT
 13674 00003D19 66B88C8B            <1> 	mov	ax, 256*(CMOS_REG_B+NMI)+CMOS_REG_C+NMI ; ALARM AND STATUS
 13675 00003D1D E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM FLAG MASK ADDRESS
 13676 00003D1F 90                  <1> 	nop				; I/O DELAY
 13677 00003D20 EB00                <1> 	jmp	short $+2
 13678 00003D22 E471                <1> 	in	al, CMOS_DATA		; READ AND RESET INTERRUPT REQUEST FLAGS
 13679 00003D24 A860                <1> 	test	al, 01100000b		; CHECK FOR EITHER INTERRUPT PENDING
 13680 00003D26 745D                <1> 	jz	short	RTC_I_9		; EXIT IF NOT A VALID RTC INTERRUPT
 13681                              <1> 
 13682 00003D28 86E0                <1> 	xchg	ah, al			; SAVE FLAGS AND GET ENABLE ADDRESS
 13683 00003D2A E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM ENABLE MASK ADDRESS
 13684 00003D2C 90                  <1> 	nop				; I/O DELAY
 13685 00003D2D EB00                <1> 	jmp	short $+2	
 13686 00003D2F E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ALARM ENABLE MASK
 13687 00003D31 20E0                <1> 	and	al, ah			; ALLOW ONLY SOURCES THAT ARE ENABLED
 13688 00003D33 A840                <1> 	test	al, 01000000b		; CHECK FOR PERIODIC INTERRUPT
 13689 00003D35 743B                <1> 	jz	short RTC_I_5		; SKIP IF NOT A PERIODIC INTERRUPT
 13690                              <1> 
 13691                              <1> ;-----	DECREMENT WAIT COUNT BY INTERRUPT INTERVAL
 13692                              <1> 
 13693 00003D37 66BF1000            <1> 	mov	di, KDATA		; kernel data segment
 13694 00003D3B 8EDF                <1> 	mov	ds, di
 13695                              <1> 	
 13696 00003D3D 812D[66BE0000]D003- <1> 	sub	dword [RTC_LH], 976	; DECREMENT COUNT BY 1/1024
 13697 00003D45 0000                <1>
 13698 00003D47 7329                <1> 	jnc	short RTC_I_5		; SKIP TILL 32 BIT WORD LESS THAN ZERO
 13699                              <1> 
 13700                              <1> ;-----	TURN OFF PERIODIC INTERRUPT ENABLE
 13701                              <1> 
 13702 00003D49 6650                <1> 	push	ax			; SAVE INTERRUPT FLAG MASK
 13703 00003D4B 66B88B8B            <1> 	mov	ax, 257*(CMOS_REG_B+NMI) ; INTERRUPT ENABLE REGISTER
 13704 00003D4F E670                <1> 	out	CMOS_PORT, al		; WRITE ADDRESS TO CMOS CLOCK
 13705 00003D51 90                  <1> 	nop				; I/O DELAY
 13706 00003D52 EB00                <1> 	jmp	short $+2
 13707 00003D54 E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ENABLES
 13708 00003D56 24BF                <1> 	and	al, 0BFh		; TURN OFF PIE
 13709 00003D58 86C4                <1> 	xchg	al, ah			; GET CMOS ADDRESS AND SAVE VALUE
 13710 00003D5A E670                <1> 	out	CMOS_PORT, al		; ADDRESS REGISTER B
 13711 00003D5C 86C4                <1> 	xchg	al, ah			; GET NEW INTERRUPT ENABLE MASK
 13712 00003D5E E671                <1> 	out	CMOS_DATA, al		; SET MASK IN INTERRUPT ENABLE REGISTER
 13713 00003D60 C605[6ABE0000]00    <1> 	mov	byte [RTC_WAIT_FLAG], 0	; SET FUNCTION ACTIVE FLAG OFF
 13714 00003D67 8B3D[6BBE0000]      <1> 	mov	edi, [USER_FLAG]	; SET UP (DS:DI) TO POINT TO USER FLAG
 13715 00003D6D C60780              <1> 	mov	byte [edi], 80h		; TURN ON USERS FLAG
 13716 00003D70 6658                <1> 	pop	ax			; GET INTERRUPT SOURCE BACK
 13717                              <1> RTC_I_5:
 13718 00003D72 A820                <1> 	test	al, 00100000b		; TEST FOR ALARM INTERRUPT
 13719 00003D74 740D                <1> 	jz	short RTC_I_7		; SKIP USER INTERRUPT CALL IF NOT ALARM
 13720                              <1> 
 13721 00003D76 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
 13722 00003D78 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
 13723 00003D7A FB                  <1> 	sti				; INTERRUPTS BACK ON NOW
 13724 00003D7B 52                  <1> 	push	edx
 13725 00003D7C E8D86E0000          <1> 	call	INT4Ah			; TRANSFER TO USER ROUTINE
 13726 00003D81 5A                  <1> 	pop	edx
 13727 00003D82 FA                  <1> 	cli				; BLOCK INTERRUPT FOR RETRY
 13728                              <1> RTC_I_7:				; RESTART ROUTINE TO HANDLE DELAYED
 13729 00003D83 EB94                <1> 	jmp	short RTC_I_1		;  ENTRY AND SECOND EVENT BEFORE DONE
 13730                              <1> 
 13731                              <1> RTC_I_9:				; EXIT - NO PENDING INTERRUPTS
 13732 00003D85 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
 13733 00003D87 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
 13734 00003D89 B020                <1> 	mov	al, EOI			; END OF INTERRUPT MASK TO 8259 - 2
 13735 00003D8B E6A0                <1> 	out	INTB00, al		; TO 8259 - 2
 13736 00003D8D E620                <1> 	out	INTA00,	al		; TO 8259 - 1
 13737 00003D8F 5F                  <1> 	pop	edi			; RESTORE REGISTERS
 13738 00003D90 58                  <1> 	pop	eax
 13739 00003D91 1F                  <1> 	pop	ds
 13740 00003D92 CF                  <1> 	iret				; END OF INTERRUPT
 13741                              <1> 
 13742                              <1> 
 13743                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
 13744                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (bios2.asm)
 13745                              <1> UPD_IPR:				; WAIT TILL UPDATE NOT IN PROGRESS
 13746 00003D93 51                  <1> 	push	ecx
 13747 00003D94 B9FFFF0000          <1> 	mov	ecx, 65535		; SET TIMEOUT LOOP COUNT (= 800)
 13748                              <1> 		; mov cx, 800	
 13749                              <1> UPD_10:
 13750 00003D99 B00A                <1> 	mov	al, CMOS_REG_A		; ADDRESS STATUS REGISTER A
 13751 00003D9B FA                  <1> 	cli				; NO TIMER INTERRUPTS DURING UPDATES
 13752 00003D9C E80D000000          <1> 	call	CMOS_READ		; READ UPDATE IN PROCESS FLAG
 13753 00003DA1 A880                <1> 	test	al, 80h			; IF UIP BIT IS ON ( CANNOT READ TIME )
 13754 00003DA3 7406                <1> 	jz	short UPD_90		; EXIT WITH CY= 0 IF CAN READ CLOCK NOW
 13755 00003DA5 FB                  <1> 	sti				; ALLOW INTERRUPTS WHILE WAITING
 13756 00003DA6 E2F1                <1> 	loop	UPD_10			; LOOP TILL READY OR TIMEOUT
 13757 00003DA8 31C0                <1> 	xor	eax, eax		; CLEAR RESULTS IF ERROR
 13758                              <1> 		; xor ax, ax
 13759 00003DAA F9                  <1> 	stc				; SET CARRY FOR ERROR
 13760                              <1> UPD_90:
 13761 00003DAB 59                  <1> 	pop	ecx			; RESTORE CALLERS REGISTER
 13762 00003DAC FA                  <1> 	cli				; INTERRUPTS OFF DURING SET
 13763 00003DAD C3                  <1> 	retn				; RETURN WITH CY FLAG SET
 13764                              <1> 
 13765                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
 13766                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (test4.asm)
 13767                              <1> 
 13768                              <1> ;--- CMOS_READ -----------------------------------------------------------------
 13769                              <1> ;		READ BYTE FROM CMOS_SYSTEM CLOCK CONFIGURATION TABLE	       :
 13770                              <1> ;									       :
 13771                              <1> ; INPUT: (AL)=	CMOS_TABLE ADDRESS TO BE READ				       :
 13772                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
 13773                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
 13774                              <1> ;									       :
 13775                              <1> ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL). IF BIT 7 OF (AL) WAS   :
 13776                              <1> ;		ON THEN NMI LEFT DISABLED, DURING THE CMOS READ BOTH NMI AND   :
 13777                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
 13778                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
 13779                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
 13780                              <1> ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
 13781                              <1> ;-------------------------------------------------------------------------------
 13782                              <1> 
 13783                              <1> CMOS_READ:
 13784 00003DAE 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
 13785 00003DAF D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
 13786 00003DB1 F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
 13787 00003DB2 D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
 13788 00003DB4 FA                  <1> 	cli				; DISABLE INTERRUPTS
 13789 00003DB5 E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
 13790 00003DB7 90                  <1> 	nop				; I/O DELAY
 13791 00003DB8 E471                <1> 	in	al, CMOS_DATA		; READ THE REQUESTED CMOS LOCATION
 13792 00003DBA 6650                <1> 	push	ax			; SAVE (AH) REGISTER VALUE AND CMOS BYTE
 13793                              <1> 	; 15/03/2015 ; IBM PC/XT Model 286 BIOS source code 
 13794                              <1> 		     ; ----- 10/06/85 (test4.asm)
 13795 00003DBC B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2 ; GET ADDRESS OF DEFAULT LOCATION
 13796                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
 13797 00003DBE D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
 13798 00003DC0 E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
 13799 00003DC2 6658                <1> 	pop	ax			; RESTORE (AH) AND (AL), CMOS BYTE
 13800 00003DC4 9D                  <1> 	popf	
 13801 00003DC5 C3                  <1> 	retn				; RETURN WITH FLAGS RESTORED
 13802                              <1> 
 13803                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13804                              <1> 
 13805                              <1> ;--- CMOS_WRITE ----------------------------------------------------------------
 13806                              <1> ;	WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE		       :
 13807                              <1> ;									       :
 13808                              <1> ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
 13809                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
 13810                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
 13811                              <1> ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
 13812                              <1> ;									       :
 13813                              <1> ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
 13814                              <1> ;		IF BIT 7 OF (AL) IS ON, DURING THE CMOS UPDATE BOTH NMI AND    :
 13815                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
 13816                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
 13817                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
 13818                              <1> ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
 13819                              <1> ;-------------------------------------------------------------------------------
 13820                              <1> 
 13821                              <1> CMOS_WRITE:				; WRITE (AH) TO LOCATION (AL)
 13822 00003DC6 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
 13823 00003DC7 6650                <1> 	push	ax			; SAVE WORK REGISTER VALUES
 13824 00003DC9 D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
 13825 00003DCB F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
 13826 00003DCC D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
 13827 00003DCE FA                  <1> 	cli				; DISABLE INTERRUPTS
 13828 00003DCF E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
 13829 00003DD1 88E0                <1> 	mov	al, ah			; GET THE DATA BYTE TO WRITE
 13830 00003DD3 E671                <1> 	out	CMOS_DATA, al		; PLACE IN REQUESTED CMOS LOCATION
 13831 00003DD5 B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2	; GET ADDRESS OF DEFAULT LOCATION
 13832                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
 13833 00003DD7 D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
 13834 00003DD9 E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
 13835 00003DDB 90                  <1> 	nop				; I/O DELAY
 13836 00003DDC E471                <1> 	in	al, CMOS_DATA		; OPEN STANDBY LATCH
 13837 00003DDE 6658                <1> 	pop	ax			; RESTORE WORK REGISTERS
 13838 00003DE0 9D                  <1> 	popf
 13839 00003DE1 C3                  <1> 	retn
 13840                              <1> 
 13841                              <1> ; /// End Of TIMER FUNCTIONS ///
 13842                                  %include 'sysdefs.s' ; 24/01/2015
 13843                              <1> ; ****************************************************************************
 13844                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYSTEM DEFINITIONS : sysdefs.s
 13845                              <1> ; ----------------------------------------------------------------------------
 13846                              <1> ; Last Update: 24/01/2016
 13847                              <1> ; ----------------------------------------------------------------------------
 13848                              <1> ; Beginning: 24/01/2016
 13849                              <1> ; ----------------------------------------------------------------------------
 13850                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13851                              <1> ; ----------------------------------------------------------------------------
 13852                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 13853                              <1> ; sysdefs.inc (14/11/2015)
 13854                              <1> ; ****************************************************************************
 13855                              <1> 
 13856                              <1> ; Retro UNIX 386 v1 Kernel - SYSDEFS.INC
 13857                              <1> ; Last Modification: 14/11/2015
 13858                              <1> ;
 13859                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
 13860                              <1> ; (Modified from 
 13861                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
 13862                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
 13863                              <1> ; 	UNIX.ASM (MASM 6.11) --> SYSDEFS.INC (NASM 2.11)
 13864                              <1> ; ----------------------------------------------------------------------------
 13865                              <1> ;
 13866                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
 13867                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
 13868                              <1> ; <Bell Laboratories (17/3/1972)>
 13869                              <1> ; <Preliminary Release of UNIX Implementation Document>
 13870                              <1> ;
 13871                              <1> ; ****************************************************************************
 13872                              <1> 
 13873                              <1> nproc 	equ	16  ; number of processes
 13874                              <1> nfiles 	equ	50
 13875                              <1> ntty	equ     8   ; 8+1 -> 8 (10/05/2013)
 13876                              <1> nbuf	equ	4   ; 6 ;; 21/08/2015 - 'namei' buffer problem when nbuf > 4 	
 13877                              <1> 		; NOTE: If fd0 super block buffer addres is beyond of the 1st
 13878                              <1> 		; 32K, DMA r/w routine or someting else causes a jump to 
 13879                              <1> 		; kernel panic routine (in 'alloc' routine, in u5.s)
 13880                              <1> 		; because of invalid buffer content (r/w error). 
 13881                              <1> 		; When all buffers are set before the end of the 1st 32k,
 13882                              <1> 		; there is no problem!? (14/11/2015) 
 13883                              <1> 
 13884                              <1> ;csgmnt	equ	2000h	; 26/05/2013 (segment of process 1)
 13885                              <1> ;core	equ 	0  	    ; 19/04/2013	
 13886                              <1> ;ecore	equ	32768 - 64  ; 04/06/2013 (24/05/2013)
 13887                              <1> 	; (if total size of argument list and arguments is 128 bytes)
 13888                              <1> 	; maximum executable file size = 32768-(64+40+128-6) = 32530 bytes
 13889                              <1> 	; maximum stack size = 40 bytes (+6 bytes for 'IRET' at 32570)	
 13890                              <1> 	; initial value of user's stack pointer = 32768-64-128-2 = 32574
 13891                              <1> 	; 	(sp=32768-args_space-2 at the beginning of execution)
 13892                              <1> 	; argument list offset = 32768-64-128 = 32576 (if it is 128 bytes)
 13893                              <1> 	; 'u' structure offset (for the '/core' dump file) = 32704
 13894                              <1> 	; '/core' dump file size = 32768 bytes
 13895                              <1>  
 13896                              <1> ; 08/03/2014 
 13897                              <1> ;sdsegmnt equ	6C0h  ; 256*16 bytes (swap data segment size for 16 processes)		 	 
 13898                              <1> ; 19/04/2013 Retro UNIX 8086 v1 feaure only !
 13899                              <1> ;;sdsegmnt equ 	740h  ; swap data segment (for user structures and registers)
 13900                              <1> 
 13901                              <1> ; 30/08/2013
 13902                              <1> time_count equ 4 ; 10 --> 4 01/02/2014
 13903                              <1> 
 13904                              <1> ; 05/02/2014
 13905                              <1> ; process status
 13906                              <1> ;SFREE 	equ 0
 13907                              <1> ;SRUN	equ 1
 13908                              <1> ;SWAIT	equ 2
 13909                              <1> ;SZOMB	equ 3
 13910                              <1> ;SSLEEP	equ 4 ; Retro UNIX 8086 V1 extension (for sleep and wakeup)
 13911                              <1> 
 13912                              <1> ; 09/03/2015
 13913                              <1> userdata equ 80000h ; user structure data address for current user ; temporary
 13914                              <1> swap_queue equ 90000h - 2000h ; swap queue address ; temporary
 13915                              <1> swap_alloc_table equ 0D0000h  ;  swap allocation table address ; temporary
 13916                              <1> 
 13917                              <1> ; 17/09/2015
 13918                              <1> ESPACE equ 48 ; [u.usp] (at 'sysent') - [u.sp] value for error return
 13919                              <1> 
 13920                              <1> ; 21/09/2015 (36) 
 13921                              <1> ; 01/07/2015 (35)
 13922                              <1> ; 14/07/2013 (0-34)
 13923                              <1> ; UNIX v1 system calls
 13924                              <1> _rele 	equ 0
 13925                              <1> _exit 	equ 1
 13926                              <1> _fork 	equ 2
 13927                              <1> _read 	equ 3
 13928                              <1> _write	equ 4
 13929                              <1> _open	equ 5
 13930                              <1> _close 	equ 6
 13931                              <1> _wait 	equ 7
 13932                              <1> _creat 	equ 8
 13933                              <1> _link 	equ 9
 13934                              <1> _unlink	equ 10
 13935                              <1> _exec	equ 11
 13936                              <1> _chdir	equ 12
 13937                              <1> _time 	equ 13
 13938                              <1> _mkdir 	equ 14
 13939                              <1> _chmod	equ 15
 13940                              <1> _chown	equ 16
 13941                              <1> _break	equ 17
 13942                              <1> _stat	equ 18
 13943                              <1> _seek	equ 19
 13944                              <1> _tell 	equ 20
 13945                              <1> _mount	equ 21
 13946                              <1> _umount	equ 22
 13947                              <1> _setuid	equ 23
 13948                              <1> _getuid	equ 24
 13949                              <1> _stime	equ 25
 13950                              <1> _quit	equ 26	
 13951                              <1> _intr	equ 27
 13952                              <1> _fstat	equ 28
 13953                              <1> _emt 	equ 29
 13954                              <1> _mdate 	equ 30
 13955                              <1> _stty 	equ 31
 13956                              <1> _gtty	equ 32
 13957                              <1> _ilgins	equ 33
 13958                              <1> _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
 13959                              <1> _msg	equ 35 ; Retro UNIX 386 v1 feature only !
 13960                              <1> _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
 13961                              <1> 
 13962                              <1> %macro sys 1-4
 13963                              <1>     ; 13/04/2015
 13964                              <1>     ; Retro UNIX 386 v1 system call.		
 13965                              <1>     mov eax, %1
 13966                              <1>     %if %0 >= 2   
 13967                              <1>         mov ebx, %2
 13968                              <1>         %if %0 >= 3    
 13969                              <1>             mov ecx, %3
 13970                              <1>             %if %0 = 4
 13971                              <1>                mov edx, %4   
 13972                              <1>             %endif
 13973                              <1>         %endif
 13974                              <1>     %endif
 13975                              <1>     int 30h	   
 13976                              <1> %endmacro
 13977                              <1> 
 13978                              <1> ; 13/05/2015 - ERROR CODES
 13979                              <1> ERR_FILE_NOT_OPEN  equ 10 ; 'file not open !' error
 13980                              <1> ERR_FILE_ACCESS    equ 11 ; 'permission denied !' error
 13981                              <1> ; 14/05/2015
 13982                              <1> ERR_DIR_ACCESS     equ 11 ; 'permission denied !' error
 13983                              <1> ERR_FILE_NOT_FOUND equ 12 ; 'file not found !' error
 13984                              <1> ERR_TOO_MANY_FILES equ 13 ; 'too many open files !' error
 13985                              <1> ERR_DIR_EXISTS     equ 14 ; 'directory already exists !' error 	
 13986                              <1> ; 16/05/2015		
 13987                              <1> ERR_DRV_NOT_RDY    equ 15 ; 'drive not ready !' error
 13988                              <1> ; 18/05/2015
 13989                              <1> ERR_DEV_NOT_RDY    equ 15 ; 'device not ready !' error
 13990                              <1> ERR_DEV_ACCESS     equ 11 ; 'permission denied !' error 
 13991                              <1> ERR_DEV_NOT_OPEN   equ 10 ; 'device not open !' error	
 13992                              <1> ; 07/06/2015
 13993                              <1> ERR_FILE_EOF	   equ 16 ; 'end of file !' error
 13994                              <1> ERR_DEV_VOL_SIZE   equ 16 ; 'out of volume' error
 13995                              <1> ; 09/06/2015
 13996                              <1> ERR_DRV_READ	   equ 17 ; 'disk read error !'
 13997                              <1> ERR_DRV_WRITE	   equ 18 ; 'disk write error !'
 13998                              <1> ; 16/06/2015
 13999                              <1> ERR_NOT_DIR	   equ 19 ; 'not a (valid) directory !' error
 14000                              <1> ERR_FILE_SIZE	   equ 20 ; 'file size error !'	
 14001                              <1> ; 22/06/2015
 14002                              <1> ERR_NOT_SUPERUSER  equ 11 ; 'permission denied !' error
 14003                              <1> ERR_NOT_OWNER      equ 11 ; 'permission denied !' error
 14004                              <1> ERR_NOT_FILE       equ 11 ; 'permission denied !' error	
 14005                              <1> ; 23/06/2015
 14006                              <1> ERR_FILE_EXISTS    equ 14 ; 'file already exists !' error
 14007                              <1> ERR_DRV_NOT_SAME   equ 21 ; 'not same drive !' error
 14008                              <1> ERR_DIR_NOT_FOUND  equ 12 ; 'directory not found !' error
 14009                              <1> ERR_NOT_EXECUTABLE equ 22 ; 'not executable file !' error
 14010                              <1> ; 27/06/2015
 14011                              <1> ERR_INV_PARAMETER  equ 23 ; 'invalid parameter !' error
 14012                              <1> ERR_INV_DEV_NAME   equ 24 ; 'invalid device name !' error
 14013                              <1> ; 29/06/2015
 14014                              <1> ERR_TIME_OUT	   equ 25 ; 'time out !' error			
 14015                              <1> ERR_DEV_NOT_RESP   equ 25 ; 'device not responding !' error	
 14016                              <1> 
 14017                              <1> ; 26/08/2015
 14018                              <1> ; 24/07/2015
 14019                              <1> ; 24/06/2015
 14020                              <1> MAX_ARG_LEN	   equ 256 ; max. length of sys exec arguments
 14021                              <1> ; 01/07/2015
 14022                              <1> MAX_MSG_LEN	   equ 255 ; max. msg length for 'sysmsg'
 14023                              <1> ;	 					 		
 14024                                  %include 'trdosk0.s' ; 04/01/2016 
 14025                              <1> ; ****************************************************************************
 14026                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DEFINITIONS : trdosk0.s
 14027                              <1> ; ----------------------------------------------------------------------------
 14028                              <1> ; Last Update: 29/02/2016
 14029                              <1> ; ----------------------------------------------------------------------------
 14030                              <1> ; Beginning: 04/01/2016
 14031                              <1> ; ----------------------------------------------------------------------------
 14032                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 14033                              <1> ; ----------------------------------------------------------------------------
 14034                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 14035                              <1> ; TRDOS2.ASM (09/11/2011)
 14036                              <1> ; ****************************************************************************
 14037                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
 14038                              <1> ;
 14039                              <1> ; Masterboot / Partition Table at Beginning+1BEh
 14040                              <1> ptBootable       equ 0
 14041                              <1> ptBeginHead      equ 1
 14042                              <1> ptBeginSector    equ 2
 14043                              <1> ptBeginCylinder  equ 3
 14044                              <1> ptFileSystemID   equ 4
 14045                              <1> ptEndHead        equ 5
 14046                              <1> ptEndSector      equ 6
 14047                              <1> ptEndCylinder    equ 7
 14048                              <1> ptStartSector    equ 8
 14049                              <1> ptSectors        equ 12
 14050                              <1> 
 14051                              <1> ; Boot Sector Parameters at 7C00h
 14052                              <1> DataArea1     equ -4
 14053                              <1> DataArea2     equ -2
 14054                              <1> BootStart     equ 0h
 14055                              <1> OemName       equ 03h
 14056                              <1> BytesPerSec   equ 0Bh
 14057                              <1> SecPerClust   equ 0Dh
 14058                              <1> ResSectors    equ 0Eh
 14059                              <1> FATs          equ 10h
 14060                              <1> RootDirEnts   equ 11h
 14061                              <1> Sectors       equ 13h
 14062                              <1> Media         equ 15h
 14063                              <1> FATSecs       equ 16h
 14064                              <1> SecPerTrack   equ 18h
 14065                              <1> Heads         equ 1Ah 
 14066                              <1> Hidden1       equ 1Ch
 14067                              <1> Hidden2       equ 1Eh
 14068                              <1> HugeSec1      equ 20h
 14069                              <1> HugeSec2      equ 22h
 14070                              <1> DriveNumber   equ 24h
 14071                              <1> Reserved1     equ 25h
 14072                              <1> bootsignature equ 26h                 
 14073                              <1> VolumeID      equ 27h
 14074                              <1> VolumeLabel   equ 2Bh
 14075                              <1> FileSysType   equ 36h          
 14076                              <1> Reserved2     equ 3Eh                           ; Starting cluster of P2000
 14077                              <1> 
 14078                              <1> ; FAT32 BPB Structure
 14079                              <1> FAT32_FAT_Size equ 36
 14080                              <1> FAT32_RootFClust equ 44
 14081                              <1> FAT32_FSInfoSec equ 48
 14082                              <1> FAT32_DrvNum equ 64
 14083                              <1> FAT32_BootSig equ 66
 14084                              <1> FAT32_VolID equ 67
 14085                              <1> FAT32_VolLab equ 71
 14086                              <1> FAT32_FilSysType equ 82
 14087                              <1> 
 14088                              <1> ; BIOS Disk Parameters
 14089                              <1> DPDiskNumber  equ 0h
 14090                              <1> DPDType       equ 1h
 14091                              <1> DPReturn      equ 2h
 14092                              <1> DPHeads       equ 3h
 14093                              <1> DPCylinders   equ 4h
 14094                              <1> DPSecPerTrack equ 6h
 14095                              <1> DPDisks       equ 7h
 14096                              <1> DPTableOff    equ 8h
 14097                              <1> DPTableSeg    equ 0Ah
 14098                              <1> DPNumOfSecs   equ 0Ch
 14099                              <1> 
 14100                              <1> ; BIOS INT 13h Extensions (LBA extensions)
 14101                              <1> ; Just After DP Data (DPDiskNumber+)
 14102                              <1> DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
 14103                              <1> DAP_Reserved1 equ 11h   ; Reserved Byte 
 14104                              <1> DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
 14105                              <1> DAP_Reserved2 equ 13h   ; Reserved Byte
 14106                              <1> DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
 14107                              <1> DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
 14108                              <1>                         ; C1= Selected Cylinder Number
 14109                              <1>                         ; H0= Number Of Heads (Maximum Head Number + 1)
 14110                              <1>                         ; H1= Selected Head Number
 14111                              <1>                         ; S0= Maximum Sector Number
 14112                              <1>                         ; S1= Selected Sector Number
 14113                              <1>                         ; QUAD WORD
 14114                              <1> ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
 14115                              <1>                              ; QUAD WORD (Also, value in 0h must be 18h) 
 14116                              <1>                              ; TR-DOS will not use 64 bit Flat Address
 14117                              <1> 
 14118                              <1> ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
 14119                              <1> ; Just After DP Data (DPDiskNumber+)
 14120                              <1> GetDParams_48h equ 20h ; Word. Data Length, must be 26 (1Ah) for short data.
 14121                              <1> GDP_48h_InfoFlag equ 22h ; Word
 14122                              <1> ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
 14123                              <1> GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
 14124                              <1> GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
 14125                              <1> GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
 14126                              <1> GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
 14127                              <1> GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
 14128                              <1> 
 14129                              <1> ; TR-DOS Standalone Program Extensions to the DiskParams Block
 14130                              <1> ; Just After DP Data (DPDiskNumber+)
 14131                              <1> TRDP_CurrentSector equ 3Ah  ; DX:AX (LBA)
 14132                              <1> TRDP_SectorCount equ 3Eh    ; CX (or Counter)
 14133                              <1> 
 14134                              <1> 
 14135                              <1> ; DOS Logical Disks
 14136                              <1> LD_Name equ 0
 14137                              <1> LD_DiskType equ 1
 14138                              <1> LD_PhyDrvNo equ 2
 14139                              <1> LD_FATType equ 3
 14140                              <1> LD_FSType equ 4
 14141                              <1> LD_LBAYes equ 5
 14142                              <1> LD_BPB equ 6
 14143                              <1> LD_FATBegin equ 96
 14144                              <1> LD_ROOTBegin equ 100
 14145                              <1> LD_DATABegin equ 104
 14146                              <1> LD_StartSector equ 108
 14147                              <1> LD_TotalSectors equ 112
 14148                              <1> LD_FreeSectors equ 116
 14149                              <1> LD_Clusters equ 120
 14150                              <1> LD_PartitionEntry equ 124
 14151                              <1> LD_DParamEntry equ 125
 14152                              <1> LD_MediaChanged equ 126
 14153                              <1> LD_CDirLevel equ 127
 14154                              <1> LD_CurrentDirectory equ 128
 14155                              <1> 
 14156                              <1> ; Singlix FS Extensions to DOS Logical Disks
 14157                              <1> ; 03/01/2010 (LD_BPB compatibility for CHS r/w)
 14158                              <1> 
 14159                              <1> LD_FS_Name equ 0
 14160                              <1> LD_FS_DiskType equ 1
 14161                              <1> LD_FS_PhyDrvNo equ 2
 14162                              <1> LD_FS_FATType equ 3
 14163                              <1> LD_FS_FSType equ 4
 14164                              <1> LD_FS_LBAYes equ 5
 14165                              <1> LD_FS_BPB equ 6
 14166                              <1> LD_FS_MediaAttrib equ 6
 14167                              <1> LD_FS_VersionMajor equ 7
 14168                              <1> LD_FS_RootDirD equ 8
 14169                              <1> LD_FS_MATLocation equ 12
 14170                              <1> LD_FS_Reserved1 equ 16 ;1 reserved byte
 14171                              <1> LD_FS_BytesPerSec equ 17 ; LD_BPB + 0Bh
 14172                              <1> LD_FS_Reserved2 equ 19 ;2 reserved byte
 14173                              <1> LD_FS_DATLocation equ 20
 14174                              <1> LD_FS_DATSectors equ 24
 14175                              <1> LD_FS_Reserved3 equ 28 ;3 reserved word
 14176                              <1> LD_FS_SecPerTrack equ 30 ; LD_BPB + 18h
 14177                              <1> LD_FS_NumHeads equ 32    ; LD_BPB + 1Ah
 14178                              <1> LD_FS_UnDelDirD equ 34
 14179                              <1> LD_FS_Reserved4 equ 38 ;4 reserved word
 14180                              <1> LD_FS_VolumeSerial equ 40
 14181                              <1> LD_FS_VolumeName equ 44
 14182                              <1> LD_FS_BeginSector equ 108
 14183                              <1> LD_FS_VolumeSize equ 112
 14184                              <1> LD_FS_FreeSectors equ 116
 14185                              <1> LD_FS_FirstFreeSector equ 120
 14186                              <1> LD_FS_PartitionEntry equ 124
 14187                              <1> LD_FS_DParamEntry equ 125
 14188                              <1> LD_FS_MediaChanged equ 126
 14189                              <1> LD_FS_CDirLevel equ 127
 14190                              <1> LD_FS_CDIR_Converted equ 128
 14191                              <1> 
 14192                              <1> ; Valid FAT Types
 14193                              <1> FS_FAT12 equ 1
 14194                              <1> FS_FAT16_CHS equ 2
 14195                              <1> FS_FAT32_CHS equ 3
 14196                              <1> FS_FAT16_LBA equ 4
 14197                              <1> FS_FAT32_LBA equ 5
 14198                              <1> 
 14199                              <1> ; Cursor Location
 14200                              <1> CCCpointer equ  0450h   ; BIOS data, current cursor column
 14201                              <1> ; FAT Clusters EOC sign
 14202                              <1> FAT12EOC equ 0FFFh
 14203                              <1> FAT16EOC equ 0FFFFh
 14204                              <1> ;FAT32EOC equ 0FFFFFFFh ; It is not direct usable for 8086 code
 14205                              <1> ; BAD Cluster
 14206                              <1> FAT12BADC equ 0FF7h
 14207                              <1> FAT16BADC equ 0FFF7h
 14208                              <1> ;FAT32BADC equ 0FFFFFF7h ; It is not direct usable for 8086 code
 14209                              <1> ; MS-DOS FAT16 FS (Maximum Possible) Last Cluster Number= 0FFF6h 
 14210                              <1> 
 14211                              <1> ; TRFS
 14212                              <1> 
 14213                              <1> bs_FS_JmpBoot equ 0 ; jmp short bsBootCode
 14214                              <1>                 ; db 0EBh, db 3Fh, db 90h
 14215                              <1> bs_FS_Identifier equ 3  ; db 'FS', db 0
 14216                              <1> bs_FS_BytesPerSec equ 6 ; dw 512
 14217                              <1> bs_FS_MediaAttrib equ 8 ; db 3
 14218                              <1> bs_FS_PartitionID equ 9 ; db 0A1h
 14219                              <1> bs_FS_VersionMaj equ 10 ; db 01h
 14220                              <1> bs_FS_VersionMin equ 11 ; db 0
 14221                              <1> bs_FS_BeginSector equ 12   ; dd 0 
 14222                              <1> bs_FS_VolumeSize equ 16 ; dd 2880
 14223                              <1> bs_FS_StartupFD equ 20 ; dd 0
 14224                              <1> bs_FS_MATLocation equ 24 ; dd 1
 14225                              <1> bs_FS_RootDirD equ 28 ; dd 8
 14226                              <1> bs_FS_SystemConfFD equ 32 ; dd 0
 14227                              <1> bs_FS_SwapFD equ 36 ; dd 0
 14228                              <1> bs_FS_UnDelDirD equ 40 ; dd 0
 14229                              <1> bs_FS_DriveNumber equ 44 ; db 0
 14230                              <1> bs_FS_LBA_Ready equ 45 ; db 0
 14231                              <1> bs_FS_MagicWord equ 46 
 14232                              <1> bs_FS_SecPerTrack equ 46 ; db 0A1h
 14233                              <1> bs_FS_Heads equ 47 ; db 01h 
 14234                              <1> bs_FS_OperationSys equ 48 ; db "TR-SINGLIX v1.0b"
 14235                              <1> bs_FS_Terminator equ 64 ; db 0
 14236                              <1> bs_FS_BootCode equ 65 
 14237                              <1> 
 14238                              <1> FS_MAT_DATLocation equ 12
 14239                              <1> FS_MAT_DATScount equ 16
 14240                              <1> FS_MAT_FreeSectors equ 20
 14241                              <1> FS_MAT_FirstFreeSector equ 24
 14242                              <1> FS_RDT_VolumeSerialNo equ 28
 14243                              <1> FS_RDT_VolumeName equ 64
 14244                              <1> 
 14245                              <1> ; FAT12 + FAT16 + FAT32
 14246                              <1> BS_JmpBoot equ 0
 14247                              <1> BS_OEMName equ 3
 14248                              <1> BPB_BytsPerSec equ 11
 14249                              <1> BPB_SecPerClust equ 13
 14250                              <1> BPB_RsvdSecCnt equ 14
 14251                              <1> BPB_NumFATs equ 16
 14252                              <1> BPB_RootEntCnt equ 17
 14253                              <1> BPB_TotalSec16 equ 19
 14254                              <1> BPB_Media equ 21
 14255                              <1> BPB_FATSz16 equ 22
 14256                              <1> BPB_SecPerTrk equ 24
 14257                              <1> BPB_NumHeads equ 26
 14258                              <1> BPB_HiddSec equ 28
 14259                              <1> BPB_TotalSec32 equ 32
 14260                              <1> 
 14261                              <1> ; FAT12 and FAT16 only
 14262                              <1> BS_DrvNum equ 36
 14263                              <1> BS_Reserved1 equ 37
 14264                              <1> BS_BootSig equ 38
 14265                              <1> BS_VolID equ 39
 14266                              <1> BS_VolLab equ 43
 14267                              <1> BS_FilSysType equ 54 ; 8 bytes
 14268                              <1> BS_BootCode equ 62
 14269                              <1> 
 14270                              <1> ; FAT32 only
 14271                              <1> BPB_FATSz32 equ 36 ; FAT32, 4 bytes
 14272                              <1> BPB_ExtFlags equ 40 ; FAT32, 2 bytes
 14273                              <1> BPB_FSVer equ 42 ; FAT32, 2 bytes
 14274                              <1> BPB_RootClus equ 44 ; FAT32, 4 bytes
 14275                              <1> BPB_FSInfo equ 48 ; FAT 32, 2 bytes 
 14276                              <1> BPB_BkBootSec equ 50 ; FAT32, 2 bytes
 14277                              <1> BPB_Reserved equ 52 ; FAT32, 12 bytes
 14278                              <1> BS_FAT32_DrvNum equ 64 ; FAT32, 1 byte
 14279                              <1> BS_FAT32_Reserved1 equ 65 ; FAT32, 1 byte
 14280                              <1> BS_FAT32_BootSig equ 66 ; FAT32, 1 byte
 14281                              <1> BS_FAT32_VolID equ 67 ; FAT32, 4 bytes
 14282                              <1> BS_FAT32_VolLab equ 71 ; FAT32, 11 bytes
 14283                              <1> BS_FAT32_FilSysType equ 82 ; FAT32, 8 bytes
 14284                              <1> BS_FAT32_BootCode equ 90
 14285                              <1> 
 14286                              <1> ; 29/02/2016
 14287                              <1> ;(FAT32 Free Cluster Count & First Free Cluster values)
 14288                              <1> ;[BPB_Reserved] = Free Cluster Count (offset 52)
 14289                              <1> ;[BPB_Reserved+4] = First Free Cluster (offset 56)
 14290                              <1> 
 14291                              <1> BS_Validation equ 510
 14292                              <1> 
 14293                              <1> ; 15/02/2016
 14294                              <1> ; FILE.ASM - 09/10/2011
 14295                              <1> ; Directory Entry Structure
 14296                              <1> ; 29/10/2009 (According to Microsoft FAT32 File System Specification)
 14297                              <1> DirEntry_Name equ 0
 14298                              <1> DirEntry_Attr equ 11
 14299                              <1> DirEntry_NTRes equ 12
 14300                              <1> DirEntry_CrtTimeTenth equ 13
 14301                              <1> DirEntry_CrtTime equ 14
 14302                              <1> DirEntry_CrtDate equ 16
 14303                              <1> DirEntry_LastAccDate equ 18
 14304                              <1> DirEntry_FstClusHI equ 20
 14305                              <1> DirEntry_WrtTime equ 22
 14306                              <1> DirEntry_WrtDate equ 24
 14307                              <1> DirEntry_FstClusLO equ 26
 14308                              <1> DirEntry_FileSize equ 28
 14309                                  %include 'trdosk1.s' ; 04/01/2016 
 14310                              <1> ; ****************************************************************************
 14311                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYS INIT : trdosk1.s
 14312                              <1> ; ----------------------------------------------------------------------------
 14313                              <1> ; Last Update: 30/03/2016
 14314                              <1> ; ----------------------------------------------------------------------------
 14315                              <1> ; Beginning: 04/01/2016
 14316                              <1> ; ----------------------------------------------------------------------------
 14317                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 14318                              <1> ; ----------------------------------------------------------------------------
 14319                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 14320                              <1> ; TRDOS2.ASM (09/11/2011)
 14321                              <1> ; ****************************************************************************
 14322                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
 14323                              <1> ;
 14324                              <1> 
 14325                              <1> sys_init:
 14326                              <1> 	; 30/03/2016
 14327                              <1> 	; 24/01/2016
 14328                              <1> 	; 06/01/2016
 14329                              <1> 	; 04/01/2016
 14330                              <1> 
 14331                              <1> 	; 30/03/2016
 14332                              <1> 	; Clear Logical DOS Disk Description Tables Area
 14333 00003DE2 31C0                <1> 	xor	eax, eax
 14334 00003DE4 BF00010900          <1> 	mov	edi, Logical_DOSDisks
 14335 00003DE9 B980060000          <1> 	mov	ecx, 6656/4 ; 26*256 = 6656 bytes
 14336 00003DEE F3AB                <1> 	rep	stosd ; 1664 times 4 bytes
 14337                              <1> 
 14338 00003DF0 B83F3A2F00          <1> 	mov	eax, '?:/'
 14339 00003DF5 A3[AFBE0000]        <1> 	mov	[Current_Dir_Drv], eax
 14340                              <1> 
 14341                              <1> 	; Logical DRV INIT (only for hard disks)
 14342 00003DFA E854010000          <1> 	call 	ldrv_init  ; trdosk2.s
 14343                              <1> 	
 14344                              <1> 	; When floppy_drv_init call is disabled
 14345                              <1> 	; media changed sign is needed
 14346                              <1> 	; for proper drive initialization
 14347                              <1>         
 14348 00003DFF BE00010900          <1> 	mov 	esi, Logical_DOSDisks
 14349 00003E04 B001                <1> 	mov 	al, 1 ; Initialization sign (invalid_fd_parameter)
 14350 00003E06 83C67E              <1> 	add 	esi, LD_MediaChanged ; Media Change Status = 1 (init needed)
 14351 00003E09 8806                <1> 	mov 	[esi], al ; A:
 14352 00003E0B 81C600010000        <1> 	add 	esi, 100h 
 14353 00003E11 8806                <1> 	mov 	[esi], al ; B: 
 14354                              <1>            
 14355                              <1> _current_drive_bootdisk:
 14356 00003E13 8A15[BAB80000]      <1> 	mov 	dl, [boot_drv] ; physical drive number
 14357 00003E19 80FAFF              <1> 	cmp 	dl, 0FFh
 14358 00003E1C 740A                <1> 	je 	short _last_dos_diskno_check
 14359                              <1> _boot_drive_check:
 14360 00003E1E 80FA80              <1> 	cmp 	dl, 80h
 14361 00003E21 7218                <1> 	jb 	short _current_drive_a
 14362 00003E23 80EA7E              <1> 	sub 	dl, 7Eh ; C = 2 , D = 3
 14363 00003E26 EB13                <1> 	jmp 	short _current_drive_a 
 14364                              <1> 
 14365                              <1> _last_dos_diskno_check:
 14366 00003E28 8A15[7FAE0000]      <1> 	mov 	dl, [Last_DOS_DiskNo]
 14367 00003E2E 80FA02              <1> 	cmp 	dl, 2
 14368 00003E31 7706                <1> 	ja 	short _current_drive_c
 14369 00003E33 7406                <1> 	je 	short _current_drive_a
 14370 00003E35 30D2                <1> 	xor 	dl, dl ; A:
 14371 00003E37 EB02                <1> 	jmp 	short _current_drive_a
 14372                              <1> 
 14373                              <1> _current_drive_c:
 14374 00003E39 B202                <1> 	mov 	dl, 2 ; C:
 14375                              <1> 
 14376                              <1> _current_drive_a:
 14377 00003E3B 8815[BBB80000]      <1> 	mov	[drv], dl
 14378 00003E41 BE[81AE0000]        <1>         mov     esi, msg_CRLF_temp
 14379 00003E46 E840000000          <1> 	call 	print_msg
 14380                              <1> 
 14381 00003E4B 8A15[BBB80000]      <1> 	mov	dl, [drv]
 14382 00003E51 E839090000          <1> 	call 	change_current_drive
 14383 00003E56 730C                <1> 	jnc 	short _start_mainprog
 14384                              <1> 
 14385                              <1> _drv_not_ready_error: 
 14386 00003E58 BE[45B10000]        <1> 	mov 	esi, msgl_drv_not_ready
 14387 00003E5D E829000000          <1> 	call 	print_msg
 14388 00003E62 EB05                <1> 	jmp 	short _end_of_mainprog
 14389                              <1> 
 14390                              <1> _start_mainprog:
 14391 00003E64 E8620A0000          <1>         call    dos_prompt
 14392                              <1>               
 14393                              <1> _end_of_mainprog:
 14394 00003E69 BE[81AE0000]        <1>         mov     esi, msg_CRLF_temp
 14395 00003E6E E818000000          <1> 	call 	print_msg
 14396 00003E73 BE[87AE0000]        <1> 	mov 	esi, mainprog_Version
 14397 00003E78 E80E000000          <1> 	call 	print_msg
 14398                              <1> 	; 24/01/2016
 14399 00003E7D 28E4                <1> 	sub	ah, ah
 14400 00003E7F E863CDFFFF          <1> 	call	int16h ; call getch
 14401 00003E84 E920D2FFFF          <1> 	jmp	cpu_reset
 14402                              <1> 
 14403 00003E89 EBFE                <1> infinitiveloop: jmp short infinitiveloop
 14404                              <1> 
 14405                              <1> 
 14406                              <1> print_msg:
 14407                              <1> 	; 04/01/2016
 14408                              <1> 	; 01/07/2015
 14409                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14410                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
 14411                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
 14412                              <1> 	;
 14413 00003E8B AC                  <1> 	lodsb
 14414                              <1> pmsg1:
 14415 00003E8C 56                  <1> 	push 	esi
 14416 00003E8D 0FB61D[18BE0000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; 04/01/2016 (ptty)
 14417 00003E94 B407                <1> 	mov	ah, 07h ; Black background, light gray forecolor
 14418 00003E96 E81CD9FFFF          <1> 	call 	WRITE_TTY
 14419 00003E9B 5E                  <1> 	pop	esi
 14420 00003E9C AC                  <1> 	lodsb
 14421 00003E9D 20C0                <1> 	and 	al, al
 14422 00003E9F 75EB                <1> 	jnz 	short pmsg1
 14423 00003EA1 C3                  <1> 	retn
 14424                              <1> 
 14425                              <1> clear_screen:
 14426                              <1> 	; 30/01/2016
 14427                              <1> 	; 24/01/2016
 14428                              <1> 	; 04/01/2016
 14429 00003EA2 0FB61D[18BE0000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; video page number (0 to 7)
 14430 00003EA9 8AA3[30B80000]      <1> 	mov 	ah, [ebx+vmode] ; default = 03h (80x25 text)
 14431 00003EAF 80FC04              <1> 	cmp	ah, 4
 14432 00003EB2 7205                <1> 	jb	short cls1
 14433 00003EB4 80FC07              <1> 	cmp	ah, 7
 14434 00003EB7 7524                <1> 	jne	short vga_clear
 14435                              <1> cls1:
 14436 00003EB9 3A25[16B80000]      <1> 	cmp	ah, [CRT_MODE] ; current video mode ? 
 14437                              <1> 	;je	short cls2 ; yes (current video mode = 3)
 14438                              <1> 	;;call	set_mode_3 ; set video mode to 3 (& clear screen)
 14439                              <1> 	;;retn
 14440                              <1> 	;jmp	set_mode_3
 14441 00003EBF 0F8504D6FFFF        <1> 	jne	set_mode_3
 14442                              <1> cls2:
 14443 00003EC5 B407                <1> 	mov	ah, 07h ; attribute to be used on blanked line
 14444 00003EC7 28C0                <1> 	sub 	al, al ; 0 =  entire window
 14445 00003EC9 6631C9              <1> 	xor 	cx, cx
 14446 00003ECC 66BA4F18            <1> 	mov 	dx, 184Fh
 14447 00003ED0 E838D7FFFF          <1> 	call	_scroll_up ; 24/01/2016
 14448                              <1> 	;
 14449                              <1> 	;mov	bl, [ACTIVE_PAGE] ; video page number (0 to 7)
 14450 00003ED5 6631D2              <1> 	xor 	dx, dx
 14451 00003ED8 E86ED9FFFF          <1> 	call	_set_cpos ; 24/01/2016 
 14452                              <1> 	;retn
 14453                              <1> vga_clear:
 14454 00003EDD C3                  <1> 	retn	
 14455                              <1> 
 14456                              <1> panic:
 14457                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14458                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
 14459 00003EDE BE[C9BA0000]        <1> 	mov 	esi, panic_msg
 14460 00003EE3 E8A3FFFFFF          <1> 	call 	print_msg
 14461                              <1> key_to_reboot:
 14462                              <1>         ; 24/01/2016
 14463 00003EE8 28E4                <1>         sub     ah, ah
 14464 00003EEA E8F8CCFFFF          <1>         call    int16h ; call   getch
 14465                              <1>         ; wait for a character from the current tty
 14466                              <1> 	;
 14467 00003EEF B00A                <1> 	mov	al, 0Ah
 14468 00003EF1 8A1D[18BE0000]      <1> 	mov	bl, [ptty] ; [ACTIVE_PAGE]
 14469 00003EF7 B407                <1> 	mov	ah, 07h ; Black background, 
 14470                              <1> 			; light gray forecolor
 14471 00003EF9 E8B9D8FFFF          <1> 	call 	WRITE_TTY
 14472 00003EFE E9A6D1FFFF          <1> 	jmp	cpu_reset 
 14473                              <1> 
 14474                              <1> ctrlbrk:
 14475                              <1> 	; 12/11/2015
 14476                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14477                              <1> 	; 06/12/2013 (Retro UNIX 8086 v1)
 14478                              <1> 	;
 14479                              <1> 	; INT 1Bh (control+break) handler		
 14480                              <1> 	;
 14481                              <1>       	; Retro Unix 8086 v1 feature only!
 14482                              <1>       	;
 14483 00003F03 66833D[84CE0000]00  <1> 	cmp 	word [u.intr], 0
 14484 00003F0B 7645                <1> 	jna 	short cbrk4
 14485                              <1> cbrk0:
 14486                              <1> 	; 12/11/2015
 14487                              <1> 	; 06/12/2013
 14488 00003F0D 66833D[86CE0000]00  <1> 	cmp 	word [u.quit], 0
 14489 00003F15 743B                <1> 	jz	short cbrk4
 14490                              <1> 	;
 14491                              <1> 	; 20/09/2013	
 14492 00003F17 6650                <1> 	push 	ax
 14493 00003F19 A0[18BE0000]        <1> 	mov	al, [ptty]
 14494                              <1> 	;
 14495                              <1> 	; 12/11/2015
 14496                              <1> 	;
 14497                              <1> 	; ctrl+break (EOT, CTRL+D) from serial port
 14498                              <1> 	; or ctrl+break from console (pseudo) tty
 14499                              <1> 	; (!redirection!)
 14500                              <1> 	;
 14501 00003F1E 3C08                <1> 	cmp	al, 8 ; serial port tty nums > 7
 14502 00003F20 7211                <1>         jb      short cbrk1 ; console (pseudo) tty
 14503                              <1> 	;	
 14504                              <1> 	; Serial port interrupt handler sets [ptty]
 14505                              <1> 	; to the port's tty number (as temporary).
 14506                              <1> 	;
 14507                              <1> 	; If active process is using a stdin or 
 14508                              <1> 	; stdout redirection (by the shell),
 14509                              <1>         ; console tty keyboard must be available
 14510                              <1> 	; to terminate running process,
 14511                              <1> 	; in order to prevent a deadlock. 
 14512                              <1> 	;
 14513 00003F22 52                  <1> 	push	edx
 14514 00003F23 0FB615[8FCE0000]    <1> 	movzx	edx, byte [u.uno]
 14515 00003F2A 3A82[95CB0000]      <1> 	cmp     al, [edx+p.ttyc-1] ; console tty (rw)
 14516 00003F30 5A                  <1> 	pop	edx
 14517 00003F31 7412                <1> 	je	short cbrk2
 14518                              <1> cbrk1:
 14519 00003F33 FEC0                <1> 	inc 	al  ; [u.ttyp] : 1 based tty number
 14520                              <1> 	; 06/12/2013
 14521 00003F35 3A05[70CE0000]      <1> 	cmp	al, [u.ttyp] ; recent open tty (r)
 14522 00003F3B 7408                <1> 	je	short cbrk2	
 14523 00003F3D 3A05[71CE0000]      <1>         cmp     al, [u.ttyp+1] ; recent open tty (w)
 14524 00003F43 750B                <1> 	jne	short cbrk3	
 14525                              <1> cbrk2:
 14526                              <1> 	;; 06/12/2013
 14527                              <1> 	;mov	ax, [u.quit]
 14528                              <1> 	;and	ax, ax
 14529                              <1> 	;jz	short cbrk3
 14530                              <1> 	;
 14531 00003F45 6631C0              <1> 	xor	ax, ax ; 0
 14532 00003F48 6648                <1> 	dec	ax
 14533                              <1> 	; 0FFFFh = 'ctrl+brk' keystroke
 14534 00003F4A 66A3[86CE0000]      <1> 	mov	[u.quit], ax
 14535                              <1> cbrk3:
 14536 00003F50 6658                <1> 	pop	ax
 14537                              <1> cbrk4:
 14538 00003F52 C3                  <1> 	retn
 14539                                  %include 'trdosk2.s' ; 04/01/2016
 14540                              <1> ; ****************************************************************************
 14541                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DRV INIT : trdosk2.s
 14542                              <1> ; ----------------------------------------------------------------------------
 14543                              <1> ; Last Update: 29/02/2016
 14544                              <1> ; ----------------------------------------------------------------------------
 14545                              <1> ; Beginning: 04/01/2016
 14546                              <1> ; ----------------------------------------------------------------------------
 14547                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 14548                              <1> ; ----------------------------------------------------------------------------
 14549                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 14550                              <1> ; TRDOS2.ASM (09/11/2011)
 14551                              <1> ; ****************************************************************************
 14552                              <1> ; DRV_INIT.ASM (c) 2009-2011 Erdogan TAN  [26/09/2009] Last Update: 07/08/2011
 14553                              <1> ;
 14554                              <1> 
 14555                              <1> ldrv_init: ; Logical Drive Initialization
 14556                              <1> 	; 12/02/2016
 14557                              <1> 	; 06/01/2016
 14558                              <1> 	;  	('diskinit.inc', 'diskio.inc' integration)
 14559                              <1> 	; 04/01/2016 (TRDOS 386 = TRDOS v2.0)
 14560                              <1> 	; 07/08/2011
 14561                              <1> 	; 20/09/2009
 14562                              <1> 	; 2005
 14563 00003F53 0FB60D[88BE0000]    <1> 	movzx	ecx, byte [HF_NUM] ; number of fixed disks
 14564 00003F5A 80F901              <1> 	cmp	cl, 1
 14565 00003F5D 7301                <1> 	jnb	short load_hd_partition_tables
 14566                              <1> 	; No hard disks
 14567 00003F5F C3                  <1> 	retn
 14568                              <1> load_hd_partition_tables:
 14569 00003F60 8B35[8CBE0000]      <1> 	mov	esi, [HDPM_TBL_VEC] ; primary master disk FDPT
 14570 00003F66 BF[AEC20000]        <1> 	mov 	edi, PTable_hd0
 14571 00003F6B B280                <1> 	mov 	dl, 80h
 14572                              <1> load_next_hd_partition_table:
 14573 00003F6D 51                  <1> 	push	ecx
 14574 00003F6E 57                  <1> 	push	edi
 14575 00003F6F 56                  <1> 	push	esi ; FDPT (+ DPTE) address
 14576 00003F70 8A4614              <1> 	mov	al, [esi+20] ; DPTE offset 4
 14577 00003F73 2440                <1> 	and	al, 40h ;  LBA bit (bit 6)
 14578                              <1> 	;shr	al, 6
 14579 00003F75 A2[AEC40000]        <1> 	mov 	[HD_LBA_yes], al
 14580 00003F7A E81C040000          <1> 	call	load_masterboot
 14581 00003F7F 7275                <1> 	jc	short pass_pt_this_hard_disk
 14582                              <1> 
 14583 00003F81 BE[6CC20000]        <1> 	mov	esi, PartitionTable
 14584 00003F86 89F3                <1> 	mov	ebx, esi
 14585                              <1> 	;mov	ecx, 16
 14586 00003F88 B110                <1> 	mov	cl, 16
 14587 00003F8A F3A5                <1> 	rep 	movsd
 14588 00003F8C 89DE                <1> 	mov 	esi, ebx 
 14589 00003F8E C605[BDB80000]04    <1> 	mov 	byte [hdc], 4 ; 4 - partition index
 14590                              <1> loc_validate_hdp_partition:
 14591 00003F95 807E0400            <1> 	cmp 	byte [esi+ptFileSystemID], 0
 14592 00003F99 7641                <1> 	jna	short loc_validate_next_hdp_partition2
 14593 00003F9B 56                  <1> 	push	esi ; Masterboot partition table offset
 14594 00003F9C 52                  <1> 	push	edx ; dl = Physical drive number 
 14595 00003F9D FE05[AFC40000]      <1> 	inc	byte [PP_Counter]
 14596 00003FA3 31FF                <1>         xor	edi, edi ; 0  
 14597                              <1> 	; Input -> ESI = PartitionTable offset
 14598                              <1> 	; DL = Hard disk drive number 
 14599                              <1> 	; EDI = 0 -> Primary Partition
 14600                              <1> 	; EDI > 0 -> Extended Partition's Start Sector   
 14601 00003FA5 E879010000          <1> 	call 	validate_hd_fat_partition
 14602 00003FAA 730A                <1> 	jnc 	short loc_set_valid_hdp_partition_entry
 14603                              <1> 	;pop	edx
 14604                              <1> 	;push	edx
 14605 00003FAC 8B1424              <1> 	mov	edx, [esp] 
 14606 00003FAF E8C5020000          <1> 	call	validate_hd_fs_partition
 14607 00003FB4 7224                <1> 	jc	short loc_validate_next_hdp_partition1
 14608                              <1> loc_set_valid_hdp_partition_entry:
 14609 00003FB6 8A0D[7FAE0000]      <1> 	mov 	cl, [Last_DOS_DiskNo] 
 14610 00003FBC 80C141              <1> 	add 	cl, 'A'
 14611                              <1> 	; ESI = Logical dos drive description table address
 14612 00003FBF 880E                <1> 	mov	[esi+LD_Name], cl
 14613 00003FC1 8A6602              <1> 	mov	ah, [esi+LD_PhyDrvNo]
 14614 00003FC4 88E0                <1> 	mov	al, ah ; Physical drive number
 14615 00003FC6 2C80                <1> 	sub	al, 80h
 14616 00003FC8 C0E002              <1> 	shl	al, 2
 14617 00003FCB 0404                <1> 	add	al, 4 ; 0 Based
 14618 00003FCD 2A05[BDB80000]      <1> 	sub	al, [hdc] ; 4 - partition index
 14619                              <1> 	; AL = Partition entry/index, 0 based
 14620                              <1> 	;  0 -> hd 0, Partition Table offset = 0
 14621                              <1> 	; 15 -> hd 3, Partition Table offset = 3
 14622                              <1> 	;mov	[esi+LD_PartitionEntry], al 
 14623 00003FD3 80EC7E              <1> 	sub 	ah, 7Eh
 14624                              <1> 	; AH = Physical drive index, zero based
 14625                              <1> 	;  0 for drive A:, 2 for drive C:
 14626                              <1> 	;mov 	[esi+LD_DParamEntry], ah 
 14627 00003FD6 6689467C            <1> 	mov 	[esi+LD_PartitionEntry], ax
 14628                              <1> loc_validate_next_hdp_partition1:
 14629 00003FDA 5A                  <1> 	pop 	edx ; dl = Physical drive number 
 14630 00003FDB 5E                  <1> 	pop	esi ; Masterboot partition table offset
 14631                              <1> loc_validate_next_hdp_partition2:
 14632                              <1> 	; ESI = PartitionTable offset
 14633                              <1> 	; DL = Hard/Fixed disk drive number
 14634 00003FDC FE0D[BDB80000]      <1> 	dec	byte [hdc] ; 4 - partition index
 14635 00003FE2 7412                <1> 	jz	short pass_pt_this_hard_disk
 14636 00003FE4 83C610              <1> 	add	esi, 16 ; 10h
 14637 00003FE7 EBAC                <1> 	jmp	short loc_validate_hdp_partition
 14638                              <1> loc_next_hd_partition_table:
 14639 00003FE9 FEC2                <1> 	inc	dl
 14640 00003FEB 83C620              <1> 	add	esi, 32 ; next FDPT address
 14641 00003FEE 83C740              <1> 	add	edi, 64 ; next partition table destination
 14642 00003FF1 E977FFFFFF          <1>         jmp     load_next_hd_partition_table
 14643                              <1> pass_pt_this_hard_disk:
 14644 00003FF6 5E                  <1> 	pop	esi ; FDPT (+ DPTE) address
 14645 00003FF7 5F                  <1> 	pop	edi ; Ptable_hd?
 14646 00003FF8 59                  <1> 	pop	ecx
 14647 00003FF9 E2EE                <1> 	loop	loc_next_hd_partition_table
 14648 00003FFB 803D[AFC40000]01    <1> 	cmp	byte [PP_Counter], 1
 14649 00004002 7301                <1> 	jnb	short load_extended_dos_partitions
 14650                              <1> 	; Empty partition table
 14651 00004004 C3                  <1> 	retn 
 14652                              <1> load_extended_dos_partitions:
 14653 00004005 BE[AEC20000]        <1> 	mov	esi, PTable_hd0
 14654 0000400A BF[AEC30000]        <1> 	mov	edi, PTable_ep0
 14655 0000400F C605[BDB80000]80    <1> 	mov	byte [hdc], 80h
 14656                              <1> next_hd_extd_partition:
 14657 00004016 56                  <1> 	push	esi ; PTable_hd? offset
 14658 00004017 57                  <1> 	push	edi ; PTable_ep?
 14659                              <1> 	;mov	ecx, 4
 14660 00004018 B104                <1> 	mov	cl, 4
 14661 0000401A 8A15[BDB80000]      <1> 	mov	dl, byte [hdc]
 14662                              <1> hd_check_fs_id_05h:
 14663 00004020 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
 14664 00004023 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
 14665 00004025 7404                <1> 	je	short loc_set_ep_start_sector
 14666 00004027 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
 14667 00004029 7546                <1> 	jne	short continue_to_check_ep
 14668                              <1> loc_set_ep_start_sector:
 14669 0000402B FE05[B0C40000]      <1> 	inc	byte [EP_Counter]
 14670 00004031 88D4                <1> 	mov	ah, dl ; byte [hdc]
 14671 00004033 86E0                <1> 	xchg	ah, al ; al = Drv Number, ah = Partition Identifier
 14672 00004035 50                  <1> 	push	eax 
 14673 00004036 30E4                <1> 	xor	ah, ah  
 14674 00004038 2C80                <1> 	sub	al, 80h
 14675 0000403A 50                  <1> 	push	eax
 14676 0000403B C0E002              <1> 	shl	al, 2 ; al = al * 4
 14677 0000403E 0FB6D8              <1> 	movzx	ebx, al
 14678 00004041 81C3[B1C40000]      <1> 	add	ebx, EP_StartSector
 14679 00004047 8B4608              <1> 	mov	eax, [esi+ptStartSector]
 14680                              <1>         ; EAX = Extended partition's start sector
 14681 0000404A 8903                <1>         mov	[ebx], eax
 14682 0000404C 58                  <1> 	pop	eax ; AL = Drv number - 80h, AH = 0 
 14683 0000404D 5A                  <1> 	pop	edx ; DL = Drv number, DH = Partition ID
 14684 0000404E BB[AEC00000]        <1> 	mov	ebx, MasterBootBuff
 14685 00004053 803D[AEC40000]01    <1> 	cmp	byte [HD_LBA_yes], 1 ; LBA ready = Yes
 14686 0000405A 7240                <1> 	jb	short loc_hd_load_ep_05h
 14687 0000405C 80FE05              <1> 	cmp	dh, 05h
 14688 0000405F 743B                <1> 	je	short loc_hd_load_ep_05h
 14689                              <1> loc_hd_load_ep_0Fh:
 14690                              <1> 	; 04/01/2016
 14691 00004061 51                  <1> 	push	ecx
 14692 00004062 8B4E08              <1> 	mov	ecx, [esi+ptStartSector] ; sector number
 14693                              <1> 	;mov	ebx, MasterBootBuff ; buffer address
 14694                              <1> 	; LBA read/write (with private LBA function) 
 14695                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 14696                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 14697 00004065 B41B                <1> 	mov	ah, 1Bh ; LBA read
 14698 00004067 B001                <1> 	mov	al, 1 ; sector count
 14699 00004069 E85EE8FFFF          <1> 	call	int13h
 14700 0000406E 59                  <1> 	pop	ecx
 14701 0000406F 733F                <1> 	jnc	short loc_hd_move_ep_table
 14702                              <1> continue_to_check_ep:
 14703 00004071 83C610              <1> 	add	esi, 16
 14704 00004074 E2AA                <1> 	loop	hd_check_fs_id_05h
 14705                              <1> continue_check_ep_next_disk:
 14706 00004076 5F                  <1> 	pop	edi ; PTable_ep?
 14707 00004077 5E                  <1> 	pop	esi ; PTable_hd?
 14708 00004078 A0[88BE0000]        <1> 	mov	al, [HF_NUM] ; number of hard disks
 14709 0000407D 047F                <1> 	add	al, 7Fh
 14710 0000407F 3805[BDB80000]      <1> 	cmp	[hdc], al
 14711 00004085 0F8392000000        <1> 	jnb	loc_validating_hd_partitions_ok
 14712 0000408B 83C640              <1> 	add	esi, 64
 14713 0000408E 83C740              <1> 	add	edi, 64
 14714 00004091 FE05[BDB80000]      <1> 	inc	byte [hdc]
 14715 00004097 E97AFFFFFF          <1> 	jmp	next_hd_extd_partition
 14716                              <1> loc_hd_load_ep_05h:
 14717 0000409C 51                  <1> 	push	ecx 
 14718 0000409D 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 14719 000040A0 668B4E02            <1>         mov     cx, word [esi+ptBeginSector]
 14720 000040A4 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14721                              <1> 	;mov	ebx, MasterBootBuff
 14722 000040A8 E81FE8FFFF          <1> 	call	int13h
 14723 000040AD 59                  <1> 	pop	ecx  
 14724 000040AE 72C1                <1> 	jc	short continue_to_check_ep
 14725                              <1> loc_hd_move_ep_table:
 14726                              <1>         ;pop	edi
 14727                              <1> 	;push	edi  ; PTable_ep?
 14728 000040B0 8B3C24              <1> 	mov	edi, [esp]        
 14729 000040B3 BE[6CC20000]        <1>         mov	esi, PartitionTable ; Extended
 14730 000040B8 89F3                <1> 	mov	ebx, esi
 14731                              <1> 	;mov	ecx, 16
 14732 000040BA B110                <1> 	mov	cl, 16
 14733 000040BC F3A5                <1>        	rep	movsd
 14734 000040BE 89DE                <1> 	mov	esi, ebx 
 14735                              <1> loc_set_hde_sub_partition_count:
 14736 000040C0 C605[AFC40000]04    <1> 	mov	byte [PP_Counter], 4
 14737                              <1> loc_validate_hde_partition:
 14738 000040C7 807E0400            <1> 	cmp	byte [esi+ptFileSystemID], 0
 14739 000040CB 763F                <1> 	jna	short loc_validate_next_hde_partition2
 14740 000040CD 56                  <1> 	push	esi ; Extended partition table offset
 14741 000040CE 8A15[BDB80000]      <1> 	mov	dl, byte [hdc]
 14742 000040D4 0FB6C2              <1> 	movzx	eax, dl
 14743 000040D7 2C80                <1> 	sub	al, 80h
 14744 000040D9 C0E002              <1> 	shl	al, 2
 14745                              <1> 	; 06/01/2016 
 14746                              <1> 	; (TRDOS v1.0 had a bug here, in 'DRV_INIT.ASM')
 14747                              <1> 	; BUGFIX *
 14748                              <1> 	;mov	ecx, eax
 14749 000040DC 88C1                <1> 	mov	cl, al
 14750 000040DE 80C104              <1> 	add	cl, 4
 14751 000040E1 2A0D[AFC40000]      <1> 	sub	cl, [PP_Counter] ; 4 to 1
 14752                              <1> 	; CL = Partition entry/index, 0 based
 14753                              <1>         ;  0 -> hd 0, Partition Table offset = 0
 14754                              <1>         ; 15 -> hd 3, Partition Table offset = 3
 14755 000040E7 88D5                <1>       	mov	ch, dl   
 14756 000040E9 80ED7E              <1> 	sub	ch, 7Eh ;
 14757                              <1> 	; CH = Physical drive index, zero based
 14758                              <1> 	;  0 for drive A:, 2 for drive C:	
 14759                              <1> 	; BUGFIX *
 14760 000040EC 51                  <1> 	push	ecx ; *
 14761 000040ED BF[B1C40000]        <1> 	mov	edi, EP_StartSector
 14762 000040F2 01C7                <1> 	add	edi, eax
 14763                              <1> 	; Input -> ESI = PartitionTable offset
 14764                              <1> 	; DL = Hard disk drive number   
 14765                              <1> 	; EDI = Extended partition start sector pointer
 14766 000040F4 E82A000000          <1> 	call	validate_hd_fat_partition
 14767 000040F9 59                  <1> 	pop	ecx ; *
 14768 000040FA 720F                <1> 	jc	short loc_validate_next_hde_partition1
 14769                              <1> loc_set_valid_hde_partition_entry:
 14770                              <1> 	; 06/01/2016 (TRDOS v2.0)
 14771                              <1> 	; BUGFIX *
 14772                              <1> 	;mov	[esi+LD_PartitionEntry], cl 
 14773                              <1> 	;mov	[esi+LD_DParamEntry], ch 
 14774 000040FC 66894E7C            <1> 	mov	[esi+LD_PartitionEntry], cx 
 14775                              <1> 	;
 14776 00004100 8A0D[7FAE0000]      <1> 	mov	cl, [Last_DOS_DiskNo] 
 14777 00004106 80C141              <1> 	add	cl, 'A'
 14778 00004109 880E                <1> 	mov	[esi+LD_Name], cl
 14779                              <1> loc_validate_next_hde_partition1:
 14780 0000410B 5E                  <1> 	pop	esi ; Extended partition table offset
 14781                              <1> loc_validate_next_hde_partition2:
 14782                              <1> 	; ESI = Extended partition table offset
 14783                              <1> 	; DL = Hard disk drive number
 14784 0000410C FE0D[AFC40000]      <1> 	dec	byte [PP_Counter]
 14785 00004112 0F845EFFFFFF        <1> 	jz	continue_check_ep_next_disk
 14786 00004118 83C610              <1> 	add 	esi, 16 ; 10h
 14787 0000411B EBAA                <1> 	jmp	short loc_validate_hde_partition
 14788                              <1> loc_validating_hd_partitions_ok:
 14789 0000411D A0[7FAE0000]        <1> 	mov	al, [Last_DOS_DiskNo]
 14790                              <1> loc_drv_init_retn:
 14791 00004122 C3                  <1> 	retn
 14792                              <1> 
 14793                              <1> validate_hd_fat_partition:
 14794                              <1> 	; 12/02/2016
 14795                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
 14796                              <1> 	; 07/08/2011
 14797                              <1> 	; 23/07/2011
 14798                              <1> 	; Input
 14799                              <1> 	;   DL = Hard/Fixed Disk Drive Number
 14800                              <1> 	;   ESI = PartitionTable offset
 14801                              <1> 	;   EDI = Extend. Part. Start Sector Pointer
 14802                              <1> 	;   EDI = 0 -> Primary Partition 
 14803                              <1> 	;   byte [Last_DOS_DiskNo]
 14804                              <1>  	; Output
 14805                              <1> 	;  cf=0 -> Validated
 14806                              <1> 	;   ESI = Logical dos drv desc. table
 14807                              <1> 	;   EBX = FAT boot sector buffer
 14808                              <1> 	;   byte [Last_DOS_DiskNo]
 14809                              <1> 	;  cf=1 -> Not a valid FAT partition
 14810                              <1> 	; EAX, EDX, ECX, EDI -> changed 
 14811                              <1> 	
 14812                              <1> 	;mov 	esi, PartitionTable
 14813 00004123 8A6604              <1> 	mov 	ah, [esi+ptFileSystemID]
 14814 00004126 80FC06              <1> 	cmp 	ah, 06h ; FAT16 CHS partition
 14815                              <1> 	; 12/02/2016
 14816                              <1> 	;jb	short loc_not_a_valid_fat_partition2
 14817 00004129 7305                <1>  	jnb	short vhdp_FAT16_32
 14818                              <1> 	;
 14819 0000412B 80FC04              <1> 	cmp	ah, 04h ; FAT16 CHS partition (< 32MB)		
 14820 0000412E 7519                <1> 	jne	short loc_not_a_valid_fat_partition1
 14821                              <1> vhdp_FAT16_32:
 14822 00004130 B002                <1> 	mov	al, 2
 14823 00004132 7417                <1> 	je	short loc_set_valid_hd_partition_params
 14824 00004134 80FC0E              <1> 	cmp	ah, 0Eh ; FAT16 LBA partition
 14825 00004137 7710                <1> 	ja	short loc_not_a_valid_fat_partition1
 14826 00004139 7410                <1> 	je	short loc_set_valid_hd_partition_params
 14827                              <1> 
 14828 0000413B FEC0                <1> 	inc	al ; 3
 14829 0000413D 80FC0B              <1> 	cmp	ah, 0Bh ; FAT32 CHS partition 
 14830 00004140 7409                <1> 	je	short loc_set_valid_hd_partition_params
 14831 00004142 7206                <1> 	jb	short loc_not_a_valid_fat_partition2
 14832 00004144 80FC0C              <1> 	cmp	ah, 0Ch ; FAT32 LBA partition
 14833 00004147 7402                <1> 	je	short loc_set_valid_hd_partition_params
 14834                              <1> loc_not_a_valid_fat_partition1:
 14835 00004149 F9                  <1> 	stc
 14836                              <1> loc_not_a_valid_fat_partition2:
 14837 0000414A C3                  <1> 	retn
 14838                              <1> 
 14839                              <1> loc_set_valid_hd_partition_params:
 14840 0000414B FE05[7FAE0000]      <1> 	inc 	byte [Last_DOS_DiskNo] ; > 1
 14841                              <1> 	;
 14842 00004151 31DB                <1> 	xor	ebx, ebx
 14843 00004153 8A3D[7FAE0000]      <1> 	mov	bh, [Last_DOS_DiskNo] ; * 256	
 14844 00004159 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 14845                              <1> 	;
 14846 0000415F C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
 14847 00004163 885302              <1> 	mov	byte [ebx+LD_PhyDrvNo], dl
 14848                              <1> 	;mov	byte [ebx+LD_FATType], al ; 2 or 3
 14849                              <1> 	;mov	byte [ebx+LD_FSType], ah ; 06h, 0Eh, 0Bh, 0Ch
 14850 00004166 66894303            <1> 	mov	word [ebx+LD_FATType], ax
 14851                              <1> 	;
 14852 0000416A 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
 14853 0000416D 09FF                <1> 	or	edi, edi 
 14854 0000416F 7402                <1> 	jz	short pass_hd_FAT_ep_start_sector_adding
 14855                              <1> loc_add_hd_FAT_ep_start_sector:
 14856 00004171 030F                <1> 	add	ecx, [edi]
 14857                              <1> pass_hd_FAT_ep_start_sector_adding:
 14858 00004173 894B6C              <1> 	mov	[ebx+LD_StartSector], ecx
 14859                              <1> loc_hd_FAT_logical_drv_init:
 14860 00004176 89DD                <1> 	mov	ebp, ebx
 14861                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
 14862 00004178 A0[AEC40000]        <1> 	mov	al, [HD_LBA_yes] ; 07/01/2016
 14863 0000417D 884305              <1> 	mov	[ebx+LD_LBAYes], al
 14864 00004180 BB[C1C40000]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
 14865 00004185 08C0                <1> 	or	al, al
 14866 00004187 740C                <1> 	jz	short loc_hd_FAT_drv_init_load_bs_chs
 14867                              <1> loc_hd_FAT_drv_init_load_bs_lba:
 14868                              <1> 	; DL = Physical drive number
 14869                              <1>    	;mov	ecx, [esi+ptStartSector] ; sector number
 14870                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
 14871                              <1> 	; LBA read/write (with private LBA function) 
 14872                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 14873                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 14874 00004189 B41B                <1> 	mov	ah, 1Bh ; LBA read
 14875 0000418B B001                <1> 	mov	al, 1 ; sector count
 14876 0000418D E83AE7FFFF          <1> 	call	int13h
 14877 00004192 7313                <1> 	jnc	short loc_hd_drv_FAT_boot_validation
 14878                              <1> loc_not_a_valid_fat_partition3:
 14879 00004194 C3                  <1> 	retn
 14880                              <1> loc_hd_FAT_drv_init_load_bs_chs:
 14881 00004195 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 14882 00004198 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
 14883 0000419C 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14884                              <1> 	;mov	ebx, DOSBootSectorBuff
 14885 000041A0 E827E7FFFF          <1> 	call	int13h
 14886 000041A5 72ED                <1> 	jc	short loc_not_a_valid_fat_partition3
 14887                              <1> loc_hd_drv_FAT_boot_validation:
 14888                              <1> 	;mov	esi, DOSBootSectorBuff
 14889 000041A7 89DE                <1> 	mov	esi, ebx
 14890 000041A9 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 14891 000041B2 751A                <1> 	jne	short loc_not_a_valid_fat_partition4
 14892 000041B4 807E15F8            <1> 	cmp	byte [esi+BPB_Media], 0F8h
 14893 000041B8 7514                <1> 	jne	short loc_not_a_valid_fat_partition4
 14894 000041BA 66837E1600          <1> 	cmp	word [esi+BPB_FATSz16], 0
 14895 000041BF 770F                <1> 	ja	short loc_hd_FAT16_BPB
 14896 000041C1 807E4229            <1> 	cmp	byte [esi+BS_FAT32_BootSig], 29h
 14897 000041C5 7507                <1> 	jne	short loc_not_a_valid_fat_partition4
 14898                              <1> loc_hd_FAT32_BPB:
 14899 000041C7 B92D000000          <1> 	mov	ecx, 45
 14900 000041CC EB0D                <1> 	jmp	short loc_hd_move_FAT_BPB
 14901                              <1> 	;
 14902                              <1> loc_not_a_valid_fat_partition4:
 14903 000041CE F9                  <1> 	stc
 14904 000041CF C3                  <1> 	retn
 14905                              <1> 	;
 14906                              <1> loc_hd_FAT16_BPB:
 14907 000041D0 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
 14908 000041D4 75F8                <1> 	jne	short loc_not_a_valid_fat_partition4
 14909 000041D6 B920000000          <1> 	mov	ecx, 32
 14910                              <1> loc_hd_move_FAT_BPB:
 14911 000041DB 89EF                <1> 	mov 	edi, ebp
 14912                              <1> 	;mov	esi, ebx ; Boot sector
 14913 000041DD 57                  <1> 	push	edi
 14914 000041DE 83C706              <1> 	add	edi, LD_BPB
 14915 000041E1 F366A5              <1> 	rep	movsw 
 14916 000041E4 5E                  <1> 	pop	esi
 14917 000041E5 0FB74614            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RsvdSecCnt]
 14918 000041E9 03466C              <1> 	add	eax, [esi+LD_StartSector]
 14919 000041EC 894660              <1> 	mov	[esi+LD_FATBegin], eax
 14920 000041EF 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
 14921 000041F3 7224                <1> 	jb	short loc_set_FAT16_RootDirLoc
 14922                              <1> loc_set_FAT32_RootDirLoc:
 14923 000041F5 8B462A              <1> 	mov	eax, [esi+LD_BPB+BPB_FATSz32]
 14924 000041F8 0FB65E16            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_NumFATs]
 14925 000041FC F7E3                <1> 	mul	ebx
 14926 000041FE 034660              <1> 	add	eax, [esi+LD_FATBegin]
 14927                              <1> loc_set_FAT32_data_begin:
 14928 00004201 894668              <1> 	mov	[esi+LD_DATABegin], eax
 14929 00004204 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 14930                              <1> 	; If Root Directory Cluster <> 2 then
 14931                              <1> 	; change the beginning sector value 
 14932                              <1> 	; of the root dir by adding sector offset.
 14933 00004207 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
 14934 0000420A 83E802              <1> 	sub	eax, 2
 14935 0000420D 7442                <1> 	jz	short short loc_set_32bit_FAT_total_sectors  
 14936                              <1> 	;movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
 14937 0000420F 8A5E13              <1> 	mov	bl, byte [esi+LD_BPB+BPB_SecPerClust] 
 14938 00004212 F7E3                <1> 	mul	ebx
 14939 00004214 014664              <1> 	add	[esi+LD_ROOTBegin], eax
 14940 00004217 EB38                <1> 	jmp	short loc_set_32bit_FAT_total_sectors
 14941                              <1> 	;
 14942                              <1> loc_set_FAT16_RootDirLoc:
 14943 00004219 0FB64616            <1> 	movzx	eax, byte [esi+LD_BPB+BPB_NumFATs]
 14944 0000421D 0FB7561C            <1> 	movzx	edx, word [esi+LD_BPB+BPB_FATSz16]
 14945 00004221 F7E2                <1> 	mul	edx
 14946 00004223 034660              <1> 	add	eax, [esi+LD_FATBegin]  
 14947 00004226 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 14948                              <1> loc_set_FAT16_data_begin:
 14949 00004229 894668              <1> 	mov	[esi+LD_DATABegin], eax 
 14950 0000422C B820000000          <1> 	mov	eax, 20h  ; Size of a directory entry
 14951                              <1> 	;movzx	edx, word [esi+LD_BPB+BPB_RootEntCnt]
 14952 00004231 668B5617            <1>         mov     dx, [esi+LD_BPB+BPB_RootEntCnt]
 14953 00004235 F7E2                <1>         mul	edx
 14954                              <1> 	;mov	ecx, 511
 14955 00004237 66B9FF01            <1> 	mov	cx, 511
 14956 0000423B 01C8                <1> 	add	eax, ecx
 14957 0000423D 41                  <1> 	inc	ecx ; 512
 14958 0000423E F7F1                <1> 	div	ecx
 14959 00004240 014668              <1> 	add	[esi+LD_DATABegin], eax
 14960 00004243 0FB74619            <1> 	movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
 14961 00004247 6685C0              <1> 	test	ax, ax
 14962 0000424A 7405                <1> 	jz	short loc_set_32bit_FAT_total_sectors
 14963                              <1> loc_set_16bit_FAT_total_sectors:
 14964 0000424C 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 14965 0000424F EB06                <1> 	jmp	short loc_set_hd_FAT_cluster_count
 14966                              <1> loc_set_32bit_FAT_total_sectors:
 14967 00004251 8B4626              <1> 	mov	eax, [esi+LD_BPB+BPB_TotalSec32]
 14968 00004254 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 14969                              <1> loc_set_hd_FAT_cluster_count:
 14970 00004257 8B5668              <1> 	mov	edx, [esi+LD_DATABegin]
 14971 0000425A 2B566C              <1> 	sub	edx, [esi+LD_StartSector]
 14972 0000425D 29D0                <1> 	sub	eax, edx
 14973 0000425F 31D2                <1> 	xor	edx, edx ; 0
 14974 00004261 0FB64E13            <1>         movzx   ecx, byte [esi+LD_BPB+BPB_SecPerClust]
 14975 00004265 F7F1                <1>         div	ecx 
 14976 00004267 894678              <1> 	mov	[esi+LD_Clusters], eax
 14977                              <1> 	; Maximum Valid Cluster Number= EAX +1
 14978                              <1> 	; with 2 reserved clusters= EAX +2
 14979                              <1> loc_set_hd_FAT_fs_free_sectors:
 14980                              <1> 	;mov	dword [esi+LD_FreeSectors], 0
 14981 0000426A E859010000          <1> 	call	get_free_FAT_sectors
 14982 0000426F 7207                <1> 	jc	short loc_validate_hd_FAT_partition_retn
 14983 00004271 894674              <1> 	mov	[esi+LD_FreeSectors], eax
 14984 00004274 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6  ; Volume Name Reset
 14985                              <1> 	;mov	cl, [Last_DOS_DiskNo] 
 14986                              <1> 	;add	cl, 'A'
 14987                              <1> 	;mov	[esi+LD_FS_Name], cl
 14988                              <1> 
 14989                              <1> loc_validate_hd_FAT_partition_retn:         
 14990 00004278 C3                  <1> 	retn
 14991                              <1> 
 14992                              <1> validate_hd_fs_partition:
 14993                              <1> 	; 13/02/2016
 14994                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 14995                              <1> 	; 29/01/2011
 14996                              <1> 	; 23/07/2011
 14997                              <1> 	; Input
 14998                              <1> 	;   DL = Hard/Fixed Disk Drive Number
 14999                              <1> 	;   ESI = PartitionTable offset
 15000                              <1> 	;   byte [Last_DOS_DiskNo]
 15001                              <1> 	; Output
 15002                              <1> 	;  cf=0 -> Validated
 15003                              <1> 	;   ESI = Logical dos drv desc. table
 15004                              <1> 	;   EBX = Singlix FS boot sector buffer
 15005                              <1> 	;   byte [Last_DOS_DiskNo]
 15006                              <1> 	;  cf=1 -> Not a valid 'Singlix FS' partition
 15007                              <1> 	; EAX, EDX, ECX, EDI -> changed 
 15008                              <1> 
 15009                              <1> 	;mov	esi, PartitionTable
 15010 00004279 8A6604              <1> 	mov	ah, [esi+ptFileSystemID]
 15011 0000427C 80FCA1              <1> 	cmp	ah, 0A1h ; SINGLIX FS1 (trfs1) partition
 15012 0000427F 7549                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15013                              <1> loc_set_valid_hd_fs_partition_params:
 15014 00004281 FE05[7FAE0000]      <1> 	inc	byte [Last_DOS_DiskNo] ; > 1
 15015 00004287 30C0                <1> 	xor	al, al ; mov al, 0
 15016                              <1> 	;mov	[drv], dl
 15017 00004289 29DB                <1> 	sub	ebx, ebx ; 0
 15018 0000428B 8A3D[7FAE0000]      <1> 	mov	bh, [Last_DOS_DiskNo] 
 15019 00004291 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 15020 00004297 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
 15021 0000429B 885302              <1> 	mov	[ebx+LD_PhyDrvNo], dl
 15022                              <1> 	;mov	[ebx+LD_FATType], al ; 0
 15023                              <1> 	;mov	[ebx+LD_FSType], ah
 15024 0000429E 66894303            <1> 	mov	[ebx+LD_FATType], ax
 15025                              <1> 	;mov	eax, [esi+ptStartSector]
 15026                              <1> 	;mov	[ebx+LD_StartSector], eax
 15027                              <1> loc_hd_fs_logical_drv_init:
 15028 000042A2 89DD                <1> 	mov	ebp, ebx ; 10/01/2016
 15029                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
 15030 000042A4 A0[AEC40000]        <1> 	mov	al, [HD_LBA_yes] ; 10/01/2016
 15031 000042A9 884305              <1> 	mov	[ebx+LD_LBAYes], al
 15032 000042AC 89DE                <1> 	mov	esi, ebx
 15033 000042AE BB[C1C40000]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer addressh
 15034 000042B3 08C0                <1> 	or	al, al
 15035 000042B5 7515                <1> 	jnz	short loc_hd_fs_drv_init_load_bs_lba
 15036                              <1> loc_hd_fs_drv_init_load_bs_chs:
 15037 000042B7 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 15038 000042BA 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
 15039 000042BE 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 15040                              <1> 	;mov	ebx, DOSBootSectorBuff
 15041 000042C2 E805E6FFFF          <1> 	call	int13h
 15042 000042C7 7311                <1> 	jnc	short loc_hd_drv_fs_boot_validation
 15043                              <1> loc_validate_hd_fs_partition_err_retn:
 15044 000042C9 C3                  <1> 	retn
 15045                              <1> loc_validate_hd_fs_partition_stc_retn:
 15046 000042CA F9                  <1> 	stc
 15047 000042CB C3                  <1> 	retn
 15048                              <1> loc_hd_fs_drv_init_load_bs_lba:
 15049                              <1> 	; DL = Physical drive number
 15050                              <1> 	;mov	esi, ebx
 15051 000042CC 8B4E08              <1>    	mov	ecx, [esi+ptStartSector] ; sector number
 15052                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
 15053                              <1> 	; LBA read/write (with private LBA function) 
 15054                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 15055                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 15056 000042CF B41B                <1> 	mov	ah, 1Bh ; LBA read
 15057 000042D1 B001                <1> 	mov	al, 1 ; sector count
 15058 000042D3 E8F4E5FFFF          <1> 	call	int13h
 15059 000042D8 72EF                <1> 	jc	short loc_validate_hd_fs_partition_err_retn
 15060                              <1> loc_hd_drv_fs_boot_validation:
 15061                              <1> 	;mov	esi, DOSBootSectorBuff
 15062 000042DA 89DE                <1> 	mov	esi, ebx ; Boot sector buffer
 15063 000042DC 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 15064 000042E5 75E3                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15065                              <1>         ;
 15066                              <1> 	;Singlix FS Extensions to TR-DOS (7/6/2009) 
 15067 000042E7 66817E035346        <1> 	cmp	word [esi+bs_FS_Identifier], 'SF'
 15068 000042ED 75DB                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15069                              <1>         ;'A1h' check is not necessary
 15070                              <1> 	;  if 'FS' check is passed as OK/Yes.
 15071 000042EF 807E09A1            <1> 	cmp	byte [esi+bs_FS_PartitionID], 0A1h
 15072 000042F3 75D5                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 15073                              <1> 	;
 15074 000042F5 89EF                <1> 	mov	edi, ebp ; 10/01/2016
 15075                              <1> 	;
 15076 000042F7 8A462D              <1> 	mov	al, byte [esi+bs_FS_LBA_Ready]
 15077 000042FA 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
 15078                              <1> 	;
 15079                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
 15080 000042FD 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
 15081 00004300 884706              <1> 	mov	byte [edi+LD_FS_MediaAttrib], al
 15082                              <1> 	;
 15083 00004303 8A460A              <1> 	mov	al, [esi+bs_FS_VersionMaj]
 15084 00004306 884707              <1> 	mov	[edi+LD_FS_VersionMajor], al
 15085                              <1> 	;
 15086 00004309 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
 15087 0000430D 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
 15088 00004311 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
 15089 00004314 6698                <1> 	cbw
 15090 00004316 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
 15091 0000431A 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
 15092                              <1> 	;cbw
 15093 0000431D 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
 15094                              <1> 	;
 15095 00004321 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
 15096 00004324 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
 15097 00004327 8B5618              <1> 	mov	edx, [esi+bs_FS_MATLocation]
 15098 0000432A 89570C              <1> 	mov	[edi+LD_FS_MATLocation], edx
 15099 0000432D 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
 15100 00004330 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
 15101 00004333 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
 15102 00004336 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
 15103 00004339 8B4710              <1> 	mov	eax, [edi+bs_FS_VolumeSize]
 15104 0000433C 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
 15105                              <1> 	;
 15106 0000433F 89D0                <1> 	mov	eax, edx ; [edi+LD_FS_MATLocation]
 15107 00004341 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
 15108 00004344 89FE                <1> 	mov	esi, edi
 15109                              <1> mread_hd_fs_MAT_sector:
 15110                              <1>        ;mov	ebx, DOSBootSectorBuff
 15111 00004346 B901000000          <1> 	mov	ecx, 1
 15112 0000434B E8F6670000          <1> 	call	disk_read
 15113 00004350 7248                <1> 	jc	short loc_validate_hd_fs_partition_retn
 15114                              <1> 	; EDI will not be changed
 15115 00004352 89DE                <1> 	mov	esi, ebx
 15116                              <1> use_hdfs_mat_sector_params:
 15117 00004354 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
 15118 00004357 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
 15119 0000435A 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
 15120 0000435D 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
 15121 00004360 8B4614              <1> 	mov	eax, [esi+FS_MAT_FreeSectors]
 15122 00004363 894774              <1>         mov     [edi+LD_FS_FreeSectors], eax
 15123 00004366 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
 15124 00004369 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
 15125 0000436C 8B4708              <1> 	mov	eax, [edi+LD_FS_RootDirD]
 15126 0000436F 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
 15127 00004372 89FE                <1> 	mov	esi, edi   
 15128                              <1> read_hd_fs_RDT_sector:
 15129 00004374 BB[C1C40000]        <1> 	mov	ebx, DOSBootSectorBuff
 15130                              <1> 	;mov	ecx, 1
 15131 00004379 B101                <1> 	mov	cl, 1
 15132 0000437B E8C6670000          <1> 	call	disk_read
 15133 00004380 7218                <1> 	jc	short loc_validate_hd_fs_partition_retn
 15134                              <1> 	; EDI will not be changed
 15135 00004382 89DE                <1> 	mov	esi, ebx
 15136                              <1> use_hdfs_RDT_sector_params:
 15137 00004384 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
 15138 00004387 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
 15139 0000438A 57                  <1> 	push	edi
 15140                              <1> 	;mov	ecx, 16
 15141 0000438B B110                <1> 	mov	cl, 16
 15142 0000438D 83C640              <1> 	add	esi, FS_RDT_VolumeName
 15143 00004390 83C72C              <1> 	add	edi, LD_FS_VolumeName
 15144 00004393 F3A5                <1> 	rep	movsd ; 64 bytes
 15145 00004395 5E                  <1> 	pop	esi
 15146                              <1> 		; Volume Name Reset
 15147 00004396 C6467E06            <1>         mov     byte [esi+LD_FS_MediaChanged], 6
 15148                              <1> 	;
 15149                              <1>         ;mov	cl, [Last_DOS_DiskNo] 
 15150                              <1> 	;add	cl, 'A'
 15151                              <1> 	;mov	[esi+LD_FS_Name], cl
 15152                              <1> 
 15153                              <1> loc_validate_hd_fs_partition_retn:
 15154 0000439A C3                  <1> 	retn
 15155                              <1> 
 15156                              <1> load_masterboot:
 15157                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15158                              <1> 	; 2005 - 2011
 15159                              <1> 	; input -> DL = drive number
 15160 0000439B B40D                <1> 	mov	ah, 0Dh ; Alternate disk reset
 15161 0000439D E82AE5FFFF          <1> 	call	int13h
 15162 000043A2 7301                <1> 	jnc	short pass_reset_error
 15163                              <1> harddisk_error:
 15164 000043A4 C3                  <1>   	retn
 15165                              <1> pass_reset_error:
 15166 000043A5 BB[AEC00000]        <1> 	mov	ebx, MasterBootBuff
 15167 000043AA 66B80102            <1> 	mov	ax, 0201h
 15168 000043AE 66B90100            <1> 	mov	cx, 1
 15169 000043B2 30F6                <1> 	xor	dh, dh
 15170 000043B4 E813E5FFFF          <1>  	call	int13h
 15171 000043B9 72E9                <1> 	jc	short harddisk_error
 15172                              <1> 	;
 15173 000043BB 66813D[ACC20000]55- <1> 	cmp	word [MBIDCode], 0AA55h
 15174 000043C3 AA                  <1>
 15175 000043C4 7401                <1> 	je	short load_masterboot_ok
 15176 000043C6 F9                  <1> 	stc
 15177                              <1> load_masterboot_ok:
 15178 000043C7 C3                  <1> 	retn
 15179                              <1> 
 15180                              <1> get_free_FAT_sectors:
 15181                              <1> 	; 29/02/2016
 15182                              <1> 	; 13/02/2016
 15183                              <1> 	; 04/02/2016
 15184                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
 15185                              <1> 	; 11/07/2010
 15186                              <1> 	; 21/06/2009
 15187                              <1> 	; INPUT: ESI = Logical DOS Drive Description Table address
 15188                              <1> 	; OUTPUT: STC => Error
 15189                              <1>         ;	cf = 0 and EAX = Free FAT sectors
 15190                              <1> 	; Also, related parameters and FAT buffer will be reset and updated
 15191                              <1> 
 15192 000043C8 31C0                <1> 	xor	eax, eax
 15193                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Reset
 15194                              <1> 	
 15195 000043CA 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
 15196 000043CE 7650                <1> 	jna	short loc_gfc_get_fat_free_clusters
 15197                              <1> 
 15198                              <1> 	; 29/02/2016
 15199 000043D0 48                  <1> 	dec	eax ; 0FFFFFFFFh
 15200 000043D1 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count (reset)
 15201 000043D4 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster (reset)
 15202 000043D7 40                  <1> 	inc	eax ; 0
 15203                              <1> 	;
 15204 000043D8 668B4636            <1> 	mov	ax, [esi+LD_BPB+BPB_FSInfo]
 15205 000043DC 03466C              <1> 	add	eax, [esi+LD_StartSector]
 15206                              <1> 
 15207 000043DF BB[C1C40000]        <1> 	mov	ebx, DOSBootSectorBuff
 15208 000043E4 B901000000          <1> 	mov	ecx, 1
 15209 000043E9 E858670000          <1>  	call	disk_read
 15210 000043EE 7301                <1> 	jnc	short loc_gfc_check_fsinfo_signs
 15211                              <1> retn_gfc_get_fsinfo_sec:
 15212 000043F0 C3                  <1> 	retn
 15213                              <1> 
 15214                              <1> loc_gfc_check_fsinfo_signs:
 15215 000043F1 BB[C1C40000]        <1> 	mov 	ebx, DOSBootSectorBuff ; 13/02/2016
 15216 000043F6 813B52526141        <1>         cmp     dword [ebx], 41615252h
 15217 000043FC 7520                <1> 	jne	short retn_gfc_get_fsinfo_stc
 15218                              <1> 	;add	ebx, 484
 15219                              <1> 	;cmp	dword [ebx], 61417272h
 15220 000043FE 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 15221 00004407 61                  <1>
 15222 00004408 7514                <1> 	jne	short retn_gfc_get_fsinfo_stc
 15223                              <1> 	;add	ebx, 4
 15224                              <1> 	;mov	eax, [ebx]
 15225 0000440A 8B83E8010000        <1> 	mov	eax, [ebx+488]
 15226                              <1> 	; 29/02/2016
 15227 00004410 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
 15228 00004413 8B93EC010000        <1> 	mov	edx,  [ebx+492] 
 15229 00004419 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster
 15230                              <1> 	;
 15231 0000441C EB12                <1> 	jmp	short retn_from_get_free_fat32_clusters
 15232                              <1> 
 15233                              <1> retn_gfc_get_fsinfo_stc:
 15234 0000441E F9                  <1> 	stc
 15235 0000441F C3                  <1> 	retn
 15236                              <1> 
 15237                              <1> loc_gfc_get_fat_free_clusters:
 15238                              <1> 	;mov	eax, 2
 15239 00004420 B002                <1> 	mov	al, 2
 15240                              <1> 	;mov	[FAT_CurrentCluster], eax
 15241                              <1> loc_gfc_loop_get_next_cluster:
 15242 00004422 E893460000          <1> 	call	get_next_cluster
 15243 00004427 730E                <1> 	jnc	short loc_gfc_free_fat_clusters_cont
 15244 00004429 21C0                <1> 	and	eax, eax
 15245 0000442B 7411                <1> 	jz	short loc_gfc_pass_inc_free_cluster_count
 15246                              <1>  
 15247                              <1> retn_from_get_free_fat_clusters:
 15248 0000442D 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors] ; Free clusters !
 15249                              <1> retn_from_get_free_fat32_clusters:
 15250 00004430 0FB65E13            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
 15251 00004434 F7E3                <1>       	mul	ebx
 15252                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Free sectors
 15253                              <1> retn_get_free_sectors_calc:
 15254 00004436 C3                  <1> 	retn
 15255                              <1> 
 15256                              <1> loc_gfc_free_fat_clusters_cont:
 15257 00004437 09C0                <1> 	or	eax, eax
 15258 00004439 7503                <1> 	jnz	short loc_gfc_pass_inc_free_cluster_count
 15259 0000443B FF4674              <1> 	inc	dword [esi+LD_FreeSectors] ; Free clusters !
 15260                              <1>    
 15261                              <1> loc_gfc_pass_inc_free_cluster_count:
 15262                              <1> 	;mov	eax, [FAT_CurrentCluster]
 15263 0000443E 89C8                <1> 	mov	eax, ecx ; [FAT_CurrentCluster]
 15264 00004440 3B4678              <1> 	cmp	eax, [esi+LD_Clusters]
 15265 00004443 77E8                <1> 	ja	short retn_from_get_free_fat_clusters
 15266 00004445 40                  <1> 	inc	eax
 15267                              <1> 	;mov	[FAT_CurrentCluster], eax
 15268 00004446 EBDA                <1> 	jmp	short loc_gfc_loop_get_next_cluster
 15269                              <1> 
 15270                              <1> floppy_drv_init:
 15271                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15272                              <1> 	; 24/07/2011
 15273                              <1> 	; 04/07/2009
 15274                              <1> 	; INPUT ->
 15275                              <1> 	;	DL = Drive number (0,1)
 15276                              <1> 	; OUTPUT ->
 15277                              <1> 	;	BL = drive name
 15278                              <1> 	;	BH = drive number
 15279                              <1> 	;	ESI = Logical DOS drv description table
 15280                              <1> 	;	EAX = Volume serial number
 15281                              <1>  
 15282 00004448 BE[BEB80000]        <1> 	mov	esi, fd0_type ; 10/01/2016
 15283 0000444D BF00010900          <1> 	mov	edi, Logical_DOSDisks
 15284 00004452 08D2                <1> 	or	dl, dl
 15285 00004454 7407                <1> 	jz	short loc_drv_init_fd0_fd1
 15286 00004456 81C700010000        <1> 	add	edi, 100h
 15287 0000445C 46                  <1> 	inc	esi ; fd1_type ; 10/01/2016
 15288                              <1> loc_drv_init_fd0_fd1:
 15289 0000445D C6477E00            <1> 	mov	byte [edi+LD_MediaChanged], 0
 15290 00004461 803E01              <1> 	cmp	byte [esi], 1 ; type (>0 if it is existing) 
 15291                              <1> 		; 4 = 1.44 MB, 80 track, 3 1/2"
 15292 00004464 7221                <1> 	jb	short read_fd_boot_sector_retn
 15293 00004466 885702              <1> 	mov	[edi+LD_PhyDrvNo], dl
 15294                              <1> read_fd_boot_sector:
 15295 00004469 30F6                <1> 	xor	dh, dh
 15296 0000446B B904000000          <1> 	mov	ecx, 4 ; Retry Count
 15297                              <1> read_fd_boot_sector_again:
 15298 00004470 51                  <1> 	push 	ecx
 15299                              <1> 	;mov	cx, 1
 15300 00004471 B101                <1> 	mov	cl, 1
 15301 00004473 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 15302 00004477 BB[C1C40000]        <1> 	mov	ebx, DOSBootSectorBuff
 15303 0000447C E84BE4FFFF          <1> 	call	int13h
 15304 00004481 59                  <1> 	pop	ecx
 15305 00004482 7304                <1> 	jnc	short use_fd_boot_sector_params
 15306 00004484 E2EA                <1> 	loop	read_fd_boot_sector_again
 15307                              <1> 
 15308                              <1> read_fd_boot_sector_stc_retn:
 15309 00004486 F9                  <1> 	stc
 15310                              <1> read_fd_boot_sector_retn:
 15311 00004487 C3                  <1> 	retn
 15312                              <1> 
 15313                              <1> use_fd_boot_sector_params:
 15314                              <1> 	;mov	esi, DOSBootSectorBuff
 15315 00004488 89DE                <1> 	mov	esi, ebx
 15316 0000448A 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 15317 00004493 75F1                <1> 	jne	short read_fd_boot_sector_stc_retn
 15318 00004495 66817E035346        <1>         cmp     word [esi+bs_FS_Identifier], 'SF'
 15319 0000449B 0F85A2000000        <1>         jne     use_fd_fatfs_boot_sector_params
 15320                              <1> 	;
 15321 000044A1 8A462D              <1> 	mov	al, [esi+bs_FS_LBA_Ready]
 15322 000044A4 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
 15323                              <1> 	;
 15324                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
 15325 000044A7 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
 15326 000044AA 884706              <1> 	mov	[edi+LD_FS_MediaAttrib], al
 15327                              <1> 	;
 15328 000044AD 8A460A              <1>         mov	al, [esi+bs_FS_VersionMaj]
 15329 000044B0 884707              <1> 	mov	byte [edi+LD_FS_VersionMajor], al
 15330 000044B3 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
 15331 000044B7 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
 15332 000044BB 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
 15333 000044BE 6698                <1> 	cbw
 15334 000044C0 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
 15335 000044C4 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
 15336                              <1> 	;cbw
 15337 000044C7 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
 15338                              <1> 	;
 15339 000044CB 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
 15340 000044CE 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
 15341 000044D1 8B4618              <1> 	mov	eax, [esi+bs_FS_MATLocation]
 15342 000044D4 89470C              <1> 	mov	[edi+LD_FS_MATLocation], eax
 15343 000044D7 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
 15344 000044DA 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
 15345 000044DD 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
 15346 000044E0 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
 15347 000044E3 8B4610              <1> 	mov	eax, [esi+bs_FS_VolumeSize]
 15348 000044E6 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
 15349                              <1> 	;		
 15350 000044E9 89FE                <1> 	mov	esi, edi
 15351 000044EB 8B460C              <1>  	mov	eax, [esi+LD_FS_MATLocation]
 15352                              <1> 	;add	eax, [edi+LD_FS_BeginSector]
 15353                              <1> read_fd_MAT_sector_again:
 15354                              <1> 	;mov	ebx, DOSBootSectorBuff
 15355                              <1> 	;mov	ecx, 1
 15356 000044EE B101                <1> 	mov	cl, 1
 15357 000044F0 E857660000          <1> 	call	chs_read
 15358 000044F5 89DE                <1> 	mov	esi, ebx
 15359 000044F7 7301                <1> 	jnc	short use_fdfs_mat_sector_params
 15360                              <1> 	;jmp	short read_fd_boot_sector_retn
 15361 000044F9 C3                  <1> 	retn
 15362                              <1> use_fdfs_mat_sector_params:
 15363 000044FA 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
 15364 000044FD 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
 15365 00004500 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
 15366 00004503 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
 15367 00004506 8B4714              <1> 	mov	eax, [edi+FS_MAT_FreeSectors]
 15368 00004509 894774              <1> 	mov	[edi+LD_FS_FreeSectors], eax
 15369 0000450C 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
 15370 0000450F 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
 15371                              <1> 	;
 15372 00004512 89FE                <1> 	mov	esi, edi
 15373 00004514 8B4608              <1>  	mov	eax, [esi+LD_FS_RootDirD]
 15374                              <1> read_fd_RDT_sector_again:
 15375                              <1> 	;mov	ebx, DOSBootSectorBuff
 15376                              <1> 	;mov	cx, 1
 15377 00004517 B101                <1> 	mov	cl, 1
 15378 00004519 E82E660000          <1> 	call	chs_read
 15379 0000451E 89DE                <1> 	mov	esi, ebx
 15380 00004520 7220                <1> 	jc	short read_fd_RDT_sector_retn
 15381                              <1> use_fdfs_RDT_sector_params:
 15382 00004522 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
 15383 00004525 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
 15384 00004528 57                  <1> 	push	edi
 15385                              <1> 	;mov	ecx, 16
 15386 00004529 B110                <1> 	mov	cl, 16	
 15387 0000452B 83C640              <1> 	add	esi, FS_RDT_VolumeName
 15388 0000452E 83C72C              <1> 	add	edi, LD_FS_VolumeName
 15389 00004531 F3A5                <1> 	rep	movsd ; 64 bytes
 15390 00004533 5E                  <1> 	pop	esi
 15391 00004534 C6460300            <1> 	mov	byte [esi+LD_FATType], 0
 15392 00004538 C64604A1            <1> 	mov	byte [esi+LD_FSType], 0A1h  
 15393 0000453C E9AA000000          <1>         jmp     loc_cont_use_fd_boot_sector_params
 15394                              <1> 
 15395                              <1> read_fd_RDT_sector_stc_retn:
 15396 00004541 F9                  <1> 	stc
 15397                              <1> read_fd_RDT_sector_retn:
 15398 00004542 C3                  <1> 	retn
 15399                              <1> 
 15400                              <1> use_fd_fatfs_boot_sector_params:
 15401 00004543 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
 15402 00004547 75F8                <1> 	jne	short read_fd_RDT_sector_stc_retn
 15403 00004549 807E15F0            <1> 	cmp	byte [esi+BPB_Media], 0F0h
 15404 0000454D 72F3                <1> 	jb	short read_fd_RDT_sector_retn
 15405 0000454F 57                  <1> 	push	edi
 15406 00004550 83C706              <1> 	add	edi, LD_BPB
 15407                              <1> 	;mov	ecx, 16
 15408 00004553 B110                <1> 	mov	cl, 16
 15409 00004555 F3A5                <1> 	rep	movsd ; 64 bytes 
 15410 00004557 5E                  <1> 	pop	esi
 15411 00004558 31C0                <1> 	xor	eax, eax
 15412 0000455A 89466C              <1> 	mov	[esi+LD_StartSector], eax ; 0
 15413 0000455D 668B461C            <1> 	mov	ax, [esi+LD_BPB+BPB_FATSz16]
 15414 00004561 8A4E16              <1> 	mov	cl, [esi+LD_BPB+BPB_NumFATs] 
 15415 00004564 F7E1                <1>   	mul	ecx
 15416                              <1> 	; edx = 0 !
 15417 00004566 668B5614            <1> 	mov	dx, [esi+LD_BPB+BPB_RsvdSecCnt]
 15418 0000456A 66895660            <1> 	mov	[esi+LD_FATBegin], dx
 15419                              <1> 	;add	eax, edx
 15420 0000456E 6601D0              <1> 	add	ax, dx
 15421 00004571 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 15422 00004574 894668              <1> 	mov	[esi+LD_DATABegin], eax 
 15423 00004577 668B5617            <1> 	mov	dx, [esi+LD_BPB+BPB_RootEntCnt]
 15424                              <1> 	;shl	edx, 5 ; * 32 (Size of a directory entry)
 15425 0000457B 66C1E205            <1> 	shl	dx, 5
 15426                              <1> 	;add	edx, 511
 15427 0000457F 6681C2FF01          <1> 	add	dx, 511
 15428                              <1> 	;shr	edx, 9 ; edx = ((edx*32)+511) / 512
 15429 00004584 66C1EA09            <1> 	shr	dx, 9
 15430 00004588 015668              <1> 	add 	[esi+LD_DATABegin], edx
 15431                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
 15432 0000458B 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
 15433 0000458F 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 15434 00004592 2B4668              <1> 	sub	eax, [esi+LD_DATABegin]
 15435                              <1>   	;movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust]
 15436 00004595 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]  
 15437 00004598 80F901              <1> 	cmp	cl, 1
 15438 0000459B 7605                <1> 	jna	short save_fd_fatfs_cluster_count
 15439                              <1> 	;sub	edx, edx
 15440 0000459D 6629D2              <1> 	sub	dx, dx ; 0
 15441 000045A0 F7F1                <1> 	div	ecx
 15442                              <1> save_fd_fatfs_cluster_count:
 15443 000045A2 894678              <1> 	mov	[esi+LD_Clusters], eax
 15444                              <1> 
 15445                              <1>       ; Maximum Valid Cluster Number = EAX +1
 15446                              <1>       ; with 2 reserved clusters= EAX +2
 15447                              <1>  
 15448                              <1> reset_FAT_buffer_decriptors:
 15449 000045A5 29C0                <1> 	sub	eax, eax ; 0  
 15450 000045A7 A2[C5C60000]        <1> 	mov	[FAT_BuffValidData], al ; 0
 15451 000045AC A2[C6C60000]        <1> 	mov	[FAT_BuffDrvName], al ; 0
 15452 000045B1 A3[C9C60000]        <1> 	mov	[FAT_BuffSector], eax ; 0
 15453                              <1> 
 15454                              <1> read_fd_FAT_sectors:
 15455 000045B6 BB001C0900          <1>   	mov	ebx, FAT_Buffer
 15456 000045BB 668B4614            <1> 	mov	ax, [esi+LD_BPB+BPB_RsvdSecCnt]
 15457                              <1> 	;mov	ecx, 3
 15458 000045BF B103                <1> 	mov	cl, 3 ; 3 sectors
 15459 000045C1 E886650000          <1> 	call	chs_read
 15460 000045C6 7240                <1> 	jc	short read_fd_FAT_sectors_retn
 15461                              <1> use_fd_FAT_sectors:
 15462 000045C8 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo]
 15463 000045CB 0441                <1> 	add	al, 'A' 
 15464 000045CD A2[C6C60000]        <1> 	mov	[FAT_BuffDrvName], al 
 15465 000045D2 C605[C5C60000]01    <1>  	mov	byte [FAT_BuffValidData], 1
 15466 000045D9 E82B000000          <1> 	call	fd_init_calculate_free_clusters
 15467 000045DE 7228                <1> 	jc	short read_fd_FAT_sectors_retn
 15468                              <1>   
 15469                              <1> loc_use_fd_boot_sector_params_FAT:
 15470 000045E0 C6460301            <1> 	mov	byte [esi+LD_FATType], 1 ; FAT 12
 15471 000045E4 C6460401            <1> 	mov	byte [esi+LD_FSType], 1
 15472 000045E8 8B462D              <1>         mov     eax, [esi+LD_BPB+VolumeID]
 15473                              <1> loc_cont_use_fd_boot_sector_params:
 15474 000045EB 8A7E02              <1> 	mov	bh, [esi+LD_PhyDrvNo]
 15475 000045EE 887E7D              <1> 	mov	[esi+LD_DParamEntry], bh
 15476 000045F1 88FB                <1> 	mov	bl, bh
 15477 000045F3 80C341              <1> 	add	bl, 'A'
 15478 000045F6 881E                <1> 	mov	byte [esi+LD_Name], bl
 15479 000045F8 C6460101            <1> 	mov	byte [esi+LD_DiskType], 1
 15480 000045FC C6460500            <1> 	mov	byte [esi+LD_LBAYes], 0
 15481 00004600 C6467C00            <1> 	mov	byte [esi+LD_PartitionEntry], 0
 15482 00004604 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6 ; Volume Name Reset
 15483                              <1> 
 15484                              <1> read_fd_FAT_sectors_retn:
 15485 00004608 C3                  <1> 	retn   
 15486                              <1> 
 15487                              <1> fd_init_calculate_free_clusters:
 15488                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15489                              <1> 	; 04/07/2009
 15490                              <1> 	; INPUT ->
 15491                              <1> 	;     ESI = Logical DOS drive description table address
 15492                              <1> 	; OUTPUT ->
 15493                              <1> 	;    [ESI+LD_FreeSectors] will be set
 15494                              <1> 	
 15495 00004609 29C0                <1> 	sub	eax, eax
 15496 0000460B 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; 0
 15497 0000460E B002                <1> 	mov	al, 2 ; eax = 2
 15498                              <1> 
 15499                              <1> fd_init_loop_get_next_cluster:
 15500 00004610 E830000000          <1> 	call	fd_init_get_next_cluster
 15501 00004615 722D                <1> 	jc	short fd_init_calculate_free_clusters_retn
 15502                              <1> 
 15503                              <1> fd_init_free_fat_clusters:
 15504                              <1> 	;cmp 	eax, 0
 15505                              <1> 	;ja	short fd_init_pass_inc_free_cluster_count
 15506                              <1> 	;and	eax, eax
 15507                              <1> 	;jnz	short fd_init_pass_inc_free_cluster_count
 15508 00004617 6621C0              <1> 	and	ax, ax
 15509 0000461A 7504                <1> 	jnz	short fd_init_pass_inc_free_cluster_count
 15510                              <1> 	;inc	dword [esi+LD_FreeSectors]
 15511 0000461C 66FF4674            <1>         inc	word [esi+LD_FreeSectors]
 15512                              <1>     
 15513                              <1> fd_init_pass_inc_free_cluster_count:
 15514                              <1>   	;mov	eax, [FAT_CurrentCluster]
 15515 00004620 66A1[C1C60000]      <1> 	mov	ax, [FAT_CurrentCluster]
 15516                              <1> 	;cmp	eax, [esi+LD_Clusters]
 15517 00004626 663B4678            <1> 	cmp	ax, [esi+LD_Clusters]
 15518 0000462A 7704                <1> 	ja	short short retn_from_fd_init_calculate_free_clusters
 15519                              <1> 	;inc	eax
 15520 0000462C 6640                <1> 	inc	ax
 15521 0000462E EBE0                <1> 	jmp	short fd_init_loop_get_next_cluster
 15522                              <1> 
 15523                              <1> retn_from_fd_init_calculate_free_clusters:
 15524 00004630 8A4613              <1>   	mov	al, [esi+LD_BPB+BPB_SecPerClust]
 15525 00004633 3C01                <1>   	cmp	al, 1
 15526 00004635 760D                <1> 	jna	short fd_init_calculate_free_clusters_retn
 15527                              <1> 	;movzx	eax, al
 15528 00004637 6698                <1> 	cbw
 15529                              <1> 	;mov	ecx, [esi+LD_FreeSectors]
 15530 00004639 668B4E74            <1> 	mov	cx, [esi+LD_FreeSectors] ; Count of free clusters
 15531                              <1>   	;mul	ecx
 15532 0000463D 66F7E1              <1> 	mul	cx
 15533                              <1> 	;mov	[esi+LD_FreeSectors], eax
 15534 00004640 66894674            <1> 	mov	[esi+LD_FreeSectors], ax
 15535                              <1> fd_init_calculate_free_clusters_retn:
 15536 00004644 C3                  <1> 	retn
 15537                              <1> 
 15538                              <1> fd_init_get_next_cluster:
 15539                              <1> 	; 04/02/2016
 15540                              <1> 	; 02/02/2016
 15541                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15542                              <1> 	; 04/07/2009
 15543                              <1> 	; INPUT ->
 15544                              <1> 	;    EAX = Current cluster
 15545                              <1> 	;    ESI = Logical DOS drive description table address
 15546                              <1> 	;    EDX = 0
 15547                              <1> 	; OUTPUT ->
 15548                              <1> 	;    EAX = Next cluster
 15549                              <1> 
 15550 00004645 A3[C1C60000]        <1> 	mov	[FAT_CurrentCluster], eax
 15551                              <1> fd_init_get_next_cluster_readnext:
 15552 0000464A 29D2                <1> 	sub	edx, edx ; 0
 15553 0000464C BB00040000          <1>   	mov	ebx, 1024 ; 400h
 15554 00004651 F7F3                <1>   	div	ebx
 15555                              <1>   	; EAX = Count of 3 FAT sectors
 15556                              <1>   	; EDX = Buffer entry index
 15557 00004653 89C1                <1> 	mov	ecx, eax
 15558                              <1> 	;mov	eax, 3
 15559 00004655 B003                <1> 	mov	al, 3
 15560 00004657 F7E2                <1> 	mul	edx ; Multiply by 3
 15561 00004659 66D1E8              <1> 	shr	ax, 1 ; Divide by 2
 15562 0000465C 89C3                <1> 	mov	ebx, eax ; Buffer byte offset
 15563 0000465E 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 15564 00004664 89C8                <1> 	mov	eax, ecx
 15565                              <1> 	;mov	edx, 3
 15566 00004666 66BA0300            <1> 	mov	dx, 3
 15567 0000466A F7E2                <1> 	mul	edx 
 15568                              <1>   	; EAX = FAT Beginning Sector
 15569                              <1> 	; EDX = 0
 15570 0000466C 8A0E                <1> 	mov	cl, [esi+LD_Name]
 15571                              <1> 	;cmp	byte [FAT_BuffValidData], 0
 15572                              <1> 	;jna	short fd_init_load_FAT_sectors0
 15573 0000466E 3A0D[C6C60000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 15574 00004674 751E                <1> 	jne	short fd_init_load_FAT_sectors0
 15575 00004676 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 15576 0000467C 751C                <1> 	jne	short fd_init_load_FAT_sectors1
 15577                              <1> 	;mov	eax, [FAT_CurrentCluster]
 15578 0000467E A0[C1C60000]        <1> 	mov	al, [FAT_CurrentCluster]
 15579                              <1> 	;shr	eax, 1
 15580 00004683 D0E8                <1> 	shr	al, 1
 15581 00004685 668B03              <1> 	mov	ax, [ebx]
 15582 00004688 7306                <1>   	jnc	short fd_init_gnc_even
 15583 0000468A 66C1E804            <1> 	shr	ax, 4
 15584                              <1> fd_init_gnc_clc_retn:
 15585 0000468E F8                  <1> 	clc
 15586 0000468F C3                  <1> 	retn
 15587                              <1> 
 15588                              <1> fd_init_gnc_even:
 15589 00004690 80E40F              <1> 	and	ah, 0Fh
 15590 00004693 C3                  <1> 	retn
 15591                              <1> 
 15592                              <1> fd_init_load_FAT_sectors0:
 15593 00004694 880D[C6C60000]      <1> 	mov 	[FAT_BuffDrvName], cl
 15594                              <1> fd_init_load_FAT_sectors1:
 15595 0000469A C605[C5C60000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 15596 000046A1 A3[C9C60000]        <1> 	mov	[FAT_BuffSector], eax
 15597 000046A6 034660              <1> 	add	eax, [esi+LD_FATBegin]
 15598 000046A9 BB001C0900          <1>  	mov	ebx, FAT_Buffer
 15599                              <1> 	;movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
 15600 000046AE 668B4E1C            <1> 	mov	cx, [esi+LD_BPB+BPB_FATSz16]
 15601 000046B2 662B0D[C9C60000]    <1> 	sub	cx, [FAT_BuffSector]
 15602                              <1>         ;cmp	ecx, 3
 15603 000046B9 6683F903            <1> 	cmp	cx, 3
 15604 000046BD 7605                <1> 	jna	short fdinit_pass_fix_sector_count_3
 15605                              <1> 	;mov	ecx, 3
 15606 000046BF B903000000          <1> 	mov	ecx, 3
 15607                              <1> fdinit_pass_fix_sector_count_3:  
 15608 000046C4 E883640000          <1> 	call	chs_read
 15609 000046C9 730D                <1> 	jnc	short fd_init_FAT_sectors_no_load_error
 15610 000046CB C605[C5C60000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 15611                              <1> 		; Drv not ready or read Error !
 15612 000046D2 B80F000000          <1> 	mov	eax, ERR_DRV_NOT_RDY ; 15
 15613                              <1> 	;xor	edx, edx
 15614 000046D7 C3                  <1> 	retn
 15615                              <1> 
 15616                              <1> fd_init_FAT_sectors_no_load_error:
 15617 000046D8 C605[C5C60000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 15618 000046DF A1[C1C60000]        <1> 	mov	eax, [FAT_CurrentCluster]
 15619 000046E4 E961FFFFFF          <1>         jmp     fd_init_get_next_cluster_readnext
 15620                              <1> 
 15621                              <1> get_FAT_volume_name:
 15622                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15623                              <1> 	; 12/09/2009
 15624                              <1> 	; INPUT ->
 15625                              <1> 	;	BH = Logical DOS drive number (0,1,2,3,4 ...)
 15626                              <1> 	;       BL = 0
 15627                              <1> 	; OUTPUT ->
 15628                              <1> 	;	CF = 0 -> ESI = Volume name address
 15629                              <1> 	; 	CF = 1 -> Root volume name not found
 15630                              <1> 
 15631                              <1> 	;mov 	ah, 0FFh
 15632                              <1> 	;mov 	al, [Last_Dos_DiskNo]
 15633                              <1> 	;cmp 	al, bh
 15634                              <1> 	;jb     short loc_gfvn_dir_load_err
 15635                              <1> 
 15636 000046E9 89DE                <1> 	mov	esi, ebx
 15637 000046EB 81E600FF0000        <1> 	and	esi, 0FF00h ; esi = bh
 15638 000046F1 81C600010900        <1> 	add	esi, Logical_DOSDisks
 15639 000046F7 8A06                <1> 	mov     al, [esi+LD_Name]
 15640 000046F9 8A6603              <1> 	mov     ah, [esi+LD_FATType]
 15641 000046FC 80FC01              <1> 	cmp     ah, 1
 15642 000046FF 7210                <1> 	jb    	short loc_gfvn_dir_load_err
 15643 00004701 3C41                <1> 	cmp 	al, 'A'
 15644 00004703 720C                <1> 	jb      short loc_gfvn_dir_load_err
 15645 00004705 80FC02              <1> 	cmp 	ah, 2 
 15646 00004708 7708                <1> 	ja      short get_FAT32_root_cluster
 15647                              <1> 	
 15648 0000470A E806450000          <1> 	call    load_FAT_root_directory
 15649 0000470F 730B                <1> 	jnc     short loc_get_volume_name
 15650                              <1> 
 15651                              <1> loc_gfvn_dir_load_err:
 15652 00004711 C3                  <1> 	retn
 15653                              <1> 
 15654                              <1> get_FAT32_root_cluster:
 15655 00004712 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
 15656 00004715 E886450000          <1> 	call    load_FAT_sub_directory
 15657 0000471A 7224                <1> 	jc	short loc_get_volume_name_retn
 15658                              <1> 
 15659                              <1> loc_get_volume_name:
 15660 0000471C BE00000800          <1>         mov     esi, Directory_Buffer
 15661 00004721 6631C9              <1> 	xor	cx, cx ; 0
 15662                              <1> check_root_volume_name:
 15663 00004724 8A06                <1> 	mov	al, [esi]
 15664 00004726 08C0                <1> 	or      al, al
 15665 00004728 7416                <1> 	jz      short loc_get_volume_name_retn
 15666 0000472A 807E0B08            <1> 	cmp     byte [esi+0Bh], 08h
 15667 0000472E 7410                <1> 	je      short loc_get_volume_name_retn
 15668 00004730 663B0D[DBC60000]    <1> 	cmp     cx, [DirBuff_LastEntry]
 15669 00004737 7308                <1> 	jnb     short pass_check_root_volume_name
 15670 00004739 6641                <1> 	inc     cx
 15671 0000473B 83C620              <1> 	add     esi, 32
 15672 0000473E EBE4                <1> 	jmp     short check_root_volume_name
 15673                              <1> 
 15674                              <1> loc_get_volume_name_retn:
 15675 00004740 C3                  <1> 	retn
 15676                              <1>     
 15677                              <1> pass_check_root_volume_name:
 15678 00004741 803D[D7C60000]03    <1> 	cmp	byte [DirBuff_FATType], 3
 15679 00004748 7230                <1> 	jb	short loc_get_volume_name_retn_xor
 15680                              <1> 
 15681 0000474A BB001C0900          <1> 	mov	ebx, FAT_Buffer
 15682 0000474F BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15683 00004754 31C0                <1> 	xor	eax, eax
 15684 00004756 8A25[D6C60000]      <1> 	mov	ah, [DirBuff_DRV]
 15685 0000475C 80EC41              <1> 	sub	ah, 'A' 
 15686 0000475F 01C6                <1> 	add	esi, eax
 15687 00004761 A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 15688 00004766 E84F430000          <1> 	call	get_next_cluster
 15689 0000476B 7305                <1> 	jnc 	short loc_gfvn_load_FAT32_dir_cluster
 15690                              <1>   	
 15691 0000476D 83F801              <1> 	cmp     eax, 1
 15692 00004770 F5                  <1> 	cmc
 15693 00004771 C3                  <1> 	retn
 15694                              <1>   
 15695                              <1> loc_gfvn_load_FAT32_dir_cluster:
 15696 00004772 E829450000          <1> 	call	load_FAT_sub_directory
 15697 00004777 73A3                <1> 	jnc	short loc_get_volume_name
 15698 00004779 C3                  <1> 	retn
 15699                              <1> 
 15700                              <1> loc_get_volume_name_retn_xor:
 15701 0000477A 31C0                <1> 	xor 	eax, eax
 15702 0000477C C3                  <1> 	retn
 15703                              <1> 
 15704                              <1> get_media_change_status:
 15705                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15706                              <1> 	; 09/09/2009
 15707                              <1> 	; INPUT:
 15708                              <1> 	;     DL = Drive number (physical)
 15709                              <1> 	; OUTPUT: clc & AH = 6 media changed
 15710                              <1> 	;     clc & AH = 0 media not changed         
 15711                              <1> 	;     stc -> Drive not ready or an error 
 15712                              <1>   
 15713 0000477D B416                <1> 	mov	ah, 16h
 15714 0000477F E848E1FFFF          <1>   	call	int13h
 15715 00004784 80FC06              <1> 	cmp	ah, 06h
 15716 00004787 7405                <1> 	je	short loc_gmc_status_retn
 15717 00004789 08E4                <1> 	or	ah, ah
 15718 0000478B 7401                <1> 	jz	short loc_gmc_status_retn
 15719                              <1> loc_gmc_status_stc_retn:    
 15720 0000478D F9                  <1> 	stc
 15721                              <1> loc_gmc_status_retn:
 15722 0000478E C3                  <1> 	retn
 15723                                  %include 'trdosk3.s' ; 06/01/2016
 15724                              <1> ; ****************************************************************************
 15725                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk3.s
 15726                              <1> ; ----------------------------------------------------------------------------
 15727                              <1> ; Last Update: 24/03/2016
 15728                              <1> ; ----------------------------------------------------------------------------
 15729                              <1> ; Beginning: 06/01/2016
 15730                              <1> ; ----------------------------------------------------------------------------
 15731                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 15732                              <1> ; ----------------------------------------------------------------------------
 15733                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 15734                              <1> ; MAINPROG.ASM (09/11/2011)
 15735                              <1> ; ****************************************************************************
 15736                              <1> ; MAINPROG.ASM [ TRDOS KERNEL - COMMAND EXECUTER SECTION - MAIN PROGRAM ]
 15737                              <1> ; (c) 2004-2011  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/11/2011
 15738                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ] Last Update: 09/11/2011
 15739                              <1> ; DIR.ASM [ DIRECTORY FUNCTIONS ] Last Update: 09/10/2011
 15740                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
 15741                              <1> 
 15742                              <1> change_current_drive:
 15743                              <1> 	; 02/02/2016
 15744                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
 15745                              <1> 	; 18/08/2011
 15746                              <1> 	; 09/09/2009
 15747                              <1> 	; INPUT:
 15748                              <1> 	;   DL = Logical DOS Drive Number
 15749                              <1> 	; OUTPUT:
 15750                              <1> 	;  cf=1 -> Not successful
 15751                              <1> 	;   EAX = Error code
 15752                              <1> 	;  cf=0 ->
 15753                              <1> 	;   EAX = 0 (successful)
 15754                              <1> 
 15755 0000478F 31DB                <1> 	xor	ebx, ebx
 15756 00004791 88D7                <1> 	mov	bh, dl
 15757                              <1> 
 15758                              <1> 	;cmp	dl, 1
 15759                              <1> 	;jna	short loc_ccdrv_initial_media_change_check
 15760                              <1> 	;cmp	bh, [Last_Dos_DiskNo]
 15761                              <1> 	;ja	short loc_ccdrv_drive_not_ready_err
 15762                              <1> 
 15763                              <1> loc_ccdrv_initial_media_change_check:
 15764 00004793 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15765 00004798 01DE                <1> 	add	esi, ebx
 15766                              <1> loc_ccdrv_dos_drive_name_check:
 15767 0000479A 80FA02              <1> 	cmp	dl, 2
 15768 0000479D 720F                <1> 	jb	short loc_ccdrv_dos_drive_name_check_ok
 15769                              <1> 
 15770 0000479F 8A06                <1> 	mov	al, [esi+LD_Name]
 15771 000047A1 2C41                <1> 	sub	al, 'A'
 15772 000047A3 38D0                <1> 	cmp	al, dl
 15773 000047A5 7407                <1> 	je	short loc_ccdrv_dos_drive_name_check_ok
 15774                              <1> 
 15775                              <1> loc_ccdrv_drive_not_ready_err:
 15776 000047A7 B815000000          <1> 	mov	eax, 15h ; Drive not ready
 15777                              <1> loc_change_current_drive_stc_retn:
 15778 000047AC F9                  <1> 	stc
 15779 000047AD C3                  <1> 	retn  
 15780                              <1> 
 15781                              <1> loc_ccdrv_dos_drive_name_check_ok:
 15782 000047AE 8A667E              <1> 	mov	ah, [esi+LD_MediaChanged]
 15783 000047B1 80FC06              <1> 	cmp	ah, 6  ; VOLUME NAME CHECK/MOVE SIGN
 15784 000047B4 7450                <1> 	je	short loc_ccdrv_get_FAT_volume_name_0
 15785                              <1> 
 15786 000047B6 80FA01              <1> 	cmp	dl, 1
 15787 000047B9 7778                <1> 	ja	short loc_gmcs_init_drv_hd
 15788                              <1> 
 15789                              <1> loc_gmcs_init_drv_fd:
 15790 000047BB 08E4                <1> 	or	ah, ah 
 15791                              <1> 	; AH = 1 is initialization sign (invalid_fd_parameter)
 15792 000047BD 7517                <1> 	jnz	short loc_ccdrv_call_fd_init
 15793                              <1> 
 15794 000047BF E8B9FFFFFF          <1> 	call	get_media_change_status
 15795 000047C4 72E1                <1> 	jc	short loc_ccdrv_drive_not_ready_err
 15796                              <1> 
 15797 000047C6 20E4                <1> 	and	ah, ah
 15798 000047C8 7471                <1> 	jz	short loc_change_current_drv3
 15799                              <1> 
 15800 000047CA 80F406              <1> 	xor	ah, 6
 15801 000047CD 75D8                <1> 	jnz	short loc_ccdrv_drive_not_ready_err
 15802                              <1> 
 15803                              <1> loc_ccdrv_call_fd_init_check_vol_id:
 15804 000047CF E8410A0000          <1> 	call	get_volume_serial_number
 15805 000047D4 7308                <1> 	jnc	short loc_ccdrv_check_vol_serial
 15806                              <1> 
 15807                              <1> loc_ccdrv_call_fd_init:
 15808 000047D6 E86DFCFFFF          <1> 	call	floppy_drv_init
 15809 000047DB 7315                <1> 	jnc	short loc_reset_drv_fd_current_dir
 15810                              <1> 
 15811                              <1> loc_ccdrv_fdinit_fail_retn:
 15812 000047DD C3                  <1> 	retn
 15813                              <1> 
 15814                              <1> loc_ccdrv_check_vol_serial:
 15815 000047DE A3[A4BE0000]        <1> 	mov	[Current_VolSerial], eax
 15816                              <1> 	;mov	dl, bh
 15817 000047E3 E860FCFFFF          <1> 	call	floppy_drv_init
 15818 000047E8 72F3                <1> 	jc	short loc_ccdrv_fdinit_fail_retn
 15819                              <1> 
 15820 000047EA 3B05[A4BE0000]      <1> 	cmp	eax, [Current_VolSerial]
 15821 000047F0 7445                <1> 	je	short loc_change_current_drv2
 15822                              <1> 
 15823                              <1> loc_reset_drv_fd_current_dir:
 15824 000047F2 31C0                <1> 	xor	eax, eax              
 15825 000047F4 88467F              <1>         mov	[esi+LD_CDirLevel], al
 15826 000047F7 89F7                <1> 	mov	edi, esi
 15827 000047F9 81C780000000        <1> 	add	edi, LD_CurrentDirectory
 15828 000047FF B920000000          <1> 	mov	ecx, 32
 15829 00004804 F3AB                <1> 	rep	stosd   
 15830                              <1>  
 15831                              <1> loc_ccdrv_get_FAT_volume_name_0:
 15832 00004806 8A4603              <1> 	mov	al, [esi+LD_FATType]
 15833 00004809 08C0                <1> 	or	al, al
 15834 0000480B 742A                <1> 	jz	short loc_change_current_drv2
 15835                              <1> 
 15836 0000480D 56                  <1> 	push	esi 
 15837 0000480E 3C02                <1> 	cmp	al, 2
 15838 00004810 7705                <1> 	ja	short loc_ccdrv_get_FAT32_vol_name
 15839                              <1>              
 15840                              <1> loc_ccdrv_get_FAT2_16_vol_name:
 15841 00004812 83C631              <1> 	add	esi, LD_BPB + VolumeLabel
 15842 00004815 EB03                <1> 	jmp	short loc_ccdrv_get_FAT_volume_name_1
 15843                              <1> 
 15844                              <1> loc_ccdrv_get_FAT32_vol_name:
 15845 00004817 83C64D              <1> 	add	esi, LD_BPB + FAT32_VolLab
 15846                              <1> loc_ccdrv_get_FAT_volume_name_1:
 15847 0000481A 53                  <1> 	push	ebx
 15848 0000481B 56                  <1> 	push	esi
 15849 0000481C E8C8FEFFFF          <1> 	call	get_FAT_volume_name
 15850 00004821 5F                  <1> 	pop	edi
 15851 00004822 5B                  <1> 	pop	ebx
 15852                              <1> 	; BL = 0
 15853 00004823 720B                <1> 	jc	short loc_change_current_drv1
 15854 00004825 20C0                <1> 	and	al, al
 15855 00004827 7407                <1> 	jz	short loc_change_current_drv1
 15856                              <1> 
 15857                              <1> loc_ccdrv_move_FAT_volume_name:
 15858 00004829 B90B000000          <1> 	mov	ecx, 11
 15859 0000482E F3A4                <1> 	rep	movsb
 15860                              <1> 
 15861                              <1> loc_change_current_drv1:
 15862 00004830 5E                  <1> 	pop	esi
 15863 00004831 EB04                <1> 	jmp	short loc_change_current_drv2
 15864                              <1> 
 15865                              <1> loc_gmcs_init_drv_hd:
 15866 00004833 08E4                <1> 	or	ah, ah
 15867 00004835 7404                <1> 	jz	short loc_change_current_drv3
 15868                              <1> 	; BL = 0, BH = Logical DOS drive number
 15869                              <1> loc_change_current_drv2:
 15870 00004837 C6467E00            <1> 	mov	byte [esi+LD_MediaChanged], 0
 15871                              <1> loc_change_current_drv3:
 15872 0000483B 883D[AEBE0000]      <1> 	mov	[Current_Drv], bh
 15873                              <1> 
 15874                              <1> 	;call	restore_current_directory
 15875                              <1> 	;retn
 15876                              <1> 
 15877                              <1> restore_current_directory:
 15878                              <1> 	; 11/02/2016
 15879                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
 15880                              <1> 	; 25/01/2010
 15881                              <1> 	; 12/10/2009
 15882                              <1> 	;
 15883                              <1> 	; INPUT:
 15884                              <1> 	;   ESI = Logical DOS Drive Description Table
 15885                              <1> 	;
 15886                              <1> 	; OUTPUT:
 15887                              <1> 	;   ESI = Logical DOS Drive Description Table
 15888                              <1> 	;   EDI = offset Current_Dir_Drv 
 15889                              <1> 
 15890 00004841 8A4603              <1> 	mov	al, [esi+LD_FATType]
 15891 00004844 A2[ADBE0000]        <1> 	mov	[Current_FATType], al
 15892                              <1> 
 15893 00004849 8A26                <1> 	mov	ah, [esi+LD_Name] 
 15894 0000484B 8825[AFBE0000]      <1> 	mov	[Current_Dir_Drv], ah
 15895                              <1> 
 15896 00004851 20C0                <1> 	and	al, al
 15897 00004853 741D                <1> 	jz	short loc_restore_FS_current_directory
 15898                              <1> 
 15899                              <1> loc_restore_FAT_current_directory:
 15900 00004855 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
 15901 00004858 8825[ACBE0000]      <1> 	mov	[Current_Dir_Level], ah
 15902 0000485E 08E4                <1> 	or	ah, ah
 15903 00004860 7416                <1>         jz	short loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster
 15904                              <1> 
 15905 00004862 0FB6D4              <1> 	movzx	edx, ah
 15906 00004865 C0E204              <1> 	shl	dl, 4 ; * 16
 15907 00004868 01F2                <1>         add	edx, esi
 15908 0000486A 8B828C000000        <1> 	mov	eax, [edx+LD_CurrentDirectory+12]
 15909 00004870 EB2C                <1> 	jmp	short loc_ccdrv_reset_cdir_FAT_fcluster
 15910                              <1> 
 15911                              <1> loc_restore_FS_current_directory:
 15912 00004872 E864440000          <1> 	call	load_current_FS_directory 
 15913 00004877 C3                  <1> 	retn 
 15914                              <1> 
 15915                              <1> loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster:
 15916 00004878 3C03                <1> 	cmp	al, 3
 15917 0000487A 7205                <1> 	jb	short loc_ccdrv_reset_cdir_FAT_12_16_fcluster
 15918                              <1> loc_ccdrv_reset_cdir_FAT32_fcluster:
 15919 0000487C 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
 15920 0000487F EB04                <1> 	jmp	short loc_ccdrv_check_rootdir_sign
 15921                              <1> loc_ccdrv_reset_cdir_FAT_12_16_fcluster:   
 15922 00004881 30C0                <1> 	xor	al, al  ; xor eax, eax
 15923 00004883 31D2                <1> 	xor	edx, edx
 15924                              <1> loc_ccdrv_check_rootdir_sign:
 15925 00004885 80BE8000000000      <1> 	cmp	byte [esi+LD_CurrentDirectory], 0
 15926 0000488C 7510                <1> 	jne	short loc_ccdrv_reset_cdir_FAT_fcluster
 15927                              <1> loc_ccdrv_set_rootdir_FAT_fcluster:
 15928 0000488E 89868C000000        <1>         mov     [esi+LD_CurrentDirectory+12], eax
 15929 00004894 C78680000000524F4F- <1> 	mov	dword [esi+LD_CurrentDirectory], 'ROOT'
 15930 0000489D 54                  <1>
 15931                              <1> 
 15932                              <1> loc_ccdrv_reset_cdir_FAT_fcluster:
 15933 0000489E A3[A8BE0000]        <1> 	mov	[Current_Dir_FCluster], eax
 15934                              <1> 
 15935 000048A3 BF[0FC70000]        <1> 	mov	edi, PATH_Array
 15936 000048A8 89F2                <1> 	mov	edx, esi
 15937 000048AA 81C680000000        <1> 	add	esi, LD_CurrentDirectory
 15938 000048B0 B920000000          <1> 	mov	ecx, 32
 15939 000048B5 F3A5                <1> 	rep	movsd
 15940                              <1> 
 15941 000048B7 E8FC230000          <1> 	call	change_prompt_dir_string
 15942                              <1> 	
 15943 000048BC 89D6                <1> 	mov	esi, edx
 15944                              <1> 	
 15945 000048BE 29C0                <1>         sub	eax, eax
 15946                              <1>        ;sub	edx, edx
 15947 000048C0 BF[AFBE0000]        <1> 	mov	edi, Current_Dir_Drv
 15948                              <1> 
 15949 000048C5 A2[80AE0000]        <1> 	mov	[Restore_CDIR], al ; 0
 15950 000048CA C3                  <1> 	retn
 15951                              <1> 
 15952                              <1> dos_prompt:
 15953                              <1> 	; 30/01/2016
 15954                              <1> 	; 29/01/2016
 15955                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
 15956                              <1> 	; 15/09/2011
 15957                              <1> 	; 13/09/2009
 15958                              <1> 	; 2004-2005
 15959                              <1> 
 15960                              <1> loc_TRDOS_prompt:
 15961 000048CB BF[AEBF0000]        <1> 	mov	edi, TextBuffer
 15962 000048D0 C6075B              <1> 	mov	byte [edi], "["
 15963 000048D3 47                  <1> 	inc	edi
 15964 000048D4 BE[D3AE0000]        <1> 	mov	esi, TRDOSPromptLabel
 15965                              <1> get_next_prompt_label_char:
 15966 000048D9 803E20              <1> 	cmp	byte [esi], 20h
 15967 000048DC 7203                <1> 	jb	short pass_prompt_label
 15968 000048DE A4                  <1> 	movsb
 15969 000048DF EBF8                <1> 	jmp	short get_next_prompt_label_char
 15970                              <1> pass_prompt_label:
 15971 000048E1 C6075D              <1> 	mov	byte [edi], "]"
 15972 000048E4 47                  <1> 	inc	edi
 15973 000048E5 C60720              <1> 	mov	byte [edi], 20h
 15974 000048E8 47                  <1> 	inc	edi
 15975 000048E9 BE[AFBE0000]        <1> 	mov	esi, Current_Dir_Drv
 15976 000048EE 66A5                <1> 	movsw
 15977 000048F0 A4                  <1> 	movsb 
 15978                              <1> loc_prompt_current_directory:
 15979 000048F1 803E20              <1> 	cmp	byte [esi], 20h
 15980 000048F4 7203                <1> 	jb	short pass_prompt_current_directory
 15981 000048F6 A4                  <1> 	movsb
 15982 000048F7 EBF8                <1> 	jmp	short loc_prompt_current_directory  
 15983                              <1> pass_prompt_current_directory:
 15984 000048F9 C6073E              <1> 	mov	byte [edi], '>'
 15985 000048FC 47                  <1> 	inc	edi
 15986 000048FD C60700              <1> 	mov	byte [edi], 0  
 15987 00004900 BE[AEBF0000]        <1> 	mov	esi, TextBuffer
 15988 00004905 E881F5FFFF          <1> 	call	print_msg
 15989                              <1>         
 15990                              <1> 	;sub	bl, bl ; video page = 0
 15991                              <1> 	;call	get_cpos ; get cursor position
 15992 0000490A 668B15[08BE0000]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
 15993 00004911 8815[0EBF0000]      <1> 	mov	[CursorColumn], dl
 15994                              <1> 
 15995                              <1> 	; 30/01/2016 (to show cursor on the row, again)
 15996                              <1> 	; (Initial color attributes of video page 0 is 0)
 15997                              <1> 	; (see: 'StartPMP' in trdos386.s)
 15998                              <1> 	; 
 15999                              <1> 	;mov	edi, 0B8000h ; start of video page 0
 16000                              <1> 	;movzx	ecx, dl ; column	 
 16001                              <1> 	;mov	al, 80
 16002                              <1> 	;mul	dh
 16003                              <1> 	;add	ax, cx
 16004                              <1> 	;shl	ax, 1 ; character + attribute
 16005                              <1> 	;add	di, ax ; (2*80*row) + (2*column)
 16006                              <1> 	;neg	cl
 16007                              <1> 	;add	cl, 80
 16008                              <1> 	;mov	ax, 700h ;  ah = 7 (color attribute)
 16009                              <1> 	;rep	stosw	
 16010                              <1> 
 16011                              <1> loc_rw_char:
 16012 00004917 E899000000          <1> 	call	rw_char
 16013                              <1> loc_move_command:
 16014 0000491C BE[5EBF0000]        <1> 	mov	esi, CommandBuffer
 16015 00004921 89F7                <1> 	mov	edi, esi
 16016 00004923 31C9                <1> 	xor	ecx, ecx
 16017                              <1> first_command_char:
 16018 00004925 AC                  <1> 	lodsb
 16019 00004926 3C20                <1> 	cmp	al, 20h
 16020 00004928 772E                <1> 	ja	short pass_space_control
 16021 0000492A 7241                <1> 	jb	short loc_move_cmd_arguments_ok
 16022 0000492C 81FE[ADBF0000]      <1> 	cmp	esi, CommandBuffer + 79
 16023 00004932 72F1                <1> 	jb	short first_command_char
 16024 00004934 EB37                <1> 	jmp	short loc_move_cmd_arguments_ok
 16025                              <1> 
 16026                              <1> next_command_char:
 16027 00004936 AC                  <1> 	lodsb
 16028 00004937 3C20                <1> 	cmp	al, 20h
 16029 00004939 771D                <1> 	ja	short pass_space_control
 16030 0000493B 7230                <1> 	jb	short loc_move_cmd_arguments_ok
 16031                              <1> 
 16032                              <1> loc_1st_cmd_arg: ; 30/01/2016
 16033 0000493D AC                  <1> 	lodsb
 16034 0000493E 3C20                <1> 	cmp	al, 20h
 16035 00004940 74FB                <1> 	je	short loc_1st_cmd_arg
 16036 00004942 7229                <1> 	jb	short loc_move_cmd_arguments_ok
 16037                              <1> 	
 16038 00004944 C60700              <1>         mov     byte [edi], 0
 16039 00004947 47                  <1> 	inc	edi
 16040                              <1> 
 16041                              <1> loc_move_cmd_arguments:
 16042 00004948 AA                  <1> 	stosb
 16043 00004949 81FE[ADBF0000]      <1> 	cmp	esi, CommandBuffer + 79
 16044 0000494F 731C                <1> 	jnb	short loc_move_cmd_arguments_ok
 16045 00004951 AC                  <1>         lodsb
 16046 00004952 3C20                <1> 	cmp	al, 20h
 16047 00004954 73F2                <1> 	jnb	short loc_move_cmd_arguments
 16048 00004956 EB15                <1> 	jmp	short loc_move_cmd_arguments_ok
 16049                              <1> 
 16050                              <1> pass_space_control:
 16051 00004958 3C61                <1> 	cmp	al, 61h
 16052 0000495A 7206                <1> 	jb	short pass_capitalize
 16053 0000495C 3C7A                <1> 	cmp	al, 7Ah
 16054 0000495E 7702                <1> 	ja	short pass_capitalize
 16055 00004960 24DF                <1> 	and	al, 0DFh
 16056                              <1> pass_capitalize:
 16057 00004962 AA                  <1> 	stosb   
 16058 00004963 FEC1                <1> 	inc     cl
 16059 00004965 81FE[ADBF0000]      <1>         cmp     esi, CommandBuffer + 79
 16060 0000496B 72C9                <1> 	jb      short next_command_char 
 16061                              <1> 
 16062                              <1> loc_move_cmd_arguments_ok:
 16063 0000496D C60700              <1>         mov     byte [edi], 0
 16064                              <1>        
 16065                              <1> call_command_intepreter:
 16066 00004970 E8DB080000          <1> 	call    command_interpreter
 16067                              <1> 
 16068 00004975 B950000000          <1>         mov	ecx, 80
 16069                              <1> 	;mov	cx, 80
 16070 0000497A BF[5EBF0000]        <1> 	mov	edi, CommandBuffer
 16071 0000497F 30C0                <1> 	xor	al, al
 16072 00004981 F3AA                <1> 	rep	stosb
 16073                              <1> 	;cmp	byte [Program_Exit], 0
 16074                              <1> 	;ja	short loc_terminate_trdos
 16075                              <1>         
 16076                              <1> 	; 16/01/2016
 16077 00004983 803D[16B80000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80*25 color
 16078 0000498A 741D                <1> 	je	short pass_set_txt_mode
 16079                              <1> 
 16080 0000498C E869CBFFFF          <1> 	call	set_txt_mode ; set vide mode to 03h
 16081                              <1> 
 16082                              <1> loc_check_active_page:
 16083 00004991 30C0                <1> 	xor	al, al
 16084 00004993 3805[18BE0000]      <1> 	cmp	[ACTIVE_PAGE], al ; 0
 16085 00004999 0F842CFFFFFF        <1>         je      loc_TRDOS_prompt 
 16086                              <1> 	; AL = 0 = video page 0
 16087 0000499F E8F0CBFFFF          <1> 	call	set_active_page
 16088 000049A4 E922FFFFFF          <1>         jmp     loc_TRDOS_prompt ; infinitive loop
 16089                              <1> 
 16090                              <1> pass_set_txt_mode: 
 16091 000049A9 BE[C6BA0000]        <1> 	mov	esi, nextline
 16092 000049AE E8D8F4FFFF          <1> 	call	print_msg
 16093 000049B3 EBDC                <1> 	jmp     short loc_check_active_page
 16094                              <1> 
 16095                              <1> rw_char:
 16096                              <1> 	; 30/01/2016
 16097                              <1> 	; 29/01/2016
 16098                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 16099                              <1> 	; 2004-2005
 16100                              <1> 	
 16101                              <1> 	; DH = cursor row, DL = cursor column
 16102                              <1> 	; BL = 0 = video page number (active page)
 16103                              <1> 
 16104                              <1> readnextchar:
 16105 000049B5 30E4                <1> 	xor     ah, ah
 16106 000049B7 E82BC2FFFF          <1> 	call	int16h
 16107 000049BC 20C0                <1> 	and	al, al
 16108 000049BE 7439                <1> 	jz	short loc_arrow    
 16109 000049C0 3CE0                <1> 	cmp	al, 0E0h          
 16110 000049C2 7435                <1> 	je	short loc_arrow
 16111 000049C4 3C08                <1> 	cmp	al, 08h             
 16112 000049C6 7549                <1> 	jne	short char_return
 16113                              <1> loc_back:
 16114 000049C8 3A15[0EBF0000]      <1> 	cmp	dl, [CursorColumn]
 16115 000049CE 76E5                <1> 	jna     short readnextchar
 16116                              <1> prev_column:
 16117 000049D0 FECA                <1> 	dec	dl
 16118                              <1> set_cursor_pos:
 16119 000049D2 6652                <1> 	push	dx
 16120 000049D4 30DB                <1> 	xor	bl, bl ; 0 = video page 0
 16121                              <1> 	; DH = Row, DL = Column
 16122 000049D6 E870CEFFFF          <1> 	call	_set_cpos ; 17/01/2016
 16123 000049DB 665A                <1>         pop	dx
 16124 000049DD 0FB6DA              <1> 	movzx	ebx, dl
 16125 000049E0 2A1D[0EBF0000]      <1> 	sub	bl, [CursorColumn] 
 16126 000049E6 B407                <1> 	mov	ah, 7 ; color attribute
 16127 000049E8 B020                <1> 	mov	al, 20h
 16128 000049EA 8883[5EBF0000]      <1> 	mov	[CommandBuffer+ebx], al
 16129 000049F0 28DB                <1> 	sub	bl, bl ; video page 0
 16130                              <1> 	;mov	cx, 1
 16131 000049F2 E88FCDFFFF          <1> 	call	_write_c_current ; 17/01/2016
 16132                              <1> 	;mov	dx, [CURSOR_POSN]
 16133 000049F7 EBBC                <1> 	jmp	short readnextchar
 16134                              <1> loc_arrow:    
 16135 000049F9 80FC4B              <1> 	cmp	ah, 4Bh
 16136 000049FC 74CA                <1> 	je	short loc_back
 16137 000049FE 80FC53              <1> 	cmp	ah, 53h
 16138 00004A01 74C5                <1> 	je      short loc_back
 16139 00004A03 80FC4D              <1> 	cmp	ah, 4Dh
 16140 00004A06 75AD                <1> 	jne	short readnextchar
 16141 00004A08 80FA4F              <1> 	cmp	dl, 79
 16142 00004A0B 73A8                <1> 	jnb	short readnextchar
 16143 00004A0D FEC2                <1> 	inc	dl
 16144 00004A0F EBC1                <1> 	jmp	short set_cursor_pos
 16145                              <1> char_return:
 16146 00004A11 0FB6DA              <1> 	movzx	ebx, dl
 16147 00004A14 2A1D[0EBF0000]      <1> 	sub	bl, [CursorColumn] 
 16148 00004A1A 3C20                <1> 	cmp	al, 20h
 16149 00004A1C 7220                <1> 	jb	short loc_escape
 16150 00004A1E 8883[5EBF0000]      <1> 	mov	[CommandBuffer+ebx], al
 16151 00004A24 28DB                <1> 	sub	bl, bl ; 0
 16152 00004A26 80FA4F              <1> 	cmp	dl, 79
 16153 00004A29 738A                <1> 	jnb	short readnextchar
 16154 00004A2B B407                <1> 	mov	ah, 7 ; color attribute
 16155 00004A2D E885CDFFFF          <1> 	call	WRITE_TTY
 16156 00004A32 668B15[08BE0000]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
 16157 00004A39 E977FFFFFF          <1>         jmp     readnextchar
 16158                              <1> loc_escape:
 16159 00004A3E 3C1B                <1> 	cmp	al, 1Bh
 16160 00004A40 741A                <1> 	je	short rw_char_retn
 16161                              <1> 	;
 16162 00004A42 3C0D                <1> 	cmp	al, 0Dh ; CR
 16163 00004A44 0F856BFFFFFF        <1>         jne     readnextchar
 16164 00004A4A 30DB                <1> 	xor	bl, bl ; 0
 16165 00004A4C B407                <1> 	mov	ah, 7 ; attribute/color
 16166 00004A4E E864CDFFFF          <1> 	call	WRITE_TTY
 16167 00004A53 B407                <1> 	mov	ah, 7 ; attribute/color
 16168 00004A55 B00A                <1> 	mov	al, 0Ah ; LF
 16169 00004A57 E85BCDFFFF          <1> 	call	WRITE_TTY
 16170                              <1> rw_char_retn:
 16171 00004A5C C3                  <1> 	retn
 16172                              <1> 
 16173                              <1> show_date:
 16174                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16175                              <1>         ; 2004-2005
 16176                              <1> 
 16177                              <1> 	;mov	ah, 04h
 16178                              <1> 	;call	int1Ah
 16179 00004A5D E8B2F1FFFF          <1> 	call	RTC_40	; GET RTC DATE
 16180                              <1> 
 16181 00004A62 88D0                <1> 	mov	al, dl
 16182 00004A64 E875C1FFFF          <1>   	call	bcd_to_ascii
 16183 00004A69 66A3[C8AF0000]      <1> 	mov	[Day], ax
 16184                              <1> 
 16185 00004A6F 88F0                <1> 	mov	al, dh
 16186 00004A71 E868C1FFFF          <1>   	call	bcd_to_ascii
 16187 00004A76 66A3[CBAF0000]      <1> 	mov	[Month], ax
 16188                              <1> 
 16189 00004A7C 88E8                <1> 	mov	al, ch
 16190 00004A7E E85BC1FFFF          <1>   	call	bcd_to_ascii
 16191 00004A83 66A3[CEAF0000]      <1> 	mov	[Century], ax
 16192                              <1> 
 16193 00004A89 88C8                <1> 	mov	al, cl
 16194 00004A8B E84EC1FFFF          <1>   	call	bcd_to_ascii
 16195 00004A90 66A3[D0AF0000]      <1> 	mov	word [Year], ax
 16196                              <1> 
 16197 00004A96 BE[B8AF0000]        <1> 	mov	esi, Msg_Show_Date
 16198 00004A9B E8EBF3FFFF          <1> 	call	print_msg
 16199                              <1> 
 16200 00004AA0 C3                  <1> 	retn
 16201                              <1> 
 16202                              <1> set_date:
 16203                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16204                              <1>         ; 2004-2005
 16205                              <1> 
 16206 00004AA1 BE[9CAF0000]        <1> 	mov	esi, Msg_Enter_Date
 16207 00004AA6 E8E0F3FFFF          <1> 	call	print_msg
 16208                              <1> 
 16209                              <1> loc_enter_day_1:
 16210 00004AAB 30E4                <1> 	xor     ah, ah
 16211 00004AAD E835C1FFFF          <1> 	call	int16h
 16212                              <1> 	; AL = ASCII Code of the Character
 16213 00004AB2 3C0D                <1> 	cmp	al, 13
 16214 00004AB4 0F84B7010000        <1> 	je	loc_set_date_retn
 16215 00004ABA 3C1B                <1> 	cmp	al, 27
 16216 00004ABC 0F84AF010000        <1> 	je	loc_set_date_retn
 16217 00004AC2 A2[C8AF0000]        <1> 	mov	[Day], al
 16218 00004AC7 3C30                <1> 	cmp	al, '0'
 16219 00004AC9 0F82AD010000        <1> 	jb	loc_set_date_stc_0
 16220 00004ACF 3C33                <1> 	cmp	al, '3'
 16221 00004AD1 0F87A5010000        <1> 	ja	loc_set_date_stc_0
 16222                              <1> 	;sub	bl, bl ; 0
 16223 00004AD7 B407                <1> 	mov	ah, 7 ; attribute/color
 16224 00004AD9 E8D9CCFFFF          <1> 	call	WRITE_TTY
 16225                              <1> loc_enter_day_2:
 16226 00004ADE 30E4                <1> 	xor     ah, ah
 16227 00004AE0 E802C1FFFF          <1> 	call	int16h
 16228                              <1> 	; AL = ASCII Code of the Character
 16229 00004AE5 3C1B                <1> 	cmp	al, 27
 16230 00004AE7 0F8484010000        <1>         je      loc_set_date_retn
 16231 00004AED A2[C9AF0000]        <1> 	mov	[Day+1], al
 16232 00004AF2 3C30                <1> 	cmp	al, '0'
 16233 00004AF4 0F828C010000        <1>         jb      loc_set_date_stc_1
 16234 00004AFA 3C39                <1> 	cmp	al, '9'
 16235 00004AFC 0F8784010000        <1>         ja      loc_set_date_stc_1
 16236 00004B02 803D[C8AF0000]33    <1> 	cmp	byte [Day], '3'
 16237 00004B09 7208                <1> 	jb	short pass_set_day_31
 16238 00004B0B 3C31                <1> 	cmp	al, '1'
 16239 00004B0D 0F8773010000        <1>         ja      loc_set_date_stc_1
 16240                              <1> pass_set_day_31:
 16241                              <1> 	;sub	bl, bl ; 0
 16242 00004B13 B407                <1> 	mov	ah, 7 ; attribute/color
 16243 00004B15 E89DCCFFFF          <1> 	call	WRITE_TTY
 16244                              <1> loc_enter_separator_1:
 16245 00004B1A 28E4                <1> 	sub     ah, ah ; 0
 16246 00004B1C E8C6C0FFFF          <1> 	call	int16h
 16247                              <1> 	; AL = ASCII Code of the Character
 16248 00004B21 3C1B                <1> 	cmp	al, 27
 16249 00004B23 0F8448010000        <1>         je      loc_set_date_retn
 16250 00004B29 3C2D                <1> 	cmp	al, '-'
 16251 00004B2B 7408                <1> 	je	short pass_set_date_separator_1
 16252 00004B2D 3C2F                <1> 	cmp	al, '/'
 16253 00004B2F 0F856C010000        <1>         jne     loc_set_date_stc_2
 16254                              <1> pass_set_date_separator_1:
 16255                              <1> 	;xor	bl, bl ; 0
 16256 00004B35 B407                <1> 	mov	ah, 7 ; attribute/color
 16257 00004B37 E87BCCFFFF          <1> 	call	WRITE_TTY
 16258                              <1> loc_enter_month_1:
 16259 00004B3C 30E4                <1> 	xor     ah, ah ; 0
 16260 00004B3E E8A4C0FFFF          <1> 	call	int16h
 16261                              <1> 	; AL = ASCII Code of the Character
 16262 00004B43 3C1B                <1> 	cmp	al, 27
 16263 00004B45 0F8426010000        <1>         je      loc_set_date_retn
 16264 00004B4B A2[CBAF0000]        <1> 	mov	[Month], al
 16265 00004B50 3C30                <1> 	cmp	al, '0'
 16266 00004B52 0F8264010000        <1>         jb      loc_set_date_stc_3
 16267 00004B58 3C31                <1> 	cmp	al, '1'
 16268 00004B5A 0F875C010000        <1>         ja      loc_set_date_stc_3
 16269                              <1> 	;sub	bl, bl
 16270 00004B60 B407                <1> 	mov	ah, 7 ; attribute/color
 16271 00004B62 E850CCFFFF          <1> 	call	WRITE_TTY
 16272                              <1> loc_enter_month_2:
 16273 00004B67 30E4                <1> 	xor     ah, ah
 16274 00004B69 E879C0FFFF          <1> 	call	int16h
 16275                              <1> 	; AL = ASCII Code of the Character
 16276 00004B6E 3C1B                <1> 	cmp	al, 27
 16277 00004B70 0F84FB000000        <1>         je      loc_set_date_retn
 16278 00004B76 A2[CCAF0000]        <1> 	mov	[Month+1], al
 16279 00004B7B 3C30                <1> 	cmp	al, '0'
 16280 00004B7D 0F8254010000        <1>         jb      loc_set_date_stc_4
 16281 00004B83 3C39                <1> 	cmp	al, '9'
 16282 00004B85 0F874C010000        <1>         ja      loc_set_date_stc_4
 16283 00004B8B 803D[CBAF0000]31    <1> 	cmp	byte [Month], '1'
 16284 00004B92 7208                <1> 	jb	short pass_set_month_12
 16285 00004B94 3C32                <1> 	cmp	al, '2'
 16286 00004B96 0F873B010000        <1>         ja      loc_set_date_stc_4
 16287                              <1> pass_set_month_12:
 16288                              <1> 	;sub	bl, bl
 16289 00004B9C B407                <1> 	mov	ah, 7 ; attribute/color
 16290 00004B9E E814CCFFFF          <1> 	call	WRITE_TTY
 16291                              <1> loc_enter_separator_2:
 16292 00004BA3 28E4                <1> 	sub     ah, ah
 16293 00004BA5 E83DC0FFFF          <1> 	call	int16h
 16294                              <1> 	; AL = ASCII Code of the Character
 16295 00004BAA 3C1B                <1> 	cmp	al, 27
 16296 00004BAC 0F84BF000000        <1>         je      loc_set_date_retn
 16297 00004BB2 3C2D                <1> 	cmp	al, '-'
 16298 00004BB4 7408                <1> 	je	short pass_set_date_separator_2
 16299 00004BB6 3C2F                <1> 	cmp	al, '/'
 16300 00004BB8 0F8534010000        <1>         jne     loc_set_date_stc_5
 16301                              <1> pass_set_date_separator_2:
 16302                              <1> 	;xor	bl, bl
 16303 00004BBE B407                <1> 	mov	ah, 7 ; attribute/color
 16304 00004BC0 E8F2CBFFFF          <1> 	call	WRITE_TTY
 16305                              <1> loc_enter_year_1:
 16306 00004BC5 30E4                <1> 	xor    ah, ah
 16307 00004BC7 E81BC0FFFF          <1> 	call	int16h
 16308                              <1> 	; AL = ASCII Code of the Character
 16309 00004BCC 3C1B                <1> 	cmp	al, 27
 16310 00004BCE 0F849D000000        <1>         je      loc_set_date_retn
 16311 00004BD4 A2[D0AF0000]        <1> 	mov	[Year], al
 16312 00004BD9 3C30                <1> 	cmp	al, '0'
 16313 00004BDB 0F822C010000        <1>         jb      loc_set_date_stc_6
 16314 00004BE1 3C39                <1> 	cmp	al, '9'
 16315 00004BE3 0F8724010000        <1>         ja      loc_set_date_stc_6
 16316                              <1> 	;sub	bl, bl
 16317 00004BE9 B407                <1> 	mov	ah, 7 ; attribute/color
 16318 00004BEB E8C7CBFFFF          <1> 	call	WRITE_TTY
 16319                              <1> loc_enter_year_2:
 16320 00004BF0 30E4                <1> 	xor	ah, ah
 16321 00004BF2 E8F0BFFFFF          <1> 	call	int16h
 16322                              <1> 	; AL = ASCII Code of the Character
 16323 00004BF7 3C1B                <1> 	cmp	al, 27
 16324 00004BF9 7476                <1> 	je	short loc_set_date_retn
 16325 00004BFB A2[D1AF0000]        <1> 	mov	byte [Year+1], al
 16326 00004C00 3C30                <1> 	cmp	al, '0'
 16327 00004C02 0F8220010000        <1>         jb      loc_set_date_stc_7
 16328 00004C08 3C39                <1> 	cmp	al, '9'
 16329 00004C0A 0F8718010000        <1>         ja      loc_set_date_stc_7
 16330                              <1> 	;sub	bl, bl
 16331 00004C10 B407                <1> 	mov	ah, 7 ; attribute/color
 16332 00004C12 E8A0CBFFFF          <1> 	call	WRITE_TTY
 16333                              <1> loc_set_date_get_lchar_again:
 16334 00004C17 28E4                <1> 	sub	ah, ah ; 0
 16335 00004C19 E8C9BFFFFF          <1> 	call	int16h
 16336                              <1> 	; AL = ASCII Code of the Character
 16337 00004C1E 3C0D                <1> 	cmp	al, 13 ; ENTER key
 16338 00004C20 7412                <1> 	je	short loc_set_date_progress
 16339 00004C22 3C1B                <1> 	cmp	al, 27 ; ESC key
 16340 00004C24 744B                <1> 	je	short loc_set_date_retn
 16341                              <1> 	;
 16342 00004C26 E82A010000          <1> 	call	check_for_backspace
 16343 00004C2B 75EA                <1> 	jne	short loc_set_date_get_lchar_again
 16344                              <1> 
 16345                              <1> loc_set_date_bs_8:
 16346 00004C2D E811010000          <1> 	call	write_backspace
 16347 00004C32 EBBC                <1> 	jmp	short loc_enter_year_2
 16348                              <1> 
 16349                              <1> loc_set_date_progress:
 16350                              <1> 	; Get Current Date
 16351                              <1> 	;mov	ah, 04h
 16352                              <1> 	;call	int1Ah
 16353 00004C34 E8DBEFFFFF          <1> 	call	RTC_40	; GET RTC DATE
 16354                              <1> 	; CH = century (in BCD)
 16355                              <1> 
 16356 00004C39 66A1[D0AF0000]      <1> 	mov	ax, [Year]
 16357 00004C3F 662D3030            <1> 	sub	ax, '00'
 16358 00004C43 C0E004              <1> 	shl	al, 4 ; * 16
 16359 00004C46 88C1                <1> 	mov	cl, al
 16360 00004C48 00E1                <1> 	add	cl, ah
 16361 00004C4A 66A1[CBAF0000]      <1> 	mov	ax, [Month]
 16362 00004C50 662D3030            <1> 	sub	ax, '00'
 16363 00004C54 C0E004              <1> 	shl	al, 4 ; * 16
 16364 00004C57 88C6                <1> 	mov	dh, al
 16365 00004C59 00E6                <1> 	add	dh, ah
 16366 00004C5B 66A1[C8AF0000]      <1> 	mov	ax, [Day]
 16367 00004C61 662D3030            <1> 	sub	ax, '00'
 16368 00004C65 C0E004              <1> 	shl	al, 4 ; * 16
 16369 00004C68 88C2                <1> 	mov	dl, al
 16370 00004C6A 00E2                <1> 	add	dl, ah
 16371                              <1> 
 16372                              <1> 	;mov	ah, 05h
 16373                              <1> 	;call	int1Ah
 16374 00004C6C E8D0EFFFFF          <1> 	call	RTC_50	; SET RTC DATE
 16375                              <1> 
 16376                              <1> loc_set_date_retn:
 16377 00004C71 BE[C6BA0000]        <1> 	mov	esi, nextline
 16378 00004C76 E810F2FFFF          <1> 	call	print_msg
 16379 00004C7B C3                  <1> 	retn
 16380                              <1> 
 16381                              <1> loc_set_date_stc_0:
 16382                              <1> 	;xor	bl, bl ; video page 0
 16383 00004C7C E814CCFFFF          <1> 	call	beeper ; BEEP !
 16384 00004C81 E925FEFFFF          <1>         jmp     loc_enter_day_1
 16385                              <1> loc_set_date_stc_1:
 16386 00004C86 E8CA000000          <1> 	call	check_for_backspace
 16387 00004C8B 740A                <1> 	je	short loc_set_date_bs_1
 16388                              <1> 	;xor	bl, bl ; video page 0
 16389 00004C8D E803CCFFFF          <1> 	call	beeper ; BEEP !
 16390 00004C92 E947FEFFFF          <1>         jmp     loc_enter_day_2
 16391                              <1> loc_set_date_bs_1:
 16392 00004C97 E8A7000000          <1> 	call	write_backspace
 16393 00004C9C E90AFEFFFF          <1>         jmp     loc_enter_day_1
 16394                              <1> loc_set_date_stc_2:
 16395 00004CA1 E8AF000000          <1> 	call	check_for_backspace
 16396 00004CA6 740A                <1> 	je	short loc_set_date_bs_2
 16397                              <1> 	;xor	bl, bl ; video page 0
 16398 00004CA8 E8E8CBFFFF          <1> 	call	beeper ; BEEP !
 16399 00004CAD E968FEFFFF          <1>         jmp     loc_enter_separator_1
 16400                              <1> loc_set_date_bs_2:
 16401 00004CB2 E88C000000          <1> 	call	write_backspace
 16402 00004CB7 E922FEFFFF          <1>         jmp     loc_enter_day_2
 16403                              <1> loc_set_date_stc_3:
 16404 00004CBC E894000000          <1> 	call	check_for_backspace	
 16405 00004CC1 740A                <1> 	je short loc_set_date_bs_3
 16406                              <1> 	;xor	bl, bl ; video page 0
 16407 00004CC3 E8CDCBFFFF          <1> 	call	beeper ; BEEP !
 16408 00004CC8 E96FFEFFFF          <1>         jmp     loc_enter_month_1
 16409                              <1> loc_set_date_bs_3:
 16410 00004CCD E871000000          <1> 	call	write_backspace
 16411 00004CD2 E943FEFFFF          <1>         jmp     loc_enter_separator_1
 16412                              <1> loc_set_date_stc_4:
 16413 00004CD7 E879000000          <1> 	call	check_for_backspace	
 16414 00004CDC 740A                <1> 	je	short loc_set_date_bs_4
 16415                              <1> 	;xor	bl, bl ; video page 0
 16416 00004CDE E8B2CBFFFF          <1> 	call	beeper ; BEEP !
 16417 00004CE3 E97FFEFFFF          <1>         jmp     loc_enter_month_2
 16418                              <1> loc_set_date_bs_4:
 16419 00004CE8 E856000000          <1> 	call	write_backspace
 16420 00004CED E94AFEFFFF          <1>         jmp     loc_enter_month_1
 16421                              <1> loc_set_date_stc_5:
 16422 00004CF2 E85E000000          <1> 	call	check_for_backspace
 16423 00004CF7 740A                <1> 	je	short loc_set_date_bs_5
 16424                              <1> 	;xor	bl, bl ; video page 0
 16425 00004CF9 E897CBFFFF          <1> 	call	beeper ; BEEP !
 16426 00004CFE E9A0FEFFFF          <1>         jmp     loc_enter_separator_2
 16427                              <1> loc_set_date_bs_5:
 16428 00004D03 E83B000000          <1> 	call	write_backspace
 16429 00004D08 E95AFEFFFF          <1>         jmp     loc_enter_month_2
 16430                              <1> loc_set_date_stc_6:
 16431 00004D0D E843000000          <1> 	call	check_for_backspace
 16432 00004D12 740A                <1>         je      short  loc_set_date_bs_6
 16433                              <1> 	;xor	bl, bl ; video page 0
 16434 00004D14 E87CCBFFFF          <1> 	call	beeper ; BEEP !
 16435 00004D19 E9A7FEFFFF          <1>         jmp     loc_enter_year_1
 16436                              <1> loc_set_date_bs_6:
 16437 00004D1E E820000000          <1> 	call	write_backspace
 16438 00004D23 E97BFEFFFF          <1>         jmp     loc_enter_separator_2
 16439                              <1> loc_set_date_stc_7:
 16440 00004D28 E828000000          <1> 	call	check_for_backspace
 16441 00004D2D 740A                <1> 	je	short loc_set_date_bs_7
 16442                              <1> 	;xor	bl, bl ; video page 0
 16443 00004D2F E861CBFFFF          <1> 	call	beeper ; BEEP !
 16444 00004D34 E9B7FEFFFF          <1>         jmp     loc_enter_year_2
 16445                              <1> loc_set_date_bs_7:
 16446 00004D39 E805000000          <1> 	call	write_backspace
 16447 00004D3E E982FEFFFF          <1>         jmp     loc_enter_year_1
 16448                              <1> 
 16449                              <1> write_backspace:
 16450                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16451 00004D43 B008                <1> 	mov	al, 08h ; BACKSPACE
 16452                              <1> 	;xor	bl, bl
 16453 00004D45 B407                <1> 	mov	ah, 7 ; attribute/color
 16454 00004D47 E86BCAFFFF          <1> 	call	WRITE_TTY
 16455 00004D4C B020                <1> 	mov	al, 20h ; BLANK/SPACE char 
 16456                              <1> 	;xor	bl, bl
 16457 00004D4E B407                <1> 	mov	ah, 7 ; attribute/color
 16458                              <1> 	;call	_write_c_current
 16459                              <1> 	;retn
 16460 00004D50 E931CAFFFF          <1> 	jmp	_write_c_current
 16461                              <1> 
 16462                              <1> check_for_backspace:
 16463                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16464 00004D55 663D080E            <1> 	cmp	ax, 0E08h
 16465 00004D59 7410                <1> 	je	short cfbs_retn
 16466 00004D5B 663DE04B            <1> 	cmp	ax, 4BE0h
 16467 00004D5F 740A                <1> 	je	short cfbs_retn
 16468 00004D61 663D004B            <1> 	cmp	ax, 4B00h
 16469 00004D65 7404                <1> 	je	short cfbs_retn
 16470 00004D67 663DE053            <1> 	cmp	ax, 53E0h
 16471                              <1> cfbs_retn:
 16472 00004D6B C3                  <1> 	retn
 16473                              <1> 
 16474                              <1> show_time:
 16475                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16476                              <1>         ; 2004-2005
 16477                              <1> 
 16478                              <1> 	;mov	ah, 02h
 16479                              <1> 	;call	int1Ah
 16480 00004D6C E832EEFFFF          <1> 	call	RTC_20	; GET RTC TIME
 16481                              <1> 	
 16482 00004D71 88E8                <1> 	mov	al, ch
 16483 00004D73 E866BEFFFF          <1> 	call	bcd_to_ascii
 16484 00004D78 66A3[F6AF0000]      <1> 	mov	[Hour], ax
 16485                              <1> 
 16486 00004D7E 88C8                <1> 	mov	al, cl
 16487 00004D80 E859BEFFFF          <1> 	call	bcd_to_ascii
 16488 00004D85 66A3[F9AF0000]      <1> 	mov	[Minute], ax
 16489                              <1> 
 16490 00004D8B 88F0                <1> 	mov	al, dh
 16491 00004D8D E84CBEFFFF          <1> 	call	bcd_to_ascii
 16492 00004D92 66A3[FCAF0000]      <1> 	mov	[Second], ax
 16493                              <1> 
 16494 00004D98 BE[E6AF0000]        <1> 	mov	esi, Msg_Show_Time
 16495 00004D9D E8E9F0FFFF          <1> 	call	print_msg
 16496 00004DA2 C3                  <1> 	retn
 16497                              <1> 
 16498                              <1> set_time:
 16499                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16500                              <1>         ; 2004-2005
 16501                              <1> 
 16502 00004DA3 BE[D5AF0000]        <1> 	mov 	esi, Msg_Enter_Time
 16503 00004DA8 E8DEF0FFFF          <1> 	call	print_msg
 16504                              <1> 
 16505                              <1> loc_enter_hour_1:
 16506 00004DAD 30E4                <1> 	xor     ah, ah
 16507 00004DAF E833BEFFFF          <1> 	call	int16h
 16508                              <1> 	; AL = ASCII Code of the Character
 16509 00004DB4 3C0D                <1> 	cmp	al, 13 ; ENTER key
 16510 00004DB6 0F84AE010000        <1>         je      loc_set_time_retn
 16511 00004DBC 3C1B                <1> 	cmp	al, 27 ; ESC key
 16512 00004DBE 0F84A6010000        <1>         je      loc_set_time_retn
 16513 00004DC4 A2[F6AF0000]        <1> 	mov	[Hour], al
 16514 00004DC9 3C30                <1> 	cmp	al, '0'
 16515 00004DCB 0F82A4010000        <1>         jb      loc_set_time_stc_0
 16516 00004DD1 3C32                <1> 	cmp	al, '2'
 16517 00004DD3 0F879C010000        <1>         ja      loc_set_time_stc_0
 16518                              <1> 	;sub	bl, bl ; 0
 16519 00004DD9 B407                <1> 	mov	ah, 7 ; attribute/color
 16520 00004DDB E8D7C9FFFF          <1> 	call	WRITE_TTY
 16521                              <1> loc_enter_hour_2:
 16522 00004DE0 30E4                <1> 	xor     ah, ah
 16523 00004DE2 E800BEFFFF          <1> 	call	int16h
 16524                              <1> 	; AL = ASCII Code of the Character
 16525 00004DE7 3C1B                <1> 	cmp	al, 27
 16526 00004DE9 0F847B010000        <1>         je      loc_set_time_retn
 16527 00004DEF A2[F7AF0000]        <1> 	mov	[Hour+1], al
 16528 00004DF4 3C30                <1> 	cmp	al, '0'
 16529 00004DF6 0F8283010000        <1>         jb      loc_set_time_stc_1
 16530 00004DFC 3C39                <1> 	cmp	al, '9'
 16531 00004DFE 0F877B010000        <1> 	ja	loc_set_time_stc_1
 16532 00004E04 803D[F6AF0000]32    <1>         cmp     byte [Hour], '2'
 16533 00004E0B 7208                <1> 	jb	short pass_set_time_24
 16534 00004E0D 3C34                <1> 	cmp	al, '4'
 16535 00004E0F 0F876A010000        <1>         ja      loc_set_time_stc_1
 16536                              <1> pass_set_time_24:
 16537                              <1> 	;sub	bl, bl ; 0
 16538 00004E15 B407                <1> 	mov	ah, 7 ; attribute/color
 16539 00004E17 E89BC9FFFF          <1> 	call	WRITE_TTY
 16540                              <1> loc_enter_time_separator_1:
 16541 00004E1C 28E4                <1> 	sub    ah, ah ; 0
 16542 00004E1E E8C4BDFFFF          <1> 	call	int16h
 16543                              <1> 	; AL = ASCII Code of the Character
 16544 00004E23 3C1B                <1> 	cmp	al, 27
 16545 00004E25 0F843F010000        <1>         je      loc_set_time_retn
 16546 00004E2B 3C3A                <1> 	cmp	al, ':'
 16547 00004E2D 0F8567010000        <1>         jne     loc_set_time_stc_2
 16548                              <1> 	;xor	bl, bl
 16549 00004E33 B407                <1> 	mov	ah, 7 ; attribute/color
 16550 00004E35 E87DC9FFFF          <1> 	call	WRITE_TTY
 16551                              <1> loc_enter_minute_1:
 16552 00004E3A 30E4                <1> 	xor     ah, ah
 16553 00004E3C E8A6BDFFFF          <1> 	call	int16h
 16554                              <1> 	; AL = ASCII Code of the Character
 16555 00004E41 3C1B                <1> 	cmp	al, 27
 16556 00004E43 0F8421010000        <1>         je      loc_set_time_retn
 16557 00004E49 A2[F9AF0000]        <1> 	mov	[Minute], al
 16558 00004E4E 3C30                <1> 	cmp	al, '0'
 16559 00004E50 0F825F010000        <1>         jb      loc_set_time_stc_3
 16560 00004E56 3C35                <1> 	cmp	al, '5'
 16561 00004E58 0F8757010000        <1>         ja      loc_set_time_stc_3
 16562                              <1> 	;sub	bl, bl
 16563 00004E5E B407                <1> 	mov	ah, 7 ; attribute/color
 16564 00004E60 E852C9FFFF          <1> 	call	WRITE_TTY
 16565                              <1> loc_enter_minute_2:
 16566 00004E65 30E4                <1> 	xor     ah, ah
 16567 00004E67 E87BBDFFFF          <1> 	call	int16h
 16568                              <1> 	; AL = ASCII Code of the Character
 16569 00004E6C 3C1B                <1> 	cmp	al, 27
 16570 00004E6E 0F84F6000000        <1>         je      loc_set_time_retn
 16571 00004E74 A2[FAAF0000]        <1> 	mov	[Minute+1], al
 16572 00004E79 3C30                <1> 	cmp	al, '0'
 16573 00004E7B 0F824F010000        <1>         jb      loc_set_time_stc_4
 16574 00004E81 3C39                <1> 	cmp	al, '9'
 16575 00004E83 0F8747010000        <1>         ja      loc_set_time_stc_4
 16576                              <1> 	;sub	bl, bl
 16577 00004E89 B407                <1> 	mov	ah, 7 ; attribute/color
 16578 00004E8B E827C9FFFF          <1> 	call	WRITE_TTY
 16579                              <1> loc_enter_time_separator_2:
 16580 00004E90 66C705[FCAF0000]30- <1> 	mov	word [Second], 3030h
 16581 00004E98 30                  <1>
 16582 00004E99 28E4                <1> 	sub     ah, ah
 16583 00004E9B E847BDFFFF          <1> 	call	int16h
 16584                              <1> 	; AL = ASCII Code of the Character
 16585 00004EA0 3C0D                <1> 	cmp	al, 13
 16586 00004EA2 0F8485000000        <1>         je      loc_set_time_progress
 16587 00004EA8 3C1B                <1> 	cmp	al, 27
 16588 00004EAA 0F84BA000000        <1>         je      loc_set_time_retn
 16589 00004EB0 3C3A                <1> 	cmp	al, ':'
 16590 00004EB2 0F8533010000        <1>         jne     loc_set_time_stc_5
 16591                              <1> 	;xor	bl, bl
 16592 00004EB8 B407                <1> 	mov	ah, 7 ; attribute/color
 16593 00004EBA E8F8C8FFFF          <1> 	call	WRITE_TTY
 16594                              <1> loc_enter_second_1:
 16595 00004EBF 30E4                <1> 	xor     ah, ah
 16596 00004EC1 E821BDFFFF          <1> 	call	int16h
 16597                              <1> 	; AL = ASCII Code of the Character
 16598 00004EC6 3C0D                <1> 	cmp	al, 13
 16599 00004EC8 7463                <1> 	je	short loc_set_time_progress
 16600 00004ECA 3C1B                <1> 	cmp	al, 27
 16601 00004ECC 0F8498000000        <1>         je      loc_set_time_retn
 16602 00004ED2 A2[FCAF0000]        <1> 	mov	[Second], al
 16603 00004ED7 3C30                <1> 	cmp	al, '0'
 16604 00004ED9 0F8227010000        <1>         jb      loc_set_time_stc_6
 16605 00004EDF 3C35                <1> 	cmp	al, '5'
 16606 00004EE1 0F871F010000        <1>         ja      loc_set_time_stc_6
 16607                              <1> 	;sub	bl, bl
 16608 00004EE7 B407                <1> 	mov	ah, 7 ; attribute/color
 16609 00004EE9 E8C9C8FFFF          <1> 	call	WRITE_TTY
 16610                              <1> loc_enter_second_2:
 16611 00004EEE 30E4                <1> 	xor     ah, ah
 16612 00004EF0 E8F2BCFFFF          <1> 	call	int16h
 16613                              <1> 	; AL = ASCII Code of the Character
 16614 00004EF5 3C1B                <1> 	cmp	al, 27
 16615 00004EF7 7471                <1> 	je	short loc_set_time_retn
 16616 00004EF9 3C30                <1> 	cmp	al, '0'
 16617 00004EFB 0F8229010000        <1>         jb      loc_set_time_stc_7
 16618 00004F01 3C39                <1> 	cmp	al, '9'
 16619 00004F03 0F8721010000        <1>         ja      loc_set_time_stc_7
 16620                              <1> 	;sub	bl, bl
 16621 00004F09 B407                <1> 	mov	ah, 7 ; attribute/color
 16622 00004F0B E8A7C8FFFF          <1> 	call	WRITE_TTY
 16623                              <1> loc_set_time_get_lchar_again:
 16624 00004F10 28E4                <1> 	sub	ah, ah ; 0
 16625 00004F12 E8D0BCFFFF          <1> 	call	int16h
 16626                              <1> 	; AL = ASCII Code of the Character
 16627 00004F17 3C0D                <1> 	cmp	al, 13
 16628 00004F19 7412                <1> 	je	short loc_set_time_progress
 16629 00004F1B 3C1B                <1> 	cmp	al, 27
 16630 00004F1D 744B                <1> 	je	short loc_set_time_retn
 16631                              <1> 	;
 16632 00004F1F E831FEFFFF          <1> 	call	check_for_backspace
 16633 00004F24 75EA                <1> 	jne	short loc_set_time_get_lchar_again
 16634                              <1> 
 16635                              <1> loc_set_time_bs_8:
 16636 00004F26 E818FEFFFF          <1> 	call	write_backspace
 16637 00004F2B EBC1                <1> 	jmp	short loc_enter_second_2
 16638                              <1> 
 16639                              <1> loc_set_time_progress:
 16640                              <1> 	; Get Current Time
 16641                              <1> 	;mov 	ah, 02h
 16642                              <1> 	;call	int1Ah
 16643 00004F2D E871ECFFFF          <1> 	call	RTC_20	; GET RTC TIME
 16644                              <1> 	;DL = Daylight Savings Enable option (0-1)	
 16645                              <1> 
 16646 00004F32 66A1[F6AF0000]      <1> 	mov	ax, [Hour]
 16647 00004F38 662D3030            <1> 	sub	ax, '00'
 16648 00004F3C C0E004              <1> 	shl	al, 4 ; * 16
 16649 00004F3F 88C5                <1> 	mov	ch, al
 16650 00004F41 00E5                <1> 	add	ch, ah
 16651 00004F43 66A1[F9AF0000]      <1> 	mov	ax, [Minute]
 16652 00004F49 662D3030            <1> 	sub	ax, '00'
 16653 00004F4D C0E004              <1> 	shl	al, 4 ; * 16
 16654 00004F50 88C1                <1> 	mov	cl, al
 16655 00004F52 00E1                <1> 	add	cl, ah
 16656 00004F54 66A1[FCAF0000]      <1> 	mov	ax, [Second]
 16657 00004F5A 662D3030            <1> 	sub	ax, '00'
 16658 00004F5E C0E004              <1> 	shl	al, 4 ; * 16
 16659 00004F61 88C6                <1> 	mov	dh, al
 16660 00004F63 00E6                <1> 	add	dh, ah
 16661                              <1> 	
 16662                              <1> 	;mov	ah, 03h
 16663                              <1> 	;call	int1Ah
 16664 00004F65 E868ECFFFF          <1> 	call	RTC_30	; SET RTC TIME
 16665                              <1> 
 16666                              <1> loc_set_time_retn:
 16667 00004F6A BE[C6BA0000]        <1> 	mov 	esi, nextline
 16668 00004F6F E817EFFFFF          <1> 	call	print_msg
 16669 00004F74 C3                  <1> 	retn
 16670                              <1> 
 16671                              <1> loc_set_time_stc_0:
 16672                              <1> 	;xor	bl, bl ; video page 0
 16673 00004F75 E81BC9FFFF          <1> 	call	beeper ; BEEP !
 16674 00004F7A E92EFEFFFF          <1>         jmp     loc_enter_hour_1
 16675                              <1> loc_set_time_stc_1:
 16676 00004F7F E8D1FDFFFF          <1> 	call	check_for_backspace
 16677 00004F84 740A                <1> 	je	short loc_set_time_bs_1
 16678                              <1> 	;xor	bl, bl ; video page 0
 16679 00004F86 E80AC9FFFF          <1> 	call	beeper ; BEEP !
 16680 00004F8B E950FEFFFF          <1>         jmp     loc_enter_hour_2
 16681                              <1> loc_set_time_bs_1:
 16682 00004F90 E8AEFDFFFF          <1> 	call	write_backspace
 16683 00004F95 E913FEFFFF          <1>         jmp     loc_enter_hour_1
 16684                              <1> loc_set_time_stc_2:
 16685 00004F9A E8B6FDFFFF          <1> 	call	check_for_backspace
 16686 00004F9F 740A                <1> 	je	short loc_set_time_bs_2
 16687                              <1> 	;xor	bl, bl ; video page 0
 16688 00004FA1 E8EFC8FFFF          <1> 	call	beeper ; BEEP !
 16689 00004FA6 E971FEFFFF          <1>         jmp     loc_enter_time_separator_1
 16690                              <1> loc_set_time_bs_2:
 16691 00004FAB E893FDFFFF          <1> 	call	write_backspace
 16692 00004FB0 E92BFEFFFF          <1>         jmp     loc_enter_hour_2
 16693                              <1> loc_set_time_stc_3:
 16694 00004FB5 E89BFDFFFF          <1> 	call	check_for_backspace
 16695 00004FBA 740A                <1> 	je	short loc_set_time_bs_3
 16696                              <1> 	;xor	bl, bl ; video page 0
 16697 00004FBC E8D4C8FFFF          <1> 	call	beeper ; BEEP !6
 16698 00004FC1 E974FEFFFF          <1>         jmp     loc_enter_minute_1
 16699                              <1> loc_set_time_bs_3:
 16700 00004FC6 E878FDFFFF          <1> 	call	write_backspace
 16701 00004FCB E94CFEFFFF          <1>         jmp     loc_enter_time_separator_1
 16702                              <1> loc_set_time_stc_4:
 16703 00004FD0 E880FDFFFF          <1> 	call	check_for_backspace
 16704 00004FD5 740A                <1> 	je	short loc_set_time_bs_4
 16705                              <1> 	;xor	bl, bl ; video page 0
 16706 00004FD7 E8B9C8FFFF          <1> 	call	beeper ; BEEP !
 16707 00004FDC E984FEFFFF          <1>         jmp     loc_enter_minute_2
 16708                              <1> loc_set_time_bs_4:
 16709 00004FE1 E85DFDFFFF          <1> 	call	write_backspace
 16710 00004FE6 E94FFEFFFF          <1>         jmp     loc_enter_minute_1
 16711                              <1> loc_set_time_stc_5:
 16712 00004FEB E865FDFFFF          <1> 	call	check_for_backspace
 16713 00004FF0 740A                <1> 	je	short loc_set_time_bs_5
 16714                              <1> 	;xor	bl, bl ; video page 0
 16715 00004FF2 E89EC8FFFF          <1> 	call	beeper ; BEEP !
 16716 00004FF7 E994FEFFFF          <1>         jmp     loc_enter_time_separator_2
 16717                              <1> loc_set_time_bs_5:
 16718 00004FFC E842FDFFFF          <1> 	call	write_backspace
 16719 00005001 E95FFEFFFF          <1>         jmp     loc_enter_minute_2
 16720                              <1> loc_set_time_stc_6:
 16721 00005006 E84AFDFFFF          <1> 	call	check_for_backspace
 16722 0000500B 7413                <1> 	je	short loc_set_time_bs_6
 16723                              <1> 	;xor	bl, bl ; video page 0
 16724 0000500D E883C8FFFF          <1> 	call	beeper ; BEEP !
 16725 00005012 66C705[FCAF0000]30- <1> 	mov	word [Second], 3030h
 16726 0000501A 30                  <1>
 16727 0000501B E99FFEFFFF          <1>         jmp     loc_enter_second_1
 16728                              <1> loc_set_time_bs_6:
 16729 00005020 E81EFDFFFF          <1> 	call	write_backspace
 16730 00005025 E966FEFFFF          <1>         jmp     loc_enter_time_separator_2
 16731                              <1> loc_set_time_stc_7:
 16732 0000502A E826FDFFFF          <1> 	call	check_for_backspace
 16733 0000502F 740A                <1> 	je	short loc_set_time_bs_7
 16734                              <1> 	;xor	bl, bl ; video page 0
 16735 00005031 E85FC8FFFF          <1> 	call	beeper ; BEEP !
 16736 00005036 E9B3FEFFFF          <1>         jmp     loc_enter_second_2
 16737                              <1> loc_set_time_bs_7:
 16738 0000503B E803FDFFFF          <1> 	call	write_backspace
 16739 00005040 E97AFEFFFF          <1>         jmp     loc_enter_second_1
 16740                              <1> 
 16741                              <1> print_volume_info:
 16742                              <1> 	; 01/03/2016
 16743                              <1> 	; 08/02/2016
 16744                              <1> 	; 06/02/2016
 16745                              <1> 	; 04/02/2016
 16746                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16747                              <1> 	; 25/10/2009
 16748                              <1> 	;
 16749                              <1> 	; "Volume Serial No: "
 16750                              <1>  	;
 16751                              <1> 	; INPUT  : AL = DOS Drive Number
 16752                              <1> 	; OUTPUT : AH = FS Type
 16753                              <1> 	;          AL = DOS Drive Name
 16754                              <1> 	; CF = 0 -> OK
 16755                              <1> 	; CF = 1 -> Drive not ready 
 16756                              <1> 
 16757 00005045 88C4                <1> 	mov	ah, al
 16758 00005047 28C0                <1> 	sub	al, al
 16759 00005049 0FB7F0              <1> 	movzx	esi, ax	
 16760 0000504C 81C600010900        <1> 	add	esi, Logical_DOSDisks
 16761 00005052 8A06                <1> 	mov	al, [esi]
 16762 00005054 3C41                <1> 	cmp	al, 'A'  
 16763 00005056 7304                <1> 	jnb	short loc_pvi_set_vol_name
 16764 00005058 8A6604              <1> 	mov	ah, [esi+LD_FSType]
 16765 0000505B C3                  <1> 	retn
 16766                              <1> 
 16767                              <1> loc_pvi_set_vol_name:
 16768 0000505C A2[30B00000]        <1> 	mov	[Vol_Drv_Name], al
 16769 00005061 56                  <1> 	push	esi
 16770 00005062 E858010000          <1> 	call	move_volume_name_and_serial_no ;;;
 16771 00005067 7302                <1> 	jnc	short loc_pvi_mvn_ok
 16772 00005069 5E                  <1> 	pop	esi
 16773 0000506A C3                  <1> 	retn
 16774                              <1> 
 16775                              <1> loc_pvi_mvn_ok:
 16776 0000506B 8B3424              <1> 	mov	esi, [esp]
 16777 0000506E 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 16778 00005072 7509                <1> 	jne	short loc_pvi_fat_vol_size
 16779 00005074 8B4670              <1> 	mov	eax, [esi+LD_FS_VolumeSize]
 16780 00005077 0FB75E11            <1> 	movzx	ebx, word [esi+LD_FS_BytesPerSec]
 16781 0000507B EB07                <1> 	jmp	short loc_vol_size_mul32
 16782                              <1> loc_pvi_fat_vol_size:
 16783 0000507D 8B4670              <1> 	mov	eax, [esi+LD_TotalSectors]
 16784 00005080 0FB75E11            <1> 	movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
 16785                              <1> loc_vol_size_mul32:
 16786 00005084 F7E3                <1> 	mul	ebx
 16787 00005086 09D2                <1> 	or	edx, edx
 16788 00005088 7507                <1> 	jnz	short loc_vol_size_in_kbytes
 16789                              <1> loc_vol_size_in_bytes:
 16790 0000508A B9[0EB00000]        <1> 	mov	ecx, VolSize_Bytes
 16791 0000508F EB0D                <1> 	jmp	short loc_write_vol_size_str
 16792                              <1> loc_vol_size_in_kbytes:
 16793 00005091 66BB0004            <1> 	mov	bx, 1024
 16794 00005095 F7F3                <1> 	div	ebx
 16795 00005097 B9[01B00000]        <1> 	mov 	ecx, VolSize_KiloBytes
 16796 0000509C 31D2                <1> 	xor	edx, edx ; 0
 16797                              <1> loc_write_vol_size_str:
 16798 0000509E 890D[E7C60000]      <1> 	mov	[VolSize_Unit1], ecx
 16799                              <1> 	; 
 16800 000050A4 BF[FDC60000]        <1> 	mov	edi, Vol_Tot_Sec_Str_End
 16801                              <1>         ;mov	byte [edi], 0
 16802 000050A9 B90A000000          <1> 	mov	ecx, 10
 16803                              <1> loc_write_vol_size_chr:
 16804 000050AE F7F1                <1> 	div	ecx
 16805 000050B0 80C230              <1> 	add	dl, '0'
 16806 000050B3 4F                  <1> 	dec	edi	
 16807 000050B4 8817                <1> 	mov	[edi], dl
 16808 000050B6 85C0                <1> 	test	eax, eax
 16809 000050B8 7404                <1> 	jz	short loc_write_vol_size_str_ok
 16810 000050BA 28D2                <1> 	sub	dl, dl ; 0
 16811 000050BC EBF0                <1> 	jmp	short loc_write_vol_size_chr
 16812                              <1> 
 16813                              <1> loc_write_vol_size_str_ok:
 16814 000050BE 893D[EFC60000]      <1> 	mov	[Vol_Tot_Sec_Str_Start], edi
 16815                              <1> 	;
 16816 000050C4 BF[19B00000]        <1> 	mov	edi, Vol_FS_Name
 16817 000050C9 8A4E03              <1> 	mov	cl, [esi+LD_FATType]
 16818 000050CC 20C9                <1> 	and	cl, cl ; 0 ?
 16819 000050CE 7515                <1> 	jnz	short loc_write_vol_FAT_str_1
 16820 000050D0 66C7075452          <1> 	mov	word [edi], 'TR'
 16821 000050D5 C7470420465331      <1> 	mov	dword [edi+4], ' FS1'
 16822                              <1> 	;movzx	ebx, word [esi+LD_FS_BytesPerSec]
 16823 000050DC 668B5E11            <1> 	mov	bx, [esi+LD_FS_BytesPerSec]
 16824 000050E0 8B4674              <1> 	mov	eax, [esi+LD_FS_FreeSectors]
 16825 000050E3 EB36                <1> 	jmp	short loc_vol_freespace_mul32
 16826                              <1> 
 16827                              <1> loc_write_vol_FAT_str_1:
 16828 000050E5 66B83332            <1> 	mov	ax, '32' ; FAT32
 16829 000050E9 80F902              <1> 	cmp	cl, 2 ; [esi+LD_FATType]
 16830 000050EC 7708                <1> 	ja	short loc_write_vol_FAT_str_2
 16831 000050EE 66B83132            <1> 	mov	ax, '12' ; FAT12
 16832 000050F2 7202                <1> 	jb	short loc_write_vol_FAT_str_2
 16833 000050F4 B436                <1> 	mov	ah, '6'  ; FAT16
 16834                              <1> loc_write_vol_FAT_str_2:
 16835 000050F6 C70746415420        <1> 	mov	dword [edi], 'FAT '
 16836 000050FC 66894704            <1> 	mov	word [edi+4], ax
 16837                              <1> 	;
 16838                              <1> 	;movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
 16839 00005100 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec]
 16840 00005104 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
 16841                              <1> 
 16842                              <1> loc_vol_freespace_recalc0:
 16843                              <1> 	; 01/03/2016
 16844 00005107 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
 16845 0000510A 720F                <1> 	jb	short loc_vol_freespace_mul32
 16846                              <1> 	;inc	eax ; 0
 16847 0000510C 20C9                <1> 	and	cl, cl ; byte [esi+LD_FATType]
 16848 0000510E 740B                <1> 	jz	short loc_vol_freespace_mul32 	
 16849 00005110 53                  <1> 	push	ebx
 16850 00005111 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free sectors
 16851 00005115 E81C400000          <1> 	call	calculate_fat_freespace
 16852 0000511A 5B                  <1> 	pop	ebx
 16853                              <1> 
 16854                              <1> loc_vol_freespace_mul32:
 16855 0000511B F7E3                <1> 	mul	ebx
 16856 0000511D 09D2                <1> 	or	edx, edx
 16857 0000511F 7507                <1> 	jnz	short loc_vol_fspace_in_kbytes
 16858                              <1> loc_vol_fspace_in_bytes:
 16859 00005121 B9[0EB00000]        <1> 	mov	ecx, VolSize_Bytes
 16860 00005126 EB0D                <1> 	jmp	short loc_write_vol_fspace_str
 16861                              <1> loc_vol_fspace_in_kbytes:
 16862 00005128 66BB0004            <1> 	mov	bx, 1024
 16863 0000512C F7F3                <1> 	div	ebx
 16864 0000512E B9[01B00000]        <1> 	mov 	ecx, VolSize_KiloBytes
 16865 00005133 31D2                <1> 	xor	edx, edx ; 0
 16866                              <1> loc_write_vol_fspace_str:
 16867 00005135 890D[EBC60000]      <1> 	mov	[VolSize_Unit2], ecx
 16868                              <1> 	;	
 16869 0000513B BF[0DC70000]        <1> 	mov	edi, Vol_Free_Sectors_Str_End
 16870                              <1>         ;mov	byte [edi], 0
 16871 00005140 B90A000000          <1> 	mov	ecx, 10
 16872                              <1> loc_write_vol_fspace_chr:
 16873 00005145 F7F1                <1> 	div	ecx
 16874 00005147 80C230              <1> 	add	dl, '0'
 16875 0000514A 4F                  <1> 	dec	edi	
 16876 0000514B 8817                <1> 	mov	[edi], dl
 16877 0000514D 85C0                <1> 	test	eax, eax
 16878 0000514F 7404                <1> 	jz	short loc_write_vol_fspace_str_ok
 16879 00005151 28D2                <1> 	sub	dl, dl ; 0
 16880 00005153 EBF0                <1> 	jmp	short loc_write_vol_fspace_chr
 16881                              <1> 
 16882                              <1> loc_write_vol_fspace_str_ok:
 16883 00005155 893D[FFC60000]      <1> 	mov	[Vol_Free_Sectors_Str_Start], edi
 16884                              <1> 	;
 16885 0000515B BE[17B00000]        <1> 	mov	esi, Volume_in_drive
 16886 00005160 E826EDFFFF          <1> 	call	print_msg
 16887 00005165 BE[57B00000]        <1> 	mov	esi, Vol_Name
 16888 0000516A E81CEDFFFF          <1> 	call	print_msg
 16889 0000516F BE[C6BA0000]        <1> 	mov	esi, nextline
 16890 00005174 E812EDFFFF          <1> 	call	print_msg
 16891                              <1> 	;
 16892 00005179 BE[B8B00000]        <1> 	mov	esi, Vol_Total_Sector_Header
 16893 0000517E E808EDFFFF          <1> 	call	print_msg
 16894 00005183 8B35[EFC60000]      <1> 	mov	esi, [Vol_Tot_Sec_Str_Start]
 16895 00005189 E8FDECFFFF          <1> 	call	print_msg
 16896 0000518E 8B35[E7C60000]      <1> 	mov	esi, [VolSize_Unit1]
 16897 00005194 E8F2ECFFFF          <1> 	call	print_msg
 16898                              <1> 	;
 16899 00005199 BE[C9B00000]        <1> 	mov	esi, Vol_Free_Sectors_Header
 16900 0000519E E8E8ECFFFF          <1> 	call	print_msg
 16901 000051A3 8B35[FFC60000]      <1> 	mov	esi, [Vol_Free_Sectors_Str_Start]
 16902 000051A9 E8DDECFFFF          <1> 	call	print_msg
 16903 000051AE 8B35[EBC60000]      <1> 	mov	esi, [VolSize_Unit2]
 16904 000051B4 E8D2ECFFFF          <1> 	call	print_msg
 16905                              <1> 	;
 16906 000051B9 5E                  <1> 	pop	esi
 16907                              <1> 	
 16908                              <1> 	;mov	ah, [esi+LD_FSType]
 16909                              <1> 	;mov	al, [esi+LD_FATType]
 16910 000051BA 668B4603            <1> 	mov	ax, [esi+LD_FATType]
 16911                              <1> 
 16912 000051BE C3                  <1> 	retn
 16913                              <1> 
 16914                              <1> move_volume_name_and_serial_no:
 16915                              <1> 	; 08/02/2016  (TRDOS 386 = TRDOS v2.0)
 16916                              <1> 	; this routine will be called by
 16917                              <1> 	; "print_volume_info" and "print_directory"
 16918                              <1> 	; INPUT ->
 16919                              <1> 	;	ESI = Logical DOS drv descripton table address
 16920                              <1> 	; OUTPUT ->
 16921                              <1> 	;	*Volume name will be moved to text area
 16922                              <1> 	;	*Volume serial number will be converted to
 16923                              <1> 	;	 text and will be moved to text area
 16924                              <1> 	;   cf = 1 -> invalid/unknown dos drive
 16925                              <1> 	;   cf = 0 -> ecx = 0
 16926                              <1> 	;
 16927                              <1> 	; (eax, edx, ecx, esi, edi will be changed)
 16928                              <1> 
 16929 000051BF BF[57B00000]        <1> 	mov 	edi, Vol_Name
 16930                              <1> 
 16931                              <1> 	;mov	ah, [esi+LD_FSType]
 16932                              <1> 	;mov	al, [esi+LD_FATType]
 16933 000051C4 668B4603            <1> 	mov	ax, [esi+LD_FATType]
 16934 000051C8 80FCA1              <1> 	cmp	ah, 0A1h
 16935 000051CB 7418                <1> 	je	short mvn_2
 16936 000051CD 08E4                <1> 	or	ah, ah
 16937 000051CF 7404                <1> 	jz	short mvn_0
 16938 000051D1 08C0                <1> 	or	al, al
 16939 000051D3 7504                <1> 	jnz	short mvn_1
 16940                              <1> mvn_0:
 16941 000051D5 8A06                <1> 	mov	al, [esi]
 16942 000051D7 F9                  <1> 	stc
 16943 000051D8 C3                  <1> 	retn
 16944                              <1> mvn_1:
 16945 000051D9 3C02                <1> 	cmp	al, 2
 16946 000051DB 7717                <1> 	ja	short mvn_3 
 16947                              <1> 	;or	al, al
 16948                              <1> 	;jz	short mvn_2
 16949 000051DD 8B462D              <1> 	mov	eax, [esi+LD_BPB+VolumeID]
 16950 000051E0 83C631              <1> 	add	esi, LD_BPB+VolumeLabel
 16951 000051E3 EB15                <1> 	jmp	short mvn_4
 16952                              <1> mvn_2:
 16953 000051E5 8B4628              <1> 	mov	eax, [esi+LD_FS_VolumeSerial]
 16954 000051E8 83C62C              <1> 	add	esi, LD_FS_VolumeName
 16955 000051EB B910000000          <1> 	mov	ecx, 16
 16956 000051F0 F3A5                <1> 	rep	movsd
 16957 000051F2 EB10                <1> 	jmp	short mvn_5
 16958                              <1> mvn_3:
 16959 000051F4 8B4649              <1> 	mov	eax, [esi+LD_BPB+FAT32_VolID]
 16960 000051F7 83C64D              <1> 	add	esi, LD_BPB+FAT32_VolLab
 16961                              <1> mvn_4:
 16962 000051FA B90B000000          <1> 	mov	ecx, 11
 16963 000051FF F3A4                <1> 	rep	movsb
 16964 00005201 C60700              <1> 	mov	byte [edi], 0
 16965                              <1> mvn_5:
 16966                              <1> 	;mov	[Current_VolSerial], eax  
 16967 00005204 E8DEC7FFFF          <1> 	call	dwordtohex
 16968 00005209 8915[ACB00000]      <1> 	mov	[Vol_Serial1], edx
 16969 0000520F A3[B1B00000]        <1> 	mov	[Vol_Serial2], eax
 16970                              <1> 	; ecx = 0
 16971 00005214 C3                  <1> 	retn
 16972                              <1> 
 16973                              <1> get_volume_serial_number:
 16974                              <1> 	; 19/01/2016 (TRDOS 386 = TRDOS v2.0)
 16975                              <1> 	; 08/08/2010
 16976                              <1> 	;
 16977                              <1> 	; INPUT -> DL = Logical DOS Drive number
 16978                              <1> 	; OUTPUT -> EAX = Volume serial number
 16979                              <1> 	;          BL= FAT Type	    
 16980                              <1> 	;          BH = Logical DOS drv Number (DL input)
 16981                              <1> 	; cf = 1 -> Drive not ready
 16982                              <1> 
 16983 00005215 31DB                <1> 	xor	ebx, ebx
 16984 00005217 88D7                <1> 	mov	bh, dl
 16985 00005219 3815[7FAE0000]      <1> 	cmp	[Last_DOS_DiskNo], dl
 16986 0000521F 7304                <1> 	jnb	short loc_gvsn_start
 16987                              <1> loc_gvsn_stc_retn:
 16988 00005221 31C0                <1> 	xor	eax, eax
 16989 00005223 F9                  <1> 	stc 
 16990 00005224 C3                  <1>         retn 
 16991                              <1> loc_gvsn_start:
 16992 00005225 56                  <1> 	push	esi
 16993 00005226 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 16994 0000522B 01DE                <1> 	add	esi, ebx
 16995 0000522D 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
 16996 00005230 20DB                <1> 	and	bl, bl
 16997 00005232 740F                <1> 	jz	short loc_gvsn_fs
 16998 00005234 80FB02              <1> 	cmp	bl, 2
 16999 00005237 7705                <1> 	ja	short loc_gvsn_fat32
 17000                              <1> loc_gvsn_fat:
 17001 00005239 83C62D              <1> 	add	esi, LD_BPB + VolumeID
 17002 0000523C EB0E                <1> 	jmp	short loc_gvsn_return
 17003                              <1> loc_gvsn_fat32: 
 17004 0000523E 83C649              <1> 	add	esi, LD_BPB + FAT32_VolID
 17005 00005241 EB09                <1> 	jmp	short loc_gvsn_return 
 17006                              <1> loc_gvsn_fs:
 17007 00005243 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 17008 00005247 75D8                <1> 	jne	short loc_gvsn_stc_retn 
 17009 00005249 83C628              <1> 	add	esi, LD_FS_VolumeSerial
 17010                              <1> loc_gvsn_return:
 17011 0000524C 8B06                <1> 	mov	eax, [esi]
 17012 0000524E 5E                  <1> 	pop	esi
 17013 0000524F C3                  <1> 	retn
 17014                              <1> 
 17015                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ]
 17016                              <1> ; 09/11/2011
 17017                              <1> ; 29/01/2005
 17018                              <1> 
 17019                              <1> command_interpreter:
 17020                              <1> 	; 04/03/2016
 17021                              <1> 	; 04/02/2016
 17022                              <1> 	; 03/02/2016
 17023                              <1> 	; 30/01/2016
 17024                              <1> 	; 29/01/2016 (TRDOS 386 = TRDOS 2.0)
 17025                              <1> 	; 15/09/2011         
 17026                              <1> 	; 29/01/2005
 17027                              <1>         
 17028                              <1> 	; Input: ecx = command word length (CL)
 17029                              <1> 	;	 CommandBuffer = Command string offset
 17030                              <1>  
 17031 00005250 C605[A0C70000]00    <1> 	mov	byte [Program_Exit],0
 17032 00005257 80F904              <1> 	cmp	cl, 4
 17033 0000525A 0F87A8020000        <1>         ja      c_6
 17034 00005260 0F8216010000        <1>         jb      c_2
 17035                              <1> c_4:
 17036                              <1> 
 17037                              <1> cmp_cmd_exit:
 17038 00005266 BF[EDAE0000]        <1> 	mov	edi, Cmd_Exit
 17039 0000526B E8B9030000          <1> 	call	cmp_cmd	
 17040 00005270 7208                <1> 	jc	short cmp_cmd_date
 17041                              <1> 
 17042 00005272 C605[A0C70000]01    <1>         mov     byte [Program_Exit], 1
 17043 00005279 C3                  <1>         retn
 17044                              <1> 
 17045                              <1> cmp_cmd_date:
 17046 0000527A B104                <1> 	mov	cl, 4
 17047 0000527C BF[09AF0000]        <1> 	mov	edi, Cmd_Date
 17048 00005281 E8A3030000          <1> 	call	cmp_cmd	
 17049 00005286 720B                <1>         jc	short cmp_cmd_time
 17050                              <1> 	
 17051 00005288 E8D0F7FFFF          <1> 	call	show_date
 17052 0000528D E80FF8FFFF          <1> 	call	set_date
 17053 00005292 C3                  <1> 	retn
 17054                              <1> 
 17055                              <1> cmp_cmd_time:
 17056 00005293 B104                <1> 	mov	cl, 4
 17057 00005295 BF[0EAF0000]        <1> 	mov	edi, Cmd_Time
 17058 0000529A E88A030000          <1>    	call	cmp_cmd	
 17059 0000529F 720B                <1> 	jc	short cmp_cmd_show
 17060                              <1> 
 17061 000052A1 E8C6FAFFFF          <1> 	call	show_time
 17062 000052A6 E8F8FAFFFF          <1> 	call	set_time
 17063 000052AB C3                  <1> 	retn
 17064                              <1> 
 17065                              <1> cmp_cmd_show:
 17066 000052AC B104                <1> 	mov	cl, 4
 17067 000052AE BF[1FAF0000]        <1> 	mov	edi, Cmd_Show
 17068 000052B3 E871030000          <1>    	call	cmp_cmd	
 17069 000052B8 0F83E0090000        <1>         jnc     show_file
 17070                              <1> 
 17071                              <1> cmp_cmd_echo:
 17072 000052BE B104                <1> 	mov	cl, 4
 17073 000052C0 BF[64AF0000]        <1> 	mov	edi, Cmd_Echo
 17074 000052C5 E85F030000          <1>    	call	cmp_cmd	
 17075 000052CA 720A                <1> 	jc	short cmp_cmd_copy
 17076                              <1> 
 17077 000052CC 803E20              <1> 	cmp	byte [esi], 20h
 17078 000052CF 0F83B6EBFFFF        <1> 	jnb	print_msg
 17079 000052D5 C3                  <1> 	retn
 17080                              <1> 
 17081                              <1> cmp_cmd_copy:
 17082 000052D6 B104                <1> 	mov	cl, 4
 17083 000052D8 BF[42AF0000]        <1> 	mov	edi, Cmd_Copy
 17084 000052DD E847030000          <1>    	call	cmp_cmd	
 17085 000052E2 0F83F8170000        <1> 	jnc	copy_file
 17086                              <1> 
 17087                              <1> cmp_cmd_move:
 17088 000052E8 B104                <1> 	mov	cl, 4
 17089 000052EA BF[47AF0000]        <1> 	mov	edi, Cmd_Move
 17090 000052EF E835030000          <1>    	call	cmp_cmd	
 17091 000052F4 0F838C160000        <1> 	jnc	move_file
 17092                              <1> 
 17093                              <1> cmp_cmd_path:
 17094 000052FA B104                <1> 	mov	cl, 4
 17095 000052FC BF[4CAF0000]        <1> 	mov	edi, Cmd_Path
 17096 00005301 E823030000          <1>    	call	cmp_cmd	
 17097 00005306 0F83A3190000        <1> 	jnc	set_get_path
 17098                              <1> 
 17099                              <1> cmp_cmd_beep:
 17100 0000530C B104                <1> 	mov	cl, 4
 17101 0000530E BF[82AF0000]        <1> 	mov	edi, Cmd_Beep
 17102 00005313 E811030000          <1>    	call	cmp_cmd	
 17103 00005318 0F8377C5FFFF        <1> 	jnc	beeper
 17104                              <1> 
 17105                              <1> cmp_cmd_find:
 17106 0000531E B104                <1> 	mov	cl, 4
 17107 00005320 BF[56AF0000]        <1> 	mov	edi, Cmd_Find
 17108 00005325 E8FF020000          <1>    	call	cmp_cmd	
 17109 0000532A 0F82E6020000        <1>         jc      loc_cmd_failed
 17110                              <1> 
 17111                              <1> 	;call	find_and_list_files
 17112 00005330 E97B190000          <1> 	jmp	find_and_list_files
 17113                              <1> 	;retn
 17114                              <1> 
 17115                              <1> c_1:
 17116 00005335 AD                  <1> 	lodsd
 17117                              <1> cmp_cmd_help:
 17118 00005336 3C3F                <1> 	cmp	al, '?'
 17119 00005338 751D                <1>         jne     short cmp_cmd_remark
 17120                              <1> 
 17121 0000533A BE[DFAE0000]        <1> 	mov	esi, Command_List
 17122                              <1> cmd_help_next_w:
 17123 0000533F E847EBFFFF          <1> 	call	print_msg
 17124                              <1> 
 17125 00005344 803E20              <1> 	cmp	byte [esi], 20h ; 0
 17126 00005347 7232                <1> 	jb	short cmd_help_retn
 17127                              <1> 	
 17128 00005349 56                  <1> 	push	esi
 17129 0000534A BE[C6BA0000]        <1> 	mov	esi, nextline
 17130 0000534F E837EBFFFF          <1> 	call	print_msg
 17131 00005354 5E                  <1> 	pop	esi
 17132 00005355 EBE8                <1> 	jmp	short cmd_help_next_w	
 17133                              <1> 
 17134                              <1> cmp_cmd_remark:
 17135 00005357 3C2A                <1> 	cmp	al, '*'
 17136 00005359 0F85B7020000        <1>         jne     loc_cmd_failed
 17137 0000535F 46                  <1> 	inc	esi
 17138 00005360 BF[10BF0000]        <1> 	mov	edi, Remark
 17139 00005365 8A06                <1> 	mov	al, [esi]
 17140 00005367 3C20                <1> 	cmp	al, 20h
 17141 00005369 7707                <1> 	ja	short cmd_remark_write
 17142 0000536B 89FE                <1> 	mov	esi, edi ; Remark
 17143 0000536D E919EBFFFF          <1> 	jmp	print_msg
 17144                              <1> 
 17145                              <1> cmd_remark_write:
 17146 00005372 AA                  <1> 	stosb
 17147 00005373 AC                  <1> 	lodsb
 17148 00005374 3C20                <1> 	cmp	al, 20h
 17149 00005376 73FA                <1> 	jnb	short cmd_remark_write
 17150 00005378 C60700              <1> 	mov	byte [edi], 0
 17151                              <1> 
 17152                              <1> cmd_help_retn:
 17153                              <1> cmd_remark_retn:
 17154                              <1> cd_retn:
 17155 0000537B C3                  <1> 	retn
 17156                              <1> 
 17157                              <1> c_2:
 17158 0000537C 80F902              <1> 	cmp	cl, 2
 17159 0000537F 0F87B1000000        <1>         ja      c_3
 17160 00005385 BE[5EBF0000]        <1> 	mov	esi, CommandBuffer
 17161 0000538A 72A9                <1> 	jb	short c_1
 17162                              <1> 
 17163                              <1> cmp_cmd_cd:
 17164 0000538C 66AD                <1> 	lodsw
 17165 0000538E 663D4344            <1> 	cmp	ax, 'CD'
 17166 00005392 7553                <1> 	jne	short cmp_cmd_drive
 17167 00005394 46                  <1>         inc	esi
 17168                              <1> cd_0:
 17169 00005395 668B06              <1> 	mov	ax, [esi]	
 17170 00005398 3C20                <1> 	cmp	al, 20h
 17171 0000539A 76DF                <1> 	jna	short cd_retn
 17172                              <1> 	; 10/02/2016
 17173 0000539C 80FC3A              <1> 	cmp	ah, ':'
 17174 0000539F 7504                <1> 	jne	short cd_1
 17175 000053A1 46                  <1> 	inc	esi
 17176 000053A2 46                  <1> 	inc	esi
 17177 000053A3 EB4B                <1> 	jmp	short cd_2
 17178                              <1> 
 17179                              <1> cd_1:	; change current directory
 17180                              <1> 	; 29/11/2009
 17181                              <1> 	; AH = CDh	; to separate 'CD' command from others
 17182                              <1> 			; for restoring current directory
 17183                              <1> 			; 0CDh sign is for saving cdir into 
 17184                              <1> 			; DOS drv description table cdir area
 17185                              <1> 	
 17186 000053A5 B4CD                <1> 	mov	ah, 0CDh ; mov byte [CD_COMMAND], 0CDh 
 17187                              <1> 
 17188 000053A7 E8EC190000          <1> 	call	change_current_directory
 17189 000053AC 0F8306190000        <1>         jnc     change_prompt_dir_string
 17190                              <1> 
 17191                              <1> cd_error_messages:
 17192 000053B2 3C03                <1> 	cmp	al, 3
 17193 000053B4 740C                <1> 	je	short cd_path_not_found
 17194 000053B6 3C15                <1> 	cmp	al, 15h 
 17195 000053B8 745B                <1> 	je	short cd_drive_not_ready
 17196 000053BA 3C18                <1> 	cmp	al, 18h ; Bad request structure length 
 17197 000053BC 746C                <1> 	je	short cd_command_failed
 17198 000053BE 3C1A                <1> 	cmp	al, 1Ah ; Unknown media type, non-DOS disk
 17199 000053C0 7468                <1>         je      short cd_command_failed
 17200                              <1> 
 17201                              <1> cd_path_not_found:
 17202 000053C2 6650                <1> 	push	ax	
 17203 000053C4 BE[8BB10000]        <1> 	mov	esi, Msg_Dir_Not_Found
 17204 000053C9 E8BDEAFFFF          <1> 	call	print_msg
 17205 000053CE 6658                <1> 	pop	ax
 17206 000053D0 3A25[ACBE0000]      <1> 	cmp	ah, [Current_Dir_Level]
 17207 000053D6 0F83DC180000        <1>         jnb     change_prompt_dir_string
 17208 000053DC 8825[ACBE0000]      <1> 	mov	[Current_Dir_Level], ah
 17209 000053E2 E9D1180000          <1>         jmp     change_prompt_dir_string   
 17210                              <1> 
 17211                              <1> cmp_cmd_drive: ; change current drive
 17212                              <1> 	; C:, D:, E: etc.
 17213 000053E7 80FC3A              <1> 	cmp	ah, ':'
 17214 000053EA 0F8526020000        <1>         jne     loc_cmd_failed
 17215                              <1> 
 17216                              <1> cd_2:	; 'CD C:', 'CD D:' ...
 17217 000053F0 803E20              <1> 	cmp	byte [esi], 20h
 17218 000053F3 0F871D020000        <1>         ja      loc_cmd_failed
 17219                              <1> 
 17220 000053F9 24DF                <1> 	and	al, 0DFh
 17221 000053FB 2C41                <1> 	sub	al, 'A'
 17222 000053FD 0F8213020000        <1>         jc      loc_cmd_failed
 17223                              <1> 
 17224 00005403 3A05[7FAE0000]      <1>         cmp     al, [Last_DOS_DiskNo]
 17225 00005409 770A                <1>         ja	short cd_drive_not_ready
 17226                              <1> 	
 17227 0000540B 88C2                <1> 	mov	dl, al
 17228 0000540D E87DF3FFFF          <1> 	call 	change_current_drive
 17229 00005412 7201                <1> 	jc	short cd_drive_not_ready	
 17230 00005414 C3                  <1> 	retn
 17231                              <1> 
 17232                              <1> cd_drive_not_ready:
 17233 00005415 BE[48B10000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17234 0000541A E86CEAFFFF          <1> 	call	print_msg
 17235                              <1> 
 17236                              <1> cd_fail_drive_restart:
 17237 0000541F 8A15[AEBE0000]      <1> 	mov	dl, [Current_Drv]
 17238                              <1> 	;call 	change_current_drive
 17239 00005425 E965F3FFFF          <1>         jmp     change_current_drive
 17240                              <1> 	;retn
 17241                              <1> 
 17242                              <1> cd_command_failed:
 17243 0000542A BE[29B10000]        <1> 	mov	esi, Msg_Bad_Command
 17244 0000542F E857EAFFFF          <1> 	call	print_msg
 17245 00005434 EBE9                <1> 	jmp	short cd_fail_drive_restart
 17246                              <1> 
 17247                              <1> c_3:
 17248                              <1> cmp_cmd_dir:
 17249 00005436 BF[DFAE0000]        <1> 	mov	edi, Cmd_Dir
 17250 0000543B E8E9010000          <1> 	call	cmp_cmd	
 17251 00005440 0F8388020000        <1> 	jnc	print_directory_list
 17252                              <1> 
 17253                              <1> cmp_cmd_cls:
 17254 00005446 B103                <1> 	mov	cl, 3
 17255 00005448 BF[1BAF0000]        <1> 	mov	edi, Cmd_Cls
 17256 0000544D E8D7010000          <1> 	call	cmp_cmd	
 17257 00005452 0F834AEAFFFF        <1>         jnc	clear_screen
 17258                              <1> 
 17259                              <1> cmp_cmd_ver:
 17260 00005458 B103                <1> 	mov	cl, 3
 17261 0000545A BF[E9AE0000]        <1> 	mov	edi, Cmd_Ver
 17262 0000545F E8C5010000          <1> 	call	cmp_cmd	
 17263 00005464 720A                <1> 	jc	short cmp_cmd_mem
 17264                              <1> 
 17265 00005466 BE[87AE0000]        <1> 	mov	esi, mainprog_Version
 17266                              <1> 	;call	print_msg
 17267 0000546B E91BEAFFFF          <1> 	jmp	print_msg
 17268                              <1> 	;retn
 17269                              <1> 
 17270                              <1> cmp_cmd_mem:
 17271 00005470 B103                <1> 	mov	cl, 3
 17272 00005472 BF[51AF0000]        <1> 	mov	edi, Cmd_Mem
 17273 00005477 E8AD010000          <1> 	call	cmp_cmd	
 17274 0000547C 0F83AFC4FFFF        <1> 	jnc	memory_info
 17275                              <1> 
 17276                              <1> cmp_cmd_del:
 17277 00005482 B103                <1> 	mov	cl, 3
 17278 00005484 BF[24AF0000]        <1> 	mov	edi, Cmd_Del
 17279 00005489 E89B010000          <1> 	call	cmp_cmd	
 17280 0000548E 0F83320F0000        <1>         jnc     delete_file
 17281                              <1> 
 17282                              <1> cmp_cmd_set:
 17283 00005494 B103                <1> 	mov	cl, 3
 17284 00005496 BF[17AF0000]        <1> 	mov	edi, Cmd_Set
 17285 0000549B E889010000          <1> 	call	cmp_cmd	
 17286 000054A0 0F830B180000        <1>         jnc     set_get_env
 17287                              <1> 
 17288                              <1> cmp_cmd_run:
 17289 000054A6 B103                <1> 	mov	cl, 3
 17290 000054A8 BF[13AF0000]        <1> 	mov	edi, Cmd_Run
 17291 000054AD E877010000          <1> 	call	cmp_cmd	
 17292 000054B2 0F825E010000        <1>         jc      loc_cmd_failed
 17293                              <1> 
 17294 000054B8 E8F5170000          <1> 	call	set_exec_arguments
 17295 000054BD 0F8253010000        <1>         jc      loc_cmd_failed
 17296                              <1> 
 17297 000054C3 E8EB170000          <1> 	call	load_and_execute_file
 17298 000054C8 0F8273010000        <1>         jc      loc_run_cmd_failed
 17299 000054CE C3                  <1> 	retn
 17300                              <1> 
 17301                              <1> c_5:
 17302                              <1> cmp_cmd_mkdir:
 17303 000054CF BF[3CAF0000]        <1> 	mov	edi, Cmd_Mkdir
 17304 000054D4 E850010000          <1> 	call	cmp_cmd	
 17305 000054D9 0F837F0A0000        <1>         jnc     make_directory
 17306                              <1> 
 17307                              <1> cmp_cmd_rmdir:
 17308 000054DF B105                <1> 	mov	cl, 5
 17309 000054E1 BF[36AF0000]        <1> 	mov	edi, Cmd_Rmdir
 17310 000054E6 E83E010000          <1> 	call	cmp_cmd	
 17311 000054EB 0F838C0B0000        <1>         jnc     delete_directory
 17312                              <1> 
 17313                              <1> cmp_cmd_chdir:
 17314 000054F1 B105                <1> 	mov	cl, 5
 17315 000054F3 BF[7CAF0000]        <1> 	mov	edi, Cmd_Chdir
 17316 000054F8 E82C010000          <1> 	call	cmp_cmd	
 17317 000054FD 0F8213010000        <1> 	jc	loc_cmd_failed
 17318                              <1> 
 17319 00005503 E98DFEFFFF          <1> 	jmp	cd_0
 17320                              <1> 
 17321                              <1> c_6:
 17322 00005508 80F906              <1> 	cmp	cl, 6
 17323 0000550B 0F87DF000000        <1>         ja      c_8
 17324 00005511 72BC                <1> 	jb	short c_5
 17325                              <1> cmp_cmd_prompt:
 17326 00005513 BF[F2AE0000]        <1> 	mov	edi, Cmd_Prompt
 17327 00005518 E80C010000          <1> 	call	cmp_cmd	
 17328 0000551D 722E                <1>         jc	short cmp_cmd_volume
 17329                              <1> get_prompt_name_fchar:
 17330 0000551F AC                  <1> 	lodsb
 17331 00005520 3C20                <1> 	cmp	al, 20h
 17332 00005522 74FB                <1> 	je	short get_prompt_name_fchar
 17333 00005524 7712                <1> 	ja	short loc_change_prompt_label
 17334 00005526 BE[D3AE0000]        <1> 	mov	esi, TRDOSPromptLabel
 17335 0000552B C7065452444F        <1> 	mov	dword [esi], "TRDO"
 17336 00005531 66C746045300        <1>        	mov	word [esi+4], "S" 
 17337                              <1> loc_cmd_prompt_return:
 17338 00005537 C3                  <1> 	retn
 17339                              <1> loc_change_prompt_label:
 17340 00005538 66B90B00            <1> 	mov	cx, 11
 17341 0000553C BF[D3AE0000]        <1> 	mov	edi, TRDOSPromptLabel
 17342                              <1> put_char_new_prompt_label:
 17343 00005541 AA                  <1> 	stosb
 17344 00005542 AC                  <1> 	lodsb
 17345 00005543 3C20                <1> 	cmp	al, 20h
 17346 00005545 7202                <1> 	jb	short pass_put_new_prompt_label
 17347 00005547 E2F8                <1> 	loop	put_char_new_prompt_label
 17348                              <1> pass_put_new_prompt_label:
 17349 00005549 C60700              <1> 	mov	byte [edi], 0
 17350 0000554C C3                  <1> 	retn
 17351                              <1> 
 17352                              <1> cmp_cmd_volume:
 17353 0000554D B106                <1> 	mov	cl, 6
 17354 0000554F BF[F9AE0000]        <1> 	mov	edi, Cmd_Volume
 17355 00005554 E8D0000000          <1> 	call	cmp_cmd	
 17356 00005559 7255                <1>         jc	short cmp_cmd_attrib
 17357                              <1> 
 17358                              <1> cmd_vol1:
 17359 0000555B AC                  <1> 	lodsb
 17360 0000555C 3C20                <1> 	cmp	al, 20h
 17361 0000555E 7707                <1> 	ja	short cmd_vol2
 17362 00005560 A0[AEBE0000]        <1> 	mov	al, [Current_Drv]
 17363 00005565 EB3D                <1> 	jmp	short cmd_vol4
 17364                              <1> cmd_vol2:
 17365 00005567 3C41                <1> 	cmp	al, 'A'
 17366 00005569 0F82A7000000        <1>         jb      loc_cmd_failed
 17367 0000556F 3C7A                <1> 	cmp	al, 'z'
 17368 00005571 0F879F000000        <1>         ja      loc_cmd_failed
 17369 00005577 3C5A                <1> 	cmp	al, 'Z'
 17370 00005579 760A                <1> 	jna	short cmd_vol3
 17371 0000557B 3C61                <1> 	cmp	al, 'a'
 17372 0000557D 0F8293000000        <1>         jb      loc_cmd_failed
 17373 00005583 24DF                <1> 	and	al, 0DFh
 17374                              <1> cmd_vol3:
 17375 00005585 8A26                <1> 	mov	ah, [esi]
 17376 00005587 80FC3A              <1> 	cmp	ah, ':'
 17377 0000558A 0F8586000000        <1>         jne     loc_cmd_failed
 17378 00005590 2C41                <1> 	sub	al, 'A'
 17379 00005592 3A05[7FAE0000]      <1>         cmp     al, [Last_DOS_DiskNo]
 17380 00005598 760A                <1> 	jna	short cmd_vol4
 17381                              <1> 
 17382 0000559A BE[48B10000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17383 0000559F E9E7E8FFFF          <1> 	jmp	print_msg
 17384                              <1> 	
 17385                              <1> cmd_vol4:
 17386 000055A4 E89CFAFFFF          <1> 	call	print_volume_info
 17387 000055A9 0F8266FEFFFF        <1>         jc      cd_drive_not_ready
 17388 000055AF C3                  <1> 	retn
 17389                              <1> 
 17390                              <1> cmp_cmd_attrib:
 17391 000055B0 B106                <1> 	mov	cl, 6
 17392 000055B2 BF[28AF0000]        <1> 	mov	edi, Cmd_Attrib
 17393 000055B7 E86D000000          <1> 	call	cmp_cmd	
 17394 000055BC 0F83240F0000        <1>         jnc     set_file_attributes
 17395                              <1> 
 17396                              <1> cmp_cmd_rename:
 17397 000055C2 B106                <1> 	mov	cl, 6
 17398 000055C4 BF[2FAF0000]        <1> 	mov	edi, Cmd_Rename
 17399 000055C9 E85B000000          <1> 	call	cmp_cmd	
 17400 000055CE 0F835A110000        <1>         jnc     rename_file
 17401                              <1> 
 17402                              <1> cmp_cmd_device:
 17403 000055D4 B106                <1> 	mov	cl, 6
 17404 000055D6 BF[6DAF0000]        <1> 	mov	edi, Cmd_Device
 17405 000055DB E849000000          <1> 	call	cmp_cmd	
 17406 000055E0 7234                <1>         jc	short loc_cmd_failed
 17407                              <1> 
 17408 000055E2 C3                  <1> 	retn
 17409                              <1> 
 17410                              <1> c_7:
 17411                              <1> cmp_cmd_devlist:
 17412 000055E3 BF[74AF0000]        <1> 	mov	edi, Cmd_DevList
 17413 000055E8 E83C000000          <1> 	call	cmp_cmd	
 17414 000055ED 7227                <1>         jc	short loc_cmd_failed
 17415                              <1> 
 17416 000055EF C3                  <1> 	retn
 17417                              <1> 
 17418                              <1> c_8:
 17419 000055F0 80F908              <1>         cmp	cl, 8
 17420 000055F3 7721                <1> 	ja	short cmp_cmd_external
 17421 000055F5 72EC                <1> 	jb	short c_7
 17422                              <1> 
 17423                              <1> cmp_cmd_longname:
 17424 000055F7 BF[00AF0000]        <1> 	mov	edi, Cmd_LongName
 17425 000055FC E828000000          <1> 	call	cmp_cmd	
 17426 00005601 0F8341060000        <1>         jnc     get_and_print_longname
 17427                              <1> 
 17428                              <1> cmp_cmd_readfile:
 17429 00005607 B108                <1> 	mov	cl, 8
 17430 00005609 BF[5BAF0000]        <1> 	mov	edi, Cmd_ReadFile
 17431 0000560E E816000000          <1> 	call	cmp_cmd	
 17432 00005613 7201                <1>         jc	short loc_cmd_failed
 17433                              <1> 
 17434                              <1> loc_cmd_return:
 17435 00005615 C3                  <1> 	retn
 17436                              <1> 
 17437                              <1> cmp_cmd_external:
 17438                              <1> loc_cmd_failed:
 17439 00005616 803D[5EBF0000]20    <1> 	cmp	byte [CommandBuffer], 20h
 17440 0000561D 76F6                <1> 	jna	short loc_cmd_return
 17441 0000561F BE[29B10000]        <1> 	mov	esi, Msg_Bad_Command
 17442                              <1> ;	call	print_msg
 17443                              <1> ;loc_cmd_return:
 17444                              <1> ;	retn
 17445 00005624 E962E8FFFF          <1> 	jmp	print_msg
 17446                              <1> 
 17447                              <1> cmp_cmd:
 17448                              <1> 	 ; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
 17449 00005629 BE[5EBF0000]        <1>          mov  esi, CommandBuffer
 17450                              <1>          ; edi = internal command word (ASCIIZ)
 17451                              <1> 	 ; ecx = command length (<=8)
 17452                              <1> cmp_cmd_1:
 17453 0000562E AC                  <1> 	lodsb
 17454 0000562F AE                  <1> 	scasb
 17455 00005630 750D                <1> 	jne	short cmp_cmd_3
 17456 00005632 E2FA                <1> 	loop	cmp_cmd_1
 17457 00005634 AC                  <1>  	lodsb
 17458 00005635 3C20                <1> 	cmp	al, 20h
 17459 00005637 7703                <1> 	ja	short cmp_cmd_2
 17460 00005639 30C0                <1> 	xor	al, al
 17461                              <1> 	; ZF = 1 -> internal command word matches
 17462 0000563B C3                  <1> 	retn
 17463                              <1> cmp_cmd_2:
 17464                              <1> 	; ZF = 0 (CF = 0) -> external command word 	
 17465 0000563C 58                  <1> 	pop	eax ; no return to the caller from here 
 17466 0000563D EBD7                <1> 	jmp	cmp_cmd_external	
 17467                              <1> cmp_cmd_3:
 17468 0000563F F9                  <1> 	stc
 17469                              <1> 	; CF = 1 -> internal command word does not match
 17470 00005640 C3                  <1> 	retn
 17471                              <1> 
 17472                              <1> loc_run_cmd_failed:
 17473                              <1> 	; 15/03/2016
 17474                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17475                              <1> 	; 07/12/2009 (CMD_INTR.ASM)	
 17476                              <1> 	; 29/11/2009
 17477                              <1> 
 17478 00005641 E855000000          <1> 	call	restore_cdir_after_cmd_fail
 17479                              <1> 
 17480                              <1> loc_run_cmd_failed_cmp_al:
 17481                              <1> 	; End of Restore_CDIR code (29/11/2009)
 17482                              <1> 
 17483 00005646 3C01                <1> 	cmp	al, 1
 17484 00005648 74CC                <1> 	je	loc_cmd_failed
 17485                              <1> loc_run_dir_not_found:
 17486 0000564A 3C03                <1> 	cmp	al, 3
 17487 0000564C 750A                <1> 	jne	short loc_run_file_notfound_msg
 17488                              <1> 	; Path not found (MS-DOS Error Code = 3)
 17489 0000564E BE[8BB10000]        <1> 	mov	esi, Msg_Dir_Not_Found
 17490 00005653 E933E8FFFF          <1> 	jmp	print_msg
 17491                              <1> 
 17492                              <1> loc_run_file_notfound_msg:
 17493 00005658 3C02                <1> 	cmp	al, 2 ; File not found
 17494 0000565A 750A                <1> 	jne	short loc_run_file_drv_read_err
 17495                              <1> 
 17496                              <1> loc_print_file_notfound_msg: 
 17497 0000565C BE[A2B10000]        <1>         mov     esi, Msg_File_Not_Found
 17498                              <1> 	;call	proc_printmsg
 17499                              <1> 	;retn
 17500 00005661 E925E8FFFF          <1> 	jmp	print_msg
 17501                              <1> 
 17502                              <1> loc_run_file_drv_read_err:
 17503                              <1> 	; Err: 1Eh (Read fault)
 17504 00005666 3C1E                <1> 	cmp	al, 1Eh ; Drive not ready or read error
 17505 00005668 7404                <1> 	je	short loc_run_file_print_drv_read_err
 17506                              <1> 	;
 17507 0000566A 3C15                <1> 	cmp	al, 15h ; Drive not ready (or read error)
 17508 0000566C 750A                <1> 	jne	short loc_run_file_toobig
 17509                              <1> 
 17510                              <1> loc_run_file_print_drv_read_err:
 17511 0000566E BE[48B10000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17512 00005673 E913E8FFFF          <1> 	jmp	print_msg
 17513                              <1> 
 17514                              <1> loc_run_file_toobig:
 17515 00005678 3C08                <1> 	cmp	al, 8 ; Not enough free memory to load&run file
 17516 0000567A 750A                <1> 	jne	short loc_run_misc_error
 17517 0000567C BE[EAB10000]        <1> 	mov	esi, Msg_Insufficient_Memory
 17518 00005681 E905E8FFFF          <1> 	jmp	print_msg
 17519                              <1> 
 17520                              <1> 	; 15/03/2016
 17521                              <1> print_misc_error_msg:
 17522                              <1> loc_run_misc_error:
 17523                              <1> 	; AL = Error code
 17524 00005686 E81CC3FFFF          <1> 	call	bytetohex
 17525 0000568B 66A3[1EB20000]      <1>         mov     [error_code_hex], ax
 17526                              <1>                 
 17527 00005691 BE[01B20000]        <1> 	mov	esi, Msg_Error_Code 
 17528                              <1> 	;call	print_msg 
 17529                              <1> 	;retn
 17530                              <1> 
 17531 00005696 E9F0E7FFFF          <1> 	jmp	print_msg
 17532                              <1> 
 17533                              <1> restore_cdir_after_cmd_fail:
 17534                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17535 0000569B 50                  <1> 	push	eax
 17536 0000569C 8A3D[0EC70000]      <1> 	mov	bh, [RUN_CDRV] ; it is set at the beginning
 17537                              <1> 				; of the 'run' command.
 17538 000056A2 3A3D[AEBE0000]      <1> 	cmp	bh, [Current_Drv]
 17539 000056A8 7409                <1> 	je	short loc_run_restore_cdir
 17540 000056AA 88FA                <1> 	mov	dl, bh
 17541 000056AC E8DEF0FFFF          <1> 	call	change_current_drive 
 17542 000056B1 EB19                <1> 	jmp	short loc_run_err_pass_restore_cdir
 17543                              <1> 
 17544                              <1> loc_run_restore_cdir:
 17545 000056B3 803D[80AE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
 17546 000056BA 7610                <1> 	jna	short loc_run_err_pass_restore_cdir
 17547 000056BC 30DB                <1> 	xor	bl, bl
 17548 000056BE 0FB7F3              <1> 	movzx	esi, bx
 17549 000056C1 81C600010900        <1> 	add	esi, Logical_DOSDisks
 17550 000056C7 E875F1FFFF          <1> 	call	restore_current_directory
 17551                              <1> 
 17552                              <1> loc_run_err_pass_restore_cdir:
 17553 000056CC 58                  <1> 	pop	eax
 17554 000056CD C3                  <1> 	retn
 17555                              <1> 
 17556                              <1> print_directory_list:
 17557                              <1> 	; 10/02/2016
 17558                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17559                              <1> 	; 06/12/2009 ('cmp_cmd_dir')	
 17560                              <1> 	;
 17561 000056CE 66C705[50C80000]00- <1> 	mov	word [AttributesMask], 0800h ; ..except volume names..
 17562 000056D6 08                  <1>
 17563 000056D7 A0[AEBE0000]        <1> 	mov	al, [Current_Drv]
 17564 000056DC A2[0EC70000]        <1> 	mov	[RUN_CDRV], al
 17565                              <1> get_dfname_fchar:
 17566 000056E1 AC                  <1> 	lodsb
 17567 000056E2 3C20                <1> 	cmp	al, 20h
 17568 000056E4 74FB                <1> 	je	short get_dfname_fchar
 17569 000056E6 0F82A4000000        <1>         jb      loc_print_dir_call_all
 17570 000056EC 3C2D                <1> 	cmp	al, '-'
 17571 000056EE 7542                <1> 	jne	short loc_print_dir_call_flt
 17572                              <1> get_next_attr_char:
 17573 000056F0 AC                  <1> 	lodsb
 17574 000056F1 3C20                <1> 	cmp	al, 20h
 17575 000056F3 74FB                <1> 	je	short get_next_attr_char
 17576 000056F5 0F821BFFFFFF        <1>         jb      loc_cmd_failed
 17577 000056FB 24DF                <1> 	and	al, 0DFh
 17578 000056FD 3C44                <1> 	cmp	al, 'D' ; directories only ?
 17579 000056FF 7512                <1> 	jne	short pass_only_directories
 17580 00005701 AC                  <1> 	lodsb
 17581 00005702 3C20                <1> 	cmp	al, 20h
 17582 00005704 0F870CFFFFFF        <1>         ja      loc_cmd_failed
 17583 0000570A 800D[50C80000]10    <1> 	or	byte [AttributesMask], 10h ; ..directory..
 17584 00005711 EB18                <1> 	jmp	short get_dfname_fchar_attr
 17585                              <1> pass_only_directories:
 17586 00005713 3C46                <1> 	cmp	al, 'F'	; files only ?
 17587 00005715 0F85B0000000        <1>         jne     check_attr_s
 17588 0000571B AC                  <1> 	lodsb
 17589 0000571C 3C20                <1> 	cmp	al, 20h
 17590 0000571E 0F87F2FEFFFF        <1>         ja      loc_cmd_failed
 17591 00005724 800D[51C80000]10    <1> 	or	byte [AttributesMask+1], 10h ; ..except directories..
 17592                              <1> get_dfname_fchar_attr:
 17593 0000572B AC                  <1> 	lodsb
 17594 0000572C 3C20                <1> 	cmp	al, 20h
 17595 0000572E 74FB                <1> 	je	short get_dfname_fchar_attr
 17596 00005730 725E                <1> 	jb	short loc_print_dir_call_all
 17597                              <1> 
 17598                              <1> loc_print_dir_call_flt:
 17599 00005732 4E                  <1> 	dec	esi
 17600 00005733 BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 17601 00005738 E86F1C0000          <1> 	call	parse_path_name
 17602 0000573D 7308                <1>  	jnc	short loc_print_dir_change_drv_1
 17603 0000573F 3C01                <1> 	cmp	al, 1
 17604 00005741 0F87FAFEFFFF        <1>         ja      loc_run_cmd_failed
 17605                              <1> 
 17606                              <1> loc_print_dir_change_drv_1:
 17607 00005747 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 17608                              <1> loc_print_dir_change_drv_2:
 17609 0000574D 3A15[0EC70000]      <1> 	cmp	dl, [RUN_CDRV]
 17610 00005753 740B                <1> 	je	short loc_print_dir_change_directory 
 17611 00005755 E835F0FFFF          <1> 	call	change_current_drive
 17612 0000575A 0F82E1FEFFFF        <1>         jc      loc_run_cmd_failed
 17613                              <1> loc_print_dir_change_directory:
 17614 00005760 803D[53C80000]20    <1> 	cmp	byte [FindFile_Directory], 20h ; 0 or 20h ?
 17615 00005767 761D                <1> 	jna	short pass_print_dir_change_directory
 17616                              <1> 
 17617 00005769 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 17618 0000576F BE[53C80000]        <1> 	mov	esi, FindFile_Directory
 17619 00005774 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 17620 00005776 E81D160000          <1> 	call	change_current_directory
 17621 0000577B 0F82C0FEFFFF        <1>         jc      loc_run_cmd_failed
 17622                              <1> 
 17623                              <1> loc_print_dir_change_prompt_dir_string:
 17624 00005781 E832150000          <1> 	call	change_prompt_dir_string
 17625                              <1> 
 17626                              <1> pass_print_dir_change_directory:
 17627 00005786 BE[94C80000]        <1> 	mov	esi, FindFile_Name
 17628 0000578B 803E20              <1> 	cmp	byte [esi], 20h ; ; 0 or 20h ?
 17629 0000578E 7706                <1> 	ja	short loc_print_dir_call
 17630                              <1> 
 17631                              <1> loc_print_dir_call_all:
 17632 00005790 C7062A2E2A00        <1> 	mov	dword [esi], '*.*'
 17633                              <1> loc_print_dir_call:
 17634 00005796 E87E000000          <1> 	call	print_directory
 17635                              <1> 
 17636 0000579B 8A15[0EC70000]      <1> 	mov	dl, [RUN_CDRV]  ; it is set at the beginning
 17637 000057A1 3A15[AEBE0000]      <1> 	cmp	dl, [Current_Drv]
 17638 000057A7 7406                <1> 	je	short loc_print_dir_call_restore_cdir_retn
 17639 000057A9 E8E1EFFFFF          <1> 	call	change_current_drive 
 17640 000057AE C3                  <1> 	retn
 17641                              <1> 
 17642                              <1> loc_print_dir_call_restore_cdir_retn:
 17643 000057AF 803D[80AE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
 17644 000057B6 7610                <1> 	jna	short pass_print_dir_call_restore_cdir_retn
 17645                              <1> 
 17646 000057B8 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17647 000057BD 31C0                <1> 	xor	eax, eax
 17648 000057BF 88D4                <1> 	mov	ah, dl
 17649 000057C1 01C6                <1> 	add	esi, eax
 17650                              <1> 
 17651 000057C3 E879F0FFFF          <1> 	call	restore_current_directory
 17652                              <1> 
 17653                              <1> pass_print_dir_call_restore_cdir_retn:
 17654 000057C8 C3                  <1> 	retn
 17655                              <1> 
 17656                              <1> check_attr_s_cap:
 17657 000057C9 24DF                <1> 	and	al, 0DFh
 17658                              <1> check_attr_s:
 17659 000057CB 3C53                <1> 	cmp	al, 'S'
 17660 000057CD 7514                <1> 	jne	short pass_attr_s
 17661 000057CF 800D[50C80000]04    <1> 	or	byte [AttributesMask], 4 ; system
 17662 000057D6 AC                  <1> 	lodsb
 17663 000057D7 3C20                <1> 	cmp	al, 20h
 17664 000057D9 0F844CFFFFFF        <1>         je      get_dfname_fchar_attr
 17665 000057DF 72AF                <1> 	jb	short loc_print_dir_call_all
 17666 000057E1 24DF                <1> 	and	al, 0DFh
 17667                              <1> pass_attr_s:
 17668 000057E3 3C48                <1> 	cmp	al, 'H'
 17669 000057E5 7514                <1> 	jne	short pass_attr_h
 17670 000057E7 800D[50C80000]02    <1> 	or	byte [AttributesMask], 2 ; hidden
 17671                              <1> pass_attr_shr:
 17672 000057EE AC                  <1> 	lodsb
 17673 000057EF 3C20                <1> 	cmp	al, 20h
 17674 000057F1 0F8434FFFFFF        <1>         je      get_dfname_fchar_attr
 17675 000057F7 7297                <1> 	jb	short loc_print_dir_call_all
 17676 000057F9 EBCE                <1> 	jmp	short check_attr_s_cap
 17677                              <1> 
 17678                              <1> pass_attr_h:
 17679 000057FB 3C52                <1> 	cmp	al, 'R'
 17680 000057FD 7509                <1> 	jne	short pass_attr_r
 17681 000057FF 800D[50C80000]01    <1> 	or	byte [AttributesMask], 1 ; read only
 17682 00005806 EBE6                <1> 	jmp	short pass_attr_shr
 17683                              <1> 
 17684                              <1> pass_attr_r:
 17685 00005808 3C41                <1> 	cmp	al, 'A'
 17686 0000580A 0F8506FEFFFF        <1>         jne     loc_cmd_failed
 17687 00005810 800D[50C80000]20    <1> 	or	byte [AttributesMask], 20h ; archive
 17688 00005817 EBD5                <1> 	jmp	short pass_attr_shr
 17689                              <1> 
 17690                              <1> print_directory:
 17691                              <1> 	; 11/02/2016
 17692                              <1> 	; 10/02/2016
 17693                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17694                              <1> 	; 30/10/2010 ('proc_print_directory')	
 17695                              <1> 	; 19/09/2009
 17696                              <1> 	; 2005 
 17697                              <1> 	; INPUT ->
 17698                              <1> 	;	ESI = Asciiz File/Dir Name Address
 17699                              <1> 
 17700 00005819 56                  <1> 	push	esi
 17701                              <1> 
 17702 0000581A 29C0                <1> 	sub	eax, eax
 17703                              <1> 
 17704 0000581C 66A3[DCC80000]      <1> 	mov	word [Dir_Count], ax ; 0
 17705 00005822 66A3[DAC80000]      <1> 	mov 	word [File_Count], ax ; 0
 17706 00005828 A3[DEC80000]        <1> 	mov 	dword [Total_FSize], eax ; 0
 17707                              <1> 
 17708 0000582D E870E6FFFF          <1> 	call    clear_screen
 17709                              <1> 	
 17710 00005832 31C9                <1> 	xor	ecx, ecx	
 17711 00005834 8A2D[AEBE0000]      <1> 	mov     ch, [Current_Drv] ; DirBuff_Drv - 'A'
 17712 0000583A A0[AFBE0000]        <1> 	mov     al, [Current_Dir_Drv] 
 17713 0000583F A2[46B00000]        <1> 	mov     [Dir_Drive_Name], al
 17714 00005844 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17715 00005849 01CE                <1> 	add	esi, ecx
 17716                              <1> 
 17717 0000584B E86FF9FFFF          <1> 	call	move_volume_name_and_serial_no
 17718 00005850 7306                <1> 	jnc	short print_dir_strlen_check
 17719                              <1> 
 17720 00005852 5E                  <1> 	pop	esi
 17721                              <1> 	;call	beeper
 17722                              <1> 	;retn
 17723 00005853 E93DC0FFFF          <1> 	jmp	beeper  ; beep ! and return
 17724                              <1> 
 17725                              <1> print_dir_strlen_check:
 17726 00005858 BE[B1BE0000]        <1> 	mov	esi, Current_Dir_Root
 17727 0000585D BF[E3B00000]        <1> 	mov	edi, Dir_Str_Root
 17728                              <1> 	
 17729                              <1> 	;xor	ecx, ecx
 17730 00005862 8A0D[0DBF0000]      <1>         mov     cl, [Current_Dir_StrLen]
 17731 00005868 FEC1                <1> 	inc	cl
 17732 0000586A 80F940              <1> 	cmp	cl, 64
 17733 0000586D 760D                <1> 	jna	short pass_print_dir_strlen_shorting
 17734 0000586F 46                  <1> 	inc	esi
 17735 00005870 01CE                <1> 	add	esi, ecx
 17736 00005872 83EE40              <1> 	sub	esi, 64 
 17737 00005875 47                  <1> 	inc	edi
 17738 00005876 B82E2E2E20          <1> 	mov	eax, '... ' 
 17739 0000587B AB                  <1> 	stosd
 17740                              <1>  
 17741                              <1> pass_print_dir_strlen_shorting:
 17742 0000587C F3A4                <1> 	rep	movsb
 17743                              <1> 
 17744 0000587E BE[39B00000]        <1> 	mov	esi, Dir_Drive_Str
 17745 00005883 E803E6FFFF          <1> 	call	print_msg
 17746                              <1> 
 17747 00005888 BE[98B00000]        <1> 	mov	esi, Vol_Serial_Header
 17748 0000588D E8F9E5FFFF          <1> 	call	print_msg
 17749                              <1> 
 17750 00005892 BE[D8B00000]        <1> 	mov	esi, Dir_Str_Header
 17751 00005897 E8EFE5FFFF          <1> 	call	print_msg
 17752                              <1> 	
 17753 0000589C BE[C4BA0000]        <1> 	mov	esi, next2line
 17754 000058A1 E8E5E5FFFF          <1> 	call	print_msg
 17755                              <1> 
 17756                              <1> loc_print_dir_first_file:
 17757 000058A6 C605[F1C80000]10    <1> 	mov	byte [PrintDir_RowCounter], 16
 17758 000058AD 66A1[50C80000]      <1> 	mov	ax, [AttributesMask]
 17759 000058B3 5E                  <1> 	pop	esi
 17760                              <1> 
 17761 000058B4 E859020000          <1> 	call	find_first_file
 17762 000058B9 0F826F010000        <1>         jc      loc_dir_ok
 17763                              <1> 	 
 17764                              <1> loc_dfname_use_this:
 17765                              <1> 	; bl =	File Attributes (bh = Long Name Entry Length)
 17766 000058BF F6C310              <1> 	test	bl, 10h  ; Is it a directory?
 17767 000058C2 741B                <1> 	jz	short loc_not_dir
 17768                              <1> 
 17769 000058C4 66FF05[DCC80000]    <1> 	inc	word [Dir_Count]
 17770 000058CB 89F2                <1> 	mov	edx, esi 	; FindFile_DirEntry address
 17771 000058CD BE[24B20000]        <1>  	mov	esi, Type_Dir	; '<DIR>     '
 17772 000058D2 BF[3BB20000]        <1> 	mov	edi, Dir_Or_FileSize
 17773                              <1> 	; move 10 bytes
 17774 000058D7 A5                  <1> 	movsd
 17775 000058D8 A5                  <1> 	movsd
 17776 000058D9 66A5                <1> 	movsw	    	
 17777 000058DB 89D6                <1> 	mov	esi, edx
 17778 000058DD EB36                <1> 	jmp     short loc_dir_attribute
 17779                              <1> 
 17780                              <1> loc_not_dir:
 17781 000058DF 66FF05[DAC80000]    <1> 	inc	word [File_Count]
 17782 000058E6 0105[DEC80000]      <1> 	add	[Total_FSize], eax
 17783                              <1> 
 17784 000058EC B90A000000          <1> 	mov	ecx, 10  ; 32 bit divisor
 17785 000058F1 89CF                <1> 	mov	edi, ecx
 17786 000058F3 81C7[3BB20000]      <1> 	add	edi, Dir_Or_FileSize
 17787                              <1> loc_dir_rdivide:
 17788 000058F9 29D2                <1> 	sub	edx, edx
 17789 000058FB F7F1                <1> 	div	ecx 	 ; remainder in dl (< 10)
 17790 000058FD 80C230              <1> 	add     dl, '0'	 ; to make visible (ascii)
 17791 00005900 4F                  <1> 	dec	edi
 17792 00005901 8817                <1> 	mov     [edi], dl
 17793 00005903 21C0                <1> 	and	eax, eax
 17794 00005905 75F2                <1> 	jnz	short loc_dir_rdivide
 17795                              <1> 
 17796                              <1> loc_dir_fill_space:
 17797 00005907 81FF[3BB20000]      <1> 	cmp     edi, Dir_Or_FileSize
 17798 0000590D 7606                <1> 	jna     short loc_dir_attribute
 17799 0000590F 4F                  <1> 	dec     edi
 17800 00005910 C60720              <1> 	mov     byte [edi], 20h
 17801 00005913 EBF2                <1> 	jmp     short loc_dir_fill_space
 17802                              <1> 
 17803                              <1> loc_dir_attribute:
 17804 00005915 C705[46B20000]2020- <1> 	mov	dword [File_Attribute], 20202020h
 17805 0000591D 2020                <1>
 17806                              <1> 
 17807 0000591F 80FB20              <1> 	cmp	bl, 20h  ; Is it an archive file?
 17808 00005922 7207                <1> 	jb	short loc_dir_pass_arch
 17809 00005924 C605[49B20000]41    <1> 	mov	byte [File_Attribute+3], 'A'
 17810                              <1> 
 17811                              <1> loc_dir_pass_arch:
 17812 0000592B 80E307              <1> 	and	bl, 7
 17813 0000592E 7428                <1> 	jz	short loc_dir_file_name
 17814 00005930 88DF                <1> 	mov	bh, bl
 17815 00005932 80E303              <1> 	and	bl, 3
 17816 00005935 38DF                <1> 	cmp	bh, bl
 17817 00005937 7607                <1> 	jna	short loc_dir_pass_s
 17818 00005939 C605[46B20000]53    <1> 	mov	byte [File_Attribute], 'S'
 17819                              <1> 
 17820                              <1> loc_dir_pass_s:
 17821 00005940 80E302              <1> 	and     bl,2
 17822 00005943 7407                <1> 	jz      short loc_dir_pass_h
 17823 00005945 C605[47B20000]48    <1> 	mov     byte [File_Attribute+1], 'H'
 17824                              <1> loc_dir_pass_h:
 17825 0000594C 80E701              <1> 	and     bh,1
 17826 0000594F 7407                <1> 	jz      short loc_dir_file_name
 17827 00005951 C605[48B20000]52    <1> 	mov     byte [File_Attribute+2], 'R'
 17828                              <1> loc_dir_file_name:
 17829                              <1> 	;mov     bx, [esi+18h] ; Date
 17830                              <1> 	;mov     dx, [esi+16h] ; Time
 17831 00005958 8B5E16              <1> 	mov	ebx, [esi+16h]
 17832 0000595B 89F1                <1> 	mov	ecx, esi ; FindFile_DirEntry address
 17833 0000595D BF[2EB20000]        <1> 	mov     edi, File_Name
 17834                              <1> 	; move 8 bytes
 17835 00005962 A5                  <1> 	movsd
 17836 00005963 A5                  <1> 	movsd
 17837 00005964 C60720              <1> 	mov	byte [edi], 20h
 17838 00005967 47                  <1> 	inc	edi
 17839                              <1> 	; move 3 bytes
 17840 00005968 66A5                <1> 	movsw
 17841 0000596A A4                  <1> 	movsb
 17842 0000596B 89CE                <1> 	mov	esi, ecx
 17843                              <1> 
 17844                              <1> Dir_Time_start:
 17845                              <1> 	;mov	ax, dx		; Time
 17846 0000596D 6689D8              <1> 	mov	ax, bx
 17847 00005970 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
 17848 00005974 6683E03F            <1> 	and	ax, 0000111111b	; Minute Mask
 17849 00005978 D40A                <1> 	aam			; Q([AL]/10)->AH
 17850                              <1> 				; R([AL]/10)->AL
 17851                              <1> 				; [AL]+[AH]= Minute as BCD
 17852 0000597A 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
 17853 0000597E 86E0                <1> 	xchg	ah, al
 17854 00005980 66A3[59B20000]      <1> 	mov	[File_Minute], ax
 17855                              <1> 
 17856                              <1> 	;mov	al, dh
 17857 00005986 88F8                <1> 	mov	al, bh
 17858 00005988 C0E803              <1> 	shr	al, 3		; shift right 3 times
 17859 0000598B D40A                <1> 	aam			; [AL]+[AH]= Hours as BCD
 17860 0000598D 660D3030            <1> 	or	ax, '00'
 17861 00005991 86E0                <1> 	xchg	ah, al
 17862 00005993 66A3[56B20000]      <1> 	mov     [File_Hour], ax
 17863                              <1> 
 17864 00005999 C1EB10              <1> 	shr	ebx, 16		; BX = Date
 17865                              <1> 	
 17866                              <1> Dir_Date_start:
 17867 0000599C 6689D8              <1> 	mov	ax, bx		; Date
 17868 0000599F 6683E01F            <1> 	and	ax, 00011111b	; Day Mask
 17869 000059A3 D40A                <1> 	aam			; Q([AL]/10)->AH
 17870                              <1> 				; R([AL]/10)->AL
 17871                              <1> 				; [AL]+[AH]= Day as BCD
 17872 000059A5 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
 17873 000059A9 86C4                <1> 	xchg	al, ah
 17874                              <1> 
 17875 000059AB 66A3[4BB20000]      <1> 	mov	[File_Day], ax
 17876                              <1> 
 17877 000059B1 6689D8              <1> 	mov	ax, bx
 17878 000059B4 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
 17879 000059B8 6683E00F            <1> 	and	ax, 00001111b	; Month Mask
 17880 000059BC D40A                <1> 	aam
 17881 000059BE 660D3030            <1> 	or	ax, '00'
 17882 000059C2 86E0                <1> 	xchg	ah, al
 17883 000059C4 66A3[4EB20000]      <1> 	mov	[File_Month], ax
 17884                              <1> 
 17885 000059CA 6689D8              <1> 	mov	ax, bx
 17886 000059CD 66C1E809            <1> 	shr     ax, 9
 17887 000059D1 6683E07F            <1> 	and	ax, 01111111b	; Result = Year - 1980
 17888 000059D5 6605BC07            <1> 	add	ax, 1980
 17889                              <1> 
 17890 000059D9 B10A                <1> 	mov	cl, 10
 17891 000059DB F6F1                <1> 	div	cl		; Q -> AL, R -> AH 
 17892 000059DD 80CC30              <1> 	or	ah, '0'
 17893 000059E0 8825[54B20000]      <1> 	mov	[File_Year+3], ah
 17894 000059E6 D40A                <1> 	aam
 17895 000059E8 86E0                <1> 	xchg	ah, al
 17896 000059EA 80CC30              <1> 	or	ah, '0'	  ; Convert to ASCII
 17897 000059ED 8825[53B20000]      <1> 	mov	[File_Year+2], ah
 17898 000059F3 D40A                <1> 	aam
 17899 000059F5 86C4                <1> 	xchg	al, ah
 17900 000059F7 660D3030            <1> 	or	ax, '00'
 17901 000059FB 66A3[51B20000]      <1> 	mov	[File_Year], ax
 17902                              <1> 
 17903                              <1> loc_show_line:
 17904 00005A01 56                  <1> 	push	esi
 17905 00005A02 BE[2EB20000]        <1> 	mov     esi, File_Name
 17906 00005A07 E87FE4FFFF          <1> 	call	print_msg
 17907 00005A0C BE[C6BA0000]        <1> 	mov	esi, nextline
 17908 00005A11 E875E4FFFF          <1> 	call	print_msg
 17909 00005A16 5E                  <1> 	pop	esi
 17910                              <1> 
 17911 00005A17 FE0D[F1C80000]      <1> 	dec	byte [PrintDir_RowCounter]
 17912 00005A1D 0F84D4000000        <1>         jz      pause_dir_scroll
 17913                              <1> 
 17914                              <1> loc_next_entry:
 17915 00005A23 E899010000          <1> 	call	find_next_file
 17916 00005A28 0F8391FEFFFF        <1>         jnc     loc_dfname_use_this
 17917                              <1> 
 17918                              <1> loc_dir_ok:
 17919 00005A2E B90A000000          <1> 	mov     ecx, 10
 17920 00005A33 66A1[DCC80000]      <1> 	mov	ax, [Dir_Count]
 17921 00005A39 BF[6FB20000]        <1> 	mov	edi, Decimal_Dir_Count
 17922 00005A3E 6639C8              <1> 	cmp	ax, cx ; 10
 17923 00005A41 7216                <1> 	jb	short pass_ddc
 17924 00005A43 47                  <1> 	inc	edi
 17925 00005A44 6683F864            <1> 	cmp	ax, 100
 17926 00005A48 720F                <1> 	jb	short pass_ddc
 17927 00005A4A 47                  <1> 	inc	edi
 17928 00005A4B 663DE803            <1> 	cmp	ax, 1000
 17929 00005A4F 7208                <1> 	jb	short pass_ddc
 17930 00005A51 47                  <1> 	inc	edi
 17931 00005A52 663D1027            <1> 	cmp	ax, 10000
 17932 00005A56 7201                <1> 	jb	short pass_ddc
 17933 00005A58 47                  <1> 	inc	edi
 17934                              <1> pass_ddc:
 17935 00005A59 886F01              <1> 	mov     [edi+1], ch ; 0
 17936                              <1> loc_ddc_rediv:
 17937 00005A5C 31D2                <1> 	xor     edx, edx
 17938 00005A5E 66F7F1              <1> 	div     cx	; 10
 17939 00005A61 80C230              <1> 	add     dl, '0'
 17940 00005A64 8817                <1> 	mov     [edi], dl
 17941 00005A66 4F                  <1> 	dec     edi
 17942 00005A67 6609C0              <1> 	or	ax, ax
 17943 00005A6A 75F0                <1> 	jnz	short loc_ddc_rediv
 17944                              <1> 
 17945 00005A6C 66A1[DAC80000]      <1> 	mov     ax, [File_Count]
 17946 00005A72 BF[5EB20000]        <1> 	mov     edi, Decimal_File_Count
 17947 00005A77 6639C8              <1> 	cmp     ax, cx ; 10
 17948 00005A7A 7216                <1> 	jb      short pass_dfc
 17949 00005A7C 47                  <1> 	inc     edi
 17950 00005A7D 6683F864            <1> 	cmp     ax, 100
 17951 00005A81 720F                <1> 	jb      short pass_dfc
 17952 00005A83 47                  <1> 	inc     edi
 17953 00005A84 663DE803            <1> 	cmp     ax, 1000
 17954 00005A88 7208                <1> 	jb      short pass_dfc
 17955 00005A8A 47                  <1> 	inc     edi
 17956 00005A8B 663D1027            <1> 	cmp     ax, 10000
 17957 00005A8F 7201                <1> 	jb      short pass_dfc
 17958 00005A91 47                  <1> 	inc     edi
 17959                              <1> pass_dfc:
 17960                              <1> 	;mov    cx, 10
 17961 00005A92 886F01              <1> 	mov     [edi+1], ch ; 00
 17962                              <1> loc_dfc_rediv:
 17963                              <1> 	;xor	dx, dx
 17964 00005A95 30D2                <1> 	xor	dl, dl
 17965 00005A97 66F7F1              <1> 	div	cx
 17966 00005A9A 80C230              <1> 	add	dl, '0'
 17967 00005A9D 8817                <1> 	mov	[edi], dl
 17968 00005A9F 4F                  <1> 	dec	edi
 17969 00005AA0 6609C0              <1> 	or	ax, ax
 17970 00005AA3 75F0                <1> 	jnz	short loc_dfc_rediv
 17971                              <1> 
 17972 00005AA5 BF[F0C80000]        <1> 	mov     edi, TFS_Dec_End
 17973                              <1>         ;mov    byte [edi], 0
 17974 00005AAA A1[DEC80000]        <1> 	mov     eax, [Total_FSize]
 17975                              <1> 	;mov    ecx, 10
 17976                              <1> rediv_tfs_hex:
 17977                              <1> 	;sub	edx, edx
 17978 00005AAF 28D2                <1> 	sub	dl, dl
 17979 00005AB1 F7F1                <1> 	div	ecx
 17980 00005AB3 80C230              <1> 	add	dl, '0'
 17981 00005AB6 4F                  <1> 	dec     edi
 17982 00005AB7 8817                <1> 	mov     [edi], dl
 17983 00005AB9 21C0                <1> 	and	eax, eax
 17984 00005ABB 75F2                <1> 	jnz	short rediv_tfs_hex
 17985                              <1> 	
 17986 00005ABD 893D[E2C80000]      <1> 	mov	[TFS_Dec_Begin], edi
 17987 00005AC3 BE[5CB20000]        <1> 	mov	esi, Decimal_File_Count_Header
 17988 00005AC8 E8BEE3FFFF          <1> 	call	print_msg
 17989 00005ACD BE[64B20000]        <1> 	mov	esi, str_files
 17990 00005AD2 E8B4E3FFFF          <1> 	call	print_msg
 17991 00005AD7 BE[75B20000]        <1> 	mov	esi, str_dirs
 17992 00005ADC E8AAE3FFFF          <1> 	call	print_msg
 17993 00005AE1 8B35[E2C80000]      <1> 	mov	esi, [TFS_Dec_Begin]
 17994 00005AE7 E89FE3FFFF          <1> 	call	print_msg
 17995 00005AEC BE[86B20000]        <1> 	mov	esi, str_bytes
 17996 00005AF1 E895E3FFFF          <1> 	call	print_msg
 17997                              <1> 
 17998 00005AF6 C3                  <1> 	retn
 17999                              <1> 
 18000                              <1> pause_dir_scroll:
 18001 00005AF7 28E4                <1> 	sub	ah, ah           
 18002 00005AF9 E8E9B0FFFF          <1> 	call	int16h
 18003 00005AFE 3C1B                <1> 	cmp	al, 1Bh
 18004 00005B00 0F8428FFFFFF        <1>         je      loc_dir_ok
 18005 00005B06 C605[F1C80000]10    <1> 	mov	byte [PrintDir_RowCounter], 16 ; Reset counter
 18006 00005B0D E911FFFFFF          <1>         jmp     loc_next_entry
 18007                              <1> 
 18008                              <1> find_first_file:
 18009                              <1> 	; 11/02/2015
 18010                              <1> 	; 10/02/2016
 18011                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18012                              <1> 	; 09/10/2011
 18013                              <1> 	; 17/09/2009
 18014                              <1> 	; 2005
 18015                              <1> 	; INPUT ->
 18016                              <1> 	;	ESI = ASCIIZ File/Dir/Path Name Address
 18017                              <1> 	;	AL = Attributes AND mask (The AND result must be equal to AL)
 18018                              <1> 	;	      bit 0 = Read Only
 18019                              <1> 	;	      bir 1 = Hidden
 18020                              <1> 	;	      bit 2 = System
 18021                              <1> 	;	      bit 3 = Volume Label
 18022                              <1> 	;	      bit 4 = Directory
 18023                              <1> 	;	      bit 5 = Archive
 18024                              <1> 	;	      bit 6 = Reserved, must be 0
 18025                              <1> 	;	      bit 7 = Reserved, must be 0
 18026                              <1> 	;       AH = Attributes Negative AND mask (The AND result must be ZERO)
 18027                              <1> 	;
 18028                              <1> 	; OUTPUT ->
 18029                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
 18030                              <1> 	;	CF = 0 ->
 18031                              <1> 	;	     ESI = Directory Entry (FindFile_DirEntry) Location
 18032                              <1> 	;	     EDI = Directory Buffer Directory Entry Location
 18033                              <1> 	;	     EAX = File Size
 18034                              <1> 	;	      BL = Attributes of The File/Directory
 18035                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
 18036                              <1> 	;             DX > 0 : Ambiguous filename chars are used
 18037                              <1> 	;
 18038                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 18039                              <1> 
 18040 00005B12 66A3[A2C80000]      <1> 	mov	[FindFile_AttributesMask], ax
 18041 00005B18 BF[A4C80000]        <1> 	mov	edi, FindFile_DirEntry ; TR-DOS Fullfilename formatted buffer
 18042 00005B1D 31C0                <1> 	xor	eax, eax
 18043 00005B1F B90B000000          <1> 	mov	ecx, 11
 18044 00005B24 F3AB                <1> 	rep	stosd	; 44 bytes
 18045                              <1> 	;stosw		; +2 bytes 
 18046                              <1> 	    
 18047 00005B26 BF[94C80000]        <1> 	mov	edi, FindFile_Name ; FFF structure, offset 66
 18048 00005B2B 39FE                <1> 	cmp	esi, edi
 18049 00005B2D 7408                <1> 	je	short loc_fff_mfn_ok
 18050 00005B2F 89FA                <1> 	mov	edx, edi 
 18051                              <1> 	 ; move 13 bytes
 18052 00005B31 A5                  <1> 	movsd
 18053 00005B32 A5                  <1> 	movsd
 18054 00005B33 A5                  <1> 	movsd
 18055 00005B34 AA                  <1> 	stosb
 18056 00005B35 89D6                <1> 	mov	esi, edx
 18057                              <1> loc_fff_mfn_ok:
 18058 00005B37 BF[43C80000]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
 18059 00005B3C E8A0170000          <1> 	call	convert_file_name
 18060 00005B41 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
 18061                              <1> 
 18062 00005B43 66A1[A2C80000]      <1> 	mov	ax, [FindFile_AttributesMask]
 18063                              <1> 	;xor	ecx, ecx
 18064 00005B49 30C9                <1> 	xor	cl, cl  
 18065 00005B4B E89C140000          <1> 	call	locate_current_dir_file
 18066 00005B50 726E                <1> 	jc	short loc_fff_retn
 18067                              <1> 	; EDI = Directory Entry
 18068                              <1> 	; EBX = Directory Buffer Entry Index/Number
 18069                              <1> 
 18070                              <1> loc_fff_fnf_ln_check:
 18071 00005B52 30ED                <1> 	xor	ch, ch 
 18072 00005B54 80F60F              <1> 	xor	dh, 0Fh
 18073 00005B57 7408                <1> 	jz	short loc_fff_longname_yes
 18074 00005B59 882D[A1C80000]      <1> 	mov	[FindFile_LongNameYes], ch ; 0
 18075 00005B5F EB0C                <1> 	jmp	short loc_fff_longname_no
 18076                              <1> 
 18077                              <1> loc_fff_longname_yes:
 18078                              <1> 	;inc	byte [FindFile_LongNameYes]
 18079 00005B61 8A0D[AEC70000]      <1> 	mov	cl, [LFN_EntryLength]  
 18080 00005B67 880D[A1C80000]      <1> 	mov	[FindFile_LongNameEntryLength], cl ; FindFile_LongNameYes
 18081                              <1> 
 18082                              <1> loc_fff_longname_no:
 18083                              <1> 	;mov	bx, [DirBuff_CurrentEntry]
 18084 00005B6D 66891D[CCC80000]    <1> 	mov	[FindFile_DirEntryNumber], bx
 18085 00005B74 6689C2              <1> 	mov	dx, ax ; Ambigouos Filename chars used sign > 0
 18086                              <1> 
 18087 00005B77 A0[AEBE0000]        <1> 	mov	al, [Current_Drv]
 18088 00005B7C A2[52C80000]        <1> 	mov	[FindFile_Drv], al 
 18089                              <1> 
 18090 00005B81 A1[A8BE0000]        <1> 	mov	eax, [Current_Dir_FCluster]
 18091 00005B86 A3[C4C80000]        <1> 	mov	[FindFile_DirFirstCluster], eax
 18092                              <1> 
 18093 00005B8B A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 18094 00005B90 A3[C8C80000]        <1> 	mov	[FindFile_DirCluster], eax
 18095                              <1> 
 18096 00005B95 66FF05[CEC80000]    <1> 	inc	word [FindFile_MatchCounter]
 18097                              <1> 
 18098 00005B9C 89FB                <1> 	mov	ebx, edi
 18099 00005B9E 89FE                <1> 	mov	esi, edi
 18100 00005BA0 BF[A4C80000]        <1> 	mov	edi, FindFile_DirEntry
 18101 00005BA5 89F8                <1> 	mov	eax, edi
 18102 00005BA7 B108                <1> 	mov	cl, 8
 18103 00005BA9 F3A5                <1> 	rep	movsd
 18104 00005BAB 89C6                <1> 	mov	esi, eax
 18105 00005BAD 89DF                <1> 	mov	edi, ebx
 18106                              <1> 
 18107 00005BAF A1[C0C80000]        <1> 	mov	eax, [FindFile_DirEntry+28] ; File Size
 18108                              <1> 
 18109 00005BB4 8A1D[AFC80000]      <1> 	mov	bl, [FindFile_DirEntry+11] ; File Attributes 
 18110 00005BBA 8A3D[A1C80000]      <1> 	mov	bh, [FindFile_LongNameYes]
 18111                              <1> 
 18112                              <1> 	;mov	cx, [DirBuff_EntryCounter]
 18113                              <1> 	;mov	[FindFile_DirEntryNumber], cx
 18114                              <1> 	;mov	cx, [FindFile_DirEntryNumber]
 18115                              <1> 	; ecx = 0
 18116                              <1> 
 18117                              <1> loc_fff_retn:
 18118 00005BC0 C3                  <1> 	retn
 18119                              <1> 
 18120                              <1> find_next_file:
 18121                              <1> 	; 10/02/2016
 18122                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18123                              <1> 	; 06/02/2011
 18124                              <1> 	; 17/09/2009
 18125                              <1> 	; 2005
 18126                              <1> 	; INPUT ->
 18127                              <1> 	;	NONE, Find First File Parameters
 18128                              <1> 	; OUTPUT ->
 18129                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
 18130                              <1> 	;	CF = 0 -> 
 18131                              <1> 	;	    ESI = Directory Entry (FindFile_DirEntry) Location
 18132                              <1> 	;	    EDI = Directory Buffer Directory Entry Location
 18133                              <1> 	;	    EAX = File Size
 18134                              <1> 	;	      BL = Attributes of The File/Directory
 18135                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
 18136                              <1> 	;             DX > 0 : Ambiguous filename chars are used 
 18137                              <1> 	;
 18138                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 18139                              <1> 
 18140 00005BC1 66833D[CEC80000]00  <1> 	cmp	word [FindFile_MatchCounter], 0
 18141 00005BC9 7707                <1> 	ja	short loc_start_search_next_file
 18142                              <1> 
 18143                              <1> loc_fnf_stc_retn:
 18144 00005BCB F9                  <1> 	stc
 18145                              <1> loc_fnf_ax12h_retn:
 18146 00005BCC B812000000          <1> 	mov	eax, 12h ; 18, No More files
 18147                              <1> ;loc_fnf_retn:
 18148 00005BD1 C3                  <1> 	retn
 18149                              <1> 
 18150                              <1> loc_start_search_next_file:
 18151 00005BD2 668B1D[CCC80000]    <1> 	mov	bx, [FindFile_DirEntryNumber]
 18152 00005BD9 6643                <1> 	inc	bx
 18153 00005BDB 663B1D[DBC60000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 18154 00005BE2 7719                <1> 	ja	short loc_cont_search_next_file
 18155                              <1> 
 18156                              <1> loc_fnf_search:
 18157 00005BE4 BE[43C80000]        <1> 	mov	esi, Dir_Entry_Name
 18158 00005BE9 66A1[A2C80000]      <1> 	mov	ax, [FindFile_AttributesMask]
 18159 00005BEF 6631C9              <1> 	xor	cx, cx
 18160 00005BF2 E8F7140000          <1> 	call	find_directory_entry
 18161 00005BF7 0F8355FFFFFF        <1>         jnc     loc_fff_fnf_ln_check
 18162                              <1> 
 18163                              <1> loc_cont_search_next_file:
 18164 00005BFD 31DB                <1> 	xor	ebx, ebx
 18165 00005BFF 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 18166 00005C05 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 18167 00005C0A 01DE                <1> 	add	esi, ebx
 18168                              <1> 
 18169 00005C0C 803D[ACBE0000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 18170 00005C13 7608                <1> 	jna	short loc_fnf_check_FAT_type
 18171 00005C15 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 18172 00005C19 72B1                <1> 	jb	short loc_fnf_ax12h_retn
 18173 00005C1B EB06                <1> 	jmp	short loc_fnf_check_next_cluster
 18174                              <1>  
 18175                              <1> loc_fnf_check_FAT_type:
 18176 00005C1D 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
 18177 00005C21 72A9                <1> 	jb	short loc_fnf_ax12h_retn
 18178                              <1> 
 18179                              <1> loc_fnf_check_next_cluster:
 18180 00005C23 A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 18181 00005C28 E88D2E0000          <1> 	call	get_next_cluster
 18182 00005C2D 7306                <1> 	jnc	short loc_fnf_load_next_dir_cluster
 18183 00005C2F 09C0                <1> 	or	eax, eax
 18184 00005C31 7498                <1> 	jz	short loc_fnf_stc_retn
 18185                              <1> 	;mov	eax, 15h ;Drive not ready or read error
 18186 00005C33 F5                  <1>  	cmc	;stc
 18187                              <1> loc_fnf_retn:
 18188 00005C34 C3                  <1> 	retn
 18189                              <1> 
 18190                              <1> loc_fnf_load_next_dir_cluster:
 18191 00005C35 E866300000          <1> 	call	load_FAT_sub_directory
 18192 00005C3A 72F8                <1> 	jc	short loc_fnf_retn
 18193 00005C3C 6631DB              <1> 	xor	bx, bx
 18194 00005C3F 66891D[CCC80000]    <1> 	mov	[FindFile_DirEntryNumber], bx
 18195 00005C46 EB9C                <1> 	jmp	short loc_fnf_search
 18196                              <1> 
 18197                              <1> get_and_print_longname:
 18198                              <1> 	; 13/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18199                              <1> 	; 24/01/2010
 18200                              <1> 	; 17/10/2009 (CMD_INTR.ASM, 'cmp_cmd_longname')
 18201                              <1> get_longname_fchar:
 18202 00005C48 803E20              <1> 	cmp	byte [esi], 20h
 18203 00005C4B 7701                <1> 	ja	short loc_find_longname
 18204                              <1> 	;jb	short loc_longname_retn
 18205                              <1> 	;inc	esi
 18206                              <1> 	;je	short get_longname_fchar
 18207                              <1> ;loc_longname_retn:
 18208 00005C4D C3                  <1> 	retn
 18209                              <1> loc_find_longname:
 18210 00005C4E E802180000          <1> 	call	find_longname
 18211 00005C53 7320                <1> 	jnc	short loc_print_longname
 18212                              <1> 	
 18213 00005C55 08C0                <1> 	or	al, al
 18214 00005C57 7412                <1> 	jz	short loc_longname_not_found
 18215                              <1> 	  
 18216 00005C59 3C15                <1> 	cmp	al, 15h
 18217 00005C5B 0F84B4F7FFFF        <1> 	je	cd_drive_not_ready
 18218                              <1> 
 18219                              <1> loc_ln_file_dir_not_found:
 18220 00005C61 BE[B4B10000]        <1> 	mov	esi, Msg_File_Directory_Not_Found
 18221                              <1> 	;call	print_msg	
 18222                              <1>         ;retn
 18223 00005C66 E920E2FFFF          <1> 	jmp	print_msg
 18224                              <1> 
 18225                              <1> loc_longname_not_found:
 18226 00005C6B BE[D3B10000]        <1>         mov     esi, Msg_LongName_Not_Found
 18227                              <1> 	;call	print_msg	
 18228                              <1>         ;retn
 18229 00005C70 E916E2FFFF          <1> 	jmp	print_msg
 18230                              <1> 
 18231                              <1> loc_print_longname:
 18232                              <1> 	;mov	esi, LongFileName
 18233 00005C75 BF[AEBF0000]        <1> 	mov	edi, TextBuffer
 18234 00005C7A 57                  <1> 	push	edi 
 18235 00005C7B 3C00                <1> 	cmp	al, 0
 18236 00005C7D 7708                <1> 	ja	short loc_print_longname_1
 18237                              <1> loc_print_FS_longname: ; Singlix FS (64 byte ASCIIZ file name)
 18238 00005C7F AC                  <1> 	lodsb
 18239 00005C80 AA                  <1> 	stosb  
 18240 00005C81 08C0                <1> 	or	al, al
 18241 00005C83 75FA                <1> 	jnz	short loc_print_FS_longname
 18242 00005C85 EB07                <1> 	jmp	short loc_print_longname_2
 18243                              <1> 	;
 18244                              <1> loc_print_longname_1: ; MS Windows long name (UNICODE chars)
 18245 00005C87 66AD                <1> 	lodsw
 18246 00005C89 AA                  <1> 	stosb  
 18247 00005C8A 08C0                <1> 	or	al, al
 18248 00005C8C 75F9                <1> 	jnz	short loc_print_longname_1
 18249                              <1> 	;
 18250                              <1> loc_print_longname_2:	
 18251 00005C8E 5E                  <1> 	pop	esi
 18252 00005C8F E8F7E1FFFF          <1> 	call	print_msg
 18253 00005C94 BE[C6BA0000]        <1>   	mov	esi, nextline
 18254                              <1> 	;call	print_msg
 18255                              <1> 	;retn
 18256 00005C99 E9EDE1FFFF          <1> 	jmp	print_msg	
 18257                              <1> 
 18258                              <1> show_file:
 18259                              <1> 	; 18/02/2016
 18260                              <1> 	; 17/02/2016
 18261                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18262                              <1> 	; 13/09/2011 (CMD_INTR.ASM, 'cmp_cmd_show')
 18263                              <1> 	; 08/11/2009
 18264                              <1> 
 18265                              <1> loc_show_parse_path_name:
 18266 00005C9E BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 18267 00005CA3 E804170000          <1> 	call	parse_path_name
 18268 00005CA8 0F8268F9FFFF        <1> 	jc	loc_cmd_failed
 18269                              <1> 
 18270                              <1> loc_show_check_filename_exists:
 18271 00005CAE BE[94C80000]        <1> 	mov	esi, FindFile_Name
 18272 00005CB3 803E20              <1> 	cmp	byte [esi], 20h
 18273 00005CB6 0F865AF9FFFF        <1> 	jna	loc_cmd_failed
 18274                              <1> 
 18275                              <1> 	; 15/02/2016 (invalid file name check)
 18276 00005CBC E805020000          <1> 	call	check_filename 	
 18277 00005CC1 730A                <1> 	jnc	short loc_show_change_drv
 18278                              <1> 
 18279 00005CC3 BE[9CB20000]        <1> 	mov	esi, Msg_invalid_name_chars
 18280 00005CC8 E9BEE1FFFF          <1> 	jmp	print_msg
 18281                              <1>    
 18282                              <1> loc_show_change_drv:
 18283 00005CCD 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 18284 00005CD3 8835[0EC70000]      <1> 	mov	[RUN_CDRV], dh
 18285 00005CD9 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 18286 00005CDF 38F2                <1> 	cmp	dl, dh
 18287 00005CE1 740B                <1> 	je	short loc_show_change_directory
 18288 00005CE3 E8A7EAFFFF          <1> 	call	change_current_drive
 18289                              <1> 	;jc	loc_file_rw_cmd_failed
 18290 00005CE8 0F8253F9FFFF        <1> 	jc	loc_run_cmd_failed
 18291                              <1> 
 18292                              <1> loc_show_change_directory:
 18293 00005CEE 803D[53C80000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18294 00005CF5 7618                <1> 	jna	short loc_findload_showfile
 18295                              <1> 
 18296 00005CF7 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 18297 00005CFD BE[53C80000]        <1> 	mov	esi, FindFile_Directory
 18298 00005D02 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18299 00005D04 E88F100000          <1> 	call	change_current_directory
 18300                              <1> 	;jc	loc_file_rw_cmd_failed
 18301 00005D09 0F8232F9FFFF        <1> 	jc	loc_run_cmd_failed
 18302                              <1> 
 18303                              <1> ;loc_show_change_prompt_dir_string:
 18304                              <1> 	;call	change_prompt_dir_string
 18305                              <1> 
 18306                              <1> loc_findload_showfile:
 18307                              <1> 	; 15/02/2016
 18308 00005D0F BE[94C80000]        <1> 	mov	esi, FindFile_Name
 18309 00005D14 BF[43C80000]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
 18310 00005D19 E8C3150000          <1> 	call	convert_file_name
 18311 00005D1E 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
 18312                              <1> 
 18313 00005D20 28C0                <1> 	sub	al, al	; Attrib AND mask = 0
 18314                              <1> 	; Directory attribute : 10h
 18315                              <1> 	; Volume name attribute: 8h
 18316 00005D22 B418                <1> 	mov	ah, 00011000b ; 18h (Attrib NAND, AND --> zero mask)
 18317                              <1> 	;
 18318 00005D24 6631C9              <1> 	xor	cx, cx  
 18319 00005D27 E8C0120000          <1> 	call	locate_current_dir_file
 18320                              <1> 	;jc	loc_file_rw_cmd_failed
 18321 00005D2C 0F820FF9FFFF        <1> 	jc	loc_run_cmd_failed
 18322                              <1> 
 18323                              <1> loc_show_load_file:
 18324                              <1> 	; EDI = Directory Entry
 18325 00005D32 668B4714            <1> 	mov	ax, [edi+DirEntry_FstClusHI] ; First Cluster High Word
 18326 00005D36 C1E010              <1> 	shl	eax, 16
 18327 00005D39 668B471A            <1> 	mov	ax, [edi+DirEntry_FstClusLO] ; First Cluster Low Word
 18328 00005D3D A3[FCC80000]        <1> 	mov	[Show_Cluster], eax
 18329 00005D42 8B471C              <1> 	mov	eax, [edi+DirEntry_FileSize] ; File Size
 18330 00005D45 21C0                <1> 	and	eax, eax ; Empty file !
 18331 00005D47 0F8491000000        <1>         jz      end_of_show_file 
 18332 00005D4D A3[00C90000]        <1> 	mov	[Show_FileSize], eax
 18333 00005D52 31C0                <1> 	xor	eax, eax
 18334 00005D54 A3[04C90000]        <1> 	mov	[Show_FilePointer], eax ; 0
 18335 00005D59 66A3[08C90000]      <1> 	mov	[Show_ClusterPointer], ax ; 0
 18336 00005D5F 29DB                <1> 	sub	ebx, ebx
 18337 00005D61 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 18338 00005D67 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 18339 00005D6C 01DE                <1> 	add	esi, ebx
 18340 00005D6E 8935[F8C80000]      <1> 	mov	[Show_LDDDT], esi ; Logical DOS Drv Description Table addr
 18341                              <1> 
 18342 00005D74 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0	
 18343 00005D78 7713                <1> 	ja	short loc_show_calculate_cluster_size
 18344                              <1> 	; Singlix FS
 18345                              <1> 	; First Cluster Number is FDT number (in compatibility buffer)
 18346 00005D7A 8B15[FCC80000]      <1> 	mov	edx, [Show_Cluster] ; Compatibility dir. buffer value (FDT)	
 18347 00005D80 8915[F4C80000]      <1> 	mov	[Show_FDT], edx
 18348 00005D86 31C0                <1> 	xor	eax, eax
 18349 00005D88 A3[FCC80000]        <1> 	mov	[Show_Cluster], eax ; Sector index  = 0
 18350                              <1> 				    ; (next time it will be 1)			
 18351                              <1> loc_show_calculate_cluster_size:
 18352 00005D8D 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec] ; FAT 12-16-32 (512)
 18353                              <1> 	; BX = 512 = [esi+LD_FS_BytesPerSec] ; Singlix FS	
 18354 00005D91 8A4613              <1> 	mov	al, [esi+LD_BPB+BPB_SecPerClust] ; FAT 12-16-32 (<= 128)
 18355                              <1> 	; AL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 18356 00005D94 F7E3                <1> 	mul	ebx	
 18357                              <1> 
 18358                              <1> 	;cmp	eax, 65536 ; non-compatible (very big) cluster size
 18359                              <1> 	;ja	short end_of_show_file	
 18360 00005D96 66A3[0AC90000]      <1> 	mov	[Show_ClusterSize], ax
 18361                              <1> 
 18362                              <1> loc_start_show_file:
 18363 00005D9C BE[C6BA0000]        <1> 	mov	esi, nextline
 18364 00005DA1 E8E5E0FFFF          <1> 	call	print_msg
 18365                              <1> 
 18366 00005DA6 A1[FCC80000]        <1> 	mov	eax, [Show_Cluster]
 18367 00005DAB C605[0CC90000]17    <1> 	mov	byte [Show_RowCount], 23
 18368                              <1> 
 18369                              <1> 	; 17/02/2016
 18370 00005DB2 8B35[F8C80000]      <1> 	mov	esi, [Show_LDDDT]
 18371                              <1> 
 18372                              <1> loc_show_next_cluster:
 18373                              <1> 	; 15/02/2016
 18374 00005DB8 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
 18375                              <1> 	; ESI = Logical DOS drv description table address
 18376 00005DBD E81C2F0000          <1> 	call	read_cluster
 18377                              <1> 	;jc	loc_file_rw_cmd_failed
 18378 00005DC2 0F8279F8FFFF        <1> 	jc	loc_run_cmd_failed
 18379                              <1> 
 18380 00005DC8 31DB                <1> 	xor 	ebx, ebx
 18381                              <1> loc_show_next_byte:
 18382 00005DCA 803D[0CC90000]00    <1> 	cmp	byte [Show_RowCount], 0
 18383 00005DD1 7521                <1> 	jne	short pass_show_wait_for_key
 18384 00005DD3 30E4                <1> 	xor	ah, ah
 18385 00005DD5 E80DAEFFFF          <1> 	call	int16h
 18386 00005DDA 3C1B                <1> 	cmp	al, 1Bh
 18387 00005DDC 750F                <1> 	jne	short pass_exit_show
 18388                              <1> end_of_show_file:
 18389                              <1> pass_show_file:
 18390 00005DDE BE[C6BA0000]        <1> 	mov	esi, nextline
 18391 00005DE3 E8A3E0FFFF          <1> 	call	print_msg
 18392 00005DE8 E949010000          <1> 	jmp	loc_file_rw_restore_retn
 18393                              <1> 
 18394                              <1> pass_exit_show:
 18395 00005DED C605[0CC90000]14    <1> 	mov	byte [Show_RowCount], 20
 18396                              <1> pass_show_wait_for_key:
 18397 00005DF4 81C300000700        <1> 	add	ebx, Cluster_Buffer
 18398 00005DFA 8A03                <1> 	mov	al, [ebx]
 18399 00005DFC 0FB61D[18BE0000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18400 00005E03 3C0D                <1> 	cmp	al, 0Dh
 18401 00005E05 0F858A000000        <1>         jne     loc_show_check_tab_space
 18402 00005E0B FE0D[0CC90000]      <1> 	dec	byte [Show_RowCount]
 18403                              <1> pass_show_dec_rowcount:
 18404 00005E11 B407                <1> 	mov	ah, 7 ; (light gray character color, black background)
 18405 00005E13 E89FB9FFFF          <1> 	call	WRITE_TTY
 18406                              <1> loc_show_check_eof:
 18407 00005E18 FF05[04C90000]      <1> 	inc	dword [Show_FilePointer]
 18408 00005E1E A1[04C90000]        <1> 	mov	eax, [Show_FilePointer]
 18409 00005E23 3B05[00C90000]      <1> 	cmp	eax, [Show_FileSize]
 18410 00005E29 73B3                <1> 	jnb	short end_of_show_file
 18411 00005E2B 66FF05[08C90000]    <1> 	inc	word [Show_ClusterPointer]
 18412 00005E32 0FB71D[08C90000]    <1> 	movzx	ebx, word [Show_ClusterPointer]
 18413                              <1> 
 18414                              <1> 	; 17/02/2016
 18415                              <1> 	; (sector boundary -9 bits- check, 512 = 0)
 18416 00005E39 66F7C3FF01          <1>         test    bx, 1FFh ;  1 to 511
 18417 00005E3E 758A                <1> 	jnz	short loc_show_next_byte
 18418                              <1> 
 18419                              <1> 	; 16/02/2016
 18420 00005E40 8B35[F8C80000]      <1> 	mov	esi, [Show_LDDDT]
 18421                              <1> 	;
 18422 00005E46 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 18423 00005E4A 7719                <1> 	ja	short loc_show_check_fat_cluster_size
 18424                              <1> 
 18425                              <1> 	; Singlix FS
 18426                              <1> 	; 1 sector, more... (cluster size = 1 sector)
 18427 00005E4C A1[FCC80000]        <1> 	mov	eax, [Show_Cluster]
 18428 00005E51 40                  <1> 	inc	eax
 18429 00005E52 A3[FCC80000]        <1> 	mov	[Show_Cluster], eax
 18430                              <1> 
 18431 00005E57 6621DB              <1> 	and	bx, bx ; 65536 -> 0
 18432 00005E5A 0F856AFFFFFF        <1>         jnz	loc_show_next_byte
 18433 00005E60 E953FFFFFF          <1> 	jmp     loc_show_next_cluster
 18434                              <1> 	 
 18435                              <1> loc_show_check_fat_cluster_size:
 18436                              <1> 	; 17/02/2016
 18437 00005E65 663B1D[0AC90000]    <1> 	cmp	bx, [Show_ClusterSize] ; cluster size in bytes
 18438 00005E6C 0F8258FFFFFF        <1>         jb	loc_show_next_byte
 18439 00005E72 66C705[08C90000]00- <1> 	mov	word [Show_ClusterPointer], 0
 18440 00005E7A 00                  <1>
 18441                              <1> 
 18442 00005E7B A1[FCC80000]        <1> 	mov	eax, [Show_Cluster]
 18443                              <1> 	;mov	esi, [Show_LDDDT]
 18444                              <1> loc_show_get_next_cluster:
 18445 00005E80 E8352C0000          <1> 	call	get_next_cluster
 18446                              <1> 	;jc	loc_file_rw_cmd_failed
 18447 00005E85 0F82B6F7FFFF        <1> 	jc	loc_run_cmd_failed
 18448                              <1> loc_show_update_ccluster:
 18449 00005E8B A3[FCC80000]        <1> 	mov	[Show_Cluster], eax			
 18450 00005E90 E923FFFFFF          <1>         jmp     loc_show_next_cluster
 18451                              <1> 
 18452                              <1> loc_show_check_tab_space:
 18453 00005E95 3C09                <1> 	cmp	al, 09h
 18454 00005E97 0F8574FFFFFF        <1>         jne     pass_show_dec_rowcount
 18455                              <1> loc_show_put_tab_space:
 18456                              <1> 	;movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18457 00005E9D E8DBB6FFFF          <1> 	call	get_cpos
 18458                              <1> 	; dl = cursor column
 18459 00005EA2 80E207              <1> 	and	dl, 7 ; 18/02/2016
 18460                              <1> loc_show_put_space_chars:
 18461                              <1> 	;mov	al, 20h ; space
 18462                              <1> 	;mov 	ah, 7	; color attribute
 18463 00005EA5 66B82007            <1> 	mov	ax, 0720h ; 
 18464 00005EA9 0FB61D[18BE0000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18465 00005EB0 6652                <1> 	push	dx
 18466 00005EB2 E800B9FFFF          <1> 	call	WRITE_TTY
 18467 00005EB7 665A                <1> 	pop	dx
 18468                              <1> 	; 18/02/2016
 18469 00005EB9 80FA07              <1> 	cmp	dl, 7
 18470 00005EBC 0F8356FFFFFF        <1> 	jnb	loc_show_check_eof
 18471 00005EC2 FEC2                <1> 	inc	dl
 18472 00005EC4 EBDF                <1> 	jmp	short loc_show_put_space_chars
 18473                              <1> 
 18474                              <1> check_filename:
 18475                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18476                              <1> 	; 07/08/2010 (FILE.ASM, 'proc_check_filename')
 18477                              <1> 	; 10/07/2010
 18478                              <1> 	; Derived from 'proc_check_filename'
 18479                              <1> 	; in the old TRDOS.ASM (09/02/2005).
 18480                              <1> 	;
 18481                              <1> 	; INPUT -> 
 18482                              <1> 	;	ESI = Dot File Name Location
 18483                              <1> 	; OUTPUT ->
 18484                              <1> 	;	cf = 1 -> error code in AL
 18485                              <1> 	;	     AL = 0Bh -> Invalid file name   
 18486                              <1> 	;	cf = 0 -> valid file name
 18487                              <1> 	; 
 18488                              <1> 	;(EAX, ECX, EDI will be changed)
 18489                              <1> 
 18490                              <1> check_invalid_filename_chars:
 18491                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18492                              <1> 	; 10/07/2010 (FILE.ASM, 'proc_check_invalid_filename_chars')
 18493                              <1> 	; 10/02/2010
 18494                              <1> 	; Derived from 'proc_check_invalid_filename_chars'
 18495                              <1> 	; in the old TRDOS.ASM (09/02/2005).
 18496                              <1> 	;
 18497                              <1> 	; INPUT -> 
 18498                              <1> 	;	ESI = ASCIIZ FileName
 18499                              <1> 	; OUTPUT ->
 18500                              <1> 	;	cf = 1 -> invalid
 18501                              <1> 	;	cf = 0 -> valid
 18502                              <1> 	; 
 18503                              <1> 	;(EAX, ECX, ESI, EDI will be changed)
 18504                              <1>   
 18505 00005EC6 56                  <1> 	push	esi
 18506                              <1> 
 18507 00005EC7 BF[88AF0000]        <1>         mov     edi, invalid_fname_chars
 18508 00005ECC AC                  <1> 	lodsb
 18509                              <1> check_filename_next_char:
 18510 00005ECD B914000000          <1> 	mov	ecx, sizeInvFnChars
 18511 00005ED2 BF[88AF0000]        <1> 	mov	edi, invalid_fname_chars
 18512                              <1> loc_scan_invalid_filename_char:
 18513 00005ED7 AE                  <1> 	scasb 
 18514 00005ED8 741F                <1> 	je	short loc_invalid_filename_stc 
 18515 00005EDA E2FB                <1> 	loop	loc_scan_invalid_filename_char
 18516 00005EDC AC                  <1> 	lodsb
 18517 00005EDD 3C1F                <1> 	cmp	al, 1Fh  ; 20h and above 
 18518 00005EDF 77EC                <1> 	ja	short check_filename_next_char
 18519                              <1> 
 18520                              <1> check_filename_dot:
 18521 00005EE1 8B3424              <1> 	mov	esi, [esp]
 18522                              <1> 
 18523 00005EE4 B421                <1> 	mov	ah, 21h
 18524 00005EE6 B908000000          <1> 	mov	ecx, 8
 18525                              <1> loc_check_filename_next_char:
 18526 00005EEB AC                  <1> 	lodsb
 18527 00005EEC 3C2E                <1> 	cmp	al, 2Eh
 18528 00005EEE 7511                <1> 	jne	short pass_check_fn_dot_check
 18529                              <1> loc_check_filename_ext_0:
 18530 00005EF0 AC                  <1> 	lodsb
 18531 00005EF1 38E0                <1> 	cmp	al, ah ; 21h
 18532 00005EF3 7205                <1> 	jb	short loc_invalid_filename
 18533 00005EF5 3C2E                <1> 	cmp	al, 2Eh
 18534 00005EF7 7519                <1> 	jne	short loc_check_filename_ext_1
 18535                              <1> 
 18536                              <1> loc_invalid_filename_stc:
 18537                              <1> loc_check_fn_stc_rtn:
 18538 00005EF9 F9                  <1> 	stc
 18539                              <1> loc_invalid_filename:
 18540 00005EFA B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 18541                              <1> 	; Invalid file name chars
 18542                              <1> loc_check_fn_rtn:
 18543 00005EFF 5E                  <1> 	pop	esi
 18544 00005F00 C3                  <1> 	retn
 18545                              <1> 
 18546                              <1> pass_check_fn_dot_check:
 18547 00005F01 38E0                <1> 	cmp	al, ah ; 21h
 18548 00005F03 7224                <1> 	jb	short loc_check_fn_clc_rtn
 18549 00005F05 E2E4                <1> 	loop	loc_check_filename_next_char
 18550 00005F07 AC                  <1> 	lodsb
 18551 00005F08 38E0                <1> 	cmp	al, ah ; 21h
 18552 00005F0A 721D                <1> 	jb	short loc_check_fn_clc_rtn
 18553 00005F0C 3C2E                <1> 	cmp	al, 2Eh
 18554 00005F0E 75E9                <1> 	jne	short loc_check_fn_stc_rtn
 18555 00005F10 EBDE                <1> 	jmp	short loc_check_filename_ext_0
 18556                              <1> 
 18557                              <1> loc_check_filename_ext_1:
 18558 00005F12 AC                  <1> 	lodsb
 18559 00005F13 38E0                <1> 	cmp	al, ah ; 21h
 18560 00005F15 7212                <1> 	jb	short loc_check_fn_clc_rtn
 18561 00005F17 3C2E                <1> 	cmp	al, 2Eh
 18562 00005F19 74DE                <1> 	je	short loc_check_fn_stc_rtn
 18563 00005F1B AC                  <1> 	lodsb
 18564 00005F1C 38E0                <1> 	cmp	al, ah ; 21h
 18565 00005F1E 7209                <1> 	jb	short loc_check_fn_clc_rtn
 18566 00005F20 3C2E                <1> 	cmp	al, 2Eh
 18567 00005F22 74D5                <1> 	je	short loc_check_fn_stc_rtn
 18568 00005F24 AC                  <1> 	lodsb
 18569 00005F25 38E0                <1> 	cmp	al, ah ; 21h
 18570 00005F27 73D0                <1> 	jnb	short loc_check_fn_stc_rtn
 18571                              <1> 
 18572                              <1> loc_check_fn_clc_rtn:
 18573 00005F29 5E                  <1> 	pop	esi
 18574 00005F2A F8                  <1> 	clc
 18575 00005F2B C3                  <1> 	retn
 18576                              <1> 
 18577                              <1> loc_print_deleted_message:
 18578 00005F2C BE[71B30000]        <1> 	mov	esi, Msg_Deleted
 18579 00005F31 E855DFFFFF          <1> 	call	print_msg
 18580                              <1> 
 18581                              <1> 	;clc
 18582                              <1> 
 18583                              <1> loc_file_rw_restore_retn:
 18584                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18585                              <1> 	; 28/02/2010 (CMD_INTR.ASM)
 18586                              <1> loc_file_rw_cmd_failed:
 18587 00005F36 9C                  <1> 	pushf 
 18588 00005F37 E85FF7FFFF          <1> 	call	restore_cdir_after_cmd_fail	
 18589 00005F3C 9D                  <1> 	popf
 18590 00005F3D 720D                <1> 	jc	short loc_file_rw_check_write_fault
 18591 00005F3F C3                  <1> 	retn
 18592                              <1> 
 18593                              <1> loc_permission_denied:
 18594                              <1> 	; 27/02/2016
 18595 00005F40 BE[7EB30000]        <1> 	mov	esi, Msg_Permission_Denied
 18596 00005F45 E841DFFFFF          <1> 	call	print_msg
 18597 00005F4A EBEA                <1> 	jmp	short loc_file_rw_restore_retn
 18598                              <1> 
 18599                              <1> loc_file_rw_check_write_fault:
 18600 00005F4C 3C1D                <1> 	cmp	al, 1Dh ; Write Fault
 18601 00005F4E 0F85F2F6FFFF        <1>         jne     loc_run_cmd_failed_cmp_al
 18602 00005F54 BE[69B10000]        <1> 	mov	esi, Msg_Not_Ready_Write_Err
 18603                              <1> 	;call	print_msg
 18604                              <1> 	;retn
 18605 00005F59 E92DDFFFFF          <1> 	jmp	print_msg
 18606                              <1> 
 18607                              <1> make_directory:
 18608                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18609                              <1> 	; 12/03/2011 (CMD_INTR.ASM, 'cmp_cmd_mkdir')
 18610                              <1> 	; 14/08/2010
 18611                              <1> 	; 10/07/2010
 18612                              <1> 	; 29/11/2009
 18613                              <1> 	;
 18614                              <1> get_mkdir_fchar:
 18615                              <1> 	; esi = directory name
 18616 00005F5E 803E20              <1> 	cmp	byte [esi], 20h
 18617 00005F61 7701                <1>         ja	short loc_mkdir_parse_path_name
 18618                              <1> 
 18619                              <1> loc_mkdir_nodirname_retn:
 18620 00005F63 C3                  <1> 	retn
 18621                              <1> 
 18622                              <1> loc_mkdir_parse_path_name:
 18623 00005F64 BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 18624 00005F69 E83E140000          <1>         call    parse_path_name
 18625 00005F6E 0F82A2F6FFFF        <1> 	jc	loc_cmd_failed
 18626                              <1> 
 18627                              <1> loc_mkdir_check_dirname_exists:
 18628 00005F74 BE[94C80000]        <1> 	mov	esi, FindFile_Name
 18629 00005F79 803E20              <1> 	cmp	byte [esi], 20h
 18630 00005F7C 0F8694F6FFFF        <1> 	jna	loc_cmd_failed
 18631 00005F82 8935[10C90000]      <1> 	mov	[DelFile_FNPointer], esi
 18632 00005F88 E839FFFFFF          <1> 	call	check_filename
 18633 00005F8D 7259                <1> 	jc	short loc_mkdir_invalid_dir_name_chars
 18634                              <1> 
 18635                              <1> loc_mkdir_drv:
 18636 00005F8F 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 18637 00005F95 8835[0EC70000]      <1> 	mov	[RUN_CDRV], dh
 18638                              <1> 	
 18639 00005F9B 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 18640 00005FA1 38F2                <1> 	cmp	dl, dh
 18641 00005FA3 7407                <1> 	je	short loc_mkdir_change_directory
 18642                              <1> 
 18643 00005FA5 E8E5E7FFFF          <1> 	call	change_current_drive
 18644 00005FAA 728A                <1> 	jc	loc_file_rw_cmd_failed
 18645                              <1> 
 18646                              <1> loc_mkdir_change_directory:
 18647 00005FAC 803D[53C80000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18648 00005FB3 7614                <1> 	jna	short loc_mkdir_find_directory
 18649                              <1> 
 18650 00005FB5 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 18651 00005FBB BE[53C80000]        <1> 	mov	esi, FindFile_Directory
 18652 00005FC0 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18653 00005FC2 E8D10D0000          <1> 	call	change_current_directory
 18654 00005FC7 722E                <1> 	jc	short loc_mkdir_check_error_code
 18655                              <1> 
 18656                              <1> ;loc_mkdir_change_prompt_dir_string:
 18657                              <1> 	;call	change_prompt_dir_string
 18658                              <1> 
 18659                              <1> loc_mkdir_find_directory:
 18660                              <1> 	;mov	esi, FindFile_Name
 18661 00005FC9 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 18662                              <1> 	;xor	eax, eax
 18663 00005FCF 6631C0              <1> 	xor	ax, ax ; any name (dir, file, volume)
 18664 00005FD2 E83BFBFFFF          <1> 	call	find_first_file
 18665 00005FD7 721E                <1> 	jc	short loc_mkdir_check_error_code
 18666                              <1> 
 18667                              <1> loc_mkdir_directory_found:
 18668 00005FD9 BE[C9B20000]        <1> 	mov	esi, Msg_Name_Exists
 18669 00005FDE E8A8DEFFFF          <1> 	call	print_msg
 18670                              <1> 
 18671 00005FE3 E94EFFFFFF          <1>         jmp     loc_file_rw_restore_retn
 18672                              <1> 
 18673                              <1> loc_mkdir_invalid_dir_name_chars:
 18674 00005FE8 BE[9CB20000]        <1> 	mov	esi, Msg_invalid_name_chars
 18675 00005FED E899DEFFFF          <1> 	call	print_msg
 18676                              <1> 
 18677 00005FF2 E93FFFFFFF          <1>         jmp     loc_file_rw_restore_retn
 18678                              <1> 
 18679                              <1> loc_mkdir_check_error_code:
 18680 00005FF7 3C02                <1> 	cmp	al, 2
 18681                              <1> 	;je	short loc_mkdir_directory_not_found
 18682 00005FF9 7406                <1> 	je	short loc_mkdir_ask_for_yes_no
 18683 00005FFB F9                  <1> 	stc
 18684 00005FFC E935FFFFFF          <1>         jmp     loc_file_rw_cmd_failed
 18685                              <1> 
 18686                              <1> loc_mkdir_directory_not_found:
 18687                              <1> loc_mkdir_ask_for_yes_no:
 18688 00006001 BE[EAB20000]        <1> 	mov	esi, Msg_DoYouWantMkdir
 18689 00006006 E880DEFFFF          <1> 	call	print_msg
 18690 0000600B 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 18691 00006011 E875DEFFFF          <1> 	call	print_msg
 18692 00006016 BE[09B30000]        <1> 	mov	esi, Msg_YesNo
 18693 0000601B E86BDEFFFF          <1> 	call	print_msg
 18694                              <1> 
 18695 00006020 C605[13B30000]20    <1> 	mov	byte [Y_N_nextline], 20h
 18696                              <1> 
 18697                              <1> loc_mkdir_ask_again:
 18698 00006027 30E4                <1> 	xor	ah, ah
 18699 00006029 E8B9ABFFFF          <1> 	call	int16h
 18700 0000602E 3C1B                <1> 	cmp	al, 1Bh
 18701                              <1> 	;je	short loc_do_not_make_directory
 18702 00006030 7447                <1> 	je	short loc_mkdir_y_n_escape
 18703 00006032 24DF                <1> 	and	al, 0DFh ; y -> Y, n -> N
 18704 00006034 3C59                <1> 	cmp	al, 'Y' ; 'yes'
 18705 00006036 7404                <1> 	je	short loc_mkdir_yes_make_directory
 18706 00006038 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18707 0000603A 75EB                <1> 	jne	short loc_mkdir_ask_again
 18708                              <1> 
 18709                              <1> loc_do_not_make_directory:
 18710                              <1> loc_mkdir_yes_make_directory:
 18711 0000603C A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 18712 00006041 6650                <1> 	push	ax
 18713 00006043 BE[13B30000]        <1> 	mov	esi, Y_N_nextline
 18714 00006048 E83EDEFFFF          <1> 	call	print_msg
 18715 0000604D 6658                <1> 	pop	ax
 18716                              <1> 	;cmp	al, 'Y' ; 'yes'
 18717                              <1> 	;cmc
 18718                              <1>         ;jnc	loc_file_rw_restore_retn
 18719 0000604F 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18720 00006051 0F84DFFEFFFF        <1>         je	loc_file_rw_restore_retn  
 18721                              <1> 
 18722                              <1> loc_mkdir_call_make_sub_directory:
 18723 00006057 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 18724 0000605D B110                <1> 	mov	cl, 10h ; Directory attributes 
 18725 0000605F E847140000          <1> 	call	make_sub_directory
 18726                              <1> loc_rename_file_ok: ; 06/03/2016
 18727 00006064 0F82CCFEFFFF        <1>         jc	loc_file_rw_cmd_failed
 18728                              <1> move_source_file_to_destination_OK:
 18729 0000606A BE[17B30000]        <1> 	mov	esi, Msg_OK
 18730 0000606F E817DEFFFF          <1> 	call	print_msg
 18731 00006074 E9BDFEFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18732                              <1> 
 18733                              <1> loc_mkdir_y_n_escape:
 18734 00006079 B04E                <1> 	mov	al, 'N' ; 'no'
 18735 0000607B EBBF                <1> 	jmp	short loc_do_not_make_directory
 18736                              <1> 
 18737                              <1> delete_directory:
 18738                              <1> 	; 06/03/2016
 18739                              <1> 	; 01/03/2016
 18740                              <1> 	; 29/02/2016
 18741                              <1> 	; 28/02/2016
 18742                              <1> 	; 27/02/2016
 18743                              <1> 	; 26/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18744                              <1> 	; 16/10/2010 (CMD_INTR.ASM, 'cmp_cmd_rmdir')
 18745                              <1> 	; 05/06/2010
 18746                              <1> 	;
 18747                              <1> get_rmdir_fchar:
 18748                              <1> 	; esi = directory name
 18749 0000607D 803E20              <1> 	cmp	byte [esi], 20h
 18750 00006080 7701                <1>         ja	short loc_rmdir_parse_path_name
 18751                              <1> 
 18752                              <1> loc_rmdir_nodirname_retn:
 18753 00006082 C3                  <1> 	retn
 18754                              <1> 
 18755                              <1> loc_rmdir_parse_path_name:
 18756 00006083 BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 18757 00006088 E81F130000          <1> 	call	parse_path_name
 18758 0000608D 0F8283F5FFFF        <1> 	jc	loc_cmd_failed
 18759                              <1> 
 18760                              <1> loc_rmdir_check_dirname_exists:
 18761 00006093 BE[94C80000]        <1> 	mov	esi, FindFile_Name
 18762 00006098 803E20              <1> 	cmp	byte [esi], 20h
 18763 0000609B 0F8675F5FFFF        <1> 	jna	loc_cmd_failed
 18764 000060A1 8935[10C90000]      <1> 	mov	[DelFile_FNPointer], esi 
 18765                              <1> 
 18766                              <1> loc_rmdir_drv:
 18767 000060A7 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 18768 000060AD 8835[0EC70000]      <1> 	mov	[RUN_CDRV], dh
 18769                              <1> 
 18770 000060B3 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 18771 000060B9 38F2                <1> 	cmp	dl, dh
 18772 000060BB 740B                <1> 	je	short loc_rmdir_change_directory
 18773                              <1> 
 18774 000060BD E8CDE6FFFF          <1> 	call	change_current_drive
 18775 000060C2 0F826EFEFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18776                              <1> 
 18777                              <1> loc_rmdir_change_directory:
 18778 000060C8 803D[53C80000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18779 000060CF 7614                <1> 	jna	short loc_rmdir_find_directory
 18780                              <1> 
 18781 000060D1 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 18782 000060D7 BE[53C80000]        <1> 	mov	esi, FindFile_Directory
 18783 000060DC 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18784 000060DE E8B50C0000          <1> 	call	change_current_directory
 18785 000060E3 7211                <1> 	jc	short loc_rmdir_check_error_code
 18786                              <1> 
 18787                              <1> ;loc_rmdir_change_prompt_dir_string:
 18788                              <1> 	;call	change_prompt_dir_string
 18789                              <1> 
 18790                              <1> loc_rmdir_find_directory:
 18791                              <1> 	;mov	esi, FindFile_Name
 18792 000060E5 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 18793 000060EB 66B81008            <1> 	mov	ax, 0810h ; Only directories
 18794 000060EF E81EFAFFFF          <1> 	call	find_first_file
 18795 000060F4 730A                <1> 	jnc	short loc_rmdir_ambgfn_check
 18796                              <1> 
 18797                              <1> loc_rmdir_check_error_code:
 18798 000060F6 3C02                <1> 	cmp	al, 2
 18799 000060F8 740B                <1> 	je	short loc_rmdir_directory_not_found
 18800 000060FA F9                  <1> 	stc
 18801 000060FB E936FEFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18802                              <1> 
 18803                              <1> loc_rmdir_ambgfn_check:
 18804 00006100 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 18805 00006103 740F                <1> 	jz	short loc_rmdir_directory_found
 18806                              <1> 
 18807                              <1> loc_rmdir_directory_not_found:
 18808 00006105 BE[8BB10000]        <1> 	mov	esi, Msg_Dir_Not_Found
 18809 0000610A E87CDDFFFF          <1> 	call	print_msg
 18810                              <1> 
 18811 0000610F E922FEFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18812                              <1> 
 18813                              <1> loc_rmdir_directory_found:
 18814 00006114 80E307              <1> 	and	bl, 07h ; Attributes
 18815 00006117 0F8523FEFFFF        <1> 	jnz	loc_permission_denied
 18816                              <1> 
 18817                              <1> loc_rmdir_save_lnel: ; 28/02/2016
 18818                              <1>        ;mov	bh, [LongName_EntryLength]
 18819 0000611D 883D[1AC90000]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 18820                              <1> 	; edi = Directory Entry Offset (DirBuff)
 18821                              <1> 	; esi = Directory Entry (FFF Structure)
 18822                              <1> 	;mov	[DelFile_DirEntryAddr], edi ; not required
 18823                              <1> 	;mov	ax, [edi+20] ; First Cluster High Word
 18824                              <1>         ;shl	eax, 16
 18825                              <1> 	;mov	ax, [edi+26] ; First Cluster Low Word
 18826                              <1> 	; ROOT Dir First Cluster = 0
 18827                              <1>         ;cmp	eax, 2
 18828                              <1> 	;jb	loc_update_direntry_1
 18829                              <1> 
 18830                              <1> pass_rmdir_fc_check:
 18831 00006123 57                  <1> 	push	edi ; * (29/02/2016)
 18832                              <1> 
 18833 00006124 BE[1DB30000]        <1> 	mov	esi, Msg_DoYouWantRmDir
 18834 00006129 E85DDDFFFF          <1> 	call	print_msg
 18835 0000612E 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 18836 00006134 E852DDFFFF          <1> 	call	print_msg
 18837 00006139 BE[09B30000]        <1> 	mov	esi, Msg_YesNo
 18838 0000613E E848DDFFFF          <1> 	call	print_msg
 18839                              <1> 
 18840                              <1> loc_rmdir_ask_again:
 18841 00006143 30E4                <1> 	xor	ah, ah
 18842 00006145 E89DAAFFFF          <1> 	call	int16h
 18843 0000614A 3C1B                <1> 	cmp	al, 1Bh
 18844                              <1> 	;je	short loc_do_not_delete_directory
 18845 0000614C 0F8498000000        <1>         je      loc_rmdir_y_n_escape ; 06/03/2016
 18846 00006152 24DF                <1> 	and	al, 0DFh
 18847 00006154 A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 18848 00006159 3C59                <1> 	cmp	al, 'Y'
 18849 0000615B 7404                <1> 	je	short loc_rmdir_yes_delete_directory
 18850 0000615D 3C4E                <1> 	cmp	al, 'N'
 18851 0000615F 75E2                <1> 	jne	short loc_rmdir_ask_again
 18852                              <1> 
 18853                              <1> loc_do_not_delete_directory:
 18854                              <1> loc_rmdir_yes_delete_directory:
 18855 00006161 A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 18856 00006166 6650                <1> 	push	ax
 18857 00006168 BE[13B30000]        <1> 	mov	esi, Y_N_nextline
 18858 0000616D E819DDFFFF          <1> 	call	print_msg
 18859 00006172 6658                <1> 	pop	ax
 18860 00006174 5F                  <1> 	pop	edi ; * (29/02/2016)
 18861                              <1> 	;cmp	al, 'Y' ; 'yes'
 18862                              <1> 	;cmc
 18863                              <1>         ;jnc	loc_file_rw_restore_retn
 18864 00006175 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18865 00006177 0F84B9FDFFFF        <1>         je	loc_file_rw_restore_retn  
 18866                              <1> 
 18867                              <1> loc_rmdir_delete_short_name_check_dir_empty:
 18868                              <1> 	; EDI = Directory buffer entry offset/address 
 18869 0000617D 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 18870 00006181 C1E010              <1>         shl	eax, 16
 18871 00006184 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 18872                              <1> 
 18873 00006188 A3[14C90000]        <1> 	mov 	[DelFile_FCluster], eax
 18874                              <1> 
 18875                              <1> 	;mov	bx, [DirBuff_EntryCounter]
 18876 0000618D 668B1D[CCC80000]    <1> 	mov	bx, [FindFile_DirEntryNumber] ; 27/02/2016
 18877 00006194 66891D[18C90000]    <1> 	mov	[DelFile_EntryCounter], bx
 18878                              <1> 
 18879 0000619B 29DB                <1>     	sub	ebx, ebx
 18880 0000619D 8A3D[52C80000]      <1> 	mov	bh, [FindFile_Drv]
 18881 000061A3 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 18882 000061A8 01DE                <1> 	add	esi, ebx
 18883                              <1> 
 18884 000061AA 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h
 18885 000061B0 743F                <1> 	je	short loc_rmdir_delete_fs_directory
 18886                              <1> 
 18887                              <1> 	;cmp	byte [esi+LD_FATType], 1
 18888                              <1> 	;jnb	short loc_rmdir_get__last_cluster_0
 18889                              <1> 	;mov	eax, 0Bh ; Invalid Format
 18890                              <1> 	;jmp	loc_file_rw_cmd_failed
 18891                              <1>   
 18892                              <1> ;loc_rmdir_get_last_cluster_0:
 18893 000061B2 8B15[DDC60000]      <1> 	mov	edx, [DirBuff_Cluster]
 18894 000061B8 8915[44C90000]      <1> 	mov	[RmDir_ParentDirCluster], edx
 18895                              <1> 
 18896 000061BE 893D[40C90000]      <1> 	mov	[RmDir_DirEntryOffset], edi
 18897                              <1> 
 18898                              <1> 	; 01/03/2016
 18899 000061C4 C705[CDC60000]0000- <1> 	mov	dword [FAT_ClusterCounter], 0 ; Reset
 18900 000061CC 0000                <1>
 18901                              <1> 
 18902                              <1> loc_rmdir_get_last_cluster:
 18903 000061CE E8E2300000          <1> 	call	get_last_cluster
 18904 000061D3 0F82B8000000        <1>         jc      loc_rmdir_cmd_failed
 18905                              <1> 	
 18906 000061D9 3B05[14C90000]      <1> 	cmp	eax, [DelFile_FCluster]
 18907 000061DF 752F                <1> 	jne	short loc_rmdir_multi_dir_clusters
 18908                              <1> 
 18909 000061E1 C605[3FC90000]00    <1> 	mov	byte [RmDir_MultiClusters], 0
 18910 000061E8 EB2D                <1> 	jmp	short pass_rmdir_multi_dir_clusters
 18911                              <1> 
 18912                              <1> loc_rmdir_y_n_escape:
 18913 000061EA B04E                <1> 	mov	al, 'N' ; 'no'
 18914 000061EC E970FFFFFF          <1>         jmp     loc_do_not_delete_directory
 18915                              <1> 
 18916                              <1> loc_rmdir_delete_fs_directory:
 18917 000061F1 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 18918 000061F5 0F8545FDFFFF        <1> 	jne	loc_permission_denied
 18919                              <1> 
 18920 000061FB E8B40A0000          <1> 	call	delete_fs_directory
 18921 00006200 0F8326FDFFFF        <1> 	jnc	loc_print_deleted_message
 18922                              <1> 
 18923 00006206 09C0                <1> 	or	eax, eax
 18924 00006208 745D                <1> 	jz	loc_rmdir_directory_not_empty_2         
 18925 0000620A F9                  <1> 	stc
 18926 0000620B E926FDFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18927                              <1>  
 18928                              <1> loc_rmdir_multi_dir_clusters:
 18929 00006210 C605[3FC90000]01    <1> 	mov	byte [RmDir_MultiClusters], 1
 18930                              <1> 
 18931                              <1> pass_rmdir_multi_dir_clusters:
 18932 00006217 A3[48C90000]        <1> 	mov 	[RmDir_DirLastCluster], eax
 18933 0000621C 890D[4CC90000]      <1> 	mov	[RmDir_PreviousCluster], ecx
 18934                              <1> 
 18935                              <1> loc_rmdir_load_fat_sub_directory:
 18936 00006222 E8792A0000          <1> 	call	load_FAT_sub_directory
 18937 00006227 7268                <1> 	jc	loc_rmdir_cmd_failed
 18938                              <1> 
 18939                              <1> loc_rmdir_find_last_dir_entry:
 18940 00006229 56                  <1> 	push	esi
 18941 0000622A BE[36C80000]        <1> 	mov	esi, Dir_File_Name
 18942 0000622F C6062A              <1> 	mov	byte [esi], '*'
 18943 00006232 C646082A            <1> 	mov	byte [esi+8], '*'
 18944 00006236 31DB                <1> 	xor	ebx, ebx ; Entry offset  = 0
 18945                              <1> loc_rmdir_find_last_dir_entry_next:
 18946 00006238 66B80008            <1> 	mov	ax, 0800h ; Except volume/long names
 18947 0000623C 6631C9              <1> 	xor	cx, cx ; 0 = Find a valid file or dir name
 18948 0000623F E8AA0E0000          <1> 	call	find_directory_entry
 18949 00006244 7271                <1> 	jc	short loc_rmdir_empty_dir_cluster
 18950 00006246 83FB01              <1> 	cmp	ebx, 1
 18951 00006249 771B                <1> 	ja	short loc_rmdir_directory_not_empty_1
 18952                              <1> loc_rmdir_dot_entry_check:
 18953 0000624B 80FD2E              <1> 	cmp	ch, '.' ; The first char of the dir entry
 18954 0000624E 7516                <1> 	jne	short loc_rmdir_directory_not_empty_1
 18955 00006250 08DB                <1> 	or	bl, bl
 18956 00006252 7506                <1> 	jnz	short loc_rmdir_dotdot_entry_check
 18957 00006254 807F0120            <1> 	cmp	byte [edi+1], 20h
 18958 00006258 EB06                <1> 	jmp	short pass_rmdir_dot_entry_check
 18959                              <1> 
 18960                              <1> loc_rmdir_dotdot_entry_check:
 18961 0000625A 66817F012E20        <1> 	cmp	word [edi+1], '. '
 18962                              <1> pass_rmdir_dot_entry_check:	
 18963 00006260 7504                <1> 	jne	short loc_rmdir_directory_not_empty_1 
 18964 00006262 FEC3                <1> 	inc	bl
 18965 00006264 EBD2                <1> 	jmp	short loc_rmdir_find_last_dir_entry_next 
 18966                              <1> 
 18967                              <1> 
 18968                              <1> loc_rmdir_directory_not_empty_1:
 18969 00006266 58                  <1> 	pop	eax ; pushed esi 
 18970                              <1> 
 18971                              <1> loc_rmdir_directory_not_empty_2:
 18972 00006267 BE[3EB30000]        <1> 	mov	esi, Msg_Dir_Not_Empty
 18973 0000626C E81ADCFFFF          <1> 	call	print_msg
 18974                              <1> 	; 01/03/2016
 18975 00006271 A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 18976 00006276 09C0                <1> 	or	eax, eax ; 0 ?
 18977 00006278 0F84B8FCFFFF        <1> 	jz	loc_file_rw_restore_retn
 18978                              <1> 	; ESI = Logical DOS Drive Description Table address	
 18979                              <1> 
 18980 0000627E 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> use ESI for Drive parameters
 18981                              <1> 	           ; BL = 1 -> add free clusters
 18982 00006282 E8AF2E0000          <1> 	call	calculate_fat_freespace
 18983 00006287 09C9                <1> 	or	ecx, ecx
 18984 00006289 0F84A7FCFFFF        <1>         jz      loc_file_rw_restore_retn ; ecx = 0 -> OK
 18985                              <1> 	; ecx > 0 -> Error (Recalculation is neeeded)
 18986 0000628F EB0E                <1> 	jmp	short loc_rmdir_cmd_return
 18987                              <1> 
 18988                              <1> 
 18989                              <1> loc_rmdir_cmd_failed:
 18990 00006291 833D[CDC60000]01    <1> 	cmp	dword [FAT_ClusterCounter], 1
 18991 00006298 0F8298FCFFFF        <1> 	jb	loc_file_rw_cmd_failed	
 18992 0000629E F9                  <1> 	stc
 18993                              <1> loc_rmdir_cmd_return:
 18994                              <1> 	; 01/03/2016
 18995 0000629F 9C                  <1> 	pushf
 18996                              <1> 	; ESI = Logical DOS Drive Description Table address	
 18997 000062A0 66BB00FF            <1> 	mov	bx, 0FF00h ; BH = FFh -> use ESI for Drive parameters
 18998                              <1> 	           ; BL = 0 -> Recalculate free cluster count
 18999 000062A4 50                  <1> 	push	eax
 19000 000062A5 E88C2E0000          <1> 	call	calculate_fat_freespace	
 19001 000062AA 58                  <1> 	pop	eax
 19002 000062AB 9D                  <1> 	popf
 19003 000062AC 0F8284FCFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19004 000062B2 E97FFCFFFF          <1> 	jmp	loc_file_rw_restore_retn
 19005                              <1> 
 19006                              <1> 
 19007                              <1> loc_rmdir_empty_dir_cluster:
 19008 000062B7 5E                  <1> 	pop	esi
 19009                              <1> 
 19010                              <1> loc_rmdir_set_prev_cluster_dir_last_cluster:
 19011 000062B8 803D[3FC90000]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
 19012 000062BF 761D                <1> 	jna	short loc_rmdir_unlink_dir_last_cluster
 19013                              <1> 
 19014 000062C1 A1[4CC90000]        <1> 	mov	eax, [RmDir_PreviousCluster]
 19015                              <1> 	;xor	ecx, ecx
 19016 000062C6 49                  <1> 	dec	ecx ; FFFFFFFFh
 19017 000062C7 E8182B0000          <1> 	call	update_cluster
 19018 000062CC 7310                <1> 	jnc	short loc_rmdir_unlink_dir_last_cluster
 19019                              <1> 
 19020                              <1> loc_rmdir_unlink_stc_retn:
 19021                              <1> 	; 01/03/2016
 19022 000062CE 83F801              <1> 	cmp	eax, 1  ; eax = 0 -> end of cluster chain
 19023 000062D1 F5                  <1> 	cmc 
 19024 000062D2 72BD                <1> 	jc	short loc_rmdir_cmd_failed
 19025 000062D4 EB1D                <1> 	jmp	short loc_rmdir_save_fat_buffer 
 19026                              <1> 	
 19027                              <1> loc_rmdir_unlink_stc_retn_0Bh:
 19028 000062D6 B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 19029 000062DB F9                  <1> 	stc
 19030 000062DC EBB3                <1> 	jmp	short loc_rmdir_cmd_failed
 19031                              <1>  
 19032                              <1> loc_rmdir_unlink_dir_last_cluster:
 19033 000062DE A1[48C90000]        <1> 	mov	eax, [RmDir_DirLastCluster]
 19034 000062E3 31C9                <1> 	xor	ecx, ecx ; 0
 19035 000062E5 E8FA2A0000          <1> 	call	update_cluster
 19036 000062EA 73EA                <1> 	jnc	short loc_rmdir_unlink_stc_retn_0Bh
 19037                              <1> 	; Because of it is the last cluster
 19038                              <1> 	; 'update_cluster' must return with eocc error 
 19039 000062EC 09C0                <1> 	or	eax, eax
 19040 000062EE 7403                <1> 	jz	short loc_rmdir_save_fat_buffer ; eocc	
 19041 000062F0 F9                  <1> 	stc
 19042 000062F1 EB9E                <1>         jmp     short loc_rmdir_cmd_failed
 19043                              <1> 	 
 19044                              <1> loc_rmdir_save_fat_buffer:
 19045 000062F3 803D[C5C60000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 19046 000062FA 7525                <1> 	jne	short loc_rmdir_calculate_FAT_freespace
 19047 000062FC E8A02D0000          <1> 	call	save_fat_buffer
 19048 00006301 728E                <1> 	jc	short loc_rmdir_cmd_failed
 19049                              <1> 
 19050                              <1> 	; 01/03/2016
 19051 00006303 803D[3FC90000]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
 19052 0000630A 7615                <1> 	jna	short loc_rmdir_calculate_FAT_freespace
 19053                              <1> 
 19054 0000630C A1[14C90000]        <1> 	mov	eax, [DelFile_FCluster]
 19055 00006311 E9B8FEFFFF          <1>         jmp     loc_rmdir_get_last_cluster
 19056                              <1> 
 19057                              <1> loc_rmdir_delete_short_name_invalid_data:
 19058 00006316 B80D000000          <1> 	mov	eax, 0Dh ; Invalid data
 19059 0000631B F9                  <1> 	stc
 19060 0000631C E970FFFFFF          <1>         jmp     loc_rmdir_cmd_failed
 19061                              <1> 
 19062                              <1> loc_rmdir_calculate_FAT_freespace:
 19063 00006321 A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 19064 00006326 66BB01FF            <1> 	mov	bx, 0FF01h
 19065                              <1> 	; BL = 1 -> Add EAX to free space count
 19066                              <1> 	; BH = FFh ->
 19067                              <1> 	; ESI = Logical DOS Drive Description Table address
 19068 0000632A E8072E0000          <1> 	call	calculate_fat_freespace
 19069                              <1> 
 19070 0000632F 21C9                <1> 	and	ecx, ecx ; ecx = 0 -> valid free sector count
 19071 00006331 7409                <1> 	jz 	short loc_rmdir_delete_short_name_continue
 19072                              <1> 
 19073                              <1> loc_rmdir_recalculate_FAT_freespace:
 19074 00006333 66BB00FF            <1>         mov     bx, 0FF00h ; BL = 0 -> Recalculate free space
 19075 00006337 E8FA2D0000          <1> 	call	calculate_fat_freespace
 19076                              <1> 	          
 19077                              <1> loc_rmdir_delete_short_name_continue:
 19078 0000633C A1[44C90000]        <1> 	mov	eax, [RmDir_ParentDirCluster]
 19079 00006341 83F802              <1> 	cmp	eax, 2
 19080 00006344 730D                <1> 	jnb	short loc_rmdir_del_short_name_load_sub_dir
 19081 00006346 E8CA280000          <1> 	call	load_FAT_root_directory
 19082 0000634B 0F82E5FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19083 00006351 EB0B                <1> 	jmp	short loc_rmdir_del_short_name_ld_chk_fclust
 19084                              <1> 
 19085                              <1> loc_rmdir_del_short_name_load_sub_dir:	
 19086 00006353 E848290000          <1> 	call	load_FAT_sub_directory
 19087 00006358 0F82D8FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19088                              <1> 
 19089                              <1> loc_rmdir_del_short_name_ld_chk_fclust:
 19090 0000635E 0FB73D[40C90000]    <1> 	movzx	edi, word [RmDir_DirEntryOffset]
 19091 00006365 81C700000800        <1> 	add	edi, Directory_Buffer
 19092                              <1> 
 19093 0000636B 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 19094 0000636F C1E010              <1> 	shl	eax, 16
 19095 00006372 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 19096                              <1>         ; Not necessary... 
 19097 00006376 3B05[14C90000]      <1> 	cmp	eax, [DelFile_FCluster]
 19098 0000637C 7598                <1> 	jne	short loc_rmdir_delete_short_name_invalid_data
 19099                              <1> 	;
 19100 0000637E C607E5              <1> 	mov	byte [edi], 0E5h ; 'Deleted' sign
 19101                              <1> 	; 27/02/2016
 19102                              <1> 	; TRDOS v1 has a bug here! it does not set
 19103                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
 19104                              <1> 	; 'save_directory_buffer' would not save the change ! 
 19105 00006381 C605[D8C60000]02    <1>   	mov	byte [DirBuff_ValidData], 2 ; change sign
 19106                              <1> 	;
 19107 00006388 E883140000          <1> 	call	save_directory_buffer
 19108 0000638D 0F82A3FBFFFF        <1> 	jc	loc_file_rw_cmd_failed 
 19109                              <1> 
 19110                              <1> loc_rmdir_del_long_name:
 19111 00006393 0FB615[1AC90000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 19112 0000639A 08D2                <1> 	or	dl, dl
 19113 0000639C 7414                <1> 	jz	short loc_rmdir_update_parent_dir_lmdt
 19114                              <1>              
 19115 0000639E 0FB705[18C90000]    <1> 	movzx	eax, word [DelFile_EntryCounter]
 19116 000063A5 29D0                <1> 	sub	eax, edx
 19117 000063A7 0F8289FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19118                              <1>  
 19119                              <1>  	; EAX = Directory Entry Number of the long name last entry
 19120 000063AD E8BE150000          <1> 	call	delete_longname
 19121                              <1> 	;jc	short loc_file_rw_cmd_failed
 19122                              <1> 
 19123                              <1> loc_rmdir_update_parent_dir_lmdt:
 19124 000063B2 E8F4140000          <1> 	call	update_parent_dir_lmdt
 19125                              <1> 	;jc	short loc_file_rw_cmd_failed
 19126                              <1> 
 19127                              <1> loc_rmdir_ok:
 19128 000063B7 BE[17B30000]        <1> 	mov	esi, Msg_OK
 19129 000063BC E8CADAFFFF          <1> 	call	print_msg
 19130 000063C1 E970FBFFFF          <1> 	jmp	loc_file_rw_restore_retn
 19131                              <1> 
 19132                              <1> 
 19133                              <1> delete_file:
 19134                              <1> 	; 29/02/2016
 19135                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
 19136                              <1> 	; 09/08/2010 (CMD_INTR.ASM, 'cmp_cmd_del')
 19137                              <1> 	; 28/02/2010
 19138                              <1> 
 19139                              <1> get_delfile_fchar:
 19140                              <1> 	; esi = file name
 19141 000063C6 803E20              <1> 	cmp	byte [esi], 20h
 19142 000063C9 7701                <1>         ja	short loc_delfile_parse_path_name
 19143                              <1> 
 19144                              <1> loc_delfile_nofilename_retn:
 19145 000063CB C3                  <1> 	retn
 19146                              <1> 
 19147                              <1> loc_delfile_parse_path_name:
 19148 000063CC BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 19149 000063D1 E8D60F0000          <1> 	call	parse_path_name
 19150 000063D6 0F823AF2FFFF        <1> 	jc	loc_cmd_failed
 19151                              <1> 
 19152                              <1> loc_delfile_check_filename_exists:
 19153 000063DC BE[94C80000]        <1> 	mov	esi, FindFile_Name
 19154 000063E1 803E20              <1> 	cmp	byte [esi], 20h
 19155 000063E4 0F862CF2FFFF        <1> 	jna	loc_cmd_failed
 19156 000063EA 8935[10C90000]      <1> 	mov	[DelFile_FNPointer], esi 
 19157                              <1> 
 19158                              <1> loc_delfile_drv:
 19159 000063F0 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 19160 000063F6 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 19161 000063FC 8835[0EC70000]      <1> 	mov	[RUN_CDRV], dh
 19162 00006402 38F2                <1> 	cmp	dl, dh
 19163 00006404 740B                <1> 	je	short loc_delfile_change_directory
 19164                              <1> 
 19165 00006406 E884E3FFFF          <1> 	call	change_current_drive
 19166 0000640B 0F8225FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19167                              <1> 
 19168                              <1> loc_delfile_change_directory:
 19169 00006411 803D[53C80000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 19170 00006418 7618                <1> 	jna	short loc_delfile_find
 19171                              <1> 
 19172 0000641A FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 19173 00006420 BE[53C80000]        <1> 	mov	esi, FindFile_Directory
 19174 00006425 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 19175 00006427 E86C090000          <1> 	call	change_current_directory
 19176 0000642C 0F8204FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19177                              <1> 
 19178                              <1> ;loc_delfile_change_prompt_dir_string:
 19179                              <1> 	;call	change_prompt_dir_string
 19180                              <1> 
 19181                              <1> loc_delfile_find:
 19182                              <1> 	;mov	esi, FindFile_Name
 19183 00006432 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 19184 00006438 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
 19185 0000643C E8D1F6FFFF          <1> 	call	find_first_file
 19186 00006441 0F82EFFAFFFF        <1> 	jc	loc_file_rw_cmd_failed
 19187                              <1> 
 19188                              <1> loc_delfile_ambgfn_check:
 19189 00006447 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 19190 0000644A 740B                <1> 	jz	short loc_delfile_found
 19191                              <1> 
 19192                              <1> loc_file_not_found:
 19193 0000644C B802000000          <1> 	mov	eax, 2 ; File not found sign
 19194 00006451 F9                  <1> 	stc
 19195 00006452 E9DFFAFFFF          <1> 	jmp	loc_file_rw_cmd_failed   
 19196                              <1> 
 19197                              <1> loc_delfile_found:
 19198 00006457 80E307              <1> 	and	bl, 07h ; Attributes
 19199 0000645A 0F85E0FAFFFF        <1>         jnz     loc_permission_denied
 19200                              <1> 
 19201                              <1> ;loc_delfile_found_save_lnel:
 19202                              <1> ;	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 19203                              <1> 
 19204                              <1> loc_delfile_ask_for_delete:
 19205 00006460 57                  <1> 	push	edi ; * (29/02/2016)
 19206                              <1> 
 19207 00006461 BE[55B30000]        <1> 	mov	esi, Msg_DoYouWantDelete
 19208 00006466 E820DAFFFF          <1> 	call	print_msg
 19209 0000646B 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 19210 00006471 E815DAFFFF          <1> 	call	print_msg
 19211 00006476 BE[09B30000]        <1> 	mov	esi, Msg_YesNo
 19212 0000647B E80BDAFFFF          <1> 	call	print_msg
 19213                              <1> 
 19214                              <1> loc_delfile_ask_again:
 19215 00006480 30E4                <1> 	xor	ah, ah
 19216 00006482 E860A7FFFF          <1> 	call	int16h
 19217 00006487 3C1B                <1> 	cmp	al, 1Bh
 19218                              <1> 	;je	short loc_do_not_delete_file
 19219 00006489 7457                <1> 	je	short loc_delfile_y_n_escape ; 06/03/2016
 19220 0000648B 24DF                <1> 	and	al, 0DFh
 19221 0000648D A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 19222 00006492 3C59                <1> 	cmp	al, 'Y'
 19223 00006494 7404                <1> 	je	short loc_yes_delete_file
 19224 00006496 3C4E                <1> 	cmp	al, 'N'
 19225 00006498 75E6                <1> 	jne	short loc_delfile_ask_again
 19226                              <1> 
 19227                              <1> loc_do_not_delete_file:
 19228                              <1> loc_yes_delete_file:
 19229 0000649A A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 19230 0000649F 6650                <1> 	push	ax
 19231 000064A1 BE[13B30000]        <1> 	mov	esi, Y_N_nextline
 19232 000064A6 E8E0D9FFFF          <1> 	call	print_msg
 19233 000064AB 6658                <1> 	pop	ax
 19234 000064AD 5F                  <1> 	pop	edi ; * (29/02/2016)
 19235                              <1> 	;cmp	al, 'Y' ; 'yes'
 19236                              <1> 	;cmc
 19237                              <1>         ;jnc	loc_file_rw_restore_retn
 19238 000064AE 3C4E                <1> 	cmp	al, 'N' ; 'no'
 19239 000064B0 0F8480FAFFFF        <1>         je	loc_file_rw_restore_retn  
 19240                              <1> 
 19241                              <1> loc_delete_file:
 19242 000064B6 8A3D[52C80000]      <1> 	mov	bh, [FindFile_Drv]
 19243                              <1> 	;mov	bl, [DelFile_LNEL]
 19244 000064BC 8A1D[A1C80000]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
 19245                              <1> 	;mov	cx, [DirBuff_EntryCounter]
 19246 000064C2 668B0D[CCC80000]    <1> 	mov	cx, [FindFile_DirEntryNumber]
 19247                              <1> 	; (*) EDI = Directory buffer entry offset/address 
 19248 000064C9 E88C160000          <1> 	call	remove_file ; (FILE.ASM, 'proc_delete_file')
 19249 000064CE 0F8358FAFFFF        <1> 	jnc	loc_print_deleted_message
 19250                              <1> 
 19251 000064D4 3C05                <1> 	cmp	al, 05h
 19252 000064D6 0F8464FAFFFF        <1> 	je	loc_permission_denied
 19253 000064DC F9                  <1> 	stc
 19254 000064DD E954FAFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19255                              <1> 
 19256                              <1> loc_delfile_y_n_escape:
 19257 000064E2 B04E                <1> 	mov	al, 'N' ; 'no'
 19258 000064E4 EBB4                <1> 	jmp	short loc_do_not_delete_file
 19259                              <1> 
 19260                              <1> set_file_attributes:
 19261                              <1> 	; 06/03/2016
 19262                              <1> 	; 04/03/2016 (TRDOS 386 =  TRDOS v2.0)
 19263                              <1> 	; 10/07/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_attrib')
 19264                              <1> 	; 23/05/2010 
 19265                              <1> 	; 17/12/2000 (P2000.ASM)
 19266                              <1> 
 19267                              <1> 	; esi = file or directory name
 19268 000064E6 6631C0              <1> 	xor	ax, ax
 19269 000064E9 66A3[A6B30000]      <1> 	mov	[Attr_Chars], ax
 19270 000064EF A2[68C90000]        <1> 	mov	[Attributes], al
 19271                              <1> 
 19272                              <1> get_attrib_fchar:
 19273                              <1> 	; esi = file name
 19274 000064F4 8A06                <1> 	mov	al, [esi]
 19275 000064F6 3C20                <1> 	cmp	al, 20h
 19276 000064F8 7623                <1> 	jna	short loc_attr_file_nofilename_retn
 19277                              <1> 
 19278                              <1> loc_scan_attrib_params:
 19279 000064FA 3C2D                <1> 	cmp	al, '-'
 19280 000064FC 0F871C010000        <1> 	ja	loc_attr_file_parse_path_name
 19281 00006502 7408                <1> 	je	short loc_attr_space
 19282                              <1> 
 19283 00006504 3C2B                <1> 	cmp	al, '+'
 19284 00006506 0F850AF1FFFF        <1> 	jne	loc_cmd_failed
 19285                              <1> 
 19286                              <1> loc_attr_space:
 19287 0000650C 8A6601              <1> 	mov	ah, [esi+1]
 19288 0000650F 80FC20              <1>  	cmp	ah, 20h
 19289 00006512 770A                <1> 	ja	short pass_attr_space
 19290 00006514 0F82FCF0FFFF        <1> 	jb	loc_cmd_failed
 19291 0000651A 46                  <1> 	inc	esi
 19292 0000651B EBEF                <1> 	jmp	short loc_attr_space
 19293                              <1> 
 19294                              <1> loc_attr_file_nofilename_retn:
 19295 0000651D C3                  <1> 	retn
 19296                              <1> 
 19297                              <1> pass_attr_space:
 19298 0000651E 80E4DF              <1> 	and	ah, 0DFh
 19299 00006521 80FC53              <1> 	cmp	ah, 'S'
 19300 00006524 0F87ECF0FFFF        <1> 	ja	loc_cmd_failed
 19301 0000652A 7204                <1> 	jb	short pass_attr_system
 19302 0000652C B404                <1> 	mov	ah, 04h   ; System
 19303 0000652E EB21                <1> 	jmp	short pass_attr_archive
 19304                              <1> 
 19305                              <1> pass_attr_system:
 19306 00006530 80FC48              <1> 	cmp	ah, 'H'
 19307 00006533 7706                <1> 	ja	short pass_attr_hidden
 19308 00006535 7213                <1> 	jb	short pass_attr_read_only
 19309 00006537 B402                <1> 	mov	ah, 02h    ; Hidden
 19310 00006539 EB16                <1> 	jmp	short pass_attr_archive
 19311                              <1> 
 19312                              <1> pass_attr_hidden:
 19313 0000653B 80FC52              <1> 	cmp	ah, 'R'
 19314 0000653E 0F87D2F0FFFF        <1> 	ja	loc_cmd_failed
 19315 00006544 7204                <1> 	jb	short pass_attr_read_only ; Read only
 19316 00006546 B401                <1> 	mov	ah, 01h
 19317 00006548 EB07                <1> 	jmp	short pass_attr_archive
 19318                              <1> 
 19319                              <1> pass_attr_read_only:
 19320 0000654A 80FC41              <1> 	cmp	ah, 'A'
 19321 0000654D 753B                <1> 	jne	short loc_chk_attr_enter
 19322 0000654F B420                <1> 	mov	ah, 20h    ; Archive
 19323                              <1> 
 19324                              <1> pass_attr_archive:
 19325 00006551 3C2D                <1> 	cmp	al, '-'
 19326 00006553 7508                <1> 	jne	short pass_reducing_attributes
 19327 00006555 0825[A6B30000]      <1> 	or	[Attr_Chars], ah
 19328 0000655B EB06                <1> 	jmp	short loc_change_attributes_inc
 19329                              <1> 
 19330                              <1> pass_reducing_attributes:
 19331 0000655D 0825[A7B30000]      <1> 	or	[Attr_Chars+1], ah
 19332                              <1> 
 19333                              <1> loc_change_attributes_inc:
 19334 00006563 46                  <1> 	inc	esi
 19335 00006564 8A6601              <1> 	mov	ah, [esi+1]
 19336 00006567 80FC20              <1> 	cmp	ah, 20h
 19337 0000656A 7227                <1> 	jb	short pass_change_attr
 19338 0000656C 74F5                <1> 	je	short loc_change_attributes_inc
 19339 0000656E 80FC2D              <1> 	cmp	ah, '-'
 19340 00006571 770D                <1> 	ja	short loc_chk_next_attr_char1
 19341 00006573 7405                <1> 	je	short loc_chk_next_attr_char0
 19342 00006575 80FC2B              <1> 	cmp	ah, '+'
 19343 00006578 7506                <1> 	jne	short loc_chk_next_attr_char1
 19344                              <1> 
 19345                              <1> loc_chk_next_attr_char0:
 19346 0000657A 46                  <1> 	inc	esi
 19347 0000657B 668B06              <1> 	mov	ax, [esi]
 19348 0000657E EB9E                <1> 	jmp	short pass_attr_space
 19349                              <1> 
 19350                              <1> loc_chk_next_attr_char1:
 19351 00006580 803E2D              <1> 	cmp	byte [esi], '-'
 19352 00006583 7799                <1> 	ja	short pass_attr_space
 19353 00006585 E988000000          <1>         jmp     loc_attr_file_check_fname_fchar
 19354                              <1> 
 19355                              <1> loc_chk_attr_enter:
 19356 0000658A 80FC0D              <1> 	cmp	ah, 0Dh
 19357 0000658D 0F8583F0FFFF        <1> 	jne	loc_cmd_failed
 19358                              <1> 
 19359                              <1> pass_change_attr:
 19360 00006593 A0[A6B30000]        <1> 	mov	al, [Attr_Chars]
 19361 00006598 F6D0                <1> 	not	al
 19362 0000659A 2005[68C90000]      <1> 	and	[Attributes], al
 19363 000065A0 A0[A7B30000]        <1> 	mov	al, [Attr_Chars+1]
 19364 000065A5 0805[68C90000]      <1> 	or	[Attributes], al
 19365                              <1> 
 19366                              <1> loc_show_attributes:
 19367 000065AB BE[C6BA0000]        <1> 	mov	esi, nextline
 19368 000065B0 E8D6D8FFFF          <1> 	call	print_msg
 19369                              <1> 
 19370                              <1> loc_show_attributes_no_nextline:
 19371 000065B5 C705[A6B30000]4E4F- <1> 	mov	dword [Attr_Chars], 'NORM'
 19372 000065BD 524D                <1>
 19373 000065BF 66C705[AAB30000]41- <1> 	mov	word [Attr_Chars+4], 'AL'
 19374 000065C7 4C                  <1>
 19375 000065C8 BE[A6B30000]        <1> 	mov	esi, Attr_Chars
 19376 000065CD A0[68C90000]        <1> 	mov	al, [Attributes]
 19377 000065D2 A804                <1> 	test	al, 04h
 19378 000065D4 7406                <1> 	jz	short pass_put_attr_s
 19379 000065D6 66C7065300          <1> 	mov	word [esi], 0053h     ; S
 19380 000065DB 46                  <1> 	inc	esi
 19381                              <1> 
 19382                              <1> pass_put_attr_s:
 19383 000065DC A802                <1> 	test	al, 02h
 19384 000065DE 7406                <1> 	jz	short pass_put_attr_h
 19385 000065E0 66C7064800          <1> 	mov	word [esi], 0048h     ; H
 19386 000065E5 46                  <1> 	inc	esi
 19387                              <1> 
 19388                              <1> pass_put_attr_h:
 19389 000065E6 A801                <1> 	test	al, 01h
 19390 000065E8 7406                <1> 	jz	short pass_put_attr_r
 19391 000065EA 66C7065200          <1> 	mov	word [esi], 0052h     ; R
 19392 000065EF 46                  <1> 	inc	esi
 19393                              <1> 
 19394                              <1> pass_put_attr_r:
 19395 000065F0 3C20                <1> 	cmp	al, 20h
 19396 000065F2 7205                <1> 	jb	short pass_put_attr_a
 19397 000065F4 66C7064100          <1> 	mov	word [esi], 0041h     ; A
 19398                              <1> 
 19399                              <1> pass_put_attr_a:
 19400 000065F9 BE[99B30000]        <1> 	mov	esi, Str_Attributes
 19401 000065FE E888D8FFFF          <1> 	call	print_msg
 19402 00006603 BE[C6BA0000]        <1> 	mov	esi, nextline
 19403 00006608 E87ED8FFFF          <1> 	call	print_msg
 19404 0000660D E924F9FFFF          <1> 	jmp	loc_file_rw_restore_retn 
 19405                              <1> 
 19406                              <1> loc_attr_file_check_fname_fchar:
 19407 00006612 46                  <1> 	inc	esi
 19408 00006613 803E20              <1> 	cmp	byte [esi], 20h
 19409 00006616 74FA                <1> 	je	short loc_attr_file_check_fname_fchar
 19410 00006618 0F8275FFFFFF        <1>         jb      pass_change_attr
 19411                              <1> 		   
 19412                              <1> loc_attr_file_parse_path_name:
 19413 0000661E BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 19414 00006623 E8840D0000          <1> 	call	parse_path_name
 19415 00006628 0F82E8EFFFFF        <1> 	jc	loc_cmd_failed
 19416                              <1> 
 19417                              <1> loc_attr_file_check_filename_exists:
 19418 0000662E BE[94C80000]        <1> 	mov	esi, FindFile_Name
 19419 00006633 803E20              <1> 	cmp	byte [esi], 20h
 19420 00006636 0F86DAEFFFFF        <1> 	jna	loc_cmd_failed
 19421 0000663C 8935[10C90000]      <1> 	mov	[DelFile_FNPointer], esi 
 19422                              <1> 
 19423                              <1> loc_attr_file_drv:
 19424 00006642 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 19425 00006648 8835[0EC70000]      <1> 	mov	[RUN_CDRV], dh
 19426                              <1> 
 19427 0000664E 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 19428 00006654 38F2                <1> 	cmp	dl, dh
 19429 00006656 740B                <1> 	je	short loc_attr_file_change_directory
 19430                              <1> 
 19431 00006658 E832E1FFFF          <1> 	call	change_current_drive
 19432 0000665D 0F82D3F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19433                              <1> 
 19434                              <1> loc_attr_file_change_directory:
 19435 00006663 803D[53C80000]20    <1>         cmp     byte [FindFile_Directory], 20h
 19436 0000666A 7618                <1> 	jna	short loc_attr_file_find
 19437                              <1> 
 19438 0000666C FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 19439                              <1> 	
 19440 00006672 BE[53C80000]        <1> 	mov	esi, FindFile_Directory
 19441 00006677 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 19442 00006679 E81A070000          <1> 	call	change_current_directory
 19443 0000667E 0F82B2F8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19444                              <1> 
 19445                              <1> ;loc_attr_file_change_prompt_dir_string:
 19446                              <1> 	;call	change_prompt_dir_string
 19447                              <1> 
 19448                              <1> loc_attr_file_find:
 19449                              <1> 	;mov	esi, FindFile_Name
 19450 00006684 8B35[10C90000]      <1> 	mov	esi, [DelFile_FNPointer]
 19451 0000668A 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
 19452 0000668E E87FF4FFFF          <1> 	call	find_first_file
 19453 00006693 0F829DF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19454                              <1> 
 19455                              <1> loc_attr_file_ambgfn_check:
 19456 00006699 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
 19457                              <1> 	;	(Note: It was BX in TRDOS v1)
 19458                              <1> 	;jz	short loc_attr_file_found
 19459 0000669C 0F85AAFDFFFF        <1>         jnz     loc_file_not_found ; 06/03/2016 
 19460                              <1> 
 19461                              <1> 	;mov	eax, 2 ; File not found sign
 19462                              <1> 	;stc
 19463                              <1> 	;jmp	loc_file_rw_cmd_failed   
 19464                              <1> 
 19465                              <1> loc_attr_file_found:
 19466                              <1> 	; EDI = Directory buffer entry offset/address
 19467                              <1> 	; BL = File (or Directory) Attributes 
 19468                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
 19469                              <1> 	; mov	bl, [EDI+0Bh]
 19470                              <1> 	
 19471 000066A2 66833D[A6B30000]00  <1> 	cmp	word [Attr_Chars], 0
 19472 000066AA 770B                <1> 	ja	short loc_attr_file_change_attributes
 19473 000066AC 881D[68C90000]      <1> 	mov	[Attributes], bl
 19474 000066B2 E9F4FEFFFF          <1> 	jmp	loc_show_attributes
 19475                              <1> 
 19476                              <1> loc_attr_file_change_attributes:
 19477 000066B7 A0[A6B30000]        <1> 	mov	al, [Attr_Chars]
 19478 000066BC F6D0                <1> 	not	al
 19479 000066BE 20C3                <1> 	and	bl, al
 19480 000066C0 A0[A7B30000]        <1> 	mov	al, [Attr_Chars+1]
 19481 000066C5 08C3                <1> 	or	bl, al
 19482                              <1> 
 19483 000066C7 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
 19484 000066CD 741D                <1> 	je	short loc_attr_file_fs_check
 19485                              <1> 
 19486 000066CF 881D[68C90000]      <1> 	mov	[Attributes], bl
 19487 000066D5 885F0B              <1> 	mov	[edi+0Bh], bl    ; Attributes (New!)
 19488                              <1> 
 19489                              <1> 	; 04/03/2016
 19490                              <1> 	; TRDOS v1 has a bug here! it does not set
 19491                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
 19492                              <1> 	; 'save_directory_buffer' would not save the new attributes ! 
 19493                              <1> 	
 19494 000066D8 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 19495                              <1> 
 19496 000066DF E82C110000          <1> 	call 	save_directory_buffer
 19497 000066E4 0F824CF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19498                              <1> 
 19499 000066EA EB33                <1> 	jmp	short loc_print_attr_changed_message
 19500                              <1> 
 19501                              <1> loc_attr_file_fs_check:
 19502 000066EC 29C0                <1> 	sub	eax, eax
 19503 000066EE 8A25[D6C60000]      <1>         mov     ah, [DirBuff_DRV]
 19504 000066F4 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 19505 000066F9 01C6                <1>         add     esi, eax
 19506 000066FB 807E04A1            <1>         cmp     byte [esi+LD_FSType], 0A1h
 19507 000066FF 7309                <1> 	jnc	short loc_attr_file_change_fs_file_attributes
 19508 00006701 66B80D00            <1> 	mov	ax, 0Dh ; Invalid Data
 19509 00006705 E92CF8FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19510                              <1> 
 19511                              <1> loc_attr_file_change_fs_file_attributes:
 19512                              <1> 	; BL = New MS-DOS File Attributes
 19513 0000670A 88D8                <1> 	mov	al, bl ; File/Directory Attributes
 19514 0000670C 30E4                <1> 	xor	ah, ah ; Attributes in MS-DOS format sign	  
 19515 0000670E E8A4050000          <1> 	call	change_fs_file_attributes
 19516 00006713 0F821DF8FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19517                              <1> 
 19518 00006719 881D[68C90000]      <1> 	mov	[Attributes], bl 
 19519                              <1> 
 19520                              <1> loc_print_attr_changed_message:
 19521 0000671F BE[94B30000]        <1> 	mov	esi, Msg_New
 19522 00006724 E862D7FFFF          <1> 	call	print_msg
 19523 00006729 E987FEFFFF          <1> 	jmp	loc_show_attributes_no_nextline
 19524                              <1> 
 19525                              <1> rename_file:
 19526                              <1> 	; 08/03/2016
 19527                              <1> 	; 06/03/2016 (TRDOS 386 =  TRDOS v2.0)
 19528                              <1> 	; 20/11/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_rename')
 19529                              <1> 	; 16/11/2010 
 19530                              <1> 
 19531                              <1> get_rename_source_fchar:
 19532                              <1> 	; esi = file name
 19533 0000672E 803E20              <1> 	cmp	byte [esi], 20h
 19534 00006731 7614                <1>         jna	short loc_rename_nofilename_retn
 19535                              <1> 
 19536 00006733 8935[8CC90000]      <1> 	mov	[SourceFilePath], esi
 19537                              <1> 
 19538                              <1> rename_scan_source_file:
 19539 00006739 46                  <1> 	inc	esi
 19540 0000673A 803E20              <1> 	cmp	byte [esi], 20h
 19541 0000673D 7409                <1> 	je	short rename_scan_destination_file_1
 19542                              <1> 	;jb	short loc_rename_nofilename_retn
 19543 0000673F 0F82D1EEFFFF        <1> 	jb	loc_cmd_failed
 19544 00006745 EBF2                <1> 	jmp	short rename_scan_source_file
 19545                              <1> 
 19546                              <1> loc_rename_nofilename_retn: ; 08/03/2016
 19547 00006747 C3                  <1> 	retn
 19548                              <1> 
 19549                              <1> rename_scan_destination_file_1:
 19550 00006748 C60600              <1> 	mov	byte [esi], 0
 19551                              <1> 
 19552                              <1> rename_scan_destination_file_2:
 19553 0000674B 46                  <1> 	inc	esi  
 19554 0000674C 803E20              <1> 	cmp	byte [esi], 20h
 19555 0000674F 74FA                <1> 	je	short rename_scan_destination_file_2
 19556                              <1> 	;jb	short loc_rename_nofilename_retn
 19557 00006751 0F82BFEEFFFF        <1> 	jb	loc_cmd_failed
 19558                              <1> 
 19559 00006757 8935[90C90000]      <1> 	mov	[DestinationFilePath], esi
 19560                              <1> 
 19561                              <1> rename_scan_destination_file_3:
 19562 0000675D 46                  <1> 	inc	esi  
 19563 0000675E 803E20              <1> 	cmp	byte [esi], 20h
 19564 00006761 77FA                <1> 	ja	short rename_scan_destination_file_3
 19565                              <1> 
 19566 00006763 C60600              <1> 	mov	byte [esi], 0
 19567                              <1> 
 19568                              <1> loc_rename_save_current_drive:
 19569 00006766 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 19570 0000676C 8835[0EC70000]      <1> 	mov	byte [RUN_CDRV], dh
 19571                              <1> 
 19572                              <1> loc_rename_sf_parse_path_name:
 19573 00006772 8B35[8CC90000]      <1> 	mov	esi, [SourceFilePath] 
 19574 00006778 BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 19575 0000677D E82A0C0000          <1> 	call	parse_path_name
 19576 00006782 0F828EEEFFFF        <1> 	jc	loc_cmd_failed
 19577                              <1> 
 19578                              <1> loc_rename_sf_check_filename_exists:
 19579 00006788 BE[94C80000]        <1> 	mov	esi, FindFile_Name
 19580 0000678D 803E20              <1> 	cmp	byte [esi], 20h
 19581 00006790 0F8680EEFFFF        <1> 	jna	loc_cmd_failed
 19582                              <1> 
 19583                              <1> 	;mov	[DelFile_FNPointer], esi 
 19584                              <1> 
 19585                              <1> loc_rename_sf_drv:
 19586                              <1> 	;mov	dh, [Current_Drv]
 19587                              <1> 	;mov	[RUN_CDRV], dh
 19588                              <1> 
 19589 00006796 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 19590 0000679C 38F2                <1> 	cmp	dl, dh ; dh = [Current_Drv]
 19591 0000679E 740B                <1> 	je	short rename_sf_change_directory
 19592                              <1> 
 19593 000067A0 E8EADFFFFF          <1> 	call	change_current_drive
 19594 000067A5 0F828BF7FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19595                              <1> 
 19596                              <1> rename_sf_change_directory:
 19597 000067AB 803D[53C80000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 19598 000067B2 7618                <1> 	jna	short rename_sf_find
 19599                              <1> 
 19600 000067B4 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 19601 000067BA BE[53C80000]        <1> 	mov	esi, FindFile_Directory
 19602 000067BF 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 19603 000067C1 E8D2050000          <1> 	call	change_current_directory
 19604 000067C6 0F826AF7FFFF        <1>  	jc	loc_file_rw_cmd_failed
 19605                              <1> 
 19606                              <1> ;rename_sf_change_prompt_dir_string:
 19607                              <1> 	;call	change_prompt_dir_string
 19608                              <1> 
 19609                              <1> rename_sf_find:
 19610                              <1> 	;mov	esi, [DelFile_FNPointer]
 19611 000067CC BE[94C80000]        <1> 	mov	esi, FindFile_Name
 19612                              <1> 
 19613 000067D1 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
 19614 000067D5 E838F3FFFF          <1> 	call	find_first_file
 19615 000067DA 0F8256F7FFFF        <1> 	jc	loc_file_rw_cmd_failed
 19616                              <1> 
 19617                              <1> loc_rename_sf_ambgfn_check:
 19618 000067E0 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 19619                              <1> 	;	(Note: It was BX in TRDOS v1)
 19620                              <1> 	;jz	short loc_rename_sf_found
 19621 000067E3 0F8563FCFFFF        <1> 	jnz	loc_file_not_found
 19622                              <1> 
 19623                              <1> 	;mov	eax, 2 ; File not found sign
 19624                              <1> 	;stc
 19625                              <1> 	;jmp	loc_file_rw_cmd_failed   
 19626                              <1> 
 19627                              <1> loc_rename_sf_found:
 19628                              <1> 	; EDI = Directory buffer entry offset/address
 19629                              <1> 	; BL = File (or Directory) Attributes 
 19630                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
 19631                              <1> 	; mov	bl, [EDI+0Bh]
 19632                              <1> 
 19633 000067E9 F6C307              <1> 	test	bl, 07h ; Attributes, S-H-R
 19634 000067EC 0F854EF7FFFF        <1> 	jnz	loc_permission_denied
 19635                              <1> 	
 19636 000067F2 BE[52C80000]        <1>         mov     esi, FindFile_Drv
 19637 000067F7 BF[94C90000]        <1>         mov     edi, SourceFile_Drv
 19638 000067FC B920000000          <1> 	mov	ecx, 32
 19639 00006801 F3A5                <1> 	rep	movsd
 19640                              <1> 
 19641                              <1> loc_rename_df_parse_path_name:
 19642 00006803 8B35[90C90000]      <1> 	mov	esi, [DestinationFilePath]
 19643 00006809 BF[52C80000]        <1> 	mov	edi, FindFile_Drv
 19644 0000680E E8990B0000          <1> 	call	parse_path_name
 19645 00006813 7219                <1> 	jc	short loc_rename_df_cmd_failed
 19646                              <1> 
 19647                              <1> 	;mov	dh, [RUN_CDRV]
 19648 00006815 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 19649                              <1> 
 19650                              <1> 	; 'rename' command is valid only for same dos drive and same dir!
 19651                              <1> 	; ('move' command must be used if source file and destination file
 19652                              <1> 	; directories are not same!) 
 19653 0000681B 8A15[52C80000]      <1> 	mov	dl, [FindFile_Drv]
 19654 00006821 38F2                <1> 	cmp	dl, dh ; are source and destination drives different ?!
 19655 00006823 7509                <1> 	jne	short loc_rename_df_cmd_failed ; yes! 
 19656                              <1> 
 19657                              <1> rename_df_check_dirname_exists:
 19658 00006825 803D[53C80000]00    <1> 	cmp	byte [FindFile_Directory], 0
 19659 0000682C 760B                <1> 	jna	short rename_df_check_filename_exists
 19660                              <1> 
 19661                              <1> 	; different source file and destination file directories !
 19662                              <1> loc_rename_df_cmd_failed:
 19663                              <1> loc_rename_df_found:
 19664 0000682E B801000000          <1> 	mov	eax, 1 ; TRDOS 'Bad command or file name' error
 19665 00006833 F9                  <1> 	stc
 19666 00006834 E9FDF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19667                              <1> 	  
 19668                              <1> rename_df_check_filename_exists:
 19669 00006839 BE[94C80000]        <1> 	mov	esi, FindFile_Name
 19670 0000683E E883F6FFFF          <1> 	call	check_filename
 19671 00006843 0F829FF7FFFF        <1> 	jc	loc_mkdir_invalid_dir_name_chars
 19672                              <1> 
 19673                              <1> 	;mov	[DelFile_FNPointer], esi 
 19674                              <1> 	;cmp	byte [esi], 20h
 19675                              <1> 	;ja	short loc_rename_df_find
 19676                              <1> 
 19677                              <1> 	;mov	dh, [Current_Drv] ; dh has not been changed
 19678                              <1> 
 19679                              <1> rename_df_drv_check_writable:
 19680 00006849 0FB6F6              <1> 	movzx	esi, dh
 19681                              <1> 	;movzx	esi, byte [Current_Drv]
 19682 0000684C 81C600010900        <1> 	add	esi, Logical_DOSDisks
 19683                              <1> 
 19684 00006852 88F2                <1> 	mov	dl, dh ; dl = [Current_Drv]
 19685 00006854 8A7601              <1> 	mov	dh, [esi+LD_DiskType]
 19686                              <1> 
 19687 00006857 80FE01              <1> 	cmp	dh, 1 ; 0 = Invalid
 19688 0000685A 7310                <1> 	jnb	short rename_df_compare_sf_df_name
 19689                              <1> 
 19690 0000685C B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected
 19691 00006861 8B1D[90C90000]      <1> 	mov	ebx, [DestinationFilePath] 
 19692 00006867 E9CAF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 19693                              <1> 
 19694                              <1> rename_df_compare_sf_df_name:
 19695 0000686C BE[94C80000]        <1> 	mov	esi, FindFile_Name
 19696 00006871 BF[D6C90000]        <1> 	mov	edi, SourceFile_Name
 19697 00006876 B90C000000          <1> 	mov	ecx, 12
 19698                              <1> rename_df_compare_sf_df_name_next: 
 19699 0000687B AC                  <1> 	lodsb
 19700 0000687C AE                  <1> 	scasb
 19701 0000687D 7506                <1> 	jne	short loc_rename_df_find
 19702 0000687F 08C0                <1> 	or	al, al
 19703 00006881 74AB                <1> 	jz	short loc_rename_df_cmd_failed
 19704 00006883 E2F6                <1> 	loop	rename_df_compare_sf_df_name_next 
 19705                              <1> 
 19706                              <1> loc_rename_df_find:
 19707                              <1> 	;mov	esi, [DelFile_FNPointer]
 19708 00006885 BE[94C80000]        <1> 	mov	esi, FindFile_Name
 19709                              <1> 
 19710 0000688A 6631C0              <1> 	xor	ax, ax ; Any
 19711 0000688D E880F2FFFF          <1> 	call	find_first_file
 19712 00006892 739A                <1> 	jnc	short loc_rename_df_found
 19713                              <1> 
 19714                              <1> loc_rename_df_check_error_code:
 19715                              <1> 	;cmp	eax, 2
 19716 00006894 3C02                <1> 	cmp	al, 2 ; Not found error
 19717 00006896 7406                <1> 	je	short rename_df_move_find_struct_to_dest
 19718 00006898 F9                  <1> 	stc
 19719 00006899 E998F6FFFF          <1> 	jmp loc_file_rw_cmd_failed
 19720                              <1> 
 19721                              <1> ;loc_rename_df_found:
 19722                              <1> ;	mov	eax, 1 ;Bad command or file name error
 19723                              <1> ;	stc
 19724                              <1> ;	jmp	loc_file_rw_cmd_failed
 19725                              <1> 
 19726                              <1> rename_df_move_find_struct_to_dest:
 19727 0000689E BE[52C80000]        <1>         mov     esi, FindFile_Drv
 19728 000068A3 BF[14CA0000]        <1>         mov     edi, DestinationFile_Drv
 19729 000068A8 B920000000          <1> 	mov	ecx, 32
 19730 000068AD F3A5                <1> 	rep	movsd
 19731                              <1> 
 19732                              <1> loc_rename_df_process_q_sf:
 19733                              <1> 	;mov	ecx, 12
 19734 000068AF B10C                <1> 	mov	cl, 12
 19735 000068B1 BE[D6C90000]        <1>  	mov	esi, SourceFile_Name
 19736 000068B6 BF[D5B30000]        <1> 	mov	edi, Rename_OldName
 19737                              <1> rename_df_process_q_nml_1_sf:
 19738 000068BB AC                  <1> 	lodsb
 19739 000068BC 3C20                <1>         cmp	al, 20h
 19740 000068BE 7603                <1>         jna	short rename_df_process_q_nml_2_sf
 19741 000068C0 AA                  <1> 	stosb
 19742 000068C1 E2F8                <1> 	loop	rename_df_process_q_nml_1_sf
 19743                              <1> 
 19744                              <1> rename_df_process_q_nml_2_sf:
 19745 000068C3 C60700              <1> 	mov	byte [edi], 0
 19746                              <1> 
 19747                              <1> loc_rename_df_process_q_df:
 19748                              <1> 	;mov	ecx, 12
 19749 000068C6 B10C                <1> 	mov	cl, 12
 19750 000068C8 BE[56CA0000]        <1> 	mov	esi, DestinationFile_Name
 19751 000068CD BF[E6B30000]        <1> 	mov	edi, Rename_NewName
 19752                              <1> rename_df_process_q_nml_1_df:
 19753 000068D2 AC                  <1> 	lodsb
 19754 000068D3 3C20                <1> 	cmp	al, 20h
 19755 000068D5 7603                <1> 	jna	short loc_rename_df_process_q_nml_2_df
 19756 000068D7 AA                  <1> 	stosb
 19757 000068D8 E2F8                <1> 	loop	rename_df_process_q_nml_1_df
 19758                              <1> 
 19759                              <1> loc_rename_df_process_q_nml_2_df:
 19760 000068DA C60700              <1> 	mov	byte [edi], 0
 19761                              <1> 
 19762                              <1> loc_rename_confirmation_question:
 19763 000068DD BE[ADB30000]        <1> 	mov	esi, Msg_DoYouWantRename
 19764 000068E2 E8A4D5FFFF          <1> 	call	print_msg
 19765                              <1> 
 19766 000068E7 A0[F1C90000]        <1> 	mov	al, [SourceFile_DirEntry+11] ; Attributes
 19767 000068EC 2410                <1> 	and	al, 10h
 19768 000068EE 750C                <1> 	jnz	short rename_confirmation_question_dir
 19769                              <1> 
 19770                              <1> rename_confirmation_question_file:
 19771 000068F0 BE[C4B30000]        <1> 	mov	esi, Rename_File
 19772 000068F5 E891D5FFFF          <1> 	call	print_msg 
 19773 000068FA EB0A                <1> 	jmp	short rename_confirmation_question_as 
 19774                              <1> 
 19775                              <1> rename_confirmation_question_dir:
 19776 000068FC BE[CAB30000]        <1> 	mov	esi, Rename_Directory
 19777 00006901 E885D5FFFF          <1> 	call	print_msg
 19778                              <1> 
 19779                              <1> rename_confirmation_question_as:
 19780 00006906 BE[D5B30000]        <1> 	mov	esi, Rename_OldName
 19781 0000690B E87BD5FFFF          <1> 	call	print_msg
 19782 00006910 BE[E2B30000]        <1> 	mov	esi, Msg_File_rename_as
 19783 00006915 E871D5FFFF          <1> 	call	print_msg
 19784 0000691A BE[09B30000]        <1> 	mov	esi, Msg_YesNo
 19785 0000691F E867D5FFFF          <1> 	call	print_msg
 19786                              <1> 
 19787                              <1> loc_rename_ask_again:
 19788 00006924 30E4                <1> 	xor	ah, ah
 19789 00006926 E8BCA2FFFF          <1> 	call	int16h
 19790 0000692B 3C1B                <1> 	cmp	al, 1Bh
 19791 0000692D 740F                <1> 	je	short loc_do_not_rename_file
 19792 0000692F 24DF                <1> 	and	al, 0DFh
 19793 00006931 A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 19794 00006936 3C59                <1> 	cmp	al, 'Y'
 19795 00006938 7404                <1> 	je	short loc_yes_rename_file
 19796 0000693A 3C4E                <1> 	cmp	al, 'N'
 19797 0000693C 75E6                <1> 	jne	short loc_rename_ask_again
 19798                              <1> 
 19799                              <1> loc_do_not_rename_file:
 19800                              <1> loc_yes_rename_file:
 19801 0000693E A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 19802 00006943 6650                <1> 	push	ax
 19803 00006945 BE[13B30000]        <1> 	mov	esi, Y_N_nextline
 19804 0000694A E83CD5FFFF          <1> 	call	print_msg
 19805 0000694F 6658                <1> 	pop	ax
 19806                              <1> 	;cmp	al, 'Y' ; 'yes'
 19807                              <1> 	;cmc
 19808                              <1>         ;jnc	loc_file_rw_restore_retn
 19809 00006951 3C4E                <1> 	cmp	al, 'N' ; 'no'
 19810 00006953 0F84DDF5FFFF        <1>         je	loc_file_rw_restore_retn  
 19811                              <1> 
 19812 00006959 BE[E6B30000]        <1> 	mov	esi, Rename_NewName
 19813 0000695E 668B0D[0ECA0000]    <1> 	mov	cx, [SourceFile_DirEntryNumber] 
 19814 00006965 66A1[FAC90000]      <1> 	mov	ax, [SourceFile_DirEntry+20] ; First Cluster, HW 
 19815 0000696B 66C1E010            <1> 	shl	ax, 16
 19816 0000696F 66A1[00CA0000]      <1> 	mov	ax, [SourceFile_DirEntry+26] ; First Cluster, LW 
 19817                              <1> 
 19818 00006975 0FB61D[E3C90000]    <1>   	movzx	ebx, byte [SourceFile_LongNameEntryLength]  
 19819 0000697C E875120000          <1>    	call	rename_directory_entry
 19820 00006981 E9DEF6FFFF          <1> 	jmp	loc_rename_file_ok	
 19821                              <1> ;loc_rename_file_ok:
 19822                              <1> ;	jc	loc_run_cmd_failed
 19823                              <1> ;	mov	esi, Msg_OK
 19824                              <1> ;	call	proc_printmsg
 19825                              <1> ;	jmp	loc_file_rw_restore_retn
 19826                              <1> 
 19827                              <1> move_file:
 19828                              <1> 	; 11/03/2016
 19829                              <1> 	; 09/03/2016
 19830                              <1> 	; 08/03/2016 (TRDOS 386 =  TRDOS v2.0)
 19831                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_move')
 19832                              <1> 	; 23/04/2011
 19833                              <1> 
 19834                              <1> get_move_source_fchar:
 19835                              <1> 	; esi = file name
 19836 00006986 803E20              <1> 	cmp	byte [esi], 20h
 19837 00006989 7614                <1>         jna	short loc_move_nofilename_retn
 19838                              <1> 
 19839 0000698B 8935[8CC90000]      <1> 	mov	[SourceFilePath], esi
 19840                              <1> 
 19841                              <1> move_scan_source_file:
 19842 00006991 46                  <1> 	inc	esi
 19843 00006992 803E20              <1> 	cmp	byte [esi], 20h
 19844 00006995 7409                <1>         je      short move_scan_destination_1
 19845                              <1> 	;jb	short loc_move_nofilename_retn
 19846 00006997 0F8279ECFFFF        <1> 	jb	loc_cmd_failed
 19847 0000699D EBF2                <1> 	jmp	short move_scan_source_file
 19848                              <1> 
 19849                              <1> loc_move_nofilename_retn:
 19850 0000699F C3                  <1> 	retn
 19851                              <1> 
 19852                              <1> move_scan_destination_1:
 19853 000069A0 C60600              <1> 	mov	byte [esi], 0
 19854                              <1> 
 19855                              <1> move_scan_destination_2:
 19856 000069A3 46                  <1> 	inc	esi  
 19857 000069A4 803E20              <1> 	cmp	byte [esi], 20h
 19858 000069A7 74FA                <1> 	je	short move_scan_destination_2
 19859                              <1> 	;jb	short loc_move_nofilename_retn
 19860 000069A9 0F8267ECFFFF        <1> 	jb	loc_cmd_failed
 19861                              <1> 
 19862 000069AF 8935[90C90000]      <1> 	mov	[DestinationFilePath], esi
 19863                              <1> 
 19864                              <1> move_scan_destination_3:
 19865 000069B5 46                  <1> 	inc	esi  
 19866 000069B6 803E20              <1> 	cmp	byte [esi], 20h
 19867 000069B9 77FA                <1> 	ja	short move_scan_destination_3
 19868 000069BB C60600              <1> 	mov	byte [esi], 0
 19869                              <1> 
 19870                              <1> loc_move_scan_destination_OK:
 19871 000069BE 8B35[8CC90000]      <1> 	mov	esi, [SourceFilePath]
 19872 000069C4 8B3D[90C90000]      <1> 	mov	edi, [DestinationFilePath]
 19873                              <1> 
 19874 000069CA B001                <1> 	mov	al, 1  ; move procedure Phase 1
 19875 000069CC E8A2120000          <1> 	call	move_source_file_to_destination_file
 19876 000069D1 7328                <1> 	jnc	short move_source_file_to_destination_question
 19877                              <1> 
 19878                              <1> loc_move_cmd_failed_1:
 19879 000069D3 08C0                <1> 	or	al, al
 19880 000069D5 0F843BECFFFF        <1> 	jz	loc_cmd_failed 
 19881 000069DB 3C11                <1> 	cmp	al, 11h
 19882 000069DD 740D                <1> 	je	short loc_msg_not_same_device   
 19883 000069DF 3C05                <1> 	cmp	al, 05h
 19884 000069E1 0F855AECFFFF        <1> 	jne	loc_run_cmd_failed
 19885                              <1> 
 19886 000069E7 E954F5FFFF          <1> 	jmp	loc_permission_denied
 19887                              <1> 
 19888                              <1> 	;mov	esi, Msg_Permission_denied
 19889                              <1> 	;call	print_msg
 19890                              <1> 	;jmp	loc_file_rw_restore_retn
 19891                              <1> 
 19892                              <1> loc_msg_not_same_device:
 19893 000069EC BE[F3B30000]        <1> 	mov	esi, msg_not_same_drv 
 19894 000069F1 E895D4FFFF          <1> 	call	print_msg
 19895 000069F6 E93BF5FFFF          <1> 	jmp	loc_file_rw_restore_retn
 19896                              <1> 
 19897                              <1> move_source_file_to_destination_question:
 19898 000069FB A0[94C90000]        <1>         mov     al, [SourceFile_Drv]
 19899 00006A00 0441                <1> 	add	al, 'A'
 19900 00006A02 A2[55B40000]        <1> 	mov	[msg_source_file_drv], al
 19901 00006A07 A0[14CA0000]        <1>         mov     al, [DestinationFile_Drv]
 19902 00006A0C 0441                <1> 	add	al, 'A'
 19903 00006A0E A2[74B40000]        <1> 	mov	[msg_destination_file_drv], al
 19904                              <1> 
 19905 00006A13 57                  <1> 	push	edi ; *
 19906                              <1> 
 19907 00006A14 BE[39B40000]        <1> 	mov	esi, msg_source_file
 19908 00006A19 E86DD4FFFF          <1> 	call	print_msg
 19909 00006A1E BE[95C90000]        <1> 	mov	esi, SourceFile_Directory
 19910 00006A23 803E20              <1> 	cmp	byte [esi], 20h
 19911 00006A26 7605                <1> 	jna	short msftdfq_sfn
 19912 00006A28 E85ED4FFFF          <1> 	call	print_msg
 19913                              <1> msftdfq_sfn:
 19914 00006A2D BE[D6C90000]        <1> 	mov	esi, SourceFile_Name
 19915 00006A32 E854D4FFFF          <1> 	call	print_msg
 19916 00006A37 BE[58B40000]        <1> 	mov	esi, msg_destination_file
 19917 00006A3C E84AD4FFFF          <1> 	call	print_msg
 19918 00006A41 BE[15CA0000]        <1> 	mov	esi, DestinationFile_Directory
 19919 00006A46 803E20              <1> 	cmp	byte [esi], 20h
 19920 00006A49 7605                <1> 	jna	short msftdfq_dfn
 19921 00006A4B E83BD4FFFF          <1> 	call	print_msg
 19922                              <1> msftdfq_dfn:
 19923 00006A50 BE[56CA0000]        <1> 	mov	esi, DestinationFile_Name
 19924 00006A55 E831D4FFFF          <1> 	call	print_msg
 19925 00006A5A BE[77B40000]        <1> 	mov	esi, msg_copy_nextline
 19926 00006A5F E827D4FFFF          <1> 	call	print_msg
 19927 00006A64 BE[77B40000]        <1> 	mov	esi, msg_copy_nextline
 19928 00006A69 E81DD4FFFF          <1> 	call	print_msg
 19929                              <1> 
 19930                              <1> loc_move_ask_for_new_file_yes_no:
 19931 00006A6E BE[05B40000]        <1> 	mov	esi, Msg_DoYouWantMoveFile
 19932 00006A73 E813D4FFFF          <1> 	call	print_msg
 19933 00006A78 BE[09B30000]        <1> 	mov	esi, Msg_YesNo
 19934 00006A7D E809D4FFFF          <1> 	call	print_msg
 19935                              <1> loc_move_ask_for_new_file_again:
 19936 00006A82 30E4                <1> 	xor	ah, ah
 19937 00006A84 E85EA1FFFF          <1> 	call	int16h
 19938 00006A89 3C1B                <1> 	cmp	al, 1Bh
 19939                              <1> 	;je	short loc_do_not_move_file
 19940 00006A8B 744F                <1> 	je	short loc_move_y_n_escape
 19941 00006A8D 24DF                <1> 	and	al, 0DFh
 19942 00006A8F A2[13B30000]        <1>         mov     [Y_N_nextline], al
 19943 00006A94 3C59                <1> 	cmp	al, 'Y'
 19944 00006A96 7404                <1> 	je	short loc_yes_move_file
 19945 00006A98 3C4E                <1> 	cmp	al, 'N'
 19946 00006A9A 75E6                <1> 	jne	short loc_move_ask_for_new_file_again
 19947                              <1> 
 19948                              <1> loc_do_not_move_file:
 19949                              <1> loc_yes_move_file:
 19950 00006A9C A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 19951 00006AA1 6650                <1> 	push	ax
 19952 00006AA3 BE[13B30000]        <1> 	mov	esi, Y_N_nextline
 19953 00006AA8 E8DED3FFFF          <1> 	call	print_msg
 19954 00006AAD 6658                <1> 	pop	ax
 19955 00006AAF 5F                  <1> 	pop	edi ; *
 19956                              <1> 	;cmp	al, 'Y' ; 'yes'
 19957                              <1> 	;cmc
 19958                              <1>         ;jnc	loc_file_rw_restore_retn
 19959 00006AB0 3C4E                <1> 	cmp	al, 'N' ; 'no'
 19960 00006AB2 0F847EF4FFFF        <1>         je	loc_file_rw_restore_retn
 19961                              <1> 
 19962                              <1> loc_move_yes_move_file:
 19963 00006AB8 B002                <1> 	mov	al, 2 ; move procedure Phase 2
 19964 00006ABA E8B4110000          <1> 	call	move_source_file_to_destination_file
 19965                              <1> 	;jc	short loc_move_cmd_failed_2
 19966 00006ABF 0F83A5F5FFFF        <1>         jnc     move_source_file_to_destination_OK
 19967                              <1> 
 19968                              <1> ;move_source_file_to_destination_OK:
 19969                              <1> ;	mov	esi, Msg_OK
 19970                              <1> ;	call	print_msg
 19971                              <1> ;	jmp	loc_file_rw_restore_retn
 19972                              <1> 
 19973                              <1> loc_move_cmd_failed_2:
 19974 00006AC5 3C27                <1> 	cmp	al, 27h
 19975 00006AC7 0F8574EBFFFF        <1> 	jne	loc_run_cmd_failed
 19976                              <1> 
 19977 00006ACD BE[1EB40000]        <1> 	mov	esi, msg_insufficient_disk_space
 19978 00006AD2 E8B4D3FFFF          <1> 	call	print_msg
 19979                              <1> 
 19980 00006AD7 E95AF4FFFF          <1> 	jmp	loc_file_rw_restore_retn
 19981                              <1> 
 19982                              <1> loc_move_y_n_escape:
 19983 00006ADC B04E                <1> 	mov	al, 'N' ; 'no'
 19984 00006ADE EBBC                <1> 	jmp	short loc_do_not_move_file
 19985                              <1> 
 19986                              <1> copy_file:
 19987                              <1> 	; 24/03/2016
 19988                              <1> 	; 21/03/2016
 19989                              <1> 	; 15/03/2016 (TRDOS 386 =  TRDOS v2.0)
 19990                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_copy')
 19991                              <1> 	; 01/08/2010
 19992                              <1> 
 19993                              <1> get_copy_source_fchar:
 19994                              <1> 	; esi = file name
 19995 00006AE0 803E20              <1> 	cmp	byte [esi], 20h
 19996 00006AE3 7614                <1>         jna     short loc_copy_nofilename_retn
 19997                              <1> 
 19998 00006AE5 8935[8CC90000]      <1> 	mov	[SourceFilePath], esi
 19999                              <1> 
 20000                              <1> copy_scan_source_file:
 20001 00006AEB 46                  <1> 	inc	esi  
 20002 00006AEC 803E20              <1> 	cmp	byte [esi], 20h
 20003 00006AEF 7409                <1> 	je	short copy_scan_destination_1
 20004                              <1> 	;jb	short loc_copy_nofilename_retn
 20005 00006AF1 0F821FEBFFFF        <1> 	jb	loc_cmd_failed
 20006 00006AF7 EBF2                <1> 	jmp	short copy_scan_source_file
 20007                              <1> 
 20008                              <1> loc_copy_nofilename_retn:
 20009 00006AF9 C3                  <1> 	retn
 20010                              <1> 
 20011                              <1> copy_scan_destination_1:
 20012 00006AFA C60600              <1> 	mov	byte [esi], 0
 20013                              <1> 
 20014                              <1> copy_scan_destination_2:
 20015 00006AFD 46                  <1> 	inc	esi  
 20016 00006AFE 803E20              <1> 	cmp	byte [esi], 20h
 20017 00006B01 74FA                <1> 	je	short copy_scan_destination_2
 20018                              <1> 	;jb	short loc_copy_nofilename_retn
 20019 00006B03 0F820DEBFFFF        <1> 	jb	loc_cmd_failed
 20020                              <1> 
 20021 00006B09 8935[90C90000]      <1> 	mov	[DestinationFilePath], esi
 20022                              <1> 
 20023                              <1> copy_scan_destination_3:
 20024 00006B0F 46                  <1> 	inc	esi  
 20025 00006B10 803E20              <1> 	cmp	byte [esi], 20h
 20026 00006B13 77FA                <1> 	ja	short copy_scan_destination_3
 20027 00006B15 C60600              <1> 	mov	byte [esi], 0
 20028                              <1> 
 20029                              <1> loc_copy_save_current_drive:
 20030 00006B18 8A35[AEBE0000]      <1> 	mov	dh, [Current_Drv]
 20031 00006B1E 8835[0EC70000]      <1> 	mov	[RUN_CDRV], dh
 20032                              <1> 
 20033                              <1> copy_source_file_to_destination_phase_1:
 20034 00006B24 8B35[8CC90000]      <1> 	mov	esi, [SourceFilePath]
 20035 00006B2A 8B3D[90C90000]      <1> 	mov	edi, [DestinationFilePath]
 20036                              <1> 
 20037 00006B30 B001                <1> 	mov	al, 1  ; copy procedure Phase 1
 20038 00006B32 E8C7130000          <1> 	call	copy_source_file_to_destination_file
 20039 00006B37 732B                <1> 	jnc	short copy_source_file_to_destination_question
 20040                              <1> 
 20041                              <1> loc_copy_cmd_failed_1:
 20042                              <1> 	; 18/03/2016 (restore current drive and directory)
 20043 00006B39 08C0                <1> 	or	al, al
 20044 00006B3B 7507                <1> 	jnz	short loc_copy_cmd_failed_2
 20045                              <1> 
 20046 00006B3D FEC0                <1>         inc     al ; mov al, 1 ; Bad command or file name !
 20047 00006B3F E9FDEAFFFF          <1> 	jmp	loc_run_cmd_failed
 20048                              <1> 
 20049                              <1> loc_copy_cmd_failed_2:
 20050 00006B44 3C27                <1> 	cmp	al, 27h ; Insufficient disk space 
 20051 00006B46 740D                <1> 	je	short loc_file_write_insuff_disk_space_msg
 20052                              <1>  
 20053 00006B48 3C05                <1> 	cmp	al, 05h
 20054 00006B4A 0F85F1EAFFFF        <1> 	jne	loc_run_cmd_failed
 20055                              <1> 	
 20056 00006B50 E9EBF3FFFF          <1> 	jmp	loc_permission_denied
 20057                              <1> 
 20058                              <1> loc_file_write_insuff_disk_space_msg:
 20059 00006B55 BE[1EB40000]        <1> 	mov	esi, msg_insufficient_disk_space
 20060 00006B5A E82CD3FFFF          <1> 	call	print_msg
 20061 00006B5F E9D2F3FFFF          <1>         jmp     loc_file_rw_restore_retn 
 20062                              <1> 
 20063                              <1> copy_source_file_to_destination_question:
 20064 00006B64 57                  <1> 	push	edi ; *
 20065                              <1> 
 20066                              <1> 	; dh = source file attributes
 20067                              <1> 	; dl > 0 -> destination file found
 20068 00006B65 20D2                <1> 	and	dl, dl            
 20069 00006B67 7449                <1> 	jz	short copy_source_file_to_destination_pass_owrq
 20070                              <1> 
 20071                              <1> loc_copy_ask_for_owr_yes_no:
 20072 00006B69 BE[7AB40000]        <1> 	mov	esi, Msg_DoYouWantOverWriteFile
 20073 00006B6E E818D3FFFF          <1> 	call	print_msg
 20074 00006B73 BE[56CA0000]        <1> 	mov	esi, DestinationFile_Name
 20075 00006B78 E80ED3FFFF          <1> 	call	print_msg
 20076 00006B7D BE[09B30000]        <1> 	mov	esi, Msg_YesNo
 20077 00006B82 E804D3FFFF          <1> 	call	print_msg
 20078                              <1> 
 20079                              <1> loc_copy_ask_for_owr_again:
 20080 00006B87 30E4                <1> 	xor	ah, ah
 20081 00006B89 E859A0FFFF          <1> 	call	int16h
 20082 00006B8E 3C1B                <1> 	cmp	al, 1Bh
 20083                              <1>         ;je     loc_do_not_copy_file
 20084 00006B90 7419                <1>         je      short loc_copy_y_n_escape
 20085 00006B92 24DF                <1> 	and	al, 0DFh
 20086 00006B94 A2[13B30000]        <1>         mov     [Y_N_nextline], al
 20087 00006B99 3C59                <1> 	cmp	al, 'Y'
 20088 00006B9B 0F84B1000000        <1>         je      loc_yes_copy_file
 20089 00006BA1 3C4E                <1> 	cmp	al, 'N'
 20090 00006BA3 0F84A9000000        <1>         je      loc_do_not_copy_file
 20091 00006BA9 EBDC                <1> 	jmp	short loc_copy_ask_for_owr_again
 20092                              <1> 
 20093                              <1> loc_copy_y_n_escape:
 20094 00006BAB B04E                <1> 	mov	al, 'N' ; 'no'
 20095 00006BAD E9A0000000          <1>         jmp     loc_do_not_copy_file
 20096                              <1> 
 20097                              <1> copy_source_file_to_destination_pass_owrq:
 20098 00006BB2 A0[94C90000]        <1> 	mov     al, [SourceFile_Drv]
 20099 00006BB7 0441                <1> 	add	al, 'A'
 20100 00006BB9 A2[55B40000]        <1> 	mov	[msg_source_file_drv], al
 20101 00006BBE A0[14CA0000]        <1>         mov     al, [DestinationFile_Drv]
 20102 00006BC3 0441                <1> 	add	al, 'A'
 20103 00006BC5 A2[74B40000]        <1> 	mov	[msg_destination_file_drv], al
 20104                              <1> 
 20105 00006BCA BE[39B40000]        <1> 	mov	esi, msg_source_file
 20106 00006BCF E8B7D2FFFF          <1> 	call	print_msg
 20107 00006BD4 BE[95C90000]        <1> 	mov	esi, SourceFile_Directory
 20108 00006BD9 803E20              <1> 	cmp	byte [esi], 20h
 20109 00006BDC 7605                <1> 	jna	short csftdfq_sfn
 20110 00006BDE E8A8D2FFFF          <1> 	call	print_msg
 20111                              <1> csftdfq_sfn:
 20112 00006BE3 BE[D6C90000]        <1> 	mov	esi, SourceFile_Name
 20113 00006BE8 E89ED2FFFF          <1> 	call	print_msg
 20114 00006BED BE[58B40000]        <1> 	mov	esi, msg_destination_file
 20115 00006BF2 E894D2FFFF          <1> 	call	print_msg
 20116 00006BF7 BE[15CA0000]        <1> 	mov	esi, DestinationFile_Directory
 20117 00006BFC 803E20              <1> 	cmp	byte [esi], 20h
 20118 00006BFF 7605                <1> 	jna	short csftdfq_dfn
 20119 00006C01 E885D2FFFF          <1> 	call	print_msg
 20120                              <1> csftdfq_dfn:
 20121 00006C06 BE[56CA0000]        <1> 	mov	esi, DestinationFile_Name
 20122 00006C0B E87BD2FFFF          <1> 	call	print_msg
 20123 00006C10 BE[77B40000]        <1> 	mov	esi, msg_copy_nextline
 20124 00006C15 E871D2FFFF          <1> 	call	print_msg
 20125 00006C1A BE[77B40000]        <1> 	mov	esi, msg_copy_nextline
 20126 00006C1F E867D2FFFF          <1> 	call	print_msg
 20127                              <1> 
 20128                              <1> loc_copy_ask_for_new_file_yes_no:
 20129 00006C24 BE[99B40000]        <1> 	mov	esi, Msg_DoYouWantCopyFile
 20130 00006C29 E85DD2FFFF          <1> 	call	print_msg
 20131 00006C2E BE[09B30000]        <1> 	mov	esi, Msg_YesNo
 20132 00006C33 E853D2FFFF          <1> 	call	print_msg
 20133                              <1> 
 20134                              <1> loc_copy_ask_for_new_file_again:
 20135 00006C38 30E4                <1> 	xor	ah, ah
 20136 00006C3A E8A89FFFFF          <1> 	call	int16h
 20137 00006C3F 3C1B                <1> 	cmp	al, 1Bh
 20138 00006C41 740F                <1> 	je	short loc_do_not_copy_file
 20139 00006C43 24DF                <1> 	and	al, 0DFh
 20140 00006C45 A2[13B30000]        <1>         mov     [Y_N_nextline], al
 20141 00006C4A 3C59                <1> 	cmp	al, 'Y'
 20142 00006C4C 7404                <1> 	je	short loc_yes_copy_file
 20143 00006C4E 3C4E                <1> 	cmp	al, 'N'
 20144 00006C50 75E6                <1> 	jne	short loc_copy_ask_for_new_file_again
 20145                              <1> 
 20146                              <1> loc_do_not_copy_file:
 20147                              <1> loc_yes_copy_file:
 20148 00006C52 A2[13B30000]        <1> 	mov	[Y_N_nextline], al
 20149 00006C57 6650                <1> 	push	ax
 20150 00006C59 BE[13B30000]        <1> 	mov	esi, Y_N_nextline
 20151 00006C5E E828D2FFFF          <1> 	call	print_msg
 20152 00006C63 6658                <1> 	pop	ax
 20153 00006C65 5F                  <1> 	pop	edi ; *
 20154                              <1> 	;cmp	al, 'Y' ; 'yes'
 20155                              <1> 	;cmc
 20156                              <1>         ;jnc	loc_file_rw_restore_retn
 20157 00006C66 3C4E                <1> 	cmp	al, 'N' ; 'no'
 20158 00006C68 0F84C8F2FFFF        <1>         je	loc_file_rw_restore_retn
 20159                              <1> 
 20160                              <1> copy_source_file_to_destination_pass_q:
 20161 00006C6E B002                <1> 	mov	al, 2  ; copy procedure Phase 2
 20162 00006C70 E889120000          <1> 	call	copy_source_file_to_destination_file
 20163                              <1> 	;jc	short loc_file_write_check_disk_space_err
 20164                              <1> 
 20165                              <1> 	; 24/03/2016
 20166 00006C75 6651                <1> 	push	cx
 20167 00006C77 BE[77B40000]        <1> 	mov	esi, msg_copy_nextline
 20168 00006C7C E80AD2FFFF          <1> 	call	print_msg
 20169                              <1> 	;pop	cx
 20170 00006C81 6658                <1> 	pop	ax
 20171                              <1> 
 20172                              <1> 	;or	cl, cl
 20173 00006C83 08C0                <1> 	or	al, al
 20174 00006C85 7419                <1> 	jz	short copy_source_file_to_destination_OK
 20175                              <1> 	
 20176                              <1> 	; 18/03/2016
 20177                              <1> 	;cmp	cl, 1Dh ; write error
 20178 00006C87 3C1D                <1> 	cmp	al, 1Dh
 20179 00006C89 7506                <1> 	jne	short copy_source_file_to_destination_not_OK
 20180                              <1> 	;
 20181                              <1> 	;mov	al, cl ; error number (write fault!)
 20182 00006C8B F9                  <1> 	stc
 20183 00006C8C E9A5F2FFFF          <1> 	jmp	loc_file_rw_cmd_failed
 20184                              <1> 
 20185                              <1> copy_source_file_to_destination_not_OK:
 20186 00006C91 BE[B2B40000]        <1> 	mov	esi, Msg_read_file_error_before_EOF
 20187 00006C96 E8F0D1FFFF          <1> 	call	print_msg
 20188 00006C9B E996F2FFFF          <1> 	jmp	loc_file_rw_restore_retn	      
 20189                              <1>  
 20190                              <1> copy_source_file_to_destination_OK:
 20191 00006CA0 BE[17B30000]        <1> 	mov	esi, Msg_OK
 20192 00006CA5 E8E1D1FFFF          <1> 	call	print_msg
 20193                              <1> 
 20194 00006CAA E987F2FFFF          <1> 	jmp	loc_file_rw_restore_retn
 20195                              <1> 
 20196                              <1> ;loc_file_write_check_disk_space_err:
 20197                              <1> 	;cmp	al, 27h ; Insufficient disk space 
 20198                              <1> 	;je	loc_file_write_insuff_disk_space_msg
 20199                              <1>         ;jb	loc_file_rw_cmd_failed
 20200                              <1> 
 20201                              <1> 	;call	print_misc_error_msg ; 15/03/2016
 20202                              <1>         ;jmp	loc_file_rw_restore_retn 
 20203                              <1> 
 20204                              <1> 
 20205                              <1> set_get_path:
 20206 00006CAF C3                  <1> 	retn
 20207                              <1> find_and_list_files:
 20208 00006CB0 C3                  <1> 	retn
 20209                              <1> set_get_env:
 20210 00006CB1 C3                  <1> 	retn
 20211                              <1> set_exec_arguments:
 20212 00006CB2 C3                  <1> 	retn
 20213                              <1> load_and_execute_file:
 20214 00006CB3 C3                  <1> 	retn
 20215                              <1> delete_fs_directory:
 20216 00006CB4 31C0                <1> 	xor eax, eax
 20217 00006CB6 C3                  <1> 	retn
 20218                              <1> 
 20219                              <1> change_fs_file_attributes:
 20220                              <1> 	; 04/03/2016 ; Temporary
 20221                              <1> 	; AL = File or directory attributes
 20222                              <1> 	; AH = 0 -> Attributes are in MS-DOS format
 20223                              <1> 	; AH > 0 -> Attributes are in SINGLIX format
 20224                              <1> 	;push	ebx
 20225                              <1> 	; ... do somethings here ...
 20226                              <1> 	;pop	ebx
 20227                              <1> 	; BL = File or directory attributes
 20228 00006CB7 C3                  <1> 	retn
 20229                                  %include 'trdosk4.s' ; 24/01/2016
 20230                              <1> ; ****************************************************************************
 20231                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - Directory Functions : trdosk4.s
 20232                              <1> ; ----------------------------------------------------------------------------
 20233                              <1> ; Last Update: 05/04/2016
 20234                              <1> ; ----------------------------------------------------------------------------
 20235                              <1> ; Beginning: 24/01/2016
 20236                              <1> ; ----------------------------------------------------------------------------
 20237                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 20238                              <1> ; ----------------------------------------------------------------------------
 20239                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 20240                              <1> ; DIR.ASM (09/10/2011)
 20241                              <1> ; ****************************************************************************
 20242                              <1> 
 20243                              <1> ; DIR.ASM  [ TRDOS KERNEL - COMMAND EXECUTER SECTION - DIRECTORY FUNCTIONS ]
 20244                              <1> ; (c) 2004-2010  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/10/2011
 20245                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
 20246                              <1> 
 20247                              <1> change_prompt_dir_string:
 20248                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 20249                              <1> 	; 27/03/2011
 20250                              <1> 	; 09/10/2009
 20251                              <1> 	; INPUT/OUTPUT => none
 20252                              <1> 	; this procedure changes current directory string/text  
 20253                              <1> 	; 2005
 20254                              <1> 
 20255 00006CB8 BF[B2BE0000]        <1> 	mov	edi, Current_Directory
 20256 00006CBD 8A25[ACBE0000]      <1> 	mov	ah, [Current_Dir_Level]
 20257 00006CC3 BE[0FC70000]        <1> 	mov	esi, PATH_Array
 20258 00006CC8 E807000000          <1> 	call	set_current_directory_string
 20259 00006CCD 880D[0DBF0000]      <1> 	mov	[Current_Dir_StrLen], cl
 20260                              <1> 
 20261 00006CD3 C3                  <1> 	retn
 20262                              <1> 
 20263                              <1> set_current_directory_string:
 20264                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 20265                              <1> 	; 27/03/2011
 20266                              <1> 	; 09/10/2009
 20267                              <1> 	; INPUT:
 20268                              <1> 	;    ESI = Path Array Address 
 20269                              <1> 	;    EDI = Current Directory String Buffer
 20270                              <1> 	;    AH = Current Directory Level
 20271                              <1> 	; OUTPUT => EAX, EBX, ESI will be changed
 20272                              <1> 	;    EDI will be same with input
 20273                              <1> 	;    ECX = Current Directory String Length 
 20274                              <1> 
 20275 00006CD4 57                  <1> 	push    edi
 20276 00006CD5 80FC00              <1> 	cmp     ah, 0
 20277 00006CD8 7652                <1> 	jna	short pass_write_path
 20278 00006CDA 83C610              <1> 	add	esi, 16
 20279 00006CDD 89F3                <1> 	mov	ebx, esi
 20280                              <1> loc_write_path:
 20281 00006CDF B908000000          <1> 	mov	ecx, 8
 20282                              <1> path_write_dirname1:
 20283 00006CE4 AC                  <1> 	lodsb
 20284 00006CE5 3C20                <1> 	cmp	al, 20h
 20285 00006CE7 7612                <1> 	jna	short pass_write_dirname1
 20286 00006CE9 AA                  <1> 	stosb
 20287 00006CEA 81FF[0CBF0000]      <1> 	cmp	edi, End_Of_Current_Dir_Str
 20288 00006CF0 733A                <1> 	jnb	short pass_write_path
 20289 00006CF2 E2F0                <1> 	loop	path_write_dirname1
 20290 00006CF4 803E20              <1> 	cmp	byte [esi], 20h
 20291 00006CF7 7624                <1> 	jna	short pass_write_dirname2
 20292 00006CF9 EB0A                <1> 	jmp     short loc_put_dot_cont_ext
 20293                              <1> pass_write_dirname1:
 20294 00006CFB 89DE                <1> 	mov	esi, ebx
 20295 00006CFD 83C608              <1> 	add	esi, 8
 20296 00006D00 803E20              <1> 	cmp	byte [esi], 20h
 20297 00006D03 7618                <1> 	jna	short pass_write_dirname2
 20298                              <1> loc_put_dot_cont_ext:
 20299 00006D05 C6072E              <1> 	mov	byte [edi], "."
 20300                              <1> 	;mov	ecx, 3
 20301 00006D08 B103                <1> 	mov	cl, 3
 20302                              <1> loc_check_dir_name_ext:
 20303 00006D0A AC                  <1> 	lodsb
 20304 00006D0B 47                  <1> 	inc	edi
 20305 00006D0C 3C20                <1> 	cmp	al, 20h
 20306 00006D0E 760D                <1> 	jna	short pass_write_dirname2
 20307 00006D10 8807                <1> 	mov	[edi], al
 20308 00006D12 81FF[0CBF0000]      <1> 	cmp	edi, End_Of_Current_Dir_Str
 20309 00006D18 7312                <1> 	jnb	short pass_write_path
 20310 00006D1A E2EE                <1> 	loop    loc_check_dir_name_ext
 20311 00006D1C 47                  <1> 	inc	edi
 20312                              <1> pass_write_dirname2:
 20313 00006D1D FECC                <1> 	dec	ah
 20314 00006D1F 740B                <1> 	jz      short pass_write_path
 20315 00006D21 83C310              <1> 	add	ebx, 16
 20316 00006D24 89DE                <1> 	mov	esi, ebx
 20317 00006D26 C6072F              <1> 	mov	byte [edi],"/"
 20318 00006D29 47                  <1> 	inc	edi
 20319 00006D2A EBB3                <1> 	jmp	short loc_write_path
 20320                              <1> pass_write_path:
 20321 00006D2C C60700              <1> 	mov	byte [edi], 0
 20322 00006D2F 47                  <1> 	inc	edi
 20323 00006D30 89F9                <1> 	mov	ecx, edi
 20324 00006D32 5F                  <1> 	pop	edi
 20325 00006D33 29F9                <1> 	sub	ecx, edi
 20326                              <1> 	; ECX = Current Directory String Length
 20327 00006D35 C3                  <1> 	retn
 20328                              <1> 
 20329                              <1> get_current_directory:
 20330                              <1> 	; 14/02/2016
 20331                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 20332                              <1> 	; 27/03/2011
 20333                              <1> 	;
 20334                              <1> 	; INPUT-> ESI = Current Directory Buffer
 20335                              <1> 	;         DL = TRDOS Logical Dos Drive Number + 1
 20336                              <1> 	;              (0= Default/Current Drive)
 20337                              <1> 	;           
 20338                              <1> 	;   Note: Required dir buffer length may be <= 92 bytes
 20339                              <1> 	;         for TRDOS (7*12 name chars + 7 slash + 0)
 20340                              <1> 	; OUTPUT ->  ESI = Current Directory Buffer
 20341                              <1> 	;            EAX, EBX, ECX, EDX, EDI will be changed
 20342                              <1> 	;            CX/CL = Current Directory String Length
 20343                              <1> 	;	     DL = Drive Number (0 based)
 20344                              <1> 	;            (If input is 0, output is current drv number) 
 20345                              <1> 	;            DH = same with input 
 20346                              <1> 	;   cf = 0 -> AL = 0
 20347                              <1> 	;   cf = 1 -> error code in AL 
 20348                              <1>               
 20349                              <1> loc_get_current_drive_0:
 20350 00006D36 80FA00              <1> 	cmp	dl, 0
 20351 00006D39 7708                <1> 	ja	short loc_get_current_drive_1
 20352 00006D3B 8A15[AEBE0000]      <1> 	mov	dl, [Current_Drv]
 20353 00006D41 EB17                <1> 	jmp	short loc_get_current_drive_2
 20354                              <1> loc_get_current_drive_1:
 20355 00006D43 FECA                <1> 	dec 	dl
 20356 00006D45 3A15[7FAE0000]      <1> 	cmp	dl, [Last_DOS_DiskNo]
 20357 00006D4B 760D                <1> 	jna	short loc_get_current_drive_2
 20358 00006D4D B80F000000          <1> 	mov	eax, 0Fh ; Invalid drive
 20359 00006D52 F5                  <1> 	cmc 	; stc
 20360 00006D53 C3                  <1> 	retn
 20361                              <1> 
 20362                              <1> loc_get_current_drive_not_ready_retn:
 20363 00006D54 5E                  <1> 	pop	esi
 20364                              <1> 	;mov	eax, 15h
 20365 00006D55 66B81500            <1> 	mov	ax, 15h ; Drive not ready
 20366 00006D59 C3                  <1> 	retn  
 20367                              <1>  
 20368                              <1> loc_get_current_drive_2:
 20369 00006D5A 31C0                <1> 	xor	eax, eax
 20370 00006D5C 88D4                <1> 	mov	ah, dl
 20371 00006D5E 56                  <1> 	push	esi
 20372 00006D5F BE00010900          <1> 	mov	esi, Logical_DOSDisks
 20373 00006D64 01C6                <1> 	add	esi, eax
 20374 00006D66 8A06                <1> 	mov	al, [esi+LD_Name] 
 20375 00006D68 3C41                <1> 	cmp	al, 'A'
 20376 00006D6A 72E8                <1> 	jb	short loc_get_current_drive_not_ready_retn
 20377                              <1> 
 20378 00006D6C 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
 20379 00006D6F 08E4                <1> 	or	ah, ah
 20380 00006D71 7506                <1> 	jnz	short loc_get_current_drive_3
 20381                              <1> 
 20382                              <1> 	;xor	ah, ah ; mov ah, 0
 20383 00006D73 8826                <1> 	mov	[esi], ah
 20384 00006D75 31C9                <1> 	xor	ecx, ecx
 20385 00006D77 EB1C                <1> 	jmp	short loc_get_current_drive_4
 20386                              <1> 
 20387                              <1> loc_get_current_drive_3:
 20388 00006D79 BF[0FC70000]        <1>         mov     edi, PATH_Array
 20389 00006D7E 57                  <1> 	push	edi
 20390 00006D7F 81C680000000        <1> 	add	esi, LD_CurrentDirectory
 20391 00006D85 B920000000          <1> 	mov	ecx, 32
 20392 00006D8A F3A5                <1> 	rep	movsd
 20393 00006D8C 5E                  <1> 	pop	esi ; Path Array Address
 20394 00006D8D 5F                  <1> 	pop	edi ; pushed esi (current dir buffer offset) 
 20395                              <1> 	;
 20396 00006D8E E841FFFFFF          <1> 	call	set_current_directory_string
 20397 00006D93 89FE                <1> 	mov	esi, edi
 20398                              <1> 
 20399                              <1> loc_get_current_drive_4:
 20400 00006D95 30C0                <1> 	xor	al, al
 20401 00006D97 C3                  <1> 	retn
 20402                              <1> 
 20403                              <1> change_current_directory:
 20404                              <1> 	; 19/02/2016
 20405                              <1> 	; 11/02/2016
 20406                              <1> 	; 10/02/2016
 20407                              <1> 	; 08/02/2016
 20408                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 20409                              <1> 	; 18/09/2011 (DIR.ASM, 09/10/2011)	
 20410                              <1> 	; 04/10/2009
 20411                              <1> 	; 2005
 20412                              <1> 	; INPUT -> 
 20413                              <1> 	;	ESI = Directory string
 20414                              <1> 	;	ah = CD command (CDh = save current dir string)
 20415                              <1> 	; OUTPUT -> 
 20416                              <1> 	; 	EDI = DOS Drive Description Table
 20417                              <1> 	; 	cf = 1 -> error
 20418                              <1> 	;	   EAX = Error code
 20419                              <1> 	;	cf = 0 -> succesful
 20420                              <1> 	;	   ESI = PATH_Array
 20421                              <1> 	;	   EAX = Current Directory First Cluster
 20422                              <1> 	;
 20423                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 20424                              <1> 	
 20425 00006D98 8825[9DC70000]      <1> 	mov	[CD_COMMAND], ah
 20426 00006D9E 803E2F              <1> 	cmp	byte [esi], '/'
 20427 00006DA1 7505                <1> 	jne	short loc_ccd_cdir_level
 20428 00006DA3 46                  <1> 	inc	esi
 20429 00006DA4 30C0                <1> 	xor	al, al
 20430 00006DA6 EB05                <1> 	jmp	short loc_ccd_parse_path_name
 20431                              <1> loc_ccd_cdir_level:
 20432 00006DA8 A0[ACBE0000]        <1> 	mov	al, [Current_Dir_Level]
 20433                              <1> loc_ccd_parse_path_name:
 20434 00006DAD 88C4                <1> 	mov	ah, al
 20435 00006DAF BF[0FC70000]        <1> 	mov	edi, PATH_Array
 20436                              <1> 
 20437                              <1> ; Reset directory levels > cdir level
 20438                              <1> 	; is this required !?
 20439                              <1> 	;
 20440                              <1> 	; Relations:
 20441                              <1> 	; MAINPROG.ASM (pass_ccdrv_reset_cdir_FAT_fcluster)
 20442                              <1> 	; proc_parse_dir_name,
 20443                              <1> 	; proc_change_current_directory (this procedure)
 20444                              <1> 	; proc_change_prompt_dir_string 
 20445                              <1>  
 20446 00006DB4 0FB6C8              <1> 	movzx	ecx, al
 20447 00006DB7 FEC1                <1> 	inc	cl
 20448 00006DB9 C0E104              <1> 	shl	cl, 4
 20449 00006DBC 01CF                <1> 	add	edi, ecx
 20450 00006DBE B107                <1> 	mov	cl, 7
 20451 00006DC0 28C1                <1> 	sub	cl, al
 20452 00006DC2 C0E102              <1> 	shl	cl, 2
 20453 00006DC5 89C3                <1> 	mov	ebx, eax
 20454 00006DC7 31C0                <1> 	xor	eax, eax ; 0
 20455 00006DC9 F3AB                <1> 	rep	stosd
 20456 00006DCB 89D8                <1> 	mov	eax, ebx
 20457                              <1> 
 20458 00006DCD BF[0FC70000]        <1> 	mov	edi, PATH_Array
 20459                              <1> 
 20460 00006DD2 803E20              <1> 	cmp	byte [esi], 20h
 20461 00006DD5 F5                  <1> 	cmc
 20462 00006DD6 7305                <1> 	jnc	short pass_ccd_parse_dir_name
 20463                              <1> 
 20464                              <1> 		; ESI = Path name
 20465                              <1> 		; AL = CCD_Level
 20466 00006DD8 E872010000          <1>         call    parse_dir_name
 20467                              <1> 		; AL = CCD_Level 
 20468                              <1> 		; AH = Last_Dir_Level
 20469                              <1> 		; (EDI = PATH_Array)
 20470                              <1> 
 20471                              <1> pass_ccd_parse_dir_name:
 20472 00006DDD 9C                  <1> 	pushf
 20473                              <1> 
 20474                              <1> 	;mov	[CCD_Level], al
 20475                              <1>         ;mov	[Last_Dir_Level], ah
 20476 00006DDE 66A3[93C70000]      <1> 	mov	[CCD_Level], ax
 20477                              <1> 
 20478 00006DE4 31DB                <1> 	xor	ebx, ebx
 20479 00006DE6 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 20480 00006DEC BE00010900          <1> 	mov	esi, Logical_DOSDisks
 20481 00006DF1 01DE                <1> 	add	esi, ebx
 20482                              <1> 
 20483 00006DF3 9D                  <1> 	popf 
 20484 00006DF4 720A                <1> 	jc	short loc_ccd_bad_path_name_retn
 20485                              <1> 
 20486 00006DF6 8935[8FC70000]      <1> 	mov	[CCD_DriveDT], esi
 20487                              <1> 
 20488 00006DFC 3C07                <1> 	cmp	al, 7
 20489 00006DFE 7209                <1> 	jb	short loc_ccd_load_child_dir
 20490                              <1> 
 20491                              <1> loc_ccd_bad_path_name_retn:
 20492 00006E00 87F7                <1> 	xchg	esi, edi
 20493                              <1> 	; DOS Error Code 
 20494 00006E02 B818000000          <1> 	mov	eax, 18h ; Bad request structure length 
 20495 00006E07 F9                  <1> 	stc
 20496                              <1> loc_ccd_retn_p:
 20497 00006E08 C3                  <1> 	retn
 20498                              <1> 
 20499                              <1> loc_ccd_load_child_dir:
 20500                              <1> 	; AL = CCD_Level
 20501 00006E09 08C0                <1> 	or	al, al
 20502 00006E0B 7468                <1> 	jz	short loc_ccd_load_root_dir
 20503                              <1> 
 20504 00006E0D 6689C1              <1> 	mov	cx, ax
 20505 00006E10 C0E004              <1> 	shl	al, 4
 20506 00006E13 0FB6F0              <1> 	movzx	esi, al
 20507 00006E16 01FE                <1>      	add	esi, edi  ; offset PATH_Array
 20508                              <1> 
 20509 00006E18 8B460C              <1> 	mov	eax, [esi+12]
 20510 00006E1B 38E9                <1> 	cmp	cl, ch
 20511 00006E1D 0F84FA000000        <1>         je      loc_ccd_load_sub_directory
 20512 00006E23 A3[A8BE0000]        <1> 	mov	[Current_Dir_FCluster], eax
 20513                              <1> 
 20514                              <1> loc_ccd_load_child_dir_next:
 20515 00006E28 83C610              <1> 	add	esi, 16 ; DOS DirEntry Format FileName Address
 20516                              <1> 
 20517                              <1>  	; Directory attribute : 10h
 20518 00006E2B B010                <1> 	mov	al, 00010000b ; 10h (Attrib AND mask)
 20519                              <1> 	;mov	ah, 11001000b ; C8h
 20520                              <1> 	; Volume name attribute: 8h
 20521 00006E2D B408                <1> 	mov	ah, 00001000b ; 08h (Attrib NAND, AND --> zero mask)
 20522                              <1> 
 20523 00006E2F 6631C9              <1> 	xor	cx, cx  
 20524 00006E32 E8B5010000          <1> 	call	locate_current_dir_file
 20525 00006E37 7353                <1> 	jnc	short loc_ccd_set_dir_cluster_ptr
 20526                              <1> 
 20527                              <1> 	 ; 19/02/2016
 20528                              <1> 	;mov	edi, [CCD_DriveDT]
 20529 00006E39 8A25[93C70000]      <1> 	mov	ah, [CCD_Level]
 20530 00006E3F 803D[9DC70000]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
 20531 00006E46 7509                <1> 	jne	short loc_ccd_load_child_dir_err
 20532                              <1> 	; It is better to save recent successful part 
 20533                              <1> 	; of the (requested) path as current directory.
 20534                              <1> 	; (Otherwise the path would be reset to back
 20535                              <1> 	; on the next 'CD' command.)
 20536 00006E48 88E1                <1> 	mov	cl, ah
 20537 00006E4A 50                  <1> 	push	eax
 20538 00006E4B E8E3000000          <1> 	call	loc_ccd_save_current_dir
 20539 00006E50 58                  <1> 	pop	eax
 20540                              <1> loc_ccd_load_child_dir_err:            
 20541 00006E51 3C03                <1> 	cmp	al, 3	; AL = 2 => File not found error
 20542 00006E53 7202                <1> 	jb	short loc_ccd_path_not_found_retn
 20543 00006E55 F9                  <1> 	stc
 20544 00006E56 C3                  <1> 	retn
 20545                              <1> 
 20546                              <1> loc_ccd_path_not_found_retn:
 20547 00006E57 B003                <1> 	mov	al, 3	; Path not found
 20548 00006E59 C3                  <1> 	retn
 20549                              <1> 
 20550                              <1> loc_ccd_load_FAT_root_dir:
 20551 00006E5A 803D[ADBE0000]02    <1> 	cmp	byte [Current_FATType], 2
 20552 00006E61 776B                <1> 	ja	short loc_ccd_load_FAT32_root_dir
 20553                              <1> 
 20554                              <1> 	;mov	esi, [CCD_DriveDT]
 20555                              <1> 	;push	esi
 20556 00006E63 E8AD1D0000          <1> 	call	load_FAT_root_directory
 20557                              <1> 	;pop	edi ; Dos Drv Description Table
 20558                              <1> 
 20559 00006E68 89F7                <1> 	mov	edi, esi
 20560 00006E6A BE[0FC70000]        <1> 	mov	esi, PATH_Array
 20561 00006E6F 7297                <1> 	jc	short loc_ccd_retn_p
 20562                              <1> 
 20563 00006E71 31C0                <1> 	xor	eax, eax
 20564 00006E73 EB78                <1>         jmp	short loc_ccd_set_cdfc
 20565                              <1> 
 20566                              <1> loc_ccd_load_root_dir:
 20567 00006E75 803D[ADBE0000]01    <1> 	cmp	byte [Current_FATType], 1
 20568 00006E7C 73DC                <1> 	jnb	short loc_ccd_load_FAT_root_dir
 20569                              <1> 
 20570                              <1> loc_ccd_load_FS_root_dir:
 20571 00006E7E E8591E0000          <1> 	call	load_FS_root_directory
 20572 00006E83 EB5C                <1> 	jmp	short pass_ccd_load_FAT_sub_directory
 20573                              <1> 
 20574                              <1> loc_ccd_load_FS_sub_directory_next:
 20575 00006E85 E8531E0000          <1> 	call	load_FS_sub_directory
 20576 00006E8A EB1F                <1> 	jmp	short pass_ccd_set_dir_cluster_ptr  
 20577                              <1> 
 20578                              <1> loc_ccd_set_dir_cluster_ptr:
 20579                              <1> 	; EDI = Directory Entry
 20580 00006E8C 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 20581 00006E90 C1E010              <1> 	shl	eax, 16
 20582 00006E93 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 20583                              <1> 
 20584 00006E97 8B35[8FC70000]      <1> 	mov	esi, [CCD_DriveDT]
 20585 00006E9D 803D[ADBE0000]01    <1> 	cmp	byte [Current_FATType], 1
 20586 00006EA4 72DF                <1> 	jb	short loc_ccd_load_FS_sub_directory_next
 20587                              <1> 	;push	esi
 20588 00006EA6 E8F51D0000          <1> 	call	load_FAT_sub_directory
 20589                              <1> 	;pop	edi ; Dos Drv Description Table
 20590                              <1> 
 20591                              <1> pass_ccd_set_dir_cluster_ptr:
 20592                              <1> 	;mov	edi, esi
 20593 00006EAB BE[0FC70000]        <1> 	mov	esi, PATH_Array
 20594 00006EB0 7264                <1> 	jc	short loc_ccd_retn_c
 20595                              <1> 
 20596 00006EB2 A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 20597                              <1> 
 20598 00006EB7 FE05[93C70000]      <1> 	inc	byte [CCD_Level]
 20599 00006EBD 0FB61D[93C70000]    <1> 	movzx	ebx, byte [CCD_Level]
 20600 00006EC4 C0E304              <1> 	shl	bl, 4 ; * 16 (<= 128)   
 20601 00006EC7 01DE                <1> 	add	esi, ebx ; 19/02/2016
 20602 00006EC9 89460C              <1> 	mov	[esi+12], eax
 20603 00006ECC EB1F                <1> 	jmp	short loc_ccd_set_cdfc
 20604                              <1> 
 20605                              <1> loc_ccd_load_FAT32_root_dir:
 20606 00006ECE BE[0FC70000]        <1> 	mov	esi, PATH_Array
 20607 00006ED3 8B460C              <1> 	mov	eax, [esi+12]
 20608 00006ED6 8B35[8FC70000]      <1> 	mov	esi, [CCD_DriveDT]
 20609                              <1>  
 20610                              <1> loc_ccd_load_FAT_sub_directory:
 20611                              <1> 	;push	esi
 20612 00006EDC E8BF1D0000          <1> 	call	load_FAT_sub_directory
 20613                              <1> 	;pop	edi ; Dos Drv Description Table
 20614                              <1> 
 20615                              <1> pass_ccd_load_FAT_sub_directory:
 20616                              <1> 	;mov	edi, esi
 20617 00006EE1 BE[0FC70000]        <1> 	mov	esi, PATH_Array
 20618 00006EE6 722E                <1> 	jc	short loc_ccd_retn_c
 20619                              <1> 
 20620 00006EE8 A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 20621                              <1> 
 20622                              <1> loc_ccd_set_cdfc:
 20623 00006EED 8A0D[93C70000]      <1> 	mov	cl, [CCD_Level]
 20624 00006EF3 880D[ACBE0000]      <1> 	mov	[Current_Dir_Level], cl
 20625 00006EF9 A3[A8BE0000]        <1> 	mov	[Current_Dir_FCluster], eax
 20626                              <1> 
 20627 00006EFE 8A2D[94C70000]      <1> 	mov	ch, [Last_Dir_Level]
 20628 00006F04 38E9                <1> 	cmp	cl, ch 
 20629 00006F06 0F821CFFFFFF        <1> 	jb	loc_ccd_load_child_dir_next
 20630                              <1> 	
 20631 00006F0C 803D[9DC70000]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
 20632 00006F13 741E                <1> 	je	short loc_ccd_save_current_dir
 20633                              <1> 
 20634                              <1>         ; jne -> don't save, restore (the previous cdir) later !
 20635                              <1>         ; (saving the cdir would prevent previous cdir restoration!)
 20636                              <1> 
 20637 00006F15 F8                  <1> 	clc
 20638                              <1> 
 20639                              <1> loc_ccd_retn_c:
 20640 00006F16 8B3D[8FC70000]      <1> 	mov	edi, [CCD_DriveDT]
 20641 00006F1C C3                  <1> 	retn
 20642                              <1> 
 20643                              <1> loc_ccd_load_sub_directory:
 20644 00006F1D 8B35[8FC70000]      <1> 	mov	esi, [CCD_DriveDT]
 20645 00006F23 803D[ADBE0000]01    <1> 	cmp	byte [Current_FATType], 1
 20646 00006F2A 73B0                <1> 	jnb	short loc_ccd_load_FAT_sub_directory 
 20647 00006F2C E8AC1D0000          <1> 	call	load_FS_sub_directory
 20648 00006F31 EBAE                <1> 	jmp	short pass_ccd_load_FAT_sub_directory 
 20649                              <1> 
 20650                              <1> loc_ccd_save_current_dir:
 20651 00006F33 BE[0FC70000]        <1> 	mov	esi, PATH_Array ; 19/02/2016
 20652 00006F38 8B3D[8FC70000]      <1> 	mov	edi, [CCD_DriveDT]
 20653 00006F3E 57                  <1> 	push	edi
 20654 00006F3F 83C77F              <1>         add     edi, LD_CDirLevel
 20655 00006F42 880F                <1> 	mov	[edi], cl
 20656 00006F44 47                  <1> 	inc	edi ; LD_CurrentDirectory 
 20657 00006F45 56                  <1> 	push	esi
 20658                              <1> 	;mov	ecx, 32  ; always < 65536 (in this procedure)
 20659 00006F46 66B92000            <1> 	mov	cx, 32
 20660 00006F4A F3A5                <1> 	rep	movsd
 20661                              <1> 	; Current directory has been saved to 
 20662                              <1> 	; the DOS drive description table, cdir area !
 20663 00006F4C 5E                  <1> 	pop	esi  ; PATH_Array
 20664 00006F4D 5F                  <1> 	pop	edi  ; Dos Drv Description Table
 20665                              <1> 
 20666 00006F4E C3                  <1> 	retn
 20667                              <1> 
 20668                              <1> parse_dir_name:
 20669                              <1> 	; 11/02/2016
 20670                              <1> 	; 10/02/2016
 20671                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
 20672                              <1> 	; 18/09/2011
 20673                              <1> 	; 17/10/2009
 20674                              <1> 	; INPUT ->
 20675                              <1> 	;	ESI = ASCIIZ Directory String Address
 20676                              <1> 	;	AL = Current Directory Level
 20677                              <1> 	;	EDI = Destination Adress
 20678                              <1> 	;	     (8 levels, each one 12+4 byte)
 20679                              <1> 	; OUTPUT ->
 20680                              <1> 	;	EDI = Dir Entry Formatted Array
 20681                              <1> 	;	     with zero cluster pointer at the last level
 20682                              <1> 	;	AH = Last Dir Level
 20683                              <1> 	;	AL = Current Dir Level
 20684                              <1> 	;
 20685                              <1> 	; (esi, ebx, ecx will be changed) 
 20686                              <1> 
 20687                              <1> 	;mov	[PATH_Array_Ptr], edi
 20688 00006F4F 88C4                <1> 	mov	ah, al
 20689 00006F51 66A3[34C80000]      <1> 	mov	[PATH_CDLevel], ax
 20690                              <1> repeat_ppdn_check_slash:
 20691 00006F57 AC                  <1> 	lodsb
 20692 00006F58 3C2F                <1> 	cmp	al, '/'
 20693 00006F5A 74FB                <1> 	je	short repeat_ppdn_check_slash
 20694 00006F5C 3C21                <1> 	cmp	al, 21h
 20695 00006F5E 7219                <1> 	jb	short loc_ppdn_retn
 20696 00006F60 57                  <1> 	push	edi
 20697                              <1> loc_ppdn_get_dir_name:
 20698 00006F61 B90C000000          <1> 	mov	ecx, 12
 20699 00006F66 BF[36C80000]        <1> 	mov	edi, Dir_File_Name
 20700                              <1> repeat_ppdn_get_dir_name:
 20701 00006F6B AA                  <1> 	stosb
 20702 00006F6C AC                  <1> 	lodsb
 20703 00006F6D 3C2F                <1> 	cmp	al, '/'
 20704 00006F6F 740A                <1> 	je	short loc_check_level_dot_conv_dir_name
 20705 00006F71 3C20                <1> 	cmp	al, 20h
 20706 00006F73 7605                <1> 	jna	short loc_ppdn_end_of_path_scan
 20707 00006F75 E2F4                <1> 	loop	repeat_ppdn_get_dir_name
 20708 00006F77 5F                  <1> 	pop	edi
 20709 00006F78 F9                  <1> 	stc
 20710                              <1> loc_ppdn_retn:
 20711 00006F79 C3                  <1> 	retn
 20712                              <1> 
 20713                              <1> loc_ppdn_end_of_path_scan:
 20714 00006F7A 4E                  <1> 	dec	esi
 20715                              <1> loc_check_level_dot_conv_dir_name:
 20716 00006F7B 31C0                <1> 	xor	eax, eax
 20717 00006F7D AA                  <1> 	stosb
 20718 00006F7E 89F3                <1> 	mov	ebx, esi
 20719 00006F80 BE[36C80000]        <1> 	mov	esi, Dir_File_Name
 20720 00006F85 AC                  <1> 	lodsb
 20721                              <1> repeat_ppdn_name_check_dot:
 20722 00006F86 3C2E                <1> 	cmp	al, '.'
 20723 00006F88 7509                <1> 	jne	short loc_ppdn_convert_sub_dir_name
 20724                              <1> repeat_ppdn_name_dot_dot:
 20725 00006F8A AC                  <1> 	lodsb
 20726 00006F8B 3C2E                <1> 	cmp	al, '.'
 20727 00006F8D 743E                <1> 	je	short loc_ppdn_dot_dot
 20728 00006F8F 3C21                <1> 	cmp	al, 21h
 20729 00006F91 7226                <1> 	jb	short pass_ppdn_convert_sub_dir_name
 20730                              <1> loc_ppdn_convert_sub_dir_name:
 20731 00006F93 8A25[35C80000]      <1> 	mov	ah, [PATH_Level]
 20732 00006F99 80FC07              <1> 	cmp	ah, 7
 20733 00006F9C 731B                <1> 	jnb	short pass_ppdn_convert_sub_dir_name
 20734 00006F9E FEC4                <1> 	inc	ah  
 20735 00006FA0 8825[35C80000]      <1> 	mov	[PATH_Level], ah
 20736 00006FA6 BE[36C80000]        <1> 	mov	esi, Dir_File_Name
 20737                              <1> 	;mov	edi, [PATH_Array_Ptr]
 20738 00006FAB B010                <1> 	mov	al, 16
 20739 00006FAD F6E4                <1> 	mul	ah
 20740 00006FAF 8B3C24              <1> 	mov	edi, [esp]
 20741                              <1> 	;push	edi 
 20742 00006FB2 01C7                <1> 	add	edi, eax
 20743 00006FB4 E828030000          <1> 	call	convert_file_name
 20744                              <1> 	;pop	edi
 20745                              <1> pass_ppdn_convert_sub_dir_name:
 20746 00006FB9 89DE                <1> 	mov	esi, ebx
 20747                              <1> repeat_ppdn_check_last_slash:
 20748 00006FBB AC                  <1> 	lodsb
 20749 00006FBC 3C2F                <1> 	cmp	al, '/'
 20750 00006FBE 74FB                <1> 	je	short repeat_ppdn_check_last_slash
 20751 00006FC0 3C21                <1> 	cmp	al, 21h
 20752 00006FC2 739D                <1> 	jnb	short loc_ppdn_get_dir_name
 20753                              <1> end_of_parse_dir_name:
 20754 00006FC4 5F                  <1> 	pop	edi
 20755 00006FC5 F5                  <1> 	cmc  
 20756                              <1> 	;mov	al, [PATH_CDLevel]
 20757                              <1> 	;mov	ah, [PATH_Level]
 20758 00006FC6 66A1[34C80000]      <1> 	mov	ax, [PATH_CDLevel]
 20759 00006FCC C3                  <1> 	retn
 20760                              <1> 
 20761                              <1> loc_ppdn_dot_dot:
 20762 00006FCD AC                  <1> 	lodsb
 20763 00006FCE 3C21                <1> 	cmp	al, 21h
 20764 00006FD0 73F2                <1> 	jnb	short end_of_parse_dir_name 
 20765                              <1> loc_ppdn_dot_dot_prev_level:
 20766 00006FD2 66A1[34C80000]      <1> 	mov	ax, [PATH_CDLevel]
 20767 00006FD8 80EC01              <1> 	sub	ah, 1
 20768 00006FDB 80D400              <1> 	adc	ah, 0
 20769 00006FDE 38E0                <1> 	cmp	al, ah
 20770 00006FE0 7602                <1> 	jna	short pass_ppdn_set_al_to_ah
 20771 00006FE2 88E0                <1> 	mov	al, ah
 20772                              <1> pass_ppdn_set_al_to_ah:
 20773 00006FE4 66A3[34C80000]      <1> 	mov	[PATH_CDLevel], ax
 20774 00006FEA EBCD                <1> 	jmp	short pass_ppdn_convert_sub_dir_name
 20775                              <1> 
 20776                              <1> locate_current_dir_file:
 20777                              <1> 	; 14/02/2016
 20778                              <1> 	; 13/02/2016
 20779                              <1> 	; 10/02/2016
 20780                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 20781                              <1> 	; 14/08/2010
 20782                              <1> 	; 19/09/2009
 20783                              <1>         ; 2005
 20784                              <1> 	; INPUT ->
 20785                              <1> 	;	ESI = DOS DirEntry Format FileName Address
 20786                              <1> 	;	AL = Attributes Mask 
 20787                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
 20788                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
 20789                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
 20790                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
 20791                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
 20792                              <1> 	;	CL = E5h -> Return the 1st deleted entry
 20793                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
 20794                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
 20795                              <1> 	;	     proper entry (which fits with Atributes Masks)
 20796                              <1> 	;	CX = 0 Find Valid File/Directory/VolumeName
 20797                              <1> 	;	? = Any One Char
 20798                              <1> 	;	* = Every Chars
 20799                              <1> 	; OUTPUT ->
 20800                              <1> 	;	EDI = Directory Entry Address (in Directory Buffer)
 20801                              <1> 	;	ESI = DOS DirEntry Format FileName Address
 20802                              <1> 	;	CF = 0 -> No Error, Proper Entry,
 20803                              <1> 	;	DL = Attributes
 20804                              <1> 	;	DH = Previous Entry Attr (LongName Check)
 20805                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
 20806                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
 20807                              <1> 	;	AX = 0 -> Filename full fits with directory entry
 20808                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
 20809                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in EAX/AL
 20810                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
 20811                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
 20812                              <1> 	;	CL > 0 -> Entry not found, CH invalid
 20813                              <1> 	;	CF = 0 -> 
 20814                              <1> 	;	EBX = Current Directory Entry Index/Number (BX)
 20815                              <1> 
 20816                              <1> 	;mov	word [DirBuff_EntryCounter], 0 ; Zero Based
 20817                              <1> 
 20818 00006FEC 8935[97C70000]      <1> 	mov	[CDLF_FNAddress], esi
 20819 00006FF2 66A3[95C70000]      <1> 	mov	[CDLF_AttributesMask], ax
 20820 00006FF8 66890D[9BC70000]    <1> 	mov	[CDLF_DEType], cx
 20821                              <1> 
 20822 00006FFF 31DB                <1> 	xor	ebx, ebx
 20823 00007001 881D[ACC70000]      <1> 	mov	[PreviousAttr], bl ; 0  ; 13/02/2016
 20824                              <1> 
 20825 00007007 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 20826 0000700D 381D[D8C60000]      <1> 	cmp	byte [DirBuff_ValidData], bl ; 0
 20827 00007013 761D                <1> 	jna	short loc_lcdf_reload_current_dir2
 20828 00007015 8A1D[D6C60000]      <1>         mov     bl, [DirBuff_DRV]
 20829 0000701B 80EB41              <1> 	sub	bl, 'A'
 20830 0000701E 38DF                <1> 	cmp	bh, bl
 20831 00007020 750E                <1> 	jne	short loc_lcdf_reload_current_dir1
 20832 00007022 8B15[DDC60000]      <1> 	mov	edx, [DirBuff_Cluster]
 20833 00007028 3B15[A8BE0000]      <1> 	cmp	edx, [Current_Dir_FCluster]
 20834 0000702E 7412                <1> 	je	short loc_cdir_locatefile_search
 20835                              <1> 
 20836                              <1> loc_lcdf_reload_current_dir1:
 20837 00007030 30DB                <1> 	xor	bl, bl
 20838                              <1> loc_lcdf_reload_current_dir2:
 20839 00007032 89DE                <1> 	mov	esi, ebx
 20840 00007034 81C600010900        <1>         add     esi, Logical_DOSDisks
 20841 0000703A E872000000          <1> 	call	reload_current_directory 
 20842 0000703F 735B                <1> 	jnc	short loc_locatefile_search_again 
 20843 00007041 C3                  <1> 	retn  
 20844                              <1> 
 20845                              <1> loc_cdir_locatefile_search:
 20846 00007042 31DB                <1> 	xor	ebx, ebx
 20847 00007044 E8A5000000          <1> 	call	find_directory_entry
 20848 00007049 7349                <1> 	jnc	short loc_cdir_locate_file_retn
 20849                              <1> 
 20850                              <1> loc_locatefile_check_stc_reason:
 20851 0000704B 08ED                <1> 	or	ch, ch
 20852 0000704D 7444                <1> 	jz	short loc_cdir_locate_file_stc_retn
 20853                              <1> 
 20854                              <1> loc_locatefile_check_next_entryblock:
 20855 0000704F 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 20856 00007055 28DB                <1> 	sub	bl, bl
 20857 00007057 0FB7F3              <1> 	movzx	esi, bx
 20858 0000705A 81C600010900        <1>         add     esi, Logical_DOSDisks
 20859                              <1> 
 20860 00007060 803D[ACBE0000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 20861 00007067 760A                <1> 	jna	short loc_locatefile_check_FAT_type
 20862                              <1>             
 20863 00007069 803D[ADBE0000]01    <1> 	cmp	byte [Current_FATType], 1
 20864 00007070 730A                <1> 	jnb	short loc_locatefile_load_subdir_cluster
 20865 00007072 C3                  <1> 	retn  
 20866                              <1> 
 20867                              <1> loc_locatefile_check_FAT_type:
 20868 00007073 803D[ADBE0000]03    <1> 	cmp	byte [Current_FATType], 3
 20869 0000707A 7218                <1> 	jb	short loc_cdir_locate_file_retn
 20870                              <1> 
 20871                              <1> loc_locatefile_load_subdir_cluster:
 20872 0000707C A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 20873 00007081 E8341A0000          <1> 	call	get_next_cluster
 20874 00007086 730D                <1> 	jnc	short loc_locatefile_next_cluster
 20875 00007088 09C0                <1> 	or	eax, eax
 20876 0000708A 7507                <1> 	jnz	short loc_locatefile_drive_not_ready_read_err
 20877 0000708C F9                  <1> 	stc
 20878                              <1> loc_locatefile_file_notfound:
 20879 0000708D B802000000          <1> 	mov	eax, 2 ; File/Directory/VolName not found
 20880 00007092 C3                  <1> 	retn
 20881                              <1> 
 20882                              <1> loc_locatefile_drive_not_ready_read_err:
 20883                              <1> 	;mov	eax, 15h ;Drive not ready or read error
 20884                              <1> loc_cdir_locate_file_stc_retn:
 20885 00007093 F5                  <1> 	cmc ;stc
 20886                              <1> loc_cdir_locate_file_retn:
 20887 00007094 C3                  <1> 	retn
 20888                              <1> 
 20889                              <1> loc_locatefile_next_cluster:
 20890 00007095 E8061C0000          <1> 	call	load_FAT_sub_directory
 20891                              <1> 	;jc	short loc_locatefile_drive_not_ready_read_err
 20892 0000709A 72F8                <1> 	jc	short loc_cdir_locate_file_retn 
 20893                              <1> 
 20894                              <1> loc_locatefile_search_again:
 20895 0000709C 8B35[97C70000]      <1> 	mov	esi, [CDLF_FNAddress] 
 20896 000070A2 66A1[95C70000]      <1> 	mov	ax, [CDLF_AttributesMask]
 20897 000070A8 668B0D[9BC70000]    <1> 	mov	cx, [CDLF_DEType] 
 20898 000070AF EB91                <1> 	jmp	short loc_cdir_locatefile_search
 20899                              <1> 
 20900                              <1> reload_current_directory:
 20901                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 20902                              <1> 	; 13/06/2010
 20903                              <1> 	; 22/09/2009
 20904                              <1>         ;
 20905                              <1> 	; INPUT ->
 20906                              <1> 	;	ESI = Dos drive description table address
 20907                              <1> 	
 20908                              <1> 	;mov	al, [esi+LD_FATType]
 20909 000070B1 A0[ADBE0000]        <1> 	mov	al, [Current_FATType]
 20910 000070B6 3C02                <1> 	cmp	al, 2
 20911 000070B8 7729                <1> 	ja	short loc_reload_FAT_sub_directory
 20912 000070BA 8A25[ACBE0000]      <1> 	mov	ah, [Current_Dir_Level]
 20913 000070C0 08C0                <1> 	or	al, al
 20914 000070C2 740A                <1> 	jz	short loc_reload_FS_directory
 20915 000070C4 08E4                <1> 	or	ah, ah
 20916 000070C6 751B                <1> 	jnz	short loc_reload_FAT_sub_directory
 20917                              <1> loc_reload_FAT_12_16_root_directory:
 20918 000070C8 E8481B0000          <1> 	call	load_FAT_root_directory
 20919 000070CD C3                  <1> 	retn
 20920                              <1> loc_reload_FS_directory:
 20921 000070CE 20E4                <1> 	and	ah, ah
 20922 000070D0 7506                <1> 	jnz	short loc_reload_FS_sub_directory 
 20923                              <1> loc_reload_FS_root_directory: 
 20924 000070D2 E8051C0000          <1> 	call	load_FS_root_directory
 20925 000070D7 C3                  <1> 	retn
 20926                              <1> loc_reload_FS_sub_directory:
 20927 000070D8 A1[A8BE0000]        <1> 	mov	eax, [Current_Dir_FCluster]
 20928 000070DD E8FB1B0000          <1> 	call	load_FS_sub_directory
 20929 000070E2 C3                  <1> 	retn 
 20930                              <1> loc_reload_FAT_sub_directory:
 20931 000070E3 A1[A8BE0000]        <1> 	mov	eax, [Current_Dir_FCluster]
 20932 000070E8 E8B31B0000          <1> 	call	load_FAT_sub_directory
 20933 000070ED C3                  <1> 	retn
 20934                              <1> 
 20935                              <1> find_directory_entry:
 20936                              <1> 	; 14/02/2016
 20937                              <1> 	; 13/02/2016
 20938                              <1> 	; 10/02/2016
 20939                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 20940                              <1> 	; 14/08/2010 (DIR.ASM, "proc_find_direntry")
 20941                              <1> 	; 19/09/2009
 20942                              <1> 	; 2005
 20943                              <1> 	; INPUT ->
 20944                              <1> 	;	ESI = Sub Dir or File Name Address
 20945                              <1> 	;	AL = Attributes Mask 
 20946                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
 20947                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
 20948                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
 20949                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
 20950                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
 20951                              <1> 	;	CL = E5h -> Return the 1st deleted entry
 20952                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
 20953                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
 20954                              <1> 	;            proper entry (which fits with Atributes Masks)
 20955                              <1> 	;	CX = 0 -> Find Valid File/Directory/VolumeName
 20956                              <1> 	;	? = Any One Char
 20957                              <1> 	;	* = Every Chars
 20958                              <1> 	;	EBX = Current Dir Entry (BX)
 20959                              <1> 	;
 20960                              <1> 	; OUTPUT -> 
 20961                              <1> 	;	EDI = Directory Entry Address (in DirectoryBuffer)
 20962                              <1> 	;	ESI = Sub Dir or File Name Address
 20963                              <1> 	;	CF = 0 -> No Error, Proper Entry,
 20964                              <1> 	;	DL = Attributes
 20965                              <1> 	;	DH = Previous Entry Attr (LongName Check)
 20966                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
 20967                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
 20968                              <1> 	;	AX = 0 -> Filename full fits with directory entry
 20969                              <1> 	;	EBX = CurrentDirEntry (BX)
 20970                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
 20971                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in AX/AL
 20972                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
 20973                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
 20974                              <1> 	;	CL > 0 -> Entry not found, CH invalid
 20975                              <1> 	;
 20976                              <1> 	; (EAX, EBX, ECX, EDX, EDI, EBP will be changed)	 
 20977                              <1> 
 20978 000070EE 663B1D[DBC60000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 20979 000070F5 0F8739010000        <1>         ja      loc_ffde_stc_retn_255
 20980                              <1> 
 20981                              <1> 	;mov    [DirBuff_CurrentEntry], bx  
 20982                              <1> 
 20983 000070FB BF00000800          <1>   	mov	edi, Directory_Buffer
 20984 00007100 66A3[A8C70000]      <1> 	mov	[FDE_AttrMask], ax
 20985                              <1> 
 20986 00007106 29C0                <1> 	sub	eax, eax
 20987                              <1>             
 20988                              <1> 	;;mov	[PreviousAttr], al ; 0 ;; 13/02/2016
 20989 00007108 66A3[AAC70000]      <1> 	mov	[AmbiguousFileName], ax ; 0
 20990                              <1> 
 20991 0000710E 6689D8              <1> 	mov	ax, bx
 20992 00007111 66C1E005            <1> 	shl	ax, 5 ; ; * 32 ; Directory entry size
 20993 00007115 01C7                <1> 	add     edi, eax
 20994                              <1> 
 20995 00007117 08ED                <1> 	or	ch, ch
 20996 00007119 0F852C010000        <1>         jnz     loc_find_free_deleted_entry_0
 20997                              <1> 
 20998 0000711F 08C9                <1> 	or      cl, cl
 20999 00007121 0F850D010000        <1>         jnz     loc_ffde_stc_retn_255
 21000                              <1>  
 21001                              <1> check_find_dir_entry:
 21002 00007127 66A1[A8C70000]      <1> 	mov	ax, [FDE_AttrMask]
 21003 0000712D 8A2F                <1> 	mov	ch, [edi]
 21004 0000712F 80FD00              <1> 	cmp     ch, 0 ; Is it never used entry?
 21005 00007132 0F86FF000000        <1> 	jna	loc_find_direntry_stc_retn 
 21006 00007138 56                  <1> 	push	esi
 21007 00007139 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
 21008 0000713C 80FDE5              <1> 	cmp	ch, 0E5h ; Is it a deleted file?
 21009 0000713F 746D                <1> 	je	short loc_find_dir_next_entry_prevdeleted
 21010                              <1> 
 21011 00007141 80FA0F              <1> 	cmp     dl, 0Fh ; longname sub component check
 21012 00007144 7505                <1> 	jne     short loc_check_attributes_mask
 21013 00007146 E8ED010000          <1> 	call	save_longname_sub_component
 21014                              <1> 
 21015                              <1> loc_check_attributes_mask:
 21016 0000714B 88C6                <1> 	mov	dh, al
 21017 0000714D 20D6                <1> 	and	dh, dl    
 21018 0000714F 38F0                <1> 	cmp	al, dh
 21019 00007151 0F85BA000000        <1>         jne     loc_find_dir_next_entry
 21020 00007157 20D4                <1> 	and	ah, dl
 21021 00007159 0F85B2000000        <1>         jnz     loc_find_dir_next_entry
 21022 0000715F 80FA0F              <1> 	cmp	dl, 0Fh
 21023 00007162 751A                <1> 	jne	short pass_direntry_attr_check
 21024                              <1> 
 21025 00007164 3C0F                <1> 	cmp	al, 0Fh ; AL = 0Fh -> find long name
 21026 00007166 0F85A5000000        <1>         jne     loc_find_dir_next_entry
 21027                              <1> 
 21028 0000716C 5E                  <1> 	pop	esi
 21029 0000716D 6631C0              <1> 	xor	ax, ax
 21030 00007170 8A35[ACC70000]      <1> 	mov	dh, [PreviousAttr]
 21031 00007176 66891D[D9C60000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 21032 0000717D C3                  <1> 	retn
 21033                              <1> 
 21034                              <1> pass_direntry_attr_check:
 21035 0000717E 89FD                <1> 	mov	ebp, edi ; 14/02/2016
 21036 00007180 B908000000          <1> 	mov	ecx, 8
 21037                              <1> loc_lodsb_find_dir:
 21038 00007185 AC                  <1> 	lodsb
 21039 00007186 3C2A                <1> 	cmp	al, '*'
 21040 00007188 7508                <1> 	jne	short pass_fde_ambiguous1_check
 21041 0000718A FE05[ABC70000]      <1>         inc     byte [AmbiguousFileName+1]
 21042 00007190 EB28                <1> 	jmp	short loc_check_direntry_extension
 21043                              <1> 
 21044                              <1> pass_fde_ambiguous1_check:
 21045 00007192 3C3F                <1> 	cmp	al, '?'
 21046 00007194 750D                <1> 	jne	short pass_fde_ambiguous2_check
 21047 00007196 FE05[AAC70000]      <1> 	inc	byte [AmbiguousFileName]
 21048 0000719C 803F20              <1> 	cmp	byte [edi], 20h
 21049 0000719F 764E                <1> 	jna	short loc_find_dir_next_entry_ebp
 21050 000071A1 EB14                <1> 	jmp	short loc_scasb_find_dir_inc_di
 21051                              <1> 
 21052                              <1> pass_fde_ambiguous2_check:
 21053 000071A3 3C20                <1> 	cmp	al, 20h
 21054 000071A5 750C                <1> 	jne	short loc_scasb_find_dir
 21055 000071A7 803F20              <1> 	cmp	byte [edi], 20h
 21056 000071AA 7543                <1> 	jne	short loc_find_dir_next_entry_ebp
 21057 000071AC EB0C                <1> 	jmp	short loc_check_direntry_extension
 21058                              <1> 
 21059                              <1> loc_find_dir_next_entry_prevdeleted:
 21060 000071AE 80CA80              <1> 	or	dl, 80h  ; Bit 7 -> deleted entry sign
 21061 000071B1 EB5E                <1> 	jmp	short loc_find_dir_next_entry
 21062                              <1> 
 21063                              <1> loc_scasb_find_dir:
 21064 000071B3 3A07                <1> 	cmp	al, [edi]
 21065 000071B5 7538                <1> 	jne	short loc_find_dir_next_entry_ebp
 21066                              <1> loc_scasb_find_dir_inc_di:
 21067 000071B7 47                  <1> 	inc	edi
 21068 000071B8 E2CB                <1> 	loop	loc_lodsb_find_dir
 21069                              <1> 
 21070                              <1> loc_check_direntry_extension:
 21071 000071BA BE08000000          <1> 	mov	esi, 8
 21072 000071BF 89F7                <1> 	mov	edi, esi ; 8
 21073 000071C1 033424              <1> 	add	esi, [esp] ; Sub Dir or File Name Address
 21074 000071C4 01EF                <1> 	add	edi, ebp
 21075 000071C6 B103                <1> 	mov	cl, 3
 21076                              <1> loc_lodsb_find_dir_ext:
 21077 000071C8 AC                  <1> 	lodsb
 21078 000071C9 3C2A                <1> 	cmp	al, '*'
 21079 000071CB 7508                <1> 	jne	short pass_fde_ambiguous3_check
 21080 000071CD FE05[ABC70000]      <1> 	inc	byte [AmbiguousFileName+1]
 21081 000071D3 EB1E                <1> 	jmp	short loc_find_dir_proper_direntry
 21082                              <1> 
 21083                              <1> pass_fde_ambiguous3_check:
 21084 000071D5 3C3F                <1> 	cmp	al, '?'
 21085 000071D7 750D                <1> 	jne	short pass_fde_ambiguous4_check
 21086 000071D9 FE05[AAC70000]      <1> 	inc	byte [AmbiguousFileName]
 21087 000071DF 803F20              <1> 	cmp	byte [edi], 20h
 21088 000071E2 760B                <1> 	jna	short loc_find_dir_next_entry_ebp
 21089 000071E4 EB49                <1> 	jmp	short loc_scasb_find_dir_ext_inc_di
 21090                              <1> 
 21091                              <1> pass_fde_ambiguous4_check:
 21092 000071E6 3C20                <1> 	cmp	al, 20h
 21093 000071E8 7541                <1> 	jne	short loc_scasb_find_dir_ext
 21094 000071EA 803F20              <1> 	cmp	byte [edi], 20h
 21095 000071ED 7404                <1> 	je	short loc_find_dir_proper_direntry
 21096                              <1> 
 21097                              <1> loc_find_dir_next_entry_ebp:
 21098 000071EF 89EF                <1> 	mov	edi, ebp ; 14/02/2016
 21099 000071F1 EB1E                <1> 	jmp	short loc_find_dir_next_entry
 21100                              <1> 
 21101                              <1> loc_find_dir_proper_direntry:
 21102 000071F3 30C9                <1> 	xor	cl, cl
 21103                              <1> loc_find_dir_proper_direntry_1:
 21104 000071F5 5E                  <1> 	pop	esi
 21105 000071F6 89EF                <1>         mov     edi, ebp
 21106 000071F8 8A2F                <1> 	mov	ch, [edi]
 21107 000071FA 8A570B              <1> 	mov     dl, [edi+0Bh] ; Dir entry attributes
 21108 000071FD 66A1[AAC70000]      <1> 	mov	ax, [AmbiguousFileName]
 21109                              <1> loc_find_dir_proper_direntry_2:
 21110 00007203 8A35[ACC70000]      <1> 	mov     dh, [PreviousAttr]
 21111 00007209 66891D[D9C60000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 21112 00007210 C3                  <1> 	retn
 21113                              <1> 
 21114                              <1> loc_find_dir_next_entry:
 21115 00007211 8815[ACC70000]      <1> 	mov	byte [PreviousAttr], dl ; LongName check
 21116                              <1> loc_find_dir_next_entry_1:
 21117 00007217 5E                  <1> 	pop	esi
 21118 00007218 83C720              <1> 	add	edi, 32
 21119                              <1> 	;inc	word [DirBuff_EntryCounter]
 21120 0000721B 6643                <1> 	inc	bx
 21121 0000721D 663B1D[DBC60000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 21122 00007224 770E                <1> 	ja	short loc_ffde_stc_retn_255
 21123 00007226 E9FCFEFFFF          <1>         jmp     check_find_dir_entry 
 21124                              <1> 
 21125                              <1> loc_scasb_find_dir_ext:
 21126 0000722B 3A07                <1> 	cmp	al, [edi]
 21127 0000722D 75C0                <1> 	jne	short loc_find_dir_next_entry_ebp
 21128                              <1> loc_scasb_find_dir_ext_inc_di:
 21129 0000722F 47                  <1> 	inc	edi
 21130 00007230 E296                <1> 	loop    loc_lodsb_find_dir_ext
 21131 00007232 EBC1                <1> 	jmp	short loc_find_dir_proper_direntry_1
 21132                              <1> 
 21133                              <1> loc_ffde_stc_retn_255:
 21134                              <1> 	;mov	cx, 0FFFFh
 21135 00007234 31C9                <1> 	xor	ecx, ecx
 21136 00007236 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 21137                              <1> 	;xor	eax, eax
 21138                              <1> loc_find_direntry_stc_retn:
 21139                              <1> loc_check_ffde_retn_1:
 21140                              <1> 	;mov	ax, 2
 21141 00007237 B802000000          <1> 	mov	eax, 2 ; File Not Found
 21142 0000723C 8A35[ACC70000]      <1> 	mov	dh, [PreviousAttr]
 21143 00007242 66891D[D9C60000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 21144 00007249 F9                  <1> 	stc
 21145 0000724A C3                  <1> 	retn
 21146                              <1> 
 21147                              <1> loc_find_free_deleted_entry_0:
 21148 0000724B 66A1[A8C70000]      <1> 	mov	ax, [FDE_AttrMask]
 21149 00007251 8A2F                <1> 	mov	ch, [edi]
 21150 00007253 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
 21151 00007256 08C9                <1> 	or	cl, cl 
 21152 00007258 7407                <1> 	jz	short loc_check_ffde_0_repeat
 21153                              <1> 	;cmp	cl, 0E5h
 21154                              <1> 	;je	short pass_loc_check_ffde_0_err
 21155 0000725A 80F9FF              <1> 	cmp	cl, 0FFh
 21156 0000725D 7432                <1> 	je	short loc_find_free_deleted_entry_1
 21157 0000725F EB4D                <1> 	jmp	short pass_loc_check_ffde_0_err
 21158                              <1> 
 21159                              <1> loc_check_ffde_0_repeat:
 21160 00007261 08ED                <1> 	or	ch, ch
 21161 00007263 7511                <1> 	jnz	short loc_check_ffde_0_next
 21162                              <1> 
 21163                              <1> loc_check_ffde_retn_2:
 21164 00007265 6629C0              <1> 	sub	ax, ax
 21165 00007268 8A35[ACC70000]      <1> 	mov	dh, [PreviousAttr]
 21166 0000726E 66891D[D9C60000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 21167 00007275 C3                  <1> 	retn
 21168                              <1>  
 21169                              <1> loc_check_ffde_0_next:
 21170 00007276 6643                <1> 	inc	bx
 21171 00007278 83C720              <1> 	add	edi, 32
 21172                              <1> 	;inc	word [DirBuff_EntryCounter]
 21173                              <1> 	 
 21174 0000727B 663B1D[DBC60000]    <1>         cmp	bx, [DirBuff_LastEntry]
 21175 00007282 77B0                <1> 	ja	short loc_ffde_stc_retn_255
 21176 00007284 8815[ACC70000]      <1> 	mov	[PreviousAttr], dl
 21177 0000728A 8A2F                <1> 	mov	ch, [edi]
 21178 0000728C 8A570B              <1> 	mov	dl, [edi+0Bh] ; file attributes
 21179 0000728F EBD0                <1> 	jmp	short loc_check_ffde_0_repeat
 21180                              <1> 
 21181                              <1> loc_find_free_deleted_entry_1:
 21182 00007291 28D2                <1> 	sub	dl, dl      
 21183                              <1> loc_find_free_deleted_entry_2:
 21184 00007293 20ED                <1> 	and	ch, ch  
 21185 00007295 74CE                <1> 	jz	short loc_check_ffde_retn_2
 21186 00007297 80FDE5              <1> 	cmp	ch, 0E5h
 21187 0000729A 74C9                <1> 	je	short loc_check_ffde_retn_2
 21188 0000729C 6643                <1> 	inc	bx
 21189 0000729E 83C720              <1> 	add	edi, 32
 21190 000072A1 663B1D[DBC60000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 21191 000072A8 778A                <1> 	ja	short loc_ffde_stc_retn_255
 21192 000072AA 8A2F                <1> 	mov	ch, [edi]
 21193 000072AC EBE5                <1> 	jmp	short loc_find_free_deleted_entry_2
 21194                              <1> 
 21195                              <1> pass_loc_check_ffde_0_err:
 21196 000072AE 38CD                <1> 	cmp	ch, cl
 21197 000072B0 741F                <1> 	je	short loc_check_ffde_attrib 
 21198                              <1> 
 21199 000072B2 6643                <1> 	inc	bx
 21200 000072B4 83C720              <1> 	add	edi, 32
 21201 000072B7 663B1D[DBC60000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 21202 000072BE 0F8770FFFFFF        <1>         ja      loc_ffde_stc_retn_255
 21203 000072C4 8815[ACC70000]      <1> 	mov	[PreviousAttr], dl
 21204 000072CA 8A2F                <1> 	mov	ch, [edi]
 21205 000072CC 8A570B              <1> 	mov	dl, [edi+0Bh]
 21206 000072CF EBDD                <1> 	jmp	short pass_loc_check_ffde_0_err
 21207                              <1> 
 21208                              <1> loc_check_ffde_attrib:
 21209 000072D1 88C6                <1> 	mov	dh, al
 21210 000072D3 20D6                <1> 	and	dh, dl    
 21211 000072D5 38F0                <1> 	cmp	al, dh
 21212 000072D7 759D                <1> 	jne	short loc_check_ffde_0_next
 21213 000072D9 20D4                <1> 	and	ah, dl
 21214 000072DB 7599                <1> 	jnz	short loc_check_ffde_0_next
 21215 000072DD 30C9                <1> 	xor	cl, cl 
 21216 000072DF EB84                <1>         jmp     loc_check_ffde_retn_2
 21217                              <1> 
 21218                              <1> convert_file_name:
 21219                              <1> 	; 06/03/2016
 21220                              <1> 	; 11/02/2016
 21221                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
 21222                              <1> 	; 06/10/2009
 21223                              <1> 	; 2005
 21224                              <1> 	;
 21225                              <1> 	; INPUT  ->
 21226                              <1> 	;	ESI = Dot File Name Location
 21227                              <1> 	;	EDI = Dir Entry Format File Name Location
 21228                              <1> 	; OUTPUT ->
 21229                              <1> 	;	EDI = Dir Entry Format File Name Location
 21230                              <1> 	;	ESI = Dot File Name Location (capitalized)
 21231                              <1> 	;
 21232                              <1> 	; (ECX, AL will be changed) 
 21233                              <1>      
 21234 000072E1 56                  <1> 	push	esi  
 21235 000072E2 57                  <1> 	push	edi
 21236                              <1> 
 21237 000072E3 B90B000000          <1> 	mov	ecx, 11
 21238 000072E8 B020                <1> 	mov	al, 20h
 21239 000072EA F3AA                <1> 	rep	stosb
 21240                              <1> 
 21241 000072EC 8B3C24              <1> 	mov	edi, [esp]
 21242                              <1> 
 21243 000072EF B10C                <1> 	mov	cl, 12 ; file name length (max.)
 21244                              <1> 	; 06/03/2016
 21245                              <1> 	; Directory entry name limit (11 bytes) check for
 21246                              <1> 	; 'rename_directory_entry' procedure.
 21247                              <1> 	; (EDI points to Directory Entry)
 21248                              <1> 	; (If the file name would not contain a dot
 21249                              <1> 	; and file name length would be 12, this would cause to
 21250                              <1> 	; overwrite the attributes byte of the directory entry.)
 21251                              <1> 	;
 21252 000072F1 B50B                <1> 	mov	ch, 11 ; directory entry's name length
 21253                              <1> loc_check_first_dot:
 21254 000072F3 8A06                <1> 	mov	al, [esi]
 21255 000072F5 3C2E                <1> 	cmp	al, 2Eh
 21256 000072F7 750C                <1> 	jne	short pass_check_first_dot
 21257 000072F9 8807                <1> 	mov	[edi], al
 21258 000072FB 47                  <1> 	inc	edi
 21259 000072FC 46                  <1> 	inc	esi
 21260 000072FD FEC9                <1> 	dec	cl
 21261 000072FF 75F2                <1> 	jnz	short loc_check_first_dot
 21262                              <1> 	;;(ecx <= 12)
 21263                              <1> 	;;loop	loc_check_first_dot 
 21264 00007301 EB30                <1> 	jmp	short stop_convert_file
 21265                              <1> 
 21266                              <1> loc_get_fchar:
 21267 00007303 8A06                <1> 	mov	al, [esi]
 21268                              <1> pass_check_first_dot:
 21269 00007305 3C61                <1> 	cmp	al, 61h ; 'a'
 21270 00007307 7208                <1> 	jb	short pass_name_capitalize
 21271 00007309 3C7A                <1> 	cmp	al, 7Ah ; 'z'
 21272 0000730B 7704                <1> 	ja	short pass_name_capitalize
 21273 0000730D 24DF                <1> 	and	al, 0DFh
 21274 0000730F 8806                <1> 	mov	[esi], al
 21275                              <1> pass_name_capitalize:
 21276 00007311 3C21                <1> 	cmp	al, 21h
 21277 00007313 721E                <1> 	jb	short stop_convert_file
 21278 00007315 3C2E                <1> 	cmp	al, 2Eh ; '.'
 21279 00007317 750C                <1> 	jne	short pass_dot_space
 21280                              <1> add_dot_space: 
 21281 00007319 80F904              <1> 	cmp	cl, 4
 21282 0000731C 760E                <1> 	jna	short inc_and_loop
 21283 0000731E 47                  <1> 	inc	edi
 21284 0000731F FECD                <1> 	dec	ch ; 06/03/2016
 21285 00007321 FEC9                <1> 	dec	cl
 21286 00007323 EBF4                <1> 	jmp	short add_dot_space
 21287                              <1> 	
 21288                              <1> 	;mov	al, 4
 21289                              <1> 	;cmp	cl, al
 21290                              <1> 	;jna	short inc_and_loop
 21291                              <1> 	;sub	cl, al
 21292                              <1> 	;add	edi, ecx
 21293                              <1> 	;mov	cl, al
 21294                              <1> 	;jmp	short inc_and_loop	
 21295                              <1> 
 21296                              <1> pass_dot_space:
 21297 00007325 8807                <1> 	mov	[edi], al
 21298                              <1> loc_after_double_dot:
 21299                              <1> 	; 06/03/2016
 21300 00007327 FECD                <1> 	dec	ch ; count down for 11 bytes dir entry limit
 21301 00007329 740A                <1> 	jz	short stop_convert_file_x
 21302 0000732B 47                  <1> 	inc	edi
 21303                              <1> inc_and_loop:
 21304 0000732C FEC9                <1> 	dec	cl ; count down for 12 bytes filename limit 
 21305 0000732E 7403                <1> 	jz	short stop_convert_file	
 21306 00007330 46                  <1> 	inc	esi
 21307                              <1> 	;;(ecx <= 12)
 21308                              <1> 	;;loop	loc_get_fchar
 21309 00007331 EBD0                <1> 	jmp	short loc_get_fchar
 21310                              <1> 
 21311                              <1> stop_convert_file:
 21312                              <1> 	; 06/03/2016
 21313 00007333 30ED                <1> 	xor	ch, ch
 21314                              <1> 	; ECX < 256 ; 'find_first_file' -> xor cl, cl
 21315                              <1> stop_convert_file_x:
 21316 00007335 5F                  <1> 	pop	edi
 21317 00007336 5E                  <1> 	pop	esi
 21318 00007337 C3                  <1> 	retn
 21319                              <1>  
 21320                              <1> save_longname_sub_component:
 21321                              <1> 	; 13/02/2016
 21322                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 21323                              <1> 	; 28/02/2010
 21324                              <1> 	; 17/10/2009
 21325                              <1> 	; INPUT ->
 21326                              <1> 	;	EDI = Directory Entry    
 21327                              <1> 	;     	// This procedure is called
 21328                              <1> 	;	// from 'find_directory_entry' procedure.
 21329                              <1> 	;	// If the last entry returns with
 21330                              <1> 	;	// a non-zero LongnameFound value and
 21331                              <1> 	;	// if LFN_CheckSum value is equal to
 21332                              <1> 	;	// the next shortname checksum,
 21333                              <1> 	;	// long name is valid.
 21334                              <1> 	;	// If a longname is longer than 65 bytes,
 21335                              <1> 	;	// it is invalid for trdos. (>45h)
 21336                              <1>  
 21337 00007338 57                  <1> 	push	edi
 21338 00007339 56                  <1> 	push	esi
 21339                              <1> 	;push	ebx
 21340                              <1> 	;push	ecx
 21341                              <1> 	;push	edx
 21342 0000733A 50                  <1> 	push	eax
 21343                              <1>            
 21344 0000733B 29C9                <1> 	sub	ecx, ecx
 21345                              <1> 	;sub	eax, eax
 21346 0000733D B11A                <1> 	mov	cl, 26
 21347                              <1> 
 21348 0000733F 0FB607              <1> 	movzx	eax, byte [edi] ; LDIR_Order
 21349 00007342 3C41                <1> 	cmp	al, 41h  ; 40h (last long entry sign) + 1
 21350 00007344 722B                <1> 	jb	short pass_pslnsc_last_long_entry
 21351                              <1> 
 21352 00007346 88C4                <1> 	mov	ah, al
 21353 00007348 80EC40              <1> 	sub	ah, 40h
 21354 0000734B 8825[AEC70000]      <1> 	mov	[LFN_EntryLength], ah
 21355                              <1> 	
 21356 00007351 3C45                <1> 	cmp	al, 45h  ; 40h (last long entry sign) + 5
 21357                              <1>  		; Max 130 byte length is usable in TRDOS
 21358                              <1> ; 26*5 = 130
 21359 00007353 7753                <1> 	ja	short loc_pslnsc_retn
 21360                              <1> 
 21361 00007355 2407                <1> 	and	al, 07h ; 0Fh
 21362 00007357 A2[ADC70000]        <1> 	mov	[LongNameFound], al
 21363                              <1> 
 21364 0000735C FEC8                <1> 	dec	al
 21365                              <1> 	;mov	cl, 26
 21366 0000735E F6E1                <1> 	mul	cl
 21367                              <1> 
 21368 00007360 89C6                <1> 	mov	esi, eax
 21369 00007362 01CE                <1> 	add	esi, ecx
 21370                              <1> 		; to make is an ASCIZZ string
 21371                              <1> 		; with ax+26 bytes length
 21372 00007364 81C6[B0C70000]      <1> 	add	esi, LongFileName
 21373 0000736A 66C7060000          <1> 	mov	word [esi], 0   
 21374 0000736F EB16                <1> 	jmp	short loc_pslsc_move_ldir_name2 
 21375                              <1> 
 21376                              <1> pass_pslnsc_last_long_entry:
 21377 00007371 3C04                <1> 	cmp	al, 04h
 21378 00007373 7733                <1> 	ja	short loc_pslnsc_retn
 21379 00007375 FE0D[ADC70000]      <1> 	dec	byte [LongNameFound]
 21380 0000737B 3A05[ADC70000]      <1> 	cmp	al, [LongNameFound]
 21381 00007381 7525                <1> 	jne	short loc_pslnsc_retn
 21382                              <1> 
 21383                              <1> loc_pslsc_move_ldir_name1:
 21384 00007383 FEC8                <1> 	dec	al
 21385                              <1> 	;mov	cl, 26
 21386 00007385 F6E1                <1> 	mul	cl
 21387                              <1> 
 21388                              <1> loc_pslsc_move_ldir_name2:
 21389 00007387 8A4F0D              <1> 	mov	cl, [edi+0Dh] ; long name checksum
 21390 0000738A 880D[AFC70000]      <1> 	mov	[LFN_CheckSum], cl 
 21391 00007390 89FE                <1> 	mov	esi, edi ; LDIR_Order
 21392 00007392 BF[B0C70000]        <1> 	mov	edi, LongFileName
 21393 00007397 01C7                <1> 	add	edi, eax
 21394 00007399 46                  <1> 	inc	esi
 21395 0000739A B105                <1> 	mov	cl, 5 ; chars 1 to 5
 21396 0000739C F366A5              <1> 	rep	movsw
 21397 0000739F 83C603              <1> 	add	esi, 3
 21398 000073A2 A5                  <1> 	movsd	; char 6 & 7 
 21399 000073A3 A5                  <1> 	movsd	; char 8 & 9
 21400 000073A4 A5                  <1> 	movsd	; char 10 & 11
 21401 000073A5 46                  <1> 	inc	esi
 21402 000073A6 46                  <1> 	inc	esi 
 21403 000073A7 A5                  <1> 	movsd   ; char 12 & 13 
 21404                              <1> 
 21405                              <1> loc_pslnsc_retn:
 21406 000073A8 58                  <1>  	pop	eax
 21407                              <1> 	;pop	edx
 21408                              <1> 	;pop	ecx
 21409                              <1> 	;pop	ebx
 21410 000073A9 5E                  <1> 	pop	esi  
 21411 000073AA 5F                  <1> 	pop	edi
 21412                              <1>  
 21413 000073AB C3                  <1>     	retn
 21414                              <1> 
 21415                              <1> parse_path_name:
 21416                              <1> 	; 10/02/2016
 21417                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
 21418                              <1> 	; 10/009/2011 ('proc_parse_pathname')
 21419                              <1> 	; 27/11/2009
 21420                              <1> 	; 05/12/2004
 21421                              <1> 	;
 21422                              <1> 	; INPUT ->
 21423                              <1> 	;	ESI = Beginning of ASCIIZ pathname string
 21424                              <1> 	;       EDI = Destination Address
 21425                              <1> 	;	      (which is TR-DOS FindFile data buffer)
 21426                              <1> 	; OUTPUT ->
 21427                              <1> 	;	CF = 1 -> Error
 21428                              <1> 	;	     EAX = Error Code (AL)
 21429                              <1> 	;
 21430                              <1> 	; (Modified registers: eax, ecx, esi, edi) 
 21431                              <1> 	
 21432                              <1> 	; Clear the pathname bytes in TR-DOS Findfile data buffer 
 21433 000073AC 57                  <1> 	push	edi
 21434 000073AD B914000000          <1> 	mov	ecx, 20  ; 80 bytes
 21435 000073B2 31C0                <1> 	xor	eax, eax
 21436 000073B4 F3AB                <1> 	rep	stosd 
 21437 000073B6 5F                  <1> 	pop	edi
 21438                              <1> 
 21439 000073B7 668B06              <1> 	mov	ax, [esi]
 21440 000073BA 80FC3A              <1> 	cmp	ah, ':'
 21441 000073BD 741C                <1> 	je	short loc_ppn_change_drive
 21442 000073BF A0[AEBE0000]        <1> 	mov	al, [Current_Drv]
 21443 000073C4 EB33                <1> 	jmp	short pass_ppn_change_drive
 21444                              <1> 
 21445                              <1> pass_ppn_cdir:
 21446 000073C6 8B35[D2C80000]      <1> 	mov	esi, [First_Path_Pos]
 21447 000073CC AC                  <1> 	lodsb
 21448                              <1> loc_ppn_get_filename:
 21449 000073CD 83C741              <1> 	add	edi, 65 ; FindFile_Name location
 21450                              <1> 	; TRDOS Filename length must not be more than 12 bytes
 21451                              <1> 	;mov	ecx, 12
 21452 000073D0 B10C                <1> 	mov	cl, 12
 21453                              <1> loc_ppn_get_fnchar_next:
 21454 000073D2 AA                  <1> 	stosb
 21455 000073D3 AC                  <1> 	lodsb
 21456 000073D4 3C21                <1> 	cmp	al, 21h
 21457 000073D6 7274                <1> 	jb	short loc_ppn_clc_return 
 21458 000073D8 E2F8                <1>         loop    loc_ppn_get_fnchar_next
 21459                              <1> loc_ppn_return:
 21460 000073DA C3                  <1> 	retn
 21461                              <1> 
 21462                              <1> loc_ppn_change_drive:
 21463 000073DB 24DF                <1> 	and	al, 0DFh
 21464 000073DD 2C41                <1> 	sub	al, 'A'; A:
 21465 000073DF 726F                <1> 	jc	short loc_ppn_invalid_drive
 21466 000073E1 3805[7FAE0000]      <1> 	cmp	[Last_DOS_DiskNo], al
 21467 000073E7 7267                <1> 	jb	short loc_ppn_invalid_drive
 21468                              <1> 
 21469 000073E9 46                  <1> 	inc	esi
 21470 000073EA 46                  <1> 	inc	esi
 21471 000073EB 8A26                <1> 	mov	ah, [esi]
 21472 000073ED 80FC21              <1> 	cmp	ah, 21h
 21473 000073F0 7307                <1> 	jnb	short pass_ppn_change_drive
 21474                              <1> 
 21475                              <1> loc_ppn_cmd_failed:
 21476                              <1> 	; File or directory name is not existing
 21477 000073F2 8807                <1> 	mov	[edi], al ; Drv 
 21478 000073F4 66B80100            <1> 	mov	ax, 1 ; eax = 1
 21479                              <1> 	; TR-DOS Error Code 1h = Bad Command Argument
 21480                              <1> 	; MS-DOS Error Code 1h : Invalid Function Number
 21481                              <1> 	;stc
 21482                              <1> 	; (MainProg ErrMsg: "Bad command or file name!")
 21483 000073F8 C3                  <1> 	retn
 21484                              <1> 
 21485                              <1> pass_ppn_change_drive:
 21486 000073F9 8935[D2C80000]      <1> 	mov	[First_Path_Pos], esi
 21487 000073FF C705[D6C80000]0000- <1> 	mov	dword [Last_Slash_Pos], 0
 21488 00007407 0000                <1>
 21489 00007409 AA                  <1> 	stosb
 21490 0000740A 8A06                <1> 	mov	al, [esi]
 21491                              <1> loc_scan_ppn_dslash:
 21492 0000740C 3C2F                <1> 	cmp	al, '/'
 21493 0000740E 7506                <1>   	jne	short loc_scan_next_slash_pos
 21494 00007410 8935[D6C80000]      <1> 	mov	[Last_Slash_Pos], esi
 21495                              <1> loc_scan_next_slash_pos:
 21496 00007416 46                  <1> 	inc	esi
 21497 00007417 8A06                <1> 	mov	al, [esi]
 21498 00007419 3C20                <1> 	cmp	al, 20h
 21499 0000741B 77EF                <1> 	ja	short loc_scan_ppn_dslash
 21500 0000741D 833D[D6C80000]00    <1> 	cmp	dword [Last_Slash_Pos], 0
 21501 00007424 76A0                <1> 	jna	short pass_ppn_cdir
 21502                              <1> 	
 21503 00007426 8B0D[D6C80000]      <1> 	mov	ecx, [Last_Slash_Pos]
 21504 0000742C 8B35[D2C80000]      <1> 	mov	esi, [First_Path_Pos]
 21505 00007432 29F1                <1> 	sub	ecx, esi
 21506 00007434 41                  <1> 	inc	ecx
 21507                              <1> 	;cmp	ecx, 64
 21508 00007435 80F940              <1> 	cmp	cl, 64
 21509 00007438 7715                <1> 	ja	short loc_ppn_invalid_drive_stc
 21510                              <1> 
 21511 0000743A 89F8                <1> 	mov	eax, edi ; Dest Dir String Location (65 byte)
 21512 0000743C F3A4                <1> 	rep	movsb
 21513                              <1> 	;mov	[edi], cl ; 0, End of Dir String
 21514 0000743E 8B35[D6C80000]      <1> 	mov	esi, [Last_Slash_Pos]
 21515 00007444 46                  <1> 	inc	esi
 21516 00007445 89C7                <1> 	mov	edi, eax
 21517 00007447 AC                  <1> 	lodsb
 21518 00007448 3C21                <1> 	cmp	al, 21h
 21519 0000744A 7381                <1> 	jnb	short loc_ppn_get_filename
 21520                              <1> loc_ppn_clc_return:
 21521                              <1> 	;clc
 21522 0000744C 31C0                <1> 	xor	eax, eax
 21523 0000744E C3                  <1> 	retn
 21524                              <1> 
 21525                              <1> loc_ppn_invalid_drive_stc:
 21526 0000744F F5                  <1> 	cmc	 ; stc
 21527                              <1> loc_ppn_invalid_drive:
 21528                              <1> 	; cf = 1
 21529                              <1> 	; The Drive Letter/Char < "A" or > "Z"
 21530 00007450 66B80F00            <1> 	mov	ax, 0Fh
 21531                              <1> 	; MS-DOS Error Code 0Fh = Disk Drive Invalid 
 21532                              <1> 	; (MainProg ErrMsg: "Drive not ready or read error!")
 21533 00007454 C3                  <1> 	retn
 21534                              <1> 
 21535                              <1> find_longname:
 21536                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
 21537                              <1> 	; 24/01/2010 (DIR.ASM, 'proc_find_longname')
 21538                              <1> 	; 17/10/2009
 21539                              <1> 	
 21540                              <1> 	; INPUT -> 
 21541                              <1> 	;	ESI = DOS short file name address
 21542                              <1> 	; 	for example: "filename.ext"
 21543                              <1> 	;
 21544                              <1> 	; OUTPUT ->
 21545                              <1> 	; 	ESI = ASCIIZ longname address (cf = 0)
 21546                              <1> 	;	cf = 1 -> error number returns in EAX (AL)
 21547                              <1> 	;	AL = 0 & CF=1 -> longname not found
 21548                              <1> 	;	     the file/directory has no longname
 21549                              <1> 	; 	cf = 0 -> AL = FAT Type 
 21550                              <1>  
 21551                              <1> 	; 17/10/2009
 21552                              <1> 	; ASCIIZ string will be returned
 21553                              <1> 	; as LongFileName
 21554                              <1> 	; clearing/reset is not needed
 21555                              <1> 	;mov	ecx, 33
 21556                              <1> 	;mov	edi, LongFileName
 21557                              <1> 	;sub	ax, ax ; 0
 21558                              <1> 	;rep	stosw
 21559                              <1> 
 21560                              <1> 	;mov	byte [LongNameFound], 0
 21561                              <1> 
 21562                              <1> 	; ESI = ASCIIZ file/directory name address
 21563                              <1> 	;   AL = Attributes AND mask 
 21564                              <1> 	;	(Result of AND must be equal to AL)
 21565                              <1> 	;   AH = Negative attributes mask 
 21566                              <1> 	;	(Result of AND must be ZERO)
 21567 00007455 66B80008            <1> 	mov	ax, 0800h 
 21568                              <1> 		; it must not be volume name or longname
 21569 00007459 E8B4E6FFFF          <1> 	call	find_first_file
 21570 0000745E 7216                <1> 	jc	short loc_fln_retn
 21571                              <1>  
 21572                              <1> loc_fln_check_FAT_Type:
 21573 00007460 803D[ADBE0000]01    <1> 	cmp	byte [Current_FATType], 1
 21574 00007467 7306                <1> 	jnb	short loc_fln_check_longname_yes_sign
 21575                              <1> 
 21576 00007469 E839000000          <1> 	call	get_fs_longname
 21577 0000746E C3                  <1> 	retn
 21578                              <1> 
 21579                              <1> loc_fln_check_longname_yes_sign:
 21580 0000746F 08FF                <1> 	or	bh, bh
 21581 00007471 7504                <1> 	jnz	short loc_fln_check_longnamefound_number
 21582                              <1> loc_fln_longname_not_found_retn:
 21583 00007473 31C0                <1> 	xor	eax, eax 
 21584                              <1> 	; cf = 1 & al = 0 -> longname not found
 21585 00007475 F9                  <1> 	stc
 21586                              <1> loc_fln_retn:
 21587 00007476 C3                  <1> 	retn
 21588                              <1> 
 21589                              <1> loc_fln_check_longnamefound_number:
 21590                              <1> 	; 'LongNameFound' is set by
 21591                              <1>         ; by 'save_longname_sub_component'
 21592                              <1> 	; which is called from
 21593                              <1> 	; 'find_directory_entry' 
 21594                              <1> 	; which is called from 
 21595                              <1> 	; 'find_first_file'
 21596                              <1> 	; It must 1 if the longname is valid
 21597 00007477 803D[ADC70000]01    <1>         cmp     byte [LongNameFound], 1
 21598 0000747E 75F3                <1> 	jne	short loc_fln_longname_not_found_retn
 21599                              <1>              
 21600                              <1> loc_fln_calculate_checksum: 
 21601 00007480 E813000000          <1> 	call	calculate_checksum
 21602                              <1> 	; AL = shortname checksum
 21603                              <1> 
 21604                              <1> loc_fln_longname_validation:
 21605                              <1> 	; 'LFN_CheckSum' has been set already
 21606                              <1> 	; by 'save_longname_sub_component'
 21607                              <1> 	; which is called from
 21608                              <1> 	; 'find_directory_entry' 
 21609                              <1> 	; which is called from 
 21610                              <1> 	; 'find_first_file'
 21611 00007485 3805[AFC70000]      <1> 	cmp	[LFN_CheckSum], al
 21612 0000748B 75E6                <1> 	jne	short loc_fln_longname_not_found_retn
 21613                              <1> 
 21614 0000748D BE[B0C70000]        <1> 	mov	esi, LongFileName
 21615 00007492 A0[ADBE0000]        <1> 	mov	al, [Current_FATType]
 21616 00007497 C3                  <1> 	retn
 21617                              <1> 
 21618                              <1> calculate_checksum:
 21619                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
 21620                              <1> 	; 17/10/2009 (DIR.ASM, 'proc_calculate_checksum')
 21621                              <1>         ;    
 21622                              <1> 	; INPUT ->
 21623                              <1> 	;	ESI = 11 byte DOS File Name location
 21624                              <1> 	;	(in DOS Directory Entry Format)
 21625                              <1> 	; OUTPUT ->
 21626                              <1> 	;	 AL = 8 bit checksum (CRC) value
 21627                              <1> 	;
 21628                              <1> 	; (Modified registers: EAX, ECX, ESI)
 21629                              <1> 
 21630                              <1> 	; Erdogan Tan [ 17-10-2009 ]
 21631                              <1> 	;  'ror al, 1' instruction
 21632                              <1> 
 21633                              <1> 	; Erdogan Tan [ 20-06-2004 ]
 21634                              <1> 	; This 8086 assembly code is an original code
 21635                              <1> 	; which is adapted from C code in
 21636                              <1> 	; Microsoft FAT32 File System Specification
 21637                              <1> 	; Version 1.03, December 6, 2000
 21638                              <1> 	; Page 28
 21639                              <1> 
 21640 00007498 30C0                <1> 	xor	al, al
 21641 0000749A B90B000000          <1> 	mov	ecx, 11
 21642                              <1> loc_next_sum:
 21643                              <1> 	;xor	ah, ah
 21644                              <1> 	;test	al, 1
 21645                              <1> 	;jz	short pass_ah_80h
 21646                              <1> 	;mov	ah, 80h
 21647                              <1> ;pass_ah_80h:
 21648                              <1> 	;shr	al, 1
 21649 0000749F D0C8                <1> 	ror	al, 1 ; 17/10/2009  
 21650 000074A1 0206                <1> 	add	al, [esi]
 21651 000074A3 46                  <1> 	inc	esi
 21652                              <1> 	;add	al, ah
 21653 000074A4 E2F9                <1> 	loop	loc_next_sum
 21654 000074A6 C3                  <1> 	retn
 21655                              <1> 
 21656                              <1> get_fs_longname:
 21657                              <1> 	; temporary (13/02/2016)
 21658 000074A7 31C0                <1> 	xor eax, eax
 21659 000074A9 F9                  <1> 	stc
 21660 000074AA C3                  <1> 	retn
 21661                              <1> 
 21662                              <1> make_sub_directory:
 21663                              <1> 	; 03/03/2016
 21664                              <1> 	; 02/03/2016
 21665                              <1> 	; 27/02/2026
 21666                              <1> 	; 26/02/2016
 21667                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 21668                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_make_directory')
 21669                              <1> 	; 10/07/2010
 21670                              <1> 	; INPUT ->
 21671                              <1> 	; 	ESI = ASCIIZ Directory Name
 21672                              <1> 	;	CL = Directory Attributes
 21673                              <1> 	; OUTPUT ->
 21674                              <1> 	;	EAX = New sub dir's first cluster
 21675                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
 21676                              <1> 	;	CF = 1 -> error code in AL (EAX)
 21677                              <1> 
 21678                              <1> 	;test	cl, 10h  ; directory
 21679                              <1> 	;jz	short loc_make_directory_access_denied
 21680                              <1> 	;test	cl, 08h ; volume name
 21681                              <1> 	;jnz	short loc_make_directory_access_denied
 21682                              <1> 
 21683 000074AB 80E107              <1> 	and	cl, 07h
 21684 000074AE 880D[2CC90000]      <1> 	mov	byte [mkdir_attrib], cl
 21685                              <1> 
 21686 000074B4 56                  <1> 	push	esi
 21687 000074B5 31DB                <1> 	xor	ebx, ebx
 21688 000074B7 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 21689 000074BD BE00010900          <1> 	mov	esi, Logical_DOSDisks
 21690 000074C2 01DE                <1> 	add	esi, ebx
 21691 000074C4 5B                  <1> 	pop	ebx
 21692                              <1> 
 21693                              <1> 	; 10/07/2010 -> 1st writable disk check for trdos
 21694                              <1> 	; LD_DiskType = 0 for write protection (read only) 
 21695 000074C5 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
 21696 000074C9 730B                <1> 	jnb	short loc_mkdir_check_file_sytem
 21697 000074CB B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected 
 21698 000074D0 BA00000000          <1> 	mov	edx, 0
 21699                              <1> 	; err retn: EDX = 0, EBX = Dir name offset
 21700                              <1> 	;ESI = Logical DOS drive description table address
 21701 000074D5 C3                  <1> 	retn
 21702                              <1> 
 21703                              <1> ;loc_make_directory_access_denied:
 21704                              <1> 	;mov	ax, 05h ; access denied (invalid attributes input)
 21705                              <1> 	;stc
 21706                              <1> 	;retn
 21707                              <1> 
 21708                              <1> loc_mkdir_check_file_sytem:
 21709 000074D6 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 21710 000074DA 730B                <1> 	jnb	short loc_mkdir_check_free_sectors
 21711                              <1> 
 21712                              <1> loc_make_fs_directory:
 21713 000074DC A1[A8BE0000]        <1> 	mov	eax, [Current_Dir_FCluster]
 21714                              <1> 	; EAX = Parent directory DDT Address
 21715                              <1> 	; ESI = Logical DOS Drive DT Address
 21716                              <1> 	; EBX = Directory name offset (as ASCIIZ name)
 21717 000074E1 E8CF150000          <1> 	call	make_fs_directory
 21718 000074E6 C3                  <1> 	retn
 21719                              <1> 
 21720                              <1> loc_mkdir_check_free_sectors:
 21721 000074E7 0FB64613            <1>         movzx   eax, byte [esi+LD_BPB+SecPerClust]
 21722 000074EB 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
 21723 000074EE 39C1                <1> 	cmp	ecx, eax
 21724 000074F0 7255                <1> 	jb	short loc_mkdir_insufficient_disk_space
 21725                              <1> 
 21726                              <1> loc_make_fat_directory:
 21727 000074F2 891D[1CC90000]      <1> 	mov	[mkdir_DirName_Offset], ebx
 21728 000074F8 890D[28C90000]      <1> 	mov	[mkdir_FreeSectors], ecx
 21729                              <1> 
 21730                              <1> 	;mov	al, [esi+LD_BPB+SecPerClust]
 21731 000074FE A2[2EC90000]        <1> 	mov	byte [mkdir_SecPerClust], al
 21732                              <1> 
 21733                              <1> loc_mkdir_gffc_1:
 21734 00007503 E809180000          <1> 	call	get_first_free_cluster
 21735 00007508 722A                <1> 	jc	short loc_mkdir_gffc_retn
 21736                              <1> 
 21737                              <1> ;loc_mkdir_gffc_1_cont: 
 21738                              <1> 	;cmp	eax, 2
 21739                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
 21740                              <1> 
 21741                              <1> ;loc_mkdir_gffc_1_save_fcluster:  
 21742 0000750A A3[20C90000]        <1> 	mov	[mkdir_FFCluster], eax
 21743                              <1> 
 21744                              <1> loc_mkdir_locate_ffe:
 21745                              <1> 	; Current directory fcluster <> Directory buffer cluster
 21746                              <1> 	; Current directory will be reloaded by
 21747                              <1> 	; 'locate_current_dir_file' procedure
 21748                              <1> 	;
 21749                              <1> 	; ESI = Logical DOS Drive Description Table Address 
 21750                              <1> 	;push	esi ; 27/02/2016
 21751 0000750F 31C0                <1> 	xor	eax, eax
 21752 00007511 89C1                <1>         mov	ecx, eax
 21753 00007513 6649                <1> 	dec	cx ; FFFFh  
 21754                              <1> 	; CX = FFFFh -> find first deleted or free entry
 21755                              <1> 	; ESI would be ASCIIZ filename address if the call
 21756                              <1> 	; would not be for first free or deleted dir entry
 21757 00007515 E8D2FAFFFF          <1> 	call	locate_current_dir_file
 21758 0000751A 734C                <1> 	jnc	short loc_mkdir_set_ff_dir_entry_1
 21759                              <1> 	;pop	esi 
 21760                              <1> 	; ESI = Logical DOS Drive Description Table Address 
 21761 0000751C 83F802              <1> 	cmp	eax, 2  ; cmp al, 2 ; File/Dir not found !
 21762 0000751F 752B                <1> 	jne	short loc_mkdir_stc_return
 21763                              <1> 
 21764                              <1> loc_mkdir_add_new_cluster:
 21765 00007521 3805[ADBE0000]      <1> 	cmp	byte [Current_FATType], al ; 2
 21766                              <1> 	;cmp	byte ptr [esi+LD_FATType], 2
 21767 00007527 770C                <1> 	ja	short loc_mkdir_add_new_cluster_check_fsc
 21768 00007529 803D[ACBE0000]01    <1> 	cmp	byte [Current_Dir_Level], 1
 21769                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
 21770 00007530 7303                <1> 	jnb	short loc_mkdir_add_new_cluster_check_fsc
 21771                              <1> 
 21772 00007532 B00C                <1> 	mov	al, 12 ; No more files 
 21773                              <1> loc_mkdir_gffc_retn:
 21774 00007534 C3                  <1> 	retn
 21775                              <1> 
 21776                              <1> loc_mkdir_add_new_cluster_check_fsc:
 21777 00007535 8B0D[28C90000]      <1> 	mov	ecx, [mkdir_FreeSectors]
 21778                              <1> 	;movzx	eax, byte [mkdir_SecPerClust]
 21779 0000753B A0[2EC90000]        <1> 	mov	al, [mkdir_SecPerClust]
 21780 00007540 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
 21781 00007543 39C1                <1> 	cmp	ecx, eax
 21782 00007545 7350                <1> 	jnb	short loc_mkdir_add_new_subdir_cluster
 21783                              <1> 
 21784                              <1> loc_mkdir_insufficient_disk_space:
 21785                              <1> 	;mov	edx, ecx
 21786                              <1> ;loc_mkdir_gffc_insufficient_disk_space:
 21787 00007547 66B82700            <1> 	mov	ax, 27h ; MSDOS err => insufficient disk space
 21788                              <1> 	; err retn: EDX = Free sectors, EBX = Dir name offset
 21789                              <1>         ; ESI -> Dos drive description table address
 21790                              <1> 	;; ecx = edx
 21791                              <1> 	;
 21792 0000754B C3                  <1> 	retn
 21793                              <1> 
 21794                              <1> loc_mkdir_stc_return:
 21795 0000754C F9                  <1> 	stc
 21796 0000754D C3                  <1> 	retn 
 21797                              <1> 
 21798                              <1> loc_mkdir_gffc_2:
 21799 0000754E E8BE170000          <1> 	call	get_first_free_cluster
 21800 00007553 72DF                <1> 	jc	short loc_mkdir_gffc_retn
 21801                              <1> 
 21802                              <1> ;loc_mkdir_gffc_1_cont: 
 21803                              <1> 	;cmp	eax, 2
 21804                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
 21805                              <1> 
 21806                              <1> ;loc_mkdir_gffc_2_save_fcluster:  
 21807 00007555 A3[20C90000]        <1> 	mov	[mkdir_FFCluster], eax
 21808                              <1> 
 21809 0000755A A1[24C90000]        <1> 	mov	eax, [mkdir_LastDirCluster]
 21810                              <1> 
 21811 0000755F E83C170000          <1> 	call	load_FAT_sub_directory 
 21812 00007564 72CE                <1> 	jc	short loc_mkdir_gffc_retn
 21813                              <1> 
 21814 00007566 31FF                <1> 	xor	edi, edi
 21815                              <1> loc_mkdir_set_ff_dir_entry_1:
 21816                              <1> 	; 27/02/2016
 21817 00007568 56                  <1> 	push	esi ; Logical DOS Drv Desc. Tbl. address
 21818                              <1> 	; EDI = Directory Entry Address
 21819 00007569 8B35[1CC90000]      <1> 	mov	esi, [mkdir_DirName_Offset]
 21820 0000756F A1[20C90000]        <1> 	mov	eax, [mkdir_FFCluster]
 21821                              <1> 
 21822 00007574 66B91000            <1> 	mov	cx, 10h	; CL = Directory attribute
 21823                              <1> 			; CH = 0 -> File size is 0
 21824 00007578 0A0D[2CC90000]      <1> 	or	cl, [mkdir_attrib] ; S, H, R  
 21825 0000757E E8B0010000          <1> 	call	make_directory_entry
 21826                              <1> 
 21827 00007583 5E                  <1> 	pop	esi
 21828                              <1> 
 21829 00007584 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 21830 0000758B E880020000          <1> 	call	save_directory_buffer
 21831 00007590 0F83DA000000        <1>         jnc     loc_mkdir_set_ff_dir_entry_2
 21832                              <1> 
 21833                              <1> loc_mkdir_return:
 21834 00007596 C3                  <1> 	retn
 21835                              <1> 
 21836                              <1> loc_mkdir_add_new_subdir_cluster:
 21837 00007597 8B15[DDC60000]      <1> 	mov	edx, [DirBuff_Cluster]
 21838 0000759D 8915[24C90000]      <1> 	mov	[mkdir_LastDirCluster], edx       
 21839                              <1> 
 21840 000075A3 A1[20C90000]        <1> 	mov	eax, [mkdir_FFCluster]
 21841 000075A8 E8F3160000          <1> 	call	load_FAT_sub_directory 
 21842 000075AD 72E7                <1> 	jc	short loc_mkdir_return
 21843                              <1> 	; eax = 0
 21844                              <1> 	; ecx =  directory buffer sector count (<= 128)
 21845                              <1> 
 21846                              <1> pass_mkdir_add_new_subdir_cluster:
 21847 000075AF 29FF                <1> 	sub	edi, edi ; 0
 21848                              <1> 	;mov	al, 128 ; double word
 21849                              <1> 	;mul	ecx ; ecx =  directory buffer sector count
 21850                              <1> 	;mov	ecx, eax
 21851                              <1> 	;shl	cx, 7 ; 128 * sector count	
 21852 000075B1 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
 21853 000075B5 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
 21854 000075B9 66F7E1              <1> 	mul	cx ; max = 128*(512/4) -> 16384 (stosd)
 21855 000075BC 6689C1              <1> 	mov	cx, ax
 21856 000075BF 6629C0              <1> 	sub	ax, ax ; 0
 21857 000075C2 F3AB                <1> 	rep	stosd ; clear directory buffer
 21858                              <1> 
 21859 000075C4 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 21860 000075CB E840020000          <1> 	call	save_directory_buffer 
 21861 000075D0 72C4                <1> 	jc	short loc_mkdir_return
 21862                              <1> 
 21863                              <1> loc_mkdir_save_added_cluster:
 21864 000075D2 A1[24C90000]        <1> 	mov	eax, [mkdir_LastDirCluster]
 21865 000075D7 8B0D[20C90000]      <1> 	mov	ecx, [mkdir_FFCluster]
 21866                              <1> 	; 01/03/2016
 21867 000075DD 31D2                <1> 	xor	edx, edx
 21868 000075DF 8915[CDC60000]      <1> 	mov	[FAT_ClusterCounter], edx ; 0 ; reset
 21869 000075E5 E8FA170000          <1> 	call	update_cluster
 21870 000075EA 7304                <1> 	jnc	short loc_mkdir_save_fat_buffer_0
 21871 000075EC 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 21872 000075EE 7518                <1> 	jnz	short loc_mkdir_save_fat_buffer_stc_retn
 21873                              <1> 
 21874                              <1> loc_mkdir_save_fat_buffer_0:
 21875 000075F0 A1[20C90000]        <1> 	mov	eax, [mkdir_FFCluster]
 21876 000075F5 A3[24C90000]        <1> 	mov	[mkdir_LastDirCluster], eax
 21877                              <1> 
 21878 000075FA 31C9                <1> 	xor	ecx, ecx
 21879 000075FC 49                  <1> 	dec	ecx ; FFFFFFFFh
 21880                              <1> 	; ESI = Logical DOS Drive Description Table address 
 21881 000075FD E8E2170000          <1> 	call	update_cluster
 21882 00007602 731A                <1> 	jnc	short loc_mkdir_save_fat_buffer_1
 21883 00007604 09C0                <1> 	or	eax, eax
 21884 00007606 7416                <1> 	jz	short loc_mkdir_save_fat_buffer_1
 21885                              <1> 
 21886                              <1> loc_mkdir_save_fat_buffer_stc_retn:
 21887                              <1> 	; 01/03/2016
 21888 00007608 803D[CDC60000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 21889 0000760F 720C                <1> 	jb	short loc_mkdir_save_fat_buffer_retn
 21890                              <1> 
 21891 00007611 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
 21892                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
 21893 00007615 50                  <1> 	push	eax
 21894 00007616 E81B1B0000          <1> 	call	calculate_fat_freespace
 21895 0000761B 58                  <1> 	pop	eax
 21896 0000761C F9                  <1> 	stc
 21897                              <1> loc_mkdir_save_fat_buffer_retn:
 21898 0000761D C3                  <1> 	retn
 21899                              <1> 
 21900                              <1> loc_mkdir_save_fat_buffer_1:
 21901                              <1> 	; byte [FAT_BuffValidData] = 2 
 21902 0000761E E87E1A0000          <1> 	call	save_fat_buffer
 21903 00007623 72E3                <1> 	jc	short loc_mkdir_save_fat_buffer_stc_retn
 21904                              <1> 
 21905                              <1> 	; 01/03/2016
 21906 00007625 803D[CDC60000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 21907 0000762C 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_2
 21908                              <1> 
 21909                              <1> 	; ESI = Logical DOS Drive Description Table address 
 21910 0000762E A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 21911 00007633 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 21912 00007637 E8FA1A0000          <1> 	call	calculate_fat_freespace
 21913                              <1> 
 21914                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 21915                              <1> 	;jnz	short loc_mkdir_save_fat_buffer_2
 21916                              <1> 
 21917                              <1> 	; ecx > 0 -> Recalculation is needed
 21918 0000763C 09C9                <1> 	or	ecx, ecx 
 21919 0000763E 7409                <1> 	jz	short loc_mkdir_save_fat_buffer_2
 21920                              <1> 
 21921 00007640 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
 21922 00007644 E8ED1A0000          <1> 	call	calculate_fat_freespace
 21923                              <1> 
 21924                              <1> loc_mkdir_save_fat_buffer_2:
 21925 00007649 C605[2FC90000]01    <1> 	mov	byte [mkdir_add_new_cluster], 1
 21926 00007650 E9C4000000          <1> 	jmp	loc_mkdir_upd_parent_dir_lmdt
 21927                              <1> 
 21928                              <1> loc_mkdir_update_sub_dir_cluster:
 21929 00007655 A1[20C90000]        <1> 	mov	eax, [mkdir_FFCluster]
 21930 0000765A 29C9                <1> 	sub	ecx, ecx ; 0
 21931                              <1> 	; 01/03/2016
 21932 0000765C 890D[CDC60000]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; Reset
 21933 00007662 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 21934                              <1> 
 21935                              <1> 	; ESI = Logical DOS Drive Descisption Table address  
 21936 00007663 E87C170000          <1> 	call	update_cluster
 21937 00007668 7379                <1> 	jnc	short loc_mkdir_save_fat_buffer_3
 21938 0000766A 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 21939 0000766C 7475                <1> 	jz	short loc_mkdir_save_fat_buffer_3
 21940                              <1> 	; 01/03/2016
 21941 0000766E EB98                <1> 	jmp	short loc_mkdir_save_fat_buffer_stc_retn
 21942                              <1> 
 21943                              <1> loc_mkdir_set_ff_dir_entry_2:
 21944                              <1> 	; ESI = Logical DOS Drive Description Table address  
 21945 00007670 A1[20C90000]        <1> 	mov	eax, [mkdir_FFCluster]
 21946                              <1> 	; Load disk sectors as a directory cluster
 21947 00007675 E826160000          <1> 	call	load_FAT_sub_directory 
 21948 0000767A 7266                <1> 	jc	short retn_make_fat_directory
 21949                              <1> 	
 21950                              <1> 	; eax = 0
 21951                              <1> 	; ecx =  directory buffer sector count (<= 128)
 21952                              <1> 
 21953 0000767C BF40000800          <1> 	mov	edi, Directory_Buffer + 64 ; 26/02/2016
 21954                              <1> 
 21955                              <1> 	; 02/03/2016
 21956 00007681 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
 21957 00007685 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
 21958 00007689 F7E1                <1> 	mul 	ecx
 21959 0000768B 89C1                <1> 	mov	ecx, eax
 21960 0000768D 6629C0              <1> 	sub	ax, ax
 21961 00007690 F3AB                <1> 	rep	stosd
 21962                              <1> 
 21963                              <1> 	;;mov	al, 128 ; double word
 21964                              <1> 	;;mul	ecx ; ecx =  directory buffer sector count
 21965                              <1> 	;;mov	ecx, eax
 21966                              <1> 	;shl	cx, 7 ; 128 * sector count	
 21967                              <1> 	;;sub	eax, eax
 21968                              <1> 	;;sub	al, al ; 0
 21969                              <1> 	;rep	stosd ; clear directory buffer
 21970                              <1> 
 21971 00007692 BF00000800          <1> 	mov	edi, Directory_Buffer ; 26/02/2016
 21972                              <1> 	
 21973 00007697 56                  <1> 	push	esi
 21974                              <1> 
 21975 00007698 BE[30C90000]        <1> 	mov	esi, mkdir_Name
 21976 0000769D 66C7062E00          <1> 	mov	word [esi], 2Eh ; db '.', '0'
 21977                              <1> 
 21978 000076A2 A1[20C90000]        <1> 	mov	eax, [mkdir_FFCluster]
 21979 000076A7 66B91000            <1> 	mov	cx, 10h ; CL = Directory attribute
 21980                              <1> 			; CH = 0 -> File size is 0
 21981 000076AB E883000000          <1> 	call	make_directory_entry
 21982                              <1> 
 21983 000076B0 BF20000800          <1> 	mov	edi, Directory_Buffer + 32 ; 26/02/2016
 21984                              <1> 
 21985                              <1> 	; 03/03/2016
 21986                              <1> 	; Following modification has been done according to 
 21987                              <1> 	; 'Microsoft Extensible Firmware Initiative
 21988                              <1> 	; FAT32 File System Specification' document,
 21989                              <1> 	; 'FAT: General Overview of On-Disk FormatPage 25'.
 21990                              <1> 	; "Finally, you set DIR_FstClusLO and DIR_FstClusHI
 21991                              <1> 	; for the dotdot entry (the second entry) to the
 21992                              <1> 	; first cluster number of the directory in which you 
 21993                              <1> 	; just created the directory (value is 0 if this directory
 21994                              <1> 	; is the root directory even for FAT32 volumes)."
 21995                              <1> 	; (Correctness of this modification has been verified
 21996                              <1> 	;  by using Windows 98 'scandisk.exe'.)
 21997                              <1> 
 21998 000076B5 29C0                <1> 	sub	eax, eax
 21999 000076B7 3805[ACBE0000]      <1> 	cmp	byte [Current_Dir_Level], al ; 0
 22000 000076BD 7605                <1> 	jna	short loc_mkdir_set_ff_dir_entry_3
 22001 000076BF A1[A8BE0000]        <1> 	mov	eax, [Current_Dir_FCluster] ; parent dir
 22002                              <1> loc_mkdir_set_ff_dir_entry_3:
 22003 000076C4 66C746012E00        <1> 	mov	word [esi+1], 2Eh ; db '.', '0'
 22004                              <1> 
 22005                              <1> 	;mov	cx, 10h
 22006 000076CA E864000000          <1> 	call	make_directory_entry
 22007                              <1> 
 22008 000076CF 5E                  <1> 	pop	esi
 22009                              <1> 
 22010 000076D0 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 22011 000076D7 E834010000          <1> 	call	save_directory_buffer
 22012 000076DC 0F8373FFFFFF        <1>         jnc     loc_mkdir_update_sub_dir_cluster
 22013                              <1>  
 22014                              <1> retn_make_fat_directory:
 22015 000076E2 C3                  <1> 	retn
 22016                              <1> 
 22017                              <1> loc_mkdir_save_fat_buffer_3:
 22018                              <1> 	; 01/03/2016
 22019                              <1> 	; byte [FAT_BuffValidData] = 2 
 22020 000076E3 E8B9190000          <1> 	call	save_fat_buffer
 22021 000076E8 0F821AFFFFFF        <1>         jc      loc_mkdir_save_fat_buffer_stc_retn
 22022                              <1> 
 22023 000076EE 803D[CDC60000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 22024 000076F5 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_4
 22025                              <1> 
 22026                              <1> 	; ESI = Logical DOS Drive Description Table address 
 22027 000076F7 A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 22028 000076FC 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 22029 00007700 E8311A0000          <1> 	call	calculate_fat_freespace
 22030                              <1> 
 22031                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 22032                              <1>         ;jnz    short loc_mkdir_save_fat_buffer_4
 22033                              <1> 
 22034                              <1> 	; ecx > 0 -> Recalculation is needed
 22035 00007705 09C9                <1> 	or	ecx, ecx 
 22036 00007707 7409                <1>         jz      short loc_mkdir_save_fat_buffer_4
 22037                              <1> 
 22038 00007709 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space
 22039 0000770D E8241A0000          <1> 	call	calculate_fat_freespace
 22040                              <1> 
 22041                              <1> loc_mkdir_save_fat_buffer_4:	
 22042 00007712 C605[2FC90000]00    <1> 	mov	byte [mkdir_add_new_cluster], 0
 22043                              <1> 
 22044                              <1> loc_mkdir_upd_parent_dir_lmdt:
 22045 00007719 E88D010000          <1> 	call	update_parent_dir_lmdt
 22046                              <1> 
 22047                              <1> 	; 01/03/2016
 22048 0000771E 803D[2FC90000]00    <1> 	cmp	byte [mkdir_add_new_cluster], 0
 22049 00007725 0F8723FEFFFF        <1>         ja      loc_mkdir_gffc_2
 22050                              <1> 
 22051                              <1> loc_mkdir_retn_new_dir_cluster:
 22052 0000772B A1[20C90000]        <1> 	mov	eax, [mkdir_FFCluster]
 22053 00007730 31D2                <1> 	xor	edx, edx
 22054                              <1> loc_mkdir_retn:
 22055 00007732 C3                  <1> 	retn
 22056                              <1> 
 22057                              <1> make_directory_entry:
 22058                              <1> 	; 02/03/2016
 22059                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 22060                              <1> 	; 09/08/2010 (DIR.ASM, 'proc_make_directory_entry')
 22061                              <1> 	; 17/07/2010
 22062                              <1> 	; INPUT ->
 22063                              <1> 	; 	EDI = Directory Entry Address
 22064                              <1> 	;	ESI = Dot File Name Location
 22065                              <1> 	;	EAX = First Cluster
 22066                              <1> 	;	File Size = 0 (Must be set later)
 22067                              <1> 	;	CL = Attributes
 22068                              <1> 	;	CH = 0 (File size = 0) 
 22069                              <1> 	;	(If CH>0, File size is in dword [EBX]) (*)
 22070                              <1> 	; OUTPUT -> 
 22071                              <1> 	;	EDI = Directory Entry Address
 22072                              <1> 	;	ESI = Dot File Name Location (Capitalized)
 22073                              <1> 	;	If CH input = 0, File Size = 0
 22074                              <1> 	;	Otherwise file size is as dword [EBX] (*)
 22075                              <1> 	;	DX = Date, AX = Time in DOS Dir Entry format
 22076                              <1> 	;	EBX = same
 22077                              <1> 	;	ECX = same
 22078                              <1> 
 22079 00007733 51                  <1> 	push	ecx
 22080                              <1> 
 22081 00007734 884F0B              <1> 	mov	[edi+11], cl ; Attributes
 22082 00007737 6689471A            <1> 	mov	[edi+26], ax ; FClusterLw, 26
 22083 0000773B C1E810              <1> 	shr	eax, 16
 22084 0000773E 66894714            <1> 	mov	[edi+20], ax ; FClusterHw, 20
 22085 00007742 6631C0              <1> 	xor	ax, ax 
 22086 00007745 6689470C            <1> 	mov	[edi+12], ax ; NTReserved, 12
 22087                              <1> 			     ; CrtTimeTenth, 13
 22088 00007749 08ED                <1> 	or	ch, ch
 22089 0000774B 7402                <1> 	jz	short loc_make_direntry_set_filesize
 22090                              <1> 
 22091 0000774D 8B03                <1> 	mov	eax, [ebx]
 22092                              <1>         
 22093                              <1> loc_make_direntry_set_filesize:
 22094 0000774F 89471C              <1> 	mov	[edi+28], eax ; FileSize, 28
 22095                              <1> 	
 22096 00007752 E88AFBFFFF          <1> 	call	convert_file_name
 22097                              <1> 	;EDI = Dir Entry Format File Name Location
 22098                              <1> 	;ESI = Dot File Name Location (capitalized)
 22099                              <1> 
 22100 00007757 E816000000          <1> 	call	convert_current_date_time
 22101                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 22102                              <1>         ; 	    AX = Time in dos dir entry format
 22103 0000775C 6689470E            <1> 	mov	[edi+14], ax ; CrtTime, 14
 22104 00007760 66895710            <1> 	mov	[edi+16], dx ; CrtDate, 16
 22105 00007764 66895712            <1> 	mov	[edi+18], dx ; LastAccDate, 18
 22106 00007768 66894716            <1> 	mov	[edi+22], ax ; WrtTime, 14
 22107 0000776C 66895718            <1> 	mov	[edi+24], dx ; WrtDate, 16
 22108 00007770 59                  <1> 	pop	ecx
 22109                              <1> 
 22110 00007771 C3                  <1> 	retn
 22111                              <1> 
 22112                              <1> convert_current_date_time:
 22113                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 22114                              <1> 	; 13/06/2010 (DIR.ASM, 'proc_convert_current_date_time')
 22115                              <1> 	; converts date&time to dos dir entry format
 22116                              <1> 	; INPUT -> none
 22117                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 22118                              <1> 	;           AX = Time in dos dir entry format
 22119                              <1>  
 22120 00007772 B404                <1> 	mov	ah, 04h ; Return Current Date
 22121 00007774 E8BDC3FFFF          <1> 	call	int1Ah 
 22122                              <1> 
 22123 00007779 88E8                <1> 	mov	al, ch ; <- century BCD
 22124 0000777B 240F                <1> 	and	al, 0Fh
 22125 0000777D 88EC                <1> 	mov	ah, ch
 22126 0000777F C0EC04              <1> 	shr	ah, 4
 22127 00007782 D50A                <1> 	aad
 22128 00007784 88C5                <1> 	mov	ch, al ; -> century 
 22129                              <1> 
 22130 00007786 88C8                <1> 	mov	al, cl ; <- year BCD
 22131 00007788 240F                <1> 	and	al, 0Fh
 22132 0000778A 88CC                <1> 	mov	ah, cl
 22133 0000778C C0EC04              <1> 	shr	ah, 4
 22134 0000778F D50A                <1> 	aad
 22135 00007791 88C1                <1> 	mov	cl, al ; -> year
 22136                              <1> 
 22137 00007793 88E8                <1> 	mov	al, ch
 22138 00007795 B464                <1> 	mov	ah, 100
 22139 00007797 F6E4                <1> 	mul	ah
 22140 00007799 30ED                <1> 	xor	ch, ch
 22141 0000779B 6601C8              <1> 	add	ax, cx
 22142 0000779E 662DBC07            <1> 	sub	ax, 1980 ; ms-dos epoch
 22143 000077A2 6689C1              <1> 	mov	cx, ax
 22144                              <1> 
 22145 000077A5 88F0                <1> 	mov	al, dh ; <- month in bcd
 22146 000077A7 240F                <1> 	and	al, 0Fh
 22147 000077A9 88F4                <1> 	mov	ah, dh
 22148 000077AB C0EC04              <1> 	shr	ah, 4
 22149 000077AE D50A                <1> 	aad
 22150 000077B0 88C6                <1> 	mov	dh, al ; -> month
 22151                              <1> 
 22152 000077B2 88D0                <1> 	mov	al, dl ; <- day BCD
 22153 000077B4 240F                <1> 	and	al, 0Fh
 22154 000077B6 88D4                <1> 	mov	ah, dl
 22155 000077B8 C0EC04              <1> 	shr	ah, 4
 22156 000077BB D50A                <1> 	aad
 22157 000077BD 88C2                <1> 	mov	dl, al ; -> day
 22158                              <1> 
 22159 000077BF 88C8                <1> 	mov	al, cl ; count of years from 1980
 22160 000077C1 66C1E004            <1> 	shl	ax, 4
 22161 000077C5 08F0                <1> 	or	al, dh ; month of year, 1 to 12
 22162 000077C7 66C1E005            <1> 	shl	ax, 5
 22163 000077CB 08D0                <1> 	or	al, dl ; day of year, 1 to 31
 22164                              <1> 	
 22165 000077CD 6650                <1> 	push	ax ; push date
 22166                              <1> 
 22167 000077CF B402                <1> 	mov	ah, 02h ; Return Current Time
 22168 000077D1 E860C3FFFF          <1> 	call	int1Ah
 22169                              <1> 
 22170 000077D6 88E8                <1> 	mov	al, ch ; <- hours BCD
 22171 000077D8 240F                <1> 	and	al, 0Fh
 22172 000077DA 88EC                <1> 	mov	ah, ch
 22173 000077DC C0EC04              <1> 	shr	ah, 4
 22174 000077DF D50A                <1> 	aad
 22175 000077E1 88C5                <1> 	mov	ch, al ; -> hours
 22176                              <1> 
 22177 000077E3 88C8                <1> 	mov	al, cl ; <- minutes BCD
 22178 000077E5 240F                <1> 	and	al, 0Fh
 22179 000077E7 88CC                <1> 	mov	ah, cl
 22180 000077E9 C0EC04              <1> 	shr	ah, 4
 22181 000077EC D50A                <1> 	aad
 22182 000077EE 88C1                <1> 	mov	cl, al ; -> minutes
 22183                              <1> 
 22184 000077F0 88F0                <1> 	mov	al, dh ; <- seconds BCD
 22185 000077F2 240F                <1> 	and	al, 0Fh
 22186 000077F4 88F4                <1> 	mov	ah, dh
 22187 000077F6 C0EC04              <1> 	shr	ah, 4
 22188 000077F9 D50A                <1> 	aad
 22189 000077FB 88C6                <1> 	mov	dh, al ; -> seconds
 22190                              <1> 
 22191 000077FD 88E8                <1> 	mov	al, ch ; hours
 22192 000077FF 66C1E006            <1> 	shl	ax, 6
 22193 00007803 08C8                <1> 	or	al, cl ; minutes
 22194 00007805 66C1E005            <1> 	shl	ax, 5
 22195 00007809 D0EE                <1> 	shr	dh, 1 ; 2 seconds
 22196                              <1> 	; There is a bug in TRDOS v1 here !
 22197                              <1> 	; it was 'or al, dl' ! 
 22198 0000780B 08F0                <1> 	or	al, dh ; seconds
 22199                              <1> 
 22200 0000780D 665A                <1> 	pop	dx ; pop date
 22201                              <1> 	
 22202 0000780F C3                  <1> 	retn
 22203                              <1> 
 22204                              <1> save_directory_buffer:
 22205                              <1> 	; 23/03/2016
 22206                              <1> 	; 26/02/2016
 22207                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
 22208                              <1> 	; 01/08/2011
 22209                              <1> 	; 14/03/2010
 22210                              <1> 	; INPUT ->
 22211                              <1> 	; 	 none
 22212                              <1> 	; OUTPUT ->
 22213                              <1> 	;  cf = 0 -> write OK...
 22214                              <1> 	;  cf = 1 -> error code in AL (EAX)
 22215                              <1> 	;  cf = 1 & AL = 0Dh => CH & CL = FS & FAT type
 22216                              <1> 	;  EBX = Directory Buffer Address
 22217                              <1> 	;
 22218                              <1> 	;  (EAX, ECX, EDX will be modified)
 22219                              <1>  
 22220 00007810 BB00000800          <1> 	mov	ebx, Directory_Buffer
 22221 00007815 803D[D8C60000]02    <1> 	cmp	byte [DirBuff_ValidData], 2
 22222 0000781C 7403                <1> 	je	short loc_save_dir_buffer
 22223 0000781E 31C0                <1> 	xor	eax, eax
 22224 00007820 C3                  <1> 	retn            
 22225                              <1> 
 22226                              <1> loc_save_dir_buffer:
 22227 00007821 56                  <1> 	push	esi
 22228 00007822 31DB                <1> 	xor	ebx, ebx 
 22229 00007824 8A3D[D6C60000]      <1>         mov     bh, [DirBuff_DRV]
 22230 0000782A 80EF41              <1> 	sub	bh, 'A'
 22231 0000782D BE00010900          <1>         mov     esi, Logical_DOSDisks
 22232 00007832 01DE                <1> 	add	esi, ebx
 22233 00007834 668B4E03            <1>         mov     cx, [esi+LD_FATType]
 22234                              <1> 	; CH = FS Type (A1h for FS)
 22235                              <1> 	; CL = FAT Type (0 for FS)
 22236 00007838 08C9                <1> 	or	cl, cl
 22237 0000783A 7433                <1> 	jz	short loc_save_dir_buff_stc_retn
 22238                              <1> 
 22239                              <1> loc_save_dir_buffer_check_cluster_no:    
 22240 0000783C A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 22241 00007841 28FF                <1> 	sub	bh, bh ; ebx = 0
 22242 00007843 09C0                <1> 	or	eax, eax
 22243 00007845 7540                <1> 	jnz	short loc_save_sub_dir_buffer
 22244 00007847 8A25[D7C60000]      <1> 	mov	ah, [DirBuff_FATType]
 22245 0000784D FEC3                <1> 	inc	bl ;  bl = 1
 22246 0000784F 38DC                <1> 	cmp	ah, bl
 22247 00007851 721D                <1> 	jb	short loc_save_dir_buff_inv_data_retn
 22248 00007853 FEC3                <1> 	inc	bl ; bl = 2
 22249 00007855 38E3                <1> 	cmp	bl, ah
 22250 00007857 7217                <1> 	jb	short loc_save_dir_buff_inv_data_retn
 22251                              <1> 
 22252                              <1> loc_save_root_dir_buffer:
 22253 00007859 668B5E17            <1> 	mov	bx, [esi+LD_BPB+RootDirEnts]
 22254 0000785D 6683C30F            <1> 	add	bx, 15
 22255 00007861 66C1EB04            <1> 	shr	bx, 4 ; 16 dir entries per sector
 22256 00007865 6609DB              <1> 	or	bx, bx
 22257 00007868 7405                <1> 	jz	short loc_save_dir_buff_stc_retn
 22258                              <1> 	;mov	ecx, ebx 
 22259 0000786A 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin] ; 26/02/2016
 22260 0000786D EB23                <1> 	jmp	short loc_write_directory_to_disk
 22261                              <1> 
 22262                              <1> loc_save_dir_buff_stc_retn:
 22263 0000786F F9                  <1> 	stc
 22264                              <1> loc_save_dir_buff_inv_data_retn:
 22265 00007870 B00D                <1> 	mov	al, 0Dh ; Invalid data !
 22266 00007872 C605[D8C60000]00    <1> 	mov	byte [DirBuff_ValidData], 0
 22267 00007879 EB05                <1> 	jmp	short loc_save_dir_buff_retn 
 22268                              <1> 
 22269                              <1> loc_write_directory_to_disk_err:
 22270                              <1> 	; 23/03/2016
 22271 0000787B B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error 
 22272                              <1> 
 22273                              <1> loc_save_dir_buff_retn:
 22274 00007880 BB00000800          <1> 	mov	ebx, Directory_Buffer
 22275 00007885 5E                  <1> 	pop	esi
 22276 00007886 C3                  <1> 	retn
 22277                              <1>  
 22278                              <1> loc_save_sub_dir_buffer:
 22279                              <1> 	; ebx  = 0
 22280 00007887 83E802              <1> 	sub	eax, 2
 22281 0000788A 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
 22282 0000788D F7E3                <1> 	mul	ebx
 22283 0000788F 034668              <1>         add     eax, [esi+LD_DATABegin]
 22284                              <1>  	;mov	ecx, ebx
 22285                              <1> 
 22286                              <1> loc_write_directory_to_disk:
 22287 00007892 89D9                <1>  	mov	ecx, ebx
 22288 00007894 BB00000800          <1> 	mov	ebx, Directory_Buffer
 22289 00007899 E899320000          <1> 	call	disk_write
 22290 0000789E 72DB                <1> 	jc	short loc_write_directory_to_disk_err
 22291                              <1> 
 22292                              <1> loc_save_dir_buff_validate_retn:
 22293 000078A0 C605[D8C60000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 22294 000078A7 31C0                <1> 	xor	eax, eax
 22295                              <1> 	; 26/02/2016
 22296 000078A9 EBD5                <1> 	jmp	short loc_save_dir_buff_retn
 22297                              <1> 
 22298                              <1> update_parent_dir_lmdt:
 22299                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
 22300                              <1> 	; 01/08/2011
 22301                              <1> 	; 16/10/2010 
 22302                              <1> 	; 
 22303                              <1> 	; INPUT -> 
 22304                              <1> 	;	none
 22305                              <1>  	; OUTPUT ->
 22306                              <1> 	;	(last modification date & time of the parent dir
 22307                              <1> 	;	will be changed/updated)
 22308                              <1> 	;
 22309                              <1> 	; (EAX, EBX, ECX, EDX, EDI will be changed)
 22310                              <1> 
 22311 000078AB 29C0                <1> 	sub	eax, eax
 22312 000078AD 8A25[ACBE0000]      <1> 	mov	ah, [Current_Dir_Level]
 22313 000078B3 A0[ADBE0000]        <1> 	mov	al, [Current_FATType]
 22314 000078B8 3C01                <1> 	cmp	al, 1
 22315 000078BA 723A                <1> 	jb	short loc_UPDLMDT_proc_retn
 22316                              <1>     
 22317                              <1> loc_update_parent_dir_lm_date_time:
 22318 000078BC 08E4                <1> 	or	ah, ah
 22319 000078BE 7436                <1> 	jz	short loc_UPDLMDT_proc_retn
 22320                              <1> 
 22321 000078C0 56                  <1> 	push	esi ; *
 22322 000078C1 8825[50C90000]      <1> 	mov	[UPDLMDT_CDirLevel], ah
 22323 000078C7 8B15[A8BE0000]      <1> 	mov	edx, [Current_Dir_FCluster]
 22324 000078CD 8915[51C90000]      <1> 	mov	[UPDLMDT_CDirFCluster], edx
 22325                              <1> 
 22326 000078D3 FECC                <1> 	dec	ah
 22327 000078D5 B90C000000          <1> 	mov	ecx, 12
 22328 000078DA BE[0FC70000]        <1>         mov     esi, PATH_Array
 22329                              <1> 
 22330 000078DF 8825[ACBE0000]      <1> 	mov	[Current_Dir_Level], ah
 22331 000078E5 08E4                <1> 	or	ah, ah
 22332 000078E7 750E                <1> 	jnz	short loc_update_parent_dir_lmdt_load_sub_dir_1
 22333 000078E9 803D[ADBE0000]02    <1> 	cmp	byte [Current_FATType], 2
 22334 000078F0 770B                <1> 	ja	short loc_update_parent_dir_lmdt_load_sub_dir_2
 22335 000078F2 28C0                <1> 	sub	al, al ; eax = 0
 22336 000078F4 EB0A                <1> 	jmp	short loc_update_parent_dir_lmdt_load_sub_dir_3
 22337                              <1> 
 22338                              <1> loc_UPDLMDT_proc_retn:
 22339 000078F6 C3                  <1> 	retn
 22340                              <1>          
 22341                              <1> loc_update_parent_dir_lmdt_load_sub_dir_1:
 22342 000078F7 B010                <1> 	mov	al, 16
 22343 000078F9 F6E4                <1> 	mul	ah 
 22344 000078FB 01C6                <1> 	add	esi, eax
 22345                              <1> 
 22346                              <1> loc_update_parent_dir_lmdt_load_sub_dir_2:  
 22347 000078FD 8B460C              <1> 	mov	eax, [esi+12] ; Parent Dir First Cluster
 22348                              <1> 
 22349                              <1> loc_update_parent_dir_lmdt_load_sub_dir_3:
 22350 00007900 A3[A8BE0000]        <1> 	mov	[Current_Dir_FCluster], eax
 22351                              <1> 
 22352 00007905 83C610              <1> 	add	esi, 16
 22353 00007908 66BF[36C8]          <1> 	mov	di, Dir_File_Name  
 22354 0000790C F3A4                <1> 	rep	movsb
 22355                              <1> 	
 22356 0000790E BE00010900          <1> 	mov	esi, Logical_DOSDisks
 22357 00007913 29DB                <1> 	sub	ebx, ebx
 22358 00007915 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 22359 0000791B 01DE                <1> 	add	esi, ebx
 22360 0000791D E88FF7FFFF          <1> 	call	reload_current_directory
 22361 00007922 7232                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
 22362                              <1> 
 22363                              <1> loc_update_parent_dir_lmdt_locate_dir: 
 22364 00007924 BE[36C80000]        <1> 	mov	esi, Dir_File_Name        
 22365 00007929 6631C9              <1> 	xor	cx, cx
 22366 0000792C 66B81008            <1> 	mov	ax, 0810h ; Only directories
 22367 00007930 E8B7F6FFFF          <1>         call    locate_current_dir_file
 22368                              <1> 	; EDI = DirBuff Directory Entry Address
 22369 00007935 721F                <1> 	jc short loc_update_parent_dir_lmdt_restore_cdirlevel
 22370                              <1> 
 22371 00007937 E836FEFFFF          <1> 	call	convert_current_date_time
 22372 0000793C 66895712            <1> 	mov	[edi+18], dx ; Last Access Date
 22373 00007940 66895718            <1> 	mov	[edi+24], dx ; Last Write Date
 22374 00007944 66894716            <1> 	mov	[edi+22], ax ; Last Write Time
 22375                              <1> 
 22376 00007948 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 22377 0000794F E8BCFEFFFF          <1> 	call	save_directory_buffer
 22378 00007954 7200                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
 22379                              <1> 	;xor	al, al 
 22380                              <1> loc_update_parent_dir_lmdt_restore_cdirlevel:
 22381                              <1>  	;current directory level restoration
 22382 00007956 8A25[50C90000]      <1> 	mov	ah, [UPDLMDT_CDirLevel]
 22383 0000795C 8825[ACBE0000]      <1> 	mov	[Current_Dir_Level], ah
 22384 00007962 8B15[51C90000]      <1>         mov     edx, [UPDLMDT_CDirFCluster]
 22385 00007968 8915[A8BE0000]      <1> 	mov	[Current_Dir_FCluster], edx
 22386                              <1> 
 22387 0000796E 5E                  <1> 	pop	esi ; *
 22388 0000796F C3                  <1> 	retn
 22389                              <1> 
 22390                              <1> delete_longname:
 22391                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
 22392                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_longname')
 22393                              <1> 	; 14/03/2010
 22394                              <1> 	; INPUT ->
 22395                              <1> 	; 	EAX = Directory Entry (Index) Number (< 65536)
 22396                              <1> 	; OUTPUT ->
 22397                              <1> 	;	cf = 0 -> OK  (EAX = 0)
 22398                              <1> 	; 	cf = 1 -> error code in EAX (AL)
 22399                              <1> 	;
 22400                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
 22401                              <1> 
 22402 00007970 66A3[7CC90000]      <1> 	mov	[DLN_EntryNumber], ax
 22403 00007976 C605[7EC90000]40    <1>         mov     byte [DLN_40h], 40h
 22404                              <1> 
 22405 0000797D E858000000          <1> 	call	locate_current_dir_entry
 22406 00007982 7308                <1> 	jnc	short loc_dln_check_attributes
 22407 00007984 C3                  <1> 	retn
 22408                              <1> 
 22409                              <1> loc_dln_longname_not_found:
 22410 00007985 B802000000          <1> 	mov	eax, 2
 22411 0000798A F9                  <1> 	stc
 22412 0000798B C3                  <1> 	retn
 22413                              <1> 
 22414                              <1> loc_dln_check_attributes:
 22415 0000798C B00F                <1> 	mov	al, 0Fh  ; long name
 22416 0000798E 8A670B              <1> 	mov	ah, [edi+0Bh] ; dir entry attributes
 22417 00007991 38C4                <1> 	cmp	ah, al
 22418 00007993 75F0                <1> 	jne	short loc_dln_longname_not_found
 22419 00007995 8A27                <1> 	mov	ah, [edi]
 22420 00007997 2A25[7EC90000]      <1> 	sub	ah, [DLN_40h]
 22421 0000799D 76E6                <1> 	jna	short loc_dln_longname_not_found         
 22422 0000799F 80FC14              <1> 	cmp	ah, 14h ; 84-64=20 -> 20*13=260 bytes
 22423 000079A2 77E1                <1> 	ja	short loc_dln_longname_not_found
 22424                              <1>              
 22425 000079A4 C607E5              <1> 	mov	byte [edi], 0E5h  ; deleted sign
 22426 000079A7 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; changed/write sign
 22427 000079AE C605[7EC90000]00    <1> 	mov	byte [DLN_40h], 0 ; 40h -> 0
 22428                              <1> 	  
 22429                              <1> loc_dln_delete_next_ln_entry:
 22430 000079B5 80FC01              <1> 	cmp	ah, 1
 22431 000079B8 7616                <1> 	jna	short loc_dln_longname_retn
 22432                              <1> loc_dln_delete_next_ln_entry_0:
 22433 000079BA 66FF05[7CC90000]    <1> 	inc	word [DLN_EntryNumber]
 22434 000079C1 0FB705[7CC90000]    <1> 	movzx	eax, word [DLN_EntryNumber] 
 22435 000079C8 E80D000000          <1> 	call	locate_current_dir_entry
 22436 000079CD 73BD                <1> 	jnc	short loc_dln_check_attributes
 22437                              <1> 
 22438                              <1> loc_dln_longname_stc_retn:
 22439 000079CF C3                  <1> 	retn 
 22440                              <1> 	   
 22441                              <1> loc_dln_longname_retn:
 22442                              <1> 	;cmp	byte [DirBuff_ValidData], 2
 22443                              <1> 	;jne	short loc_dln_longname_retn_xor_eax
 22444 000079D0 E83BFEFFFF          <1> 	call	save_directory_buffer
 22445 000079D5 72F8                <1> 	jc	short loc_dln_longname_stc_retn
 22446                              <1> 
 22447                              <1> loc_dln_longname_retn_xor_eax:
 22448 000079D7 31C0                <1> 	xor	eax, eax
 22449 000079D9 C3                  <1> 	retn
 22450                              <1> 
 22451                              <1> locate_current_dir_entry:
 22452                              <1> 	; 23/03/2016
 22453                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
 22454                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_locate_current_dir_entry')
 22455                              <1> 	; 07/03/2010
 22456                              <1> 	; INPUT ->
 22457                              <1> 	;	EAX = Directory Entry (Index) Number (< 65536) 
 22458                              <1> 	; OUTPUT ->
 22459                              <1> 	;	EDI = Directory Entry Address
 22460                              <1> 	; 	EAX = Cluster Number of Directory Buffer
 22461                              <1> 	;	EBX = Directory Buffer Entry Offset
 22462                              <1> 	;	ECX = DirBuff Valid Data identifier (CL)
 22463                              <1> 	;   	If CF = 0 and CL = 2 then
 22464                              <1> 	;	   directory buffer modified and
 22465                              <1> 	;	   must be written to disk.
 22466                              <1> 	; 	If CF = 0  and CL = 1 then
 22467                              <1> 	;	   dir buffer has been written to disk, already.
 22468                              <1> 	;	CF = 1 -> Error code in EAX (AL)
 22469                              <1> 	;
 22470                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
 22471                              <1> 
 22472                              <1> loc_locate_current_dir_entry:
 22473 000079DA 56                  <1> 	push	esi
 22474 000079DB 89C1                <1> 	mov	ecx, eax
 22475 000079DD BA20000000          <1> 	mov	edx, 32
 22476 000079E2 F7E2                <1> 	mul	edx 
 22477 000079E4 A3[88C90000]        <1> 	mov	[LCDE_ByteOffset], eax
 22478 000079E9 31DB                <1> 	xor	ebx, ebx
 22479 000079EB 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 22480 000079F1 A0[D6C60000]        <1>         mov     al, [DirBuff_DRV]
 22481 000079F6 2C41                <1> 	sub	al, 'A'
 22482 000079F8 BE00010900          <1>         mov     esi, Logical_DOSDisks
 22483 000079FD 01DE                <1> 	add	esi, ebx
 22484 000079FF 38C7                <1> 	cmp	bh, al
 22485 00007A01 0F8592000000        <1>         jne     loc_lcde_reload_current_directory
 22486                              <1> loc_lcde_cdl_check:
 22487 00007A07 803D[ACBE0000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 22488 00007A0E 772A                <1> 	ja	short loc_lcde_calc_dirbuff_cluster_offset
 22489                              <1> 	; 27/02/2016
 22490                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
 22491                              <1> 	; (Root Directory Entries for FAT32 = 0)
 22492 00007A10 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
 22493 00007A14 7324                <1> 	jnb	short loc_lcde_calc_dirbuff_cluster_offset
 22494                              <1> 
 22495                              <1> loc_lcde_cdl_check_FAT12_16:
 22496 00007A16 668B4617            <1> 	mov	ax, [esi+LD_BPB+RootDirEnts]
 22497 00007A1A 6648                <1> 	dec	ax
 22498                              <1> 	;xor	dx, dx  
 22499 00007A1C 6639C8              <1> 	cmp	ax, cx ; cx = Directory Entry (Index) Number
 22500 00007A1F 720E                <1> 	jb	short loc_lcde_stc_12h_retn
 22501 00007A21 66890D[80C90000]    <1> 	mov	[LCDE_EntryIndex], cx
 22502 00007A28 31C0                <1> 	xor	eax, eax
 22503 00007A2A E993000000          <1>         jmp     loc_lcde_check_dir_buffer_cluster
 22504                              <1> 
 22505                              <1> loc_lcde_stc_12h_retn:
 22506 00007A2F 5E                  <1> 	pop	esi
 22507 00007A30 89CB                <1> 	mov	ebx, ecx
 22508 00007A32 89D1                <1> 	mov	ecx, edx
 22509 00007A34 B812000000          <1> 	mov	eax, 12h ; No more files
 22510 00007A39 C3                  <1> 	retn 
 22511                              <1> 
 22512                              <1> loc_lcde_calc_dirbuff_cluster_offset:
 22513 00007A3A 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
 22514 00007A3D 30FF                <1> 	xor	bh, bh
 22515 00007A3F 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
 22516 00007A43 66F7E3              <1> 	mul	bx
 22517 00007A46 6609D2              <1>  	or	dx, dx ; If bytes per cluster > 32KB it is invalid
 22518 00007A49 755D                <1> 	jnz	short loc_lcde_invalid_format
 22519                              <1> 	;mov	ecx, eax
 22520 00007A4B 6689C1              <1> 	mov	cx, ax ; BYTES PER CLUSTER
 22521 00007A4E A1[88C90000]        <1> 	mov	eax, [LCDE_ByteOffset]
 22522                              <1> 	;sub	edx, edx
 22523 00007A53 F7F1                <1> 	div	ecx
 22524 00007A55 3DFFFF0000          <1> 	cmp	eax, 65535
 22525 00007A5A 774C                <1> 	ja	short loc_lcde_invalid_format
 22526                              <1> 
 22527                              <1> 	; cluster sequence number of directory (< 65536)
 22528 00007A5C 66A3[82C90000]      <1> 	mov	[LCDE_ClusterSN], ax 
 22529                              <1> 
 22530 00007A62 6689D0              <1> 	mov	ax, dx ; byte offset in cluster (directory buffer)
 22531 00007A65 66BB2000            <1> 	mov	bx, 32 ; ; 1 dir entry = 32 bytes
 22532 00007A69 6629D2              <1>         sub     dx, dx  ; 0
 22533 00007A6C 66F7F3              <1> 	div	bx 
 22534 00007A6F 66A3[80C90000]      <1> 	mov	[LCDE_EntryIndex], ax ; dir entry index/sequence number
 22535                              <1> 				      ; (in directory buffer/cluster)	  
 22536                              <1> loc_lcde_get_current_sub_dir_fcluster:
 22537 00007A75 A1[A8BE0000]        <1> 	mov	eax, [Current_Dir_FCluster]
 22538                              <1> 
 22539                              <1> loc_lcde_get_next_cluster:
 22540 00007A7A 66833D[82C90000]00  <1> 	cmp	word [LCDE_ClusterSN], 0
 22541 00007A82 763E                <1> 	jna	short loc_lcde_check_dir_buffer_cluster
 22542 00007A84 A3[84C90000]        <1> 	mov	[LCDE_Cluster], eax
 22543 00007A89 E82C100000          <1> 	call	get_next_cluster
 22544 00007A8E 7220                <1> 	jc	short loc_lcde_check_gnc_error
 22545 00007A90 66FF0D[82C90000]    <1>   	dec	word [LCDE_ClusterSN]
 22546 00007A97 EBE1                <1> 	jmp	short loc_lcde_get_next_cluster
 22547                              <1> 
 22548                              <1> loc_lcde_reload_current_directory:
 22549 00007A99 51                  <1> 	push	ecx
 22550 00007A9A E812F6FFFF          <1> 	call	reload_current_directory
 22551 00007A9F 59                  <1> 	pop	ecx
 22552 00007AA0 0F8361FFFFFF        <1>         jnc     loc_lcde_cdl_check
 22553 00007AA6 5E                  <1> 	pop	esi
 22554 00007AA7 C3                  <1> 	retn
 22555                              <1> 
 22556                              <1> loc_lcde_invalid_format:
 22557 00007AA8 B80B000000          <1> 	mov	eax, 0Bh ; MSDOS Error code: Invalid Format
 22558                              <1> 	;mov	eax, 0Dh ; MSDOS Error code: Invalid Data
 22559                              <1> loc_lcde_drive_not_ready_read_err:
 22560 00007AAD F9                  <1> 	stc
 22561 00007AAE 5E                  <1> 	pop	esi 
 22562 00007AAF C3                  <1> 	retn  
 22563                              <1> 
 22564                              <1> loc_lcde_check_gnc_error:
 22565 00007AB0 09C0                <1> 	or	eax, eax
 22566 00007AB2 75F9                <1> 	jnz	short loc_lcde_drive_not_ready_read_err
 22567 00007AB4 66FF0D[82C90000]    <1> 	dec	word [LCDE_ClusterSN]
 22568 00007ABB 75EB                <1> 	jnz	short loc_lcde_invalid_format 
 22569 00007ABD A1[84C90000]        <1> 	mov	eax, [LCDE_Cluster]
 22570                              <1> 
 22571                              <1> loc_lcde_check_dir_buffer_cluster:
 22572 00007AC2 3B05[DDC60000]      <1> 	cmp	eax, [DirBuff_Cluster]
 22573 00007AC8 755C                <1> 	jne	short loc_lcde_load_dir_cluster
 22574 00007ACA 803D[D8C60000]00    <1> 	cmp	byte [DirBuff_ValidData], 0
 22575 00007AD1 7727                <1> 	ja	short lcde_check_dir_buffer_cluster_next
 22576 00007AD3 803D[ACBE0000]00    <1> 	cmp	byte [Current_Dir_Level], 0    
 22577 00007ADA 775F                <1> 	ja	short loc_lcde_load_dir_cluster_0
 22578                              <1> 	; 27/02/2016
 22579                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
 22580 00007ADC 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
 22581 00007AE0 7359                <1> 	jnb	short loc_lcde_load_dir_cluster_0
 22582                              <1> 	;
 22583 00007AE2 0FB74E17            <1> 	movzx	ecx, word [esi+LD_BPB+RootDirEnts]
 22584 00007AE6 6683C10F            <1> 	add	cx, 15 ; round up (16 entries per sector)
 22585 00007AEA 66C1E904            <1> 	shr	cx, 4 ; 1 sector contains 16 dir entries	
 22586                              <1> 
 22587 00007AEE 8B4664              <1>         mov     eax, [esi+LD_ROOTBegin]
 22588 00007AF1 EB54                <1> 	jmp	short loc_lcde_load_dir_cluster_1 
 22589                              <1> 
 22590                              <1> loc_lcde_validate_dirBuff:
 22591 00007AF3 C605[D8C60000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 22592                              <1> 
 22593                              <1> lcde_check_dir_buffer_cluster_next:
 22594 00007AFA 0FB71D[80C90000]    <1> 	movzx	ebx, word [LCDE_EntryIndex]
 22595 00007B01 663B1D[DBC60000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 22596 00007B08 779E                <1> 	ja	short loc_lcde_invalid_format 
 22597 00007B0A B820000000          <1> 	mov	eax, 32
 22598 00007B0F F7E3                <1> 	mul	ebx
 22599                              <1> 	;or	edx, edx
 22600                              <1> 	;jnz	short loc_lcde_invalid_format
 22601                              <1> 
 22602 00007B11 BF00000800          <1> 	mov	edi, Directory_Buffer  
 22603 00007B16 01C7                <1> 	add	edi, eax ; add entry offset to buffer address
 22604                              <1> 
 22605                              <1> loc_lcde_dir_buffer_last_check:
 22606 00007B18 A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 22607 00007B1D 0FB60D[D8C60000]    <1> 	movzx	ecx, byte [DirBuff_ValidData]
 22608                              <1> 
 22609                              <1> loc_lcde_retn:
 22610 00007B24 5E                  <1> 	pop	esi
 22611 00007B25 C3                  <1> 	retn
 22612                              <1> 
 22613                              <1> loc_lcde_load_dir_cluster:
 22614                              <1> 	;cmp	byte [DirBuff_ValidData], 2
 22615                              <1> 	;jne	short loc_lcde_load_dir_cluster_n2
 22616 00007B26 50                  <1> 	push	eax
 22617 00007B27 E8E4FCFFFF          <1> 	call	save_directory_buffer
 22618 00007B2C 58                  <1> 	pop	eax
 22619 00007B2D 72F5                <1> 	jc	short loc_lcde_retn
 22620                              <1> 
 22621                              <1> loc_lcde_load_dir_cluster_n2:
 22622 00007B2F C605[D8C60000]00    <1> 	mov	byte [DirBuff_ValidData], 0
 22623 00007B36 A3[DDC60000]        <1> 	mov	[DirBuff_Cluster], eax
 22624                              <1> 
 22625                              <1> loc_lcde_load_dir_cluster_0:
 22626 00007B3B 83E802              <1> 	sub	eax, 2
 22627 00007B3E 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 22628 00007B42 F7E1                <1> 	mul	ecx
 22629 00007B44 034668              <1>         add     eax, [esi+LD_DATABegin]
 22630                              <1> 
 22631                              <1> loc_lcde_load_dir_cluster_1:
 22632 00007B47 BB00000800          <1> 	mov	ebx, Directory_Buffer
 22633                              <1> 	; ecx = sector count
 22634 00007B4C E8F52F0000          <1> 	call	disk_read
 22635 00007B51 73A0                <1> 	jnc	short loc_lcde_validate_dirBuff
 22636                              <1> 
 22637                              <1> 	; 23/03/2016
 22638 00007B53 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
 22639 00007B58 EBCA                <1> 	jmp	short loc_lcde_retn
 22640                              <1> 
 22641                              <1> 
 22642                              <1> remove_file:
 22643                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
 22644                              <1> 	; 10/04/2011 (FILE.ASM, 'proc_delete_file')
 22645                              <1> 	; 09/08/2010
 22646                              <1> 	; INPUT ->
 22647                              <1> 	;	EDI = Directory Buffer Entry Address
 22648                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
 22649                              <1> 	;	 BL = Longname Entry Length
 22650                              <1> 	;	 BH = Logical DOS Drive Number 
 22651                              <1> 
 22652 00007B5A 29C0                <1> 	sub	eax, eax
 22653 00007B5C 88FC                <1> 	mov	ah, bh
 22654 00007B5E BE00010900          <1> 	mov	esi, Logical_DOSDisks
 22655 00007B63 01C6                <1> 	add	esi, eax
 22656                              <1> 
 22657 00007B65 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 22658 00007B69 7312                <1> 	jnb	short loc_del_fat_file 
 22659                              <1>               
 22660 00007B6B 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 22661 00007B6F 7406                <1> 	je	short loc_del_fs_file
 22662                              <1> 
 22663                              <1> loc_del_file_invalid_format:
 22664 00007B71 30E4                <1> 	xor	ah, ah
 22665 00007B73 B00B                <1> 	mov	al, 0Bh ; Invalid Format
 22666 00007B75 F9                  <1> 	stc 
 22667 00007B76 C3                  <1> 	retn
 22668                              <1> 
 22669                              <1> loc_del_fs_file:
 22670 00007B77 E8370F0000          <1> 	call	delete_fs_file
 22671 00007B7C C3                  <1> 	retn
 22672                              <1> 
 22673                              <1> loc_del_fat_file:
 22674 00007B7D E808000000          <1> 	call	delete_directory_entry
 22675 00007B82 7205                <1> 	jc	short loc_del_file_err_retn 
 22676                              <1> 
 22677                              <1> loc_delfile_unlink_cluster_chain:
 22678 00007B84 E84B170000          <1> 	call	truncate_cluster_chain
 22679                              <1> 	;jc	short loc_del_file_err_retn
 22680                              <1> 
 22681                              <1> loc_delfile_return:
 22682                              <1> loc_del_file_err_retn:
 22683 00007B89 C3                  <1> 	retn
 22684                              <1> 
 22685                              <1> delete_directory_entry:
 22686                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
 22687                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_directory_entry')
 22688                              <1> 	; 10/04/2011 
 22689                              <1> 	; INPUT ->
 22690                              <1> 	; 	ESI = Logical Dos Drive Descripton Table Address 
 22691                              <1> 	;	EDI = Directory Buffer Entry Address
 22692                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
 22693                              <1> 	;	 BL = Longname Entry Length
 22694                              <1> 	; OUTPUT ->
 22695                              <1> 	; 	ESI = Logical dos drive descripton table address 
 22696                              <1> 	;	EAX = First cluster to be truncated/unlinked
 22697                              <1> 	;       CF = 1 -> Error code in EAX (AL)
 22698                              <1> 	;       CF = 0 & BH <> 0 -> LMDT write error  (BH = 1)
 22699                              <1> 	;       CF = 0 & BL <> 0 -> Long name delete error (BL = FFh) 
 22700                              <1> 	;
 22701                              <1> 	;  (EDI, EBX, ECX register contents will be changed)
 22702                              <1> 
 22703 00007B8A 881D[1AC90000]      <1> 	mov	[DelFile_LNEL], bl
 22704 00007B90 66890D[18C90000]    <1> 	mov	[DelFile_EntryCounter], cx
 22705                              <1> 
 22706 00007B97 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 22707 00007B9B C1E010              <1> 	shl	eax, 16
 22708 00007B9E 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 22709                              <1> 
 22710 00007BA2 A3[14C90000]        <1> 	mov	[DelFile_FCluster], eax
 22711                              <1> 
 22712                              <1> loc_del_short_name:
 22713 00007BA7 C607E5              <1> 	mov	byte [edi], 0E5h  ; Deleted sign
 22714                              <1> 
 22715 00007BAA C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 22716 00007BB1 E85AFCFFFF          <1> 	call	save_directory_buffer
 22717 00007BB6 723D                <1> 	jc	short loc_delete_direntry_err_return
 22718                              <1>  
 22719                              <1> loc_del_long_name:
 22720 00007BB8 0FB615[1AC90000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 22721 00007BBF 08D2                <1> 	or	dl, dl
 22722 00007BC1 7416                <1> 	jz	short loc_del_dir_entry_update_parent_dir_lm_date
 22723                              <1> 
 22724 00007BC3 8835[1AC90000]      <1> 	mov	byte [DelFile_LNEL], dh ; 0              
 22725                              <1>   
 22726 00007BC9 0FB705[18C90000]    <1> 	movzx	eax,  word [DelFile_EntryCounter]
 22727 00007BD0 29D0                <1> 	sub	eax, edx
 22728                              <1> 	;jnc	short loc_del_long_name_continue
 22729 00007BD2 7205                <1> 	jc	short loc_del_dir_entry_update_parent_dir_lm_date   
 22730                              <1> 
 22731                              <1> ;loc_del_direntry_inv_data_return:
 22732                              <1> ;	mov	eax, 0Dh ; Invalid data
 22733                              <1> ;	retn
 22734                              <1> 
 22735                              <1> loc_del_long_name_continue: 
 22736                              <1> 	; AX = Directory Entry Number of the long name last entry
 22737 00007BD4 E897FDFFFF          <1> 	call	delete_longname
 22738                              <1> 	;jc	short loc_delete_direntry_err_return
 22739                              <1> 
 22740                              <1> loc_del_dir_entry_update_parent_dir_lm_date:
 22741 00007BD9 801D[1AC90000]00    <1> 	sbb	byte [DelFile_LNEL], 0 ; 0FFh if cf = 1
 22742                              <1> 
 22743 00007BE0 E8C6FCFFFF          <1> 	call	update_parent_dir_lmdt
 22744 00007BE5 B700                <1> 	mov	bh, 0
 22745 00007BE7 80D700              <1> 	adc	bh, 0
 22746                              <1> 
 22747 00007BEA 8A1D[1AC90000]      <1> 	mov	bl, byte [DelFile_LNEL]
 22748                              <1>  
 22749                              <1> loc_delete_direntry_return:
 22750 00007BF0 A1[14C90000]        <1> 	mov	eax, [DelFile_FCluster]
 22751                              <1> loc_delete_direntry_err_return:
 22752 00007BF5 C3                  <1> 	retn
 22753                              <1> 
 22754                              <1> rename_directory_entry:
 22755                              <1> 	; 06/03/2016 (TRDOS 386 = TRDOS v2.0)
 22756                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_rename_directory_entry')
 22757                              <1> 	; 19/11/2010
 22758                              <1> 	; INPUT -> (Current Directory)
 22759                              <1> 	;	CX = Directory Entry Number
 22760                              <1> 	;      EAX = First Cluster number of file or directory
 22761                              <1> 	;      EBX = Longname Length (dir entry count) (< 256)
 22762                              <1> 	;      ESI = New file (or directory) name (no path).
 22763                              <1> 	;           (ASCIIZ string)  
 22764                              <1> 	; OUTPUT -> 
 22765                              <1> 	;      CF = 0 -> successfull
 22766                              <1> 	;      CF = 1 -> error code in EAX (AL)
 22767                              <1> 	;
 22768                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 22769                              <1> 
 22770 00007BF6 803D[ADBE0000]00    <1> 	cmp	byte [Current_FATType], 0
 22771 00007BFD 7706                <1> 	ja	short loc_rename_directory_entry
 22772                              <1> 
 22773 00007BFF E8B00E0000          <1> 	call	rename_fs_file_or_directory
 22774 00007C04 C3                  <1> 	retn 
 22775                              <1> 	
 22776                              <1> loc_rename_directory_entry:
 22777 00007C05 881D[1AC90000]      <1> 	mov	[DelFile_LNEL], bl
 22778 00007C0B 66890D[18C90000]    <1> 	mov	[DelFile_EntryCounter], cx
 22779 00007C12 A3[14C90000]        <1> 	mov	[DelFile_FCluster], eax
 22780                              <1> 
 22781 00007C17 0FB7C1              <1> 	movzx	eax, cx
 22782 00007C1A E8BBFDFFFF          <1> 	call	locate_current_dir_entry
 22783 00007C1F 7308                <1> 	jnc	short loc_rename_direntry_check_fcluster
 22784                              <1> 
 22785                              <1> loc_rename_direntry_pop_retn:
 22786 00007C21 C3                  <1> 	retn
 22787                              <1> 
 22788                              <1> loc_rename_direntry_pop_invd_retn:
 22789 00007C22 F9                  <1> 	stc
 22790                              <1> loc_rename_direntry_invd_retn:
 22791 00007C23 B80D000000          <1> 	mov	eax, 0Dh ; Invalid data
 22792                              <1> loc_rename_retn:
 22793 00007C28 C3                  <1> 	retn 
 22794                              <1> 
 22795                              <1> loc_rename_direntry_check_fcluster:
 22796 00007C29 668B5714            <1> 	mov	dx, [edi+20] ; First Cluster HW
 22797 00007C2D 66C1E210            <1> 	shl	dx, 16
 22798 00007C31 668B571A            <1> 	mov	dx, [edi+26] ; First Cluster LW
 22799 00007C35 3B15[14C90000]      <1> 	cmp	edx, [DelFile_FCluster]
 22800 00007C3B 75E5                <1> 	jne	short loc_rename_direntry_pop_invd_retn
 22801                              <1> 	; ESI = New file (or directory) name. (ASCIIZ string)
 22802                              <1> 	; 06/03/2016
 22803                              <1> 	; TRDOS v2 - NOTE: 'convert_file_name' procedure
 22804                              <1> 	; has been modified for eliminating following situation.
 22805                              <1> 	; 
 22806                              <1> 	; TRDOS v1 - NOTE: If file/dir name is more than 11 bytes
 22807                              <1> 	; without a dot, attributes (edi+11) byte will be overwritten !
 22808                              <1> 	; (Dot file name input must be proper for 11 byte dir entry
 22809                              <1> 	;  type file name output.) 
 22810 00007C3D E89FF6FFFF          <1> 	call	convert_file_name
 22811                              <1> 
 22812 00007C42 C605[D8C60000]02    <1>         mov     byte [DirBuff_ValidData], 2
 22813 00007C49 E8C2FBFFFF          <1> 	call	save_directory_buffer
 22814 00007C4E 72D8                <1> 	jc	short loc_rename_retn
 22815                              <1> 
 22816                              <1> loc_rename_direntry_del_ln:
 22817 00007C50 0FB615[1AC90000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 22818 00007C57 08D2                <1> 	or	dl, dl
 22819 00007C59 7410                <1> 	jz	short loc_rename_direntry_update_parent_dir_lm_date
 22820                              <1> 
 22821 00007C5B 0FB705[18C90000]    <1> 	movzx	eax, word [DelFile_EntryCounter]
 22822 00007C62 29D0                <1> 	sub	eax, edx
 22823 00007C64 72BD                <1> 	jc	short loc_rename_direntry_invd_retn
 22824                              <1> 
 22825                              <1> loc_rename_direntry_del_ln_continue: 
 22826                              <1> 	; EAX = Directory Entry Number of the long name last entry
 22827 00007C66 E805FDFFFF          <1> 	call	delete_longname
 22828                              <1> 
 22829                              <1> loc_rename_direntry_update_parent_dir_lm_date:
 22830 00007C6B E83BFCFFFF          <1> 	call	update_parent_dir_lmdt
 22831 00007C70 31C0                <1> 	xor	eax, eax 
 22832 00007C72 C3                  <1> 	retn
 22833                              <1> 
 22834                              <1> move_source_file_to_destination_file:
 22835                              <1> 	; 11/03/2016
 22836                              <1> 	; 10/03/2016 (TRDOS 386 = TRDOS v2.0)
 22837                              <1> 	; 01/08/2011 (FILE.ASM)
 22838                              <1> 	; 04/08/2010
 22839                              <1> 	;
 22840                              <1> 	;   Phase 1 -> Check destination file, 
 22841                              <1> 	;              'not found' is required
 22842                              <1> 	;   Phase 2 -> Check source file
 22843                              <1> 	;              'found' and proper attributes is required
 22844                              <1> 	;   Phase 3 -> Make destination directory entry,
 22845                              <1> 	;           add new dir cluster or section if it is required
 22846                              <1> 	;   Phase 4 -> Delete source directory entry.
 22847                              <1> 	;       cf = 1 causes to return before the phase 4.
 22848                              <1> 	;    (source file protection against any possible errors)    
 22849                              <1> 	;
 22850                              <1> 	; 08/05/2011 major modification
 22851                              <1> 	;            -> destination file deleting is removed   
 22852                              <1> 	;            for msdos move/rename compatibility.
 22853                              <1> 	;            (Access denied error will return if
 22854                              <1> 	;            the destination file is found...)
 22855                              <1> 	; INPUT ->
 22856                              <1> 	;	 ESI = Source File Pathname (Asciiz)
 22857                              <1> 	;        EDI = Destination File Pathname (Asciiz)
 22858                              <1> 	;        AL = 0 --> Interrupt (System call)
 22859                              <1> 	;        AL > 0 --> Command Interpreter (Question)
 22860                              <1> 	;        AL = 1 --> Question Phase
 22861                              <1> 	;        AL = 2 --> Progress Phase        
 22862                              <1> 	; OUTPUT -> 
 22863                              <1> 	;	 cf = 0 -> OK
 22864                              <1> 	;        EAX = Destination directory first cluster
 22865                              <1> 	;        ESI = Logical DOS drive description table 
 22866                              <1> 	;        EBX = Destination file structure offset
 22867                              <1> 	;        CX = 0 (CX > 0 --> calculate free space error)
 22868                              <1> 	;        cf = 1 -> Error code in EAX (AL) 
 22869                              <1> 	;
 22870                              <1> 	;  (EDX, ECX, EBX, ESI, EDI will be changed)
 22871                              <1> 
 22872 00007C73 3C02                <1> 	cmp	al, 2
 22873 00007C75 0F846D010000        <1> 	je	msftdf_df2_check_directory
 22874 00007C7B A2[94CA0000]        <1> 	mov	[move_cmd_phase], al
 22875                              <1> 
 22876                              <1> msftdf_parse_sf_path:
 22877                              <1> 	; ESI = ASCIIZ pathname (Source)
 22878 00007C80 57                  <1> 	push	edi 
 22879 00007C81 BF[94C90000]        <1> 	mov	edi, SourceFile_Drv
 22880 00007C86 E821F7FFFF          <1> 	call	parse_path_name
 22881 00007C8B 5E                  <1> 	pop	esi
 22882 00007C8C 7211                <1> 	jc	short msftdf_psf_retn
 22883                              <1> 
 22884                              <1> msftdf_parse_df_path:
 22885                              <1> 	; ESI = ASCIIZ pathname	(Destination)
 22886 00007C8E BF[14CA0000]        <1> 	mov	edi, DestinationFile_Drv
 22887 00007C93 E814F7FFFF          <1> 	call	parse_path_name
 22888 00007C98 7306                <1> 	jnc	short msftdf_check_sf_drv
 22889                              <1> 
 22890 00007C9A 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
 22891 00007C9C 7602                <1> 	jna	short msftdf_check_sf_drv
 22892                              <1> 
 22893                              <1> msftdf_stc_retn:
 22894 00007C9E F9                  <1> 	stc
 22895                              <1> msftdf_psf_retn:
 22896 00007C9F C3                  <1> 	retn 
 22897                              <1> 
 22898                              <1> msftdf_check_sf_drv:
 22899 00007CA0 A0[94C90000]        <1> 	mov	al, [SourceFile_Drv]
 22900                              <1> 
 22901                              <1> msftdf_check_df_drv:
 22902 00007CA5 8A15[14CA0000]      <1> 	mov	dl, [DestinationFile_Drv]
 22903                              <1> 
 22904                              <1> msftdf_compare_sf_df_drv:
 22905 00007CAB 29DB                <1> 	sub	ebx, ebx
 22906 00007CAD 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 22907 00007CB3 38C2                <1> 	cmp	dl, al
 22908 00007CB5 7409                <1> 	je	short msftdf_check_sf_df_drv_ok
 22909                              <1> 
 22910                              <1> msftdf_not_same_drv:
 22911                              <1>         ; DL = source file's drive number
 22912 00007CB7 88C6                <1> 	mov	dh, al ; destination file's drive number
 22913 00007CB9 B811000000          <1> 	mov	eax, 11h ; Not the same drive
 22914 00007CBE F9                  <1> 	stc
 22915 00007CBF C3                  <1> 	retn 
 22916                              <1> 
 22917                              <1> msftdf_check_sf_df_drv_ok:
 22918 00007CC0 8815[95CA0000]      <1> 	mov	[msftdf_sf_df_drv], dl
 22919                              <1> 
 22920 00007CC6 29C0                <1>         sub	eax, eax
 22921 00007CC8 88D4                <1> 	mov	ah, dl
 22922 00007CCA 0500010900          <1> 	add	eax, Logical_DOSDisks
 22923 00007CCF A3[96CA0000]        <1> 	mov	[msftdf_drv_offset], eax
 22924                              <1> 
 22925 00007CD4 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
 22926 00007CD6 7407                <1> 	je	short msftdf_df_check_directory
 22927                              <1> 
 22928                              <1> msftdf_change_drv:
 22929 00007CD8 E8B2CAFFFF          <1> 	call 	change_current_drive
 22930 00007CDD 725B                <1> 	jc	short msftdf_df_error_retn
 22931                              <1> 	  
 22932                              <1> msftdf_check_destination_file:
 22933                              <1> msftdf_df_check_directory:
 22934 00007CDF BE[15CA0000]        <1> 	mov	esi, DestinationFile_Directory
 22935 00007CE4 803E20              <1> 	cmp	byte [esi], 20h
 22936 00007CE7 760F                <1> 	jna	short msftdf_df_find_1
 22937                              <1> 
 22938                              <1> msftdf_df_change_directory:
 22939 00007CE9 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 22940 00007CEF 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 22941 00007CF1 E8A2F0FFFF          <1> 	call	change_current_directory
 22942 00007CF6 7242                <1> 	jc	short msftdf_df_error_retn
 22943                              <1> 
 22944                              <1> ;msftdf_df_change_prompt_dir_string:
 22945                              <1> ;	call 	change_prompt_dir_string
 22946                              <1> 
 22947                              <1> msftdf_df_find_1:
 22948 00007CF8 BE[56CA0000]        <1>         mov     esi, DestinationFile_Name
 22949 00007CFD 803E20              <1> 	cmp	byte [esi], 20h
 22950 00007D00 761F                <1> 	jna	short msftdf_df_copy_sf_name
 22951                              <1> 
 22952                              <1> msftdf_df_find_2:
 22953 00007D02 6631C0              <1> 	xor	ax, ax ; DestinationFile_AttributesMask -> any/zero
 22954 00007D05 E808DEFFFF          <1> 	call	find_first_file
 22955 00007D0A 737F                <1> 	jnc	short msftdf_permission_denied_retn
 22956                              <1> 
 22957                              <1> msftdf_df_check_error_code:
 22958                              <1> 	;cmp	eax, 2 ; File not found error
 22959 00007D0C 3C02                <1> 	cmp	al, 2
 22960 00007D0E 7529                <1> 	jne	short msftdf_df_stc_retn
 22961                              <1>               
 22962                              <1> msftdf_convert_df_direntry_name:
 22963 00007D10 BE[56CA0000]        <1> 	mov	esi, DestinationFile_Name
 22964 00007D15 BF[66CA0000]        <1> 	mov	edi, DestinationFile_DirEntry
 22965 00007D1A E8C2F5FFFF          <1> 	call	convert_file_name
 22966 00007D1F EB1A                <1>   	jmp	short msftdf_restore_current_dir_1
 22967                              <1> 
 22968                              <1> msftdf_df_copy_sf_name:
 22969 00007D21 89F7                <1> 	mov	edi, esi
 22970 00007D23 57                  <1> 	push	edi 
 22971 00007D24 BE[D6C90000]        <1>         mov     esi, SourceFile_Name
 22972 00007D29 B90C000000          <1> 	mov	ecx, 12
 22973                              <1> msftdf_df_copy_sf_name_loop:
 22974 00007D2E AC                  <1> 	lodsb
 22975 00007D2F AA                  <1>         stosb
 22976 00007D30 08C0                <1> 	or	al, al
 22977 00007D32 7402                <1> 	jz	short msftdf_df_copy_sf_name_ok	
 22978 00007D34 E2F8                <1>         loop    msftdf_df_copy_sf_name_loop
 22979                              <1> msftdf_df_copy_sf_name_ok:	
 22980 00007D36 5E                  <1> 	pop	esi  
 22981 00007D37 EBC9                <1> 	jmp	short msftdf_df_find_2
 22982                              <1> 
 22983                              <1> msftdf_df_stc_retn:
 22984 00007D39 F9                  <1> 	stc
 22985                              <1> msftdf_restore_cdir_failed:
 22986                              <1> msftdf_df_error_retn:
 22987 00007D3A C3                  <1> 	retn
 22988                              <1> 
 22989                              <1> msftdf_restore_current_dir_1:
 22990 00007D3B 803D[80AE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
 22991 00007D42 760D                <1> 	jna	short msftdf_sf_check_directory
 22992 00007D44 8B35[96CA0000]      <1> 	mov	esi, [msftdf_drv_offset] 
 22993 00007D4A E8F2CAFFFF          <1> 	call	restore_current_directory
 22994 00007D4F 72E9                <1> 	jc	short msftdf_restore_cdir_failed
 22995                              <1> 
 22996                              <1> msftdf_sf_check_directory:
 22997 00007D51 BE[95C90000]        <1> 	mov	esi, SourceFile_Directory
 22998 00007D56 803E20              <1> 	cmp	byte [esi], 20h
 22999 00007D59 760F                <1> 	jna	short msftdf_sf_find
 23000                              <1> msftdf_sf_change_directory:
 23001 00007D5B FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 23002 00007D61 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 23003 00007D63 E830F0FFFF          <1> 	call	change_current_directory
 23004 00007D68 7227                <1> 	jc	short msftdf_return
 23005                              <1> 
 23006                              <1> ;msftdf_sf_change_prompt_dir_string:
 23007                              <1> ;	call	change_prompt_dir_string
 23008                              <1> 
 23009                              <1> msftdf_sf_find:
 23010 00007D6A BE[D6C90000]        <1>         mov     esi, SourceFile_Name  ; Offset 66
 23011 00007D6F 66B80018            <1> 	mov	ax, 1800h ; Only files
 23012 00007D73 E89ADDFFFF          <1> 	call	find_first_file
 23013 00007D78 7217                <1> 	jc	short msftdf_return
 23014                              <1> 
 23015                              <1> msftdf_sf_ambgfn_check:
 23016 00007D7A 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
 23017 00007D7D 7407                <1> 	jz	short msftdf_sf_found
 23018                              <1> 
 23019                              <1> msftdf_ambiguous_file_name_error:
 23020 00007D7F B802000000          <1> 	mov	eax, 2 ; File not found error
 23021 00007D84 F9                  <1> 	stc
 23022 00007D85 C3                  <1> 	retn
 23023                              <1> 
 23024                              <1> msftdf_sf_found:
 23025 00007D86 80E31F              <1> 	and	bl, 1Fh ; Attributes, D-V-S-H-R
 23026 00007D89 7416                <1> 	jz	short msftdf_save_sf_structure
 23027                              <1> 
 23028                              <1> msftdf_permission_denied_retn:
 23029 00007D8B B805000000          <1> 	mov	eax, 05h ; Access (Permission) denied !
 23030 00007D90 F9                  <1> 	stc
 23031                              <1> msftdf_rest_cdir_err_retn:
 23032                              <1> msftdf_return:
 23033 00007D91 C3                  <1> 	retn
 23034                              <1> 
 23035                              <1> msftdf_phase_1_return:
 23036 00007D92 31C0                <1> 	xor	eax, eax
 23037 00007D94 A2[94CA0000]        <1> 	mov	[move_cmd_phase], al ; 0
 23038 00007D99 FEC0                <1> 	inc	al ; mov al, 1
 23039 00007D9B BB[E87D0000]        <1> 	mov	ebx, msftdf_df2_check_directory
 23040                              <1> 	;mov	edx, 0FFFFFFFFh 
 23041 00007DA0 C3                  <1> 	retn
 23042                              <1> 
 23043                              <1> msftdf_save_sf_structure:
 23044 00007DA1 BE[A4C80000]        <1> 	mov	esi, FindFile_DirEntry
 23045 00007DA6 BF[E6C90000]        <1> 	mov	edi, SourceFile_DirEntry
 23046 00007DAB B908000000          <1> 	mov	ecx, 8
 23047 00007DB0 F3A5                <1> 	rep	movsd
 23048                              <1> 
 23049                              <1> msftdf_df_copy_sf_parameters:
 23050 00007DB2 BE0B000000          <1> 	mov	esi, 11
 23051 00007DB7 89F7                <1> 	mov	edi, esi
 23052 00007DB9 81C6[E6C90000]      <1> 	add	esi, SourceFile_DirEntry
 23053 00007DBF 81C7[66CA0000]      <1> 	add	edi, DestinationFile_DirEntry
 23054                              <1> 	;mov	ecx, 21
 23055 00007DC5 B115                <1> 	mov	cl, 21
 23056 00007DC7 F3A4                <1> 	rep	movsb
 23057                              <1> 
 23058                              <1> msftdf_restore_current_dir_2:
 23059 00007DC9 803D[80AE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
 23060 00007DD0 760D                <1> 	jna	short msftdf_df2_check_move_cmd_phase
 23061 00007DD2 8B35[96CA0000]      <1>  	mov	esi, [msftdf_drv_offset]
 23062 00007DD8 E864CAFFFF          <1> 	call	restore_current_directory
 23063 00007DDD 72B2                <1> 	jc	short msftdf_rest_cdir_err_retn
 23064                              <1> 
 23065                              <1> msftdf_df2_check_move_cmd_phase:
 23066 00007DDF 803D[94CA0000]01    <1> 	cmp	byte [move_cmd_phase], 1
 23067 00007DE6 74AA                <1> 	je	short msftdf_phase_1_return
 23068                              <1> 
 23069                              <1> msftdf_df2_check_directory:
 23070 00007DE8 BE[15CA0000]        <1> 	mov	esi, DestinationFile_Directory
 23071 00007DED 803E20              <1> 	cmp	byte [esi], 20h
 23072 00007DF0 760F                <1> 	jna	short msftdf_make_dfde_locate_ffe_on_directory
 23073                              <1> msftdf_df2_change_directory:
 23074 00007DF2 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 23075 00007DF8 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 23076 00007DFA E899EFFFFF          <1> 	call	change_current_directory
 23077 00007DFF 7290                <1> 	jc	short msftdf_return
 23078                              <1> 
 23079                              <1> ;msftdf_df2_change_prompt_dir_string:
 23080                              <1> ;	call	change_prompt_dir_string
 23081                              <1> 
 23082                              <1> msftdf_make_dfde_locate_ffe_on_directory:
 23083                              <1> 	; Current directory fcluster <> Directory buffer cluster
 23084                              <1> 	; Current directory will be reloaded by
 23085                              <1> 	; 'locate_current_dir_file' procedure
 23086                              <1> 	;
 23087                              <1> 	;xor	ax, ax
 23088 00007E01 31C0                <1> 	xor	eax, eax
 23089 00007E03 89C1                <1> 	mov	ecx, eax
 23090 00007E05 6649                <1> 	dec	cx ; FFFFh  
 23091                              <1> 		; CX = FFFFh -> find first deleted or free entry
 23092                              <1> 		; ESI would be ASCIIZ filename address if the call
 23093                              <1> 		; would not be for first free or deleted dir entry  
 23094 00007E07 E8E0F1FFFF          <1> 	call	locate_current_dir_file
 23095 00007E0C 733F                <1> 	jnc	msftdf_make_dfde_set_ff_dir_entry
 23096                              <1> 	
 23097                              <1> 	;cmp	eax, 2
 23098 00007E0E 3C02                <1>         cmp	al, 2
 23099 00007E10 7537                <1> 	jne	short msftdf_error_retn
 23100                              <1> 
 23101                              <1> msftdf_add_new_dir_entry_check_fs:
 23102 00007E12 8B35[96CA0000]      <1> 	mov	esi, [msftdf_drv_offset]
 23103 00007E18 A1[DDC60000]        <1> 	mov 	eax, [DirBuff_Cluster]
 23104 00007E1D 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 23105 00007E21 7711                <1> 	ja	short msftdf_add_new_subdir_cluster
 23106                              <1> 
 23107                              <1> msftdf_add_new_fs_subdir_section:
 23108                              <1> 	;CL=0, CH=E5h --> deleted entry, CH=0 --> free entry
 23109                              <1>         ;xor	cx, cx
 23110 00007E23 30ED                <1> 	xor	ch, ch ; cx = 0 --> add a new subdir section
 23111 00007E25 E88C0C0000          <1> 	call	add_new_fs_section
 23112 00007E2A 721E                <1>         jc	short msftdf_dsfde_error_retn
 23113                              <1> 	;mov	[createfile_LastDirCluster], eax
 23114                              <1> 
 23115 00007E2C E8AC0E0000          <1> 	call	load_FS_sub_directory 
 23116                              <1> 	;mov	ebx, Directory_Buffer 
 23117 00007E31 7318                <1> 	jnc	short msftdf_add_new_fs_subdir_section_ok
 23118 00007E33 C3                  <1> 	retn	 
 23119                              <1> 
 23120                              <1> msftdf_add_new_subdir_cluster:
 23121 00007E34 E87A150000          <1> 	call	add_new_cluster
 23122 00007E39 720F                <1> 	jc	short msftdf_dsfde_error_retn
 23123                              <1> 	
 23124                              <1> 	;mov	[createfile_LastDirCluster], eax
 23125                              <1> 
 23126 00007E3B E8600E0000          <1> 	call	load_FAT_sub_directory
 23127 00007E40 7309                <1> 	jnc	short msftdf_add_new_subdir_cluster_ok
 23128                              <1> 	; EBX = Directory buffer address
 23129                              <1> 
 23130                              <1> msftdf_ansdc_update_parent_dir_lmdt:
 23131                              <1> msftdf_make_dfde_err_upd_pdir_lmdt:
 23132 00007E42 50                  <1> 	push	eax
 23133 00007E43 E863FAFFFF          <1> 	call	update_parent_dir_lmdt
 23134 00007E48 58                  <1> 	pop	eax
 23135                              <1> 
 23136                              <1> msftdf_error_retn:
 23137 00007E49 F9                  <1> 	stc
 23138                              <1> msftdf_dsfde_restore_cdir_failed:
 23139                              <1> msftdf_dsfde_error_retn:
 23140 00007E4A C3                  <1> 	retn
 23141                              <1> 
 23142                              <1> msftdf_add_new_fs_subdir_section_ok:
 23143                              <1> msftdf_add_new_subdir_cluster_ok:
 23144 00007E4B 89DF                <1> 	mov	edi, ebx ; Directory buffer address
 23145                              <1> 
 23146                              <1> msftdf_make_dfde_set_ff_dir_entry:
 23147 00007E4D 8B15[A8BE0000]      <1> 	mov	edx, [Current_Dir_FCluster]
 23148 00007E53 8915[FACA0000]      <1> 	mov	[createfile_FFCluster], edx
 23149                              <1> 	; EDI = Directory entry offset
 23150 00007E59 BE[66CA0000]        <1> 	mov	esi, DestinationFile_DirEntry
 23151 00007E5E B908000000          <1> 	mov	ecx, 8
 23152 00007E63 F3A5                <1> 	rep	movsd
 23153                              <1> 
 23154 00007E65 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2 
 23155 00007E6C E89FF9FFFF          <1> 	call	save_directory_buffer
 23156 00007E71 72CF                <1> 	jc	short msftdf_make_dfde_err_upd_pdir_lmdt
 23157                              <1> 
 23158                              <1> msftdf_make_dfde_update_pdir_lmdt:
 23159 00007E73 E833FAFFFF          <1> 	call	update_parent_dir_lmdt
 23160                              <1> 
 23161                              <1> msftdf_dsfde_restore_current_dir_1:
 23162 00007E78 803D[80AE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
 23163 00007E7F 760D                <1> 	jna	short msftdf_dsfde_check_directory
 23164 00007E81 8B35[96CA0000]      <1>  	mov	esi, [msftdf_drv_offset]
 23165 00007E87 E8B5C9FFFF          <1> 	call	restore_current_directory
 23166 00007E8C 72BC                <1> 	jc	short msftdf_dsfde_restore_cdir_failed
 23167                              <1> 
 23168                              <1> msftdf_dsfde_check_directory:
 23169 00007E8E BE[95C90000]        <1> 	mov	esi, SourceFile_Directory
 23170 00007E93 803E20              <1> 	cmp	byte [esi], 20h
 23171 00007E96 760F                <1> 	jna	short msftdf_dsfde_find_file
 23172                              <1> 
 23173                              <1> msftdf_dsfde_change_directory:
 23174 00007E98 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 23175 00007E9E 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
 23176 00007EA0 E8F3EEFFFF          <1> 	call	change_current_directory
 23177 00007EA5 72A3                <1> 	jc	short msftdf_dsfde_error_retn
 23178                              <1> 
 23179                              <1> ;msftdf_dsfde_sf_change_prompt_dir_string:
 23180                              <1> ;	call	change_prompt_dir_string
 23181                              <1> 
 23182                              <1> msftdf_dsfde_find_file:
 23183 00007EA7 BE[D6C90000]        <1> 	mov	esi, SourceFile_Name  ; Offset 66
 23184 00007EAC 668B460E            <1> 	mov	ax, [esi+14] ; 80 -> SourceFile_AttributesMask
 23185 00007EB0 E85DDCFFFF          <1> 	call	find_first_file
 23186 00007EB5 7293                <1> 	jc	short msftdf_dsfde_error_retn
 23187                              <1> 
 23188                              <1> msftdf_dsfde_delete_direntry:
 23189 00007EB7 8B35[96CA0000]      <1> 	mov	esi, [msftdf_drv_offset]
 23190                              <1> 	
 23191 00007EBD 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 23192 00007EC1 770A                <1> 	ja	short msftdf_delete_FAT_direntry
 23193                              <1> 	
 23194 00007EC3 30DB                <1> 	xor	bl, bl
 23195                              <1> 	; BL = 0 -> File
 23196                              <1> 	; EDI -> Directory buffer entry offset/address 
 23197 00007EC5 E8ED0B0000          <1> 	call	delete_fs_directory_entry
 23198 00007ECA 7315                <1> 	jnc	short msftdf_dsfde_restore_current_dir_2
 23199 00007ECC C3                  <1> 	retn
 23200                              <1> 
 23201                              <1> msftdf_delete_FAT_direntry:	
 23202 00007ECD 8A1D[A1C80000]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
 23203 00007ED3 668B0D[CCC80000]    <1> 	mov	cx, [FindFile_DirEntryNumber]
 23204                              <1> 	; ESI = Logical DOS drive description table address
 23205                              <1> 	; EDI = Directory buffer entry offset/address 
 23206 00007EDA E8ABFCFFFF          <1> 	call	delete_directory_entry
 23207 00007EDF 721C                <1> 	jc	short msftdf_retn
 23208                              <1> 
 23209                              <1> msftdf_dsfde_restore_current_dir_2:
 23210 00007EE1 803D[80AE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
 23211 00007EE8 7607                <1> 	jna	short msftdf_new_dir_fcluster_retn
 23212                              <1> 	;mov	esi, [msftdf_drv_offset]
 23213 00007EEA E852C9FFFF          <1> 	call	restore_current_directory
 23214 00007EEF 720C                <1> 	jc	short msftdf_retn
 23215                              <1> 
 23216                              <1> msftdf_new_dir_fcluster_retn:
 23217 00007EF1 31C9                <1> 	xor	ecx, ecx 
 23218 00007EF3 A1[FACA0000]        <1> 	mov	eax, [createfile_FFCluster]
 23219 00007EF8 BB[14CA0000]        <1> 	mov	ebx, DestinationFile_Drv
 23220                              <1> 
 23221                              <1> msftdf_retn:
 23222 00007EFD C3                  <1> 	retn
 23223                              <1> 
 23224                              <1> 
 23225                              <1> copy_source_file_to_destination_file:
 23226                              <1> 	; 05/04/2016
 23227                              <1> 	; 30/03/2016, 31/03/2016
 23228                              <1> 	; 24/03/2016, 25/03/2016, 28/03/2016
 23229                              <1> 	; 21/03/2016, 22/03/2016, 23/03/2016
 23230                              <1> 	; 16/03/2016, 17/03/2016, 18/03/2016
 23231                              <1> 	; 15/03/2016 (TRDOS 386 = TRDOS v2.0)
 23232                              <1> 	; 02/09/2011 (FILE.ASM 'copy_source_file_to_destination_file')
 23233                              <1> 	; 01/08/2010 - 18/05/2011
 23234                              <1> 	;
 23235                              <1> 	;   Command Interpreter phase 1 enter ->
 23236                              <1> 	;           AL = 1 -> Caller is command interpreter
 23237                              <1> 	;           AL = 2 -> The second call, re-enter/continue
 23238                              <1> 	;   Phase 1 -> Check source file
 23239                              <1> 	;              'found' is required
 23240                              <1> 	;   Phase 2 -> Check destination file, 
 23241                              <1> 	;              save 'found' or 'not found' status
 23242                              <1> 	;              'permission denied' error will be return
 23243                              <1> 	;              if attributes have not for ordinary file 
 23244                              <1> 	;              without readonly attribute
 23245                              <1> 	;   Command Interpreter phase 1 return ->
 23246                              <1> 	;              DH = Source file attributes
 23247                              <1> 	;              DL = Destination file found status
 23248                              <1> 	;              EAX = 0 
 23249                              <1> 	;   Command Interpeter phase 2 enter ->
 23250                              <1> 	;              AL = 2 -> Continue from the last position
 23251                              <1> 	;              AH = 
 23252                              <1> 	;   Phase 3 -> Load source file or use read/write cluster method
 23253                              <1> 	;   Phase 4 -> Create destination file if it is not found
 23254                              <1> 	;   Phase 5 -> Open destination file
 23255                              <1> 	;   Phase 6 -> Read from source and write to destination
 23256                              <1> 	;   Phase 7 -> Unload source file, if it is loaded at memory
 23257                              <1> 	;       cf = 1 causes to return before the phase 7
 23258                              <1> 	;              but loaded file will be unloaded
 23259                              <1> 	;	       (allocated memory block will be deallocated) 
 23260                              <1> 	;
 23261                              <1> 	; INPUT -> 
 23262                              <1> 	;	 ESI = Source File Pathname (Asciiz)
 23263                              <1> 	;        EDI = Destination File Pathname (Asciiz)
 23264                              <1> 	;        AL = 0 --> Interrupt (System call)
 23265                              <1> 	;        AL > 0 --> Command Interpreter (Question)
 23266                              <1> 	;        AL = 1 --> Question Phase
 23267                              <1> 	;        AL = 2 --> Progress Phase        
 23268                              <1> 	;
 23269                              <1> 	; OUTPUT -> 
 23270                              <1> 	;	cf = 0 -> OK
 23271                              <1> 	;	EAX = Destination file first cluster
 23272                              <1> 	;
 23273                              <1> 	;        CL > 0 if there is file reading error before EOF
 23274                              <1> 	;	        (incomplete copy) 
 23275                              <1> 	;        CH > 0 if file is (full) loaded at memory
 23276                              <1> 	;
 23277                              <1> 	;	cf = 1 -> Error code in AL (EAX) 
 23278                              <1> 	;
 23279                              <1> 	; (EBX, ECX, ESI, EDI register contents will be changed)           
 23280                              <1> 
 23281                              <1> 
 23282 00007EFE 3C02                <1> 	cmp	al, 2
 23283 00007F00 0F844C020000        <1> 	je	csftdf2_check_cdrv
 23284                              <1> 
 23285                              <1> ; Phase 1
 23286                              <1> 
 23287 00007F06 A2[BACA0000]        <1> 	mov	byte [copy_cmd_phase], al
 23288                              <1> 
 23289 00007F0B 57                  <1> 	push	edi ; *
 23290                              <1> 
 23291                              <1> csftdf_parse_sf_path:
 23292 00007F0C BF[94C90000]        <1> 	mov	edi, SourceFile_Drv
 23293 00007F11 E896F4FFFF          <1> 	call	parse_path_name
 23294 00007F16 721C                <1> 	jc	short csftdf_parse_sf_path_failed
 23295                              <1> 
 23296                              <1> csftdf_parse_df_path:	
 23297 00007F18 5E                  <1> 	pop	esi ; * (pushed edi) 
 23298                              <1> 
 23299                              <1> csftdf_sf_check_filename_exists:
 23300 00007F19 803D[D6C90000]21    <1> 	cmp	byte [SourceFile_Name], 21h
 23301 00007F20 7215                <1> 	jb	short csftdf_sf_file_not_found_error
 23302                              <1> 
 23303 00007F22 BF[14CA0000]        <1> 	mov	edi, DestinationFile_Drv
 23304 00007F27 E880F4FFFF          <1> 	call	parse_path_name
 23305 00007F2C 7310                <1> 	jnc	short csftdf_check_sf_cdrv
 23306                              <1> 	
 23307 00007F2E 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
 23308 00007F30 760C                <1> 	jna	short csftdf_check_sf_cdrv
 23309                              <1> 
 23310                              <1> csftdf_parse_df_path_failed:
 23311 00007F32 F9                  <1> 	stc 
 23312                              <1> csftdf_sf_error_retn: 
 23313 00007F33 C3                  <1> 	retn
 23314                              <1> 
 23315                              <1> csftdf_parse_sf_path_failed:	
 23316 00007F34 5F                  <1> 	pop	edi ; *
 23317 00007F35 EBFC                <1> 	jmp	short csftdf_sf_error_retn
 23318                              <1> 
 23319                              <1> csftdf_sf_file_not_found_error:
 23320 00007F37 B802000000          <1> 	mov	eax, 2 ; File not found 
 23321 00007F3C EBF5                <1> 	jmp	short csftdf_sf_error_retn
 23322                              <1> 
 23323                              <1> csftdf_check_sf_cdrv:
 23324 00007F3E 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 23325                              <1> 
 23326 00007F44 883D[BDCA0000]      <1> 	mov	[csftdf_cdrv], bh ; 23/03/2016
 23327                              <1> 
 23328 00007F4A 8A15[94C90000]      <1> 	mov	dl, [SourceFile_Drv]
 23329 00007F50 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
 23330 00007F52 7407                <1> 	je	short csftdf_sf_check_directory
 23331                              <1> 
 23332 00007F54 E836C8FFFF          <1> 	call	change_current_drive
 23333 00007F59 72D8                <1> 	jc	short csftdf_sf_error_retn
 23334                              <1> 
 23335                              <1> csftdf_sf_check_directory:
 23336 00007F5B BE[95C90000]        <1> 	mov	esi, SourceFile_Directory
 23337 00007F60 803E20              <1> 	cmp	byte [esi], 20h
 23338 00007F63 760F                <1> 	jna	short csftdf_find_sf
 23339                              <1> 
 23340                              <1> csftdf_sf_change_directory:
 23341 00007F65 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 23342 00007F6B 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 23343 00007F6D E826EEFFFF          <1> 	call	change_current_directory
 23344 00007F72 72BF                <1> 	jc	short csftdf_sf_error_retn
 23345                              <1> 
 23346                              <1> ;csftdf_sf_change_prompt_dir_string:
 23347                              <1> ;	call	change_prompt_dir_string
 23348                              <1> 
 23349                              <1> csftdf_find_sf:
 23350 00007F74 BE[D6C90000]        <1> 	mov	esi, SourceFile_Name
 23351 00007F79 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
 23352 00007F7D E890DBFFFF          <1> 	call	find_first_file
 23353 00007F82 72AF                <1> 	jc	short csftdf_sf_error_retn
 23354                              <1> 
 23355                              <1> csftdf_sf_ambgfn_check:
 23356 00007F84 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 23357 00007F87 7407                <1> 	jz	short csftdf_sf_found
 23358                              <1> 
 23359                              <1> csftdf_ambiguous_file_name_error:
 23360 00007F89 B802000000          <1> 	mov	eax, 2 ; File not found error
 23361 00007F8E F9                  <1> 	stc
 23362 00007F8F C3                  <1> 	retn
 23363                              <1> 
 23364                              <1> csftdf_sf_found:
 23365 00007F90 A3[BECA0000]        <1> 	mov	[csftdf_filesize], eax
 23366                              <1> 
 23367 00007F95 09C0                <1> 	or	eax, eax
 23368 00007F97 7507                <1> 	jnz	short csftdf_set_source_file_direnry
 23369                              <1> 
 23370                              <1> csftdf_sf_file_size_zero:
 23371 00007F99 B80E000000          <1> 	mov	eax, 0Eh ; TRDOS zero length error
 23372 00007F9E F9                  <1> 	stc
 23373 00007F9F C3                  <1> 	retn
 23374                              <1> 
 23375                              <1> csftdf_set_source_file_direnry:
 23376 00007FA0 BE[A4C80000]        <1> 	mov	esi, FindFile_DirEntry
 23377 00007FA5 BF[E6C90000]        <1> 	mov	edi, SourceFile_DirEntry
 23378 00007FAA B908000000          <1> 	mov	ecx, 8
 23379 00007FAF F3A5                <1> 	rep	movsd
 23380                              <1> 
 23381                              <1> csftdf_sf_restore_cdrv:
 23382                              <1> 	; 22/03/2016
 23383 00007FB1 8A15[BDCA0000]      <1> 	mov	dl, [csftdf_cdrv]
 23384 00007FB7 3A15[AEBE0000]      <1> 	cmp	dl, [Current_Drv]
 23385 00007FBD 7407                <1> 	je	short csftdf_sf_restore_cdir
 23386 00007FBF E8CBC7FFFF          <1> 	call	change_current_drive 
 23387 00007FC4 724F                <1> 	jc	short csftdf_df_error_retn ; 30/03/2016
 23388                              <1> 
 23389                              <1> csftdf_sf_restore_cdir:
 23390 00007FC6 803D[80AE0000]00    <1> 	cmp	byte [Restore_CDIR], 0
 23391 00007FCD 7612                <1> 	jna	short csftdf_df_check_filename_exists
 23392 00007FCF 29C0                <1> 	sub	eax, eax
 23393 00007FD1 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 23394 00007FD6 88D4                <1> 	mov	ah, dl ; byte [csftdf_cdrv]
 23395 00007FD8 01C6                <1> 	add	esi, eax
 23396 00007FDA E862C8FFFF          <1> 	call	restore_current_directory
 23397 00007FDF 7234                <1> 	jc	short csftdf_df_error_retn
 23398                              <1>   
 23399                              <1> csftdf_df_check_filename_exists:
 23400 00007FE1 803D[56CA0000]20    <1> 	cmp	byte [DestinationFile_Name], 20h
 23401 00007FE8 7716                <1> 	ja	short csftdf_check_df_cdrv
 23402                              <1> 
 23403                              <1> csftdf_copy_sf_name:
 23404 00007FEA BF[56CA0000]        <1> 	mov	edi, DestinationFile_Name
 23405 00007FEF BE[D6C90000]        <1> 	mov	esi, SourceFile_Name
 23406 00007FF4 B10C                <1> 	mov	cl, 12
 23407                              <1> 
 23408                              <1> csftdf_df_copy_sf_name_loop:
 23409 00007FF6 AC                  <1> 	lodsb
 23410 00007FF7 AA                  <1> 	stosb
 23411 00007FF8 08C0                <1> 	or	al, al
 23412 00007FFA 7404                <1> 	jz	short csftdf_check_df_cdrv             
 23413 00007FFC FEC9                <1> 	dec	cl
 23414 00007FFE 75F6                <1> 	jnz	csftdf_df_copy_sf_name_loop
 23415                              <1> 
 23416                              <1> csftdf_check_df_cdrv:
 23417 00008000 8A15[14CA0000]      <1> 	mov	dl, [DestinationFile_Drv]
 23418 00008006 3A15[AEBE0000]      <1> 	cmp	dl, [Current_Drv]
 23419 0000800C 7408                <1> 	je	short csftdf_df_check_directory
 23420                              <1> 
 23421 0000800E E87CC7FFFF          <1> 	call	change_current_drive
 23422 00008013 7301                <1> 	jnc	short csftdf_df_check_directory
 23423                              <1> 
 23424                              <1> csftdf_df_error_retn:
 23425 00008015 C3                  <1> 	retn
 23426                              <1> 
 23427                              <1> csftdf_df_check_directory:
 23428 00008016 BE[15CA0000]        <1> 	mov	esi, DestinationFile_Directory
 23429 0000801B 803E20              <1>         cmp     byte [esi], 20h
 23430 0000801E 760F                <1> 	jna	short csftdf_find_df
 23431                              <1> 
 23432                              <1> csftdf_df_change_directory:
 23433 00008020 FE05[80AE0000]      <1> 	inc	byte [Restore_CDIR]
 23434 00008026 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0 
 23435 00008028 E86BEDFFFF          <1> 	call	change_current_directory
 23436 0000802D 72E6                <1> 	jc	short csftdf_df_error_retn
 23437                              <1> 
 23438                              <1> ;csftdf_df_change_prompt_dir_string:
 23439                              <1> ;	call	change_prompt_dir_string
 23440                              <1> 
 23441                              <1> csftdf_find_df:
 23442                              <1> 	; 23/03/2016
 23443 0000802F 29DB                <1> 	sub	ebx, ebx
 23444 00008031 8A3D[14CA0000]      <1> 	mov	bh,  [DestinationFile_Drv]
 23445 00008037 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 23446 0000803D 891D[EACA0000]      <1> 	mov	[csftdf_df_drv_dt], ebx
 23447                              <1> 
 23448 00008043 BE[56CA0000]        <1> 	mov	esi, DestinationFile_Name
 23449 00008048 6631C0              <1> 	xor	ax, ax 
 23450                              <1> 		; DestinationFile_AttributesMask -> any/zero
 23451 0000804B E8C2DAFFFF          <1> 	call	find_first_file
 23452 00008050 7218                <1> 	jc	short csftdf_df_check_error_code
 23453                              <1> 
 23454                              <1> csftdf_df_ambgfn_check:
 23455 00008052 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
 23456 00008055 7511                <1> 	jnz	short csftdf_df_error_stc_retn
 23457                              <1> 	
 23458                              <1> csftdf_df_found:
 23459 00008057 C605[BCCA0000]01    <1> 	mov	byte [DestinationFileFound], 1
 23460 0000805E 80E11F              <1> 	and	cl, 1Fh ; Attributes, D-V-S-H-R
 23461 00008061 7451                <1> 	jz	short csftdf_df_save_first_cluster
 23462                              <1> 
 23463                              <1> csftdf_df_permission_denied_retn:	 
 23464 00008063 B805000000          <1> 	mov	eax, 05h ; Access/Permisson denied.
 23465                              <1> csftdf_df_error_stc_retn:
 23466 00008068 F9                  <1> 	stc
 23467 00008069 C3                  <1> 	retn
 23468                              <1> 
 23469                              <1> csftdf_df_check_error_code:
 23470                              <1> 	;cmp	eax, 2
 23471 0000806A 3C02                <1> 	cmp	al, 2
 23472 0000806C 75FA                <1> 	jne	short csftdf_df_error_stc_retn
 23473                              <1> 
 23474                              <1> 	; 21/03/2016
 23475                              <1> 	; (Capitalized file name)
 23476 0000806E BE[94C80000]        <1> 	mov	esi, FindFile_Name
 23477 00008073 BF[56CA0000]        <1> 	mov	edi, DestinationFile_Name
 23478 00008078 A5                  <1> 	movsd
 23479 00008079 A5                  <1> 	movsd	
 23480 0000807A A5                  <1> 	movsd
 23481                              <1> 	;movsb
 23482                              <1> 
 23483 0000807B C605[BCCA0000]00    <1> 	mov	byte [DestinationFileFound], 0
 23484                              <1> 
 23485                              <1> csftdf_check_disk_free_size_0:
 23486 00008082 A1[02CA0000]        <1> 	mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
 23487                              <1> 
 23488                              <1> csftdf_check_disk_free_size_1:
 23489                              <1> 	;sub	ebx, ebx
 23490                              <1> 	;mov 	esi, Logical_DOSDisks
 23491                              <1> 	;mov	bh,  [DestinationFile_Drv]
 23492                              <1> 	;add	esi, ebx
 23493                              <1> 	
 23494 00008087 8B35[EACA0000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
 23495                              <1> 
 23496 0000808D 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
 23497 00008091 01C8                <1> 	add	eax, ecx
 23498 00008093 48                  <1> 	dec	eax  ; file size (additional bytes) + 511 (round up)
 23499                              <1> csftdf_check_disk_free_size_3: ; 16/03/2016
 23500 00008094 29D2                <1> 	sub	edx, edx
 23501 00008096 F7F1                <1> 	div	ecx ; bytes per sector
 23502                              <1> 
 23503                              <1> csftdf_check_disk_free_size:
 23504 00008098 3B4674              <1> 	cmp	eax, [esi+LD_FreeSectors]
 23505 0000809B 0F8294000000        <1>         jb      csftdf_check_disk_free_size_ok
 23506 000080A1 770A                <1> 	ja	short csftdf_df_insufficient_disk_space
 23507                              <1> 
 23508 000080A3 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0 ; FS needs FDT sector also.
 23509 000080A7 0F8788000000        <1>         ja      csftdf_check_disk_free_size_ok 
 23510                              <1> 
 23511                              <1> csftdf_df_insufficient_disk_space:
 23512 000080AD B827000000          <1> 	mov	eax, 27h ; insufficient disk space
 23513 000080B2 EBB4                <1> 	jmp	short csftdf_df_error_stc_retn
 23514                              <1> 
 23515                              <1> csftdf_df_save_first_cluster:
 23516                              <1> 	; ESI = FindFile_DirEntry (for the old destination file)
 23517                              <1> 	; EAX = Old destination file size
 23518                              <1> 	; 24/03/2016
 23519                              <1> 	; EDI = Directory entry address (within Dir Buffer boundaries)
 23520 000080B4 81EF00000800        <1> 	sub	edi, Directory_Buffer  ; (<65536)
 23521 000080BA 66C1EF05            <1> 	shr	di, 5 ; Convert entry offset to entry index/number
 23522 000080BE 66893D[8ECA0000]    <1> 	mov	[DestinationFile_DirEntryNumber], di ; (<2048)
 23523                              <1> 
 23524                              <1> csftdf_df_check_sf_df_fcluster:
 23525 000080C5 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
 23526 000080C9 C1E210              <1> 	shl	edx, 16
 23527 000080CC 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
 23528 000080D0 8915[CECA0000]      <1> 	mov	[csftdf_df_cluster], edx
 23529                              <1> csftdf_df_check_sf_df_fcluster_1:
 23530 000080D6 668B15[FAC90000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
 23531 000080DD C1E210              <1> 	shl	edx, 16
 23532 000080E0 668B15[00CA0000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
 23533 000080E7 3B15[CECA0000]      <1> 	cmp	edx, [csftdf_df_cluster]
 23534 000080ED 7512                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
 23535                              <1> csftdf_df_check_sf_df_drv:
 23536 000080EF 8A15[94C90000]      <1> 	mov	dl, [SourceFile_Drv]
 23537 000080F5 3A15[14CA0000]      <1> 	cmp	dl, [DestinationFile_Drv]
 23538 000080FB 7504                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
 23539                              <1> 
 23540                              <1> 	; source and destination files are same !
 23541                              <1> 	; (they have same first cluster value on same logical disk)
 23542                              <1> 
 23543 000080FD 31C0                <1> 	xor	eax, eax ; mov eax, 0 -> Bad command or file name !
 23544 000080FF F9                  <1> 	stc
 23545 00008100 C3                  <1> 	retn 
 23546                              <1>    
 23547                              <1> csftdf_df_check_sf_df_fcluster_ok:
 23548                              <1> csftdf_df_move_findfile_struct:
 23549                              <1> 	; mov	esi, FindFile_DirEntry
 23550 00008101 BF[66CA0000]        <1> 	mov	edi, DestinationFile_DirEntry
 23551 00008106 B908000000          <1> 	mov	ecx, 8
 23552 0000810B F3A5                <1> 	rep	movsd
 23553                              <1> 	
 23554                              <1> csftdf_check_disk_free_size_2:
 23555 0000810D 89C2                <1> 	mov	edx, eax ; Old destination file size
 23556                              <1> 
 23557                              <1> 	;mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
 23558 0000810F A1[BECA0000]        <1> 	mov	eax, [csftdf_filesize] ; 23/03/2016
 23559                              <1> 
 23560                              <1> 	;;sub	ecx, ecx ; 0
 23561                              <1> 	;mov 	esi, Logical_DOSDisks
 23562                              <1> 	;mov	ch,  [DestinationFile_Drv]
 23563                              <1> 	;add	esi, ecx
 23564                              <1> 	;
 23565                              <1> 	;mov	[csftdf_df_drv_dt], esi
 23566                              <1> 
 23567 00008114 8B35[EACA0000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
 23568                              <1> 
 23569 0000811A 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
 23570 0000811E 01CA                <1> 	add	edx, ecx ; + 512
 23571 00008120 01C8                <1> 	add	eax, ecx ; + 512
 23572 00008122 4A                  <1> 	dec	edx ; old file size + 511 (round up)
 23573 00008123 48                  <1> 	dec	eax ; new file size + 511 (round up)
 23574 00008124 F7D9                <1> 	neg	ecx ; -512 ; 0FFFFFE00h
 23575 00008126 21CA                <1> 	and	edx, ecx ; = old sector count * 512 
 23576 00008128 21C8                <1> 	and	eax, ecx ; = new sector count * 512 
 23577                              <1> 
 23578 0000812A 29D0                <1> 	sub	eax, edx ; new file size - old file size (on disk)
 23579 0000812C 7607                <1> 	jna	short csftdf_check_disk_free_size_ok
 23580                              <1> 
 23581 0000812E F7D9                <1> 	neg	ecx ; 512 (bytes per sector) ; 200h
 23582                              <1> 	; check free space for additional sectors
 23583                              <1> 	; eax = number of additional sectors * bytes per sector
 23584                              <1> 	; esi = Logical DOS drive number (of destination disk)
 23585 00008130 E95FFFFFFF          <1>         jmp     csftdf_check_disk_free_size_3
 23586                              <1>  
 23587                              <1> csftdf_check_disk_free_size_ok:
 23588                              <1> 	; 18/03/2016
 23589                              <1> csftdf_df_check_copy_cmd_phase:
 23590 00008135 A0[BACA0000]        <1> 	mov	al, [copy_cmd_phase]
 23591 0000813A 3C01                <1> 	cmp	al, 1
 23592 0000813C 7514                <1> 	jne	short csftdf2_check_cdrv
 23593                              <1> 	
 23594 0000813E 31C0                <1> 	xor	eax, eax
 23595 00008140 A2[BACA0000]        <1> 	mov	[copy_cmd_phase], al ; 0
 23596                              <1> 
 23597 00008145 8A15[BCCA0000]      <1> 	mov	dl, [DestinationFileFound]            
 23598 0000814B 8A35[F1C90000]      <1> 	mov	dh, [SourceFile_DirEntry+11] ; Attributes
 23599                              <1>  
 23600                              <1> csftdf_return:	
 23601 00008151 C3                  <1> 	retn
 23602                              <1> 
 23603                              <1> ; Phase 2
 23604                              <1> 
 23605                              <1> csftdf2_check_cdrv:
 23606                              <1> 	; 18/03/2016
 23607                              <1> 	; Here, destination drive and directory are ready !
 23608                              <1> 	; (checking/restoring is not needed)
 23609                              <1> 	; (Since at the end of the phase 1)
 23610                              <1> 
 23611                              <1> ;	mov	dl, [DestinationFile_Drv]
 23612                              <1> ;	cmp	dl, [Current_Drv]
 23613                              <1> ;	je	short csftdf2_df_check_directory
 23614                              <1> ;
 23615                              <1> ;	call	change_current_drive
 23616                              <1> ;	jc	short csftdf2_read_error
 23617                              <1> ;
 23618                              <1> ;csftdf2_df_check_directory:
 23619                              <1> ;	mov	esi, DestinationFile_Directory  
 23620                              <1> ;	cmp	byte [esi], 20h
 23621                              <1> ;	jna	short csftdf2_df_check_found_or_not
 23622                              <1> ;
 23623                              <1> ;csftdf2_df_change_directory:
 23624                              <1> ;	inc	byte [Restore_CDIR]
 23625                              <1> ;	xor	ah, ah ; CD_COMMAND sign -> 0 
 23626                              <1> ;	call	change_current_directory
 23627                              <1> ;	jc	short csftdf2_stc_return
 23628                              <1> ;
 23629                              <1> ;;csftdf2_df_change_prompt_dir_string:
 23630                              <1> ;;	call	change_prompt_dir_string
 23631                              <1> 
 23632                              <1> csftdf2_df_check_found_or_not:
 23633                              <1> 	; 21/03/2016
 23634 00008152 803D[BCCA0000]00    <1> 	cmp	byte [DestinationFileFound], 0 
 23635 00008159 7739                <1> 	ja	short csftdf2_set_sf_percentage
 23636                              <1> 
 23637                              <1> csftdf2_create_file:
 23638 0000815B BE[56CA0000]        <1> 	mov	esi, DestinationFile_Name
 23639 00008160 A1[BECA0000]        <1> 	mov	eax, [csftdf_filesize]
 23640 00008165 30C9                <1> 	xor	cl, cl ; 0
 23641                              <1> 
 23642 00008167 31DB                <1> 	xor	ebx, ebx ; 0
 23643 00008169 4B                  <1> 	dec	ebx ; 0FFFFFFFFh 
 23644                              <1> 
 23645                              <1> 	; INPUT ->
 23646                              <1> 	; 	EAX -> File Size
 23647                              <1> 	; 	ESI = ASCIIZ File name
 23648                              <1> 	;	 CL = File attributes
 23649                              <1> 	;	EBX = FFFFFFFFh -> empty file sign for FAT fs
 23650                              <1> 	;	EBX <> FFFFFFFFh -> use file size for FAT fs 
 23651                              <1> 	;
 23652                              <1> 	; OUTPUT ->
 23653                              <1> 	;	EAX = New file's first cluster
 23654                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
 23655                              <1> 	;	EBX = CreateFile_Size address
 23656                              <1> 	;	ECX = Sectors per cluster (<256)
 23657                              <1> 	;	EDX = Directory Entry Index/Number (<65536)
 23658                              <1> 	;		
 23659                              <1> 	;	cf = 1 -> error code in AL (EAX)
 23660                              <1> 
 23661 0000816A E803060000          <1> 	call	create_file
 23662                              <1> 	;pop	esi
 23663 0000816F 0F82BA050000        <1>         jc      csftdf2_rw_error
 23664                              <1> 
 23665                              <1> csftdf2_create_file_OK:
 23666 00008175 A3[CECA0000]        <1> 	mov	[csftdf_df_cluster], eax
 23667                              <1> 	
 23668                              <1> 	; 24/03/2016
 23669 0000817A 668915[8ECA0000]    <1> 	mov	[DestinationFile_DirEntryNumber], dx 
 23670                              <1> 
 23671                              <1> 	; 21/03/2016
 23672 00008181 BE00000800          <1> 	mov	esi, Directory_Buffer
 23673 00008186 C1E205              <1> 	shl	edx, 5 ; 32 * index number
 23674 00008189 01D6                <1> 	add	esi, edx
 23675 0000818B BF[66CA0000]        <1> 	mov	edi, DestinationFile_DirEntry	
 23676 00008190 B108                <1> 	mov	cl, 8 ; 32 bytes
 23677 00008192 F3A5                <1> 	rep	movsd
 23678                              <1> 
 23679                              <1> csftdf2_set_sf_percentage:
 23680                              <1> 	; 17/03/2016
 23681 00008194 31C0                <1> 	xor	eax, eax	
 23682 00008196 A2[E2CA0000]        <1> 	mov 	[csftdf_percentage], al ; 0, reset
 23683                              <1> 
 23684 0000819B A3[DACA0000]        <1> 	mov	[csftdf_sf_rbytes], eax ; 0, reset
 23685 000081A0 A3[DECA0000]        <1> 	mov	[csftdf_df_wbytes], eax ; 0, reset
 23686                              <1> 
 23687 000081A5 8A25[94C90000]      <1> 	mov	ah, [SourceFile_Drv]	
 23688 000081AB BE00010900          <1> 	mov	esi, Logical_DOSDisks
 23689 000081B0 01C6                <1> 	add	esi, eax
 23690                              <1> 	
 23691 000081B2 8935[E6CA0000]      <1> 	mov	[csftdf_sf_drv_dt], esi ; 23/03/2016
 23692                              <1> 
 23693 000081B8 668B15[FAC90000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
 23694 000081BF C1E210              <1> 	shl	edx, 16
 23695 000081C2 668B15[00CA0000]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
 23696 000081C9 8915[CACA0000]      <1> 	mov	[csftdf_sf_cluster], edx
 23697                              <1> 
 23698                              <1> 	; 16/03/2016
 23699                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
 23700                              <1> 	;	related calculations) has same offset
 23701                              <1> 	;	values from LD_BPB as in FAT file system.
 23702                              <1> 	;	[esi+LD_BPB+SecPerClust] is 1 for Singlix FS.
 23703                              <1> 	;	
 23704 000081CF 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 23705 000081D3 880D[12CA0000]      <1> 	mov	[SourceFile_SecPerClust], cl
 23706                              <1> 
 23707                              <1> 	; 17/03/2016
 23708 000081D9 386E03              <1> 	cmp	[esi+LD_FATType], ch ; 0
 23709 000081DC 7707                <1> 	ja	short csftdf2_set_sf_percent_rsize1
 23710                              <1> 
 23711 000081DE B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
 23712 000081E3 EB06                <1> 	jmp	short csftdf2_set_sf_percent_rsize2	
 23713                              <1>  
 23714                              <1> csftdf2_set_sf_percent_rsize1:
 23715 000081E5 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
 23716 000081E9 F7E1                <1> 	mul	ecx
 23717                              <1> 	;sub	edx, edx
 23718                              <1> csftdf2_set_sf_percent_rsize2:
 23719 000081EB A3[D2CA0000]        <1> 	mov	[csftdf_r_size], eax
 23720                              <1> 
 23721                              <1> csftdf2_set_df_percentage:
 23722                              <1> 	;sub	eax, eax
 23723                              <1> 	;mov	ah, [DestinationFile_Drv]	
 23724                              <1> 	;mov	edi, Logical_DOSDisks
 23725                              <1> 	;add	edi, eax
 23726                              <1> 	;mov	[csftdf_df_drv_dt], edi ; 17/03/2016
 23727                              <1> 
 23728 000081F0 8B3D[EACA0000]      <1> 	mov	edi, [csftdf_df_drv_dt] ; 23/03/2016
 23729                              <1> 
 23730                              <1> 	; 16/03/2016
 23731                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
 23732                              <1> 	;	related calculations) has same offset
 23733                              <1> 	;	values from LD_BPB as in FAT file system.
 23734                              <1> 	;	[edi+LD_BPB+SecPerClust] is 1 for Singlix FS.
 23735                              <1> 	;	
 23736                              <1> 	;movzx	ecx, byte [edi+LD_BPB+SecPerClust]
 23737 000081F6 8A4F13              <1> 	mov	cl, [edi+LD_BPB+SecPerClust]
 23738 000081F9 880D[92CA0000]      <1> 	mov	[DestinationFile_SecPerClust], cl
 23739                              <1> 
 23740                              <1> 	; 17/03/2016
 23741 000081FF 386F03              <1> 	cmp	[edi+LD_FATType], ch ; 0
 23742 00008202 7707                <1> 	ja	short csftdf2_set_df_percent_wsize1
 23743                              <1> 	
 23744 00008204 B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
 23745 00008209 EB06                <1> 	jmp	short csftdf2_set_df_percent_wsize2	
 23746                              <1> 
 23747                              <1> csftdf2_set_df_percent_wsize1:
 23748 0000820B 0FB74711            <1> 	movzx	eax, word [edi+LD_BPB+BytesPerSec]
 23749 0000820F F7E1                <1> 	mul	ecx
 23750                              <1> 	;sub	edx, edx
 23751                              <1> csftdf2_set_df_percent_wsize2:
 23752 00008211 A3[D6CA0000]        <1> 	mov	[csftdf_w_size], eax
 23753                              <1> 
 23754 00008216 A1[BECA0000]        <1> 	mov	eax, [csftdf_filesize]
 23755                              <1> 
 23756 0000821B 3D00000100          <1> 	cmp	eax, 65536 ; 64KB	; small file
 23757 00008220 721F                <1> 	jb	short csftdf2_load_file ; do not display percentage
 23758                              <1> 	
 23759                              <1> csftdf2_reset_wf_percent_ptr_chk_64k:
 23760 00008222 B201                <1> 	mov	dl, 1 ; 25/03/2016
 23761                              <1> 
 23762 00008224 3D00000400          <1> 	cmp	eax, 65536*4 ; 256KB
 23763 00008229 7310                <1> 	jnb	short csftdf2_enable_percentage_display ; big file
 23764                              <1> 
 23765                              <1> 	; 64-128KB file size for floppy disks
 23766 0000822B 3815[94C90000]      <1> 	cmp	byte [SourceFile_Drv], dl ; 1 ; read from floppy disk ?
 23767 00008231 7608                <1> 	jna	short csftdf2_enable_percentage_display
 23768                              <1> 
 23769 00008233 3815[14CA0000]      <1> 	cmp	byte [DestinationFile_Drv], dl ; 1 ; write to floppy disk ?
 23770 00008239 7706                <1> 	ja	short csftdf2_load_file
 23771                              <1> 
 23772                              <1> csftdf2_enable_percentage_display:	
 23773 0000823B 8815[E2CA0000]      <1> 	mov	[csftdf_percentage], dl ; 1	
 23774                              <1> 	
 23775                              <1> csftdf2_load_file:
 23776                              <1> 	; 19/03/2016
 23777                              <1> 	; 18/03/2016
 23778                              <1> 	; 17/03/2016
 23779 00008241 B40F                <1> 	mov	ah, 0Fh
 23780 00008243 E80092FFFF          <1> 	call	int10h
 23781 00008248 881D[E3CA0000]      <1> 	mov	[csftdf_videopage], bl ; active video page
 23782 0000824E B403                <1> 	mov	ah, 03h
 23783 00008250 E8F391FFFF          <1> 	call	int10h
 23784 00008255 668915[E4CA0000]    <1> 	mov	[csftdf_cursorpos], dx
 23785                              <1> 
 23786 0000825C 29C0                <1> 	sub	eax, eax
 23787 0000825E A2[BBCA0000]        <1> 	mov	[csftdf_rw_err], al ; 0 
 23788                              <1> 
 23789                              <1> ; ///
 23790                              <1> csftdf_sf_amb: ; 15/03/2016
 23791 00008263 8B0D[BECA0000]      <1> 	mov	ecx, [csftdf_filesize]	; 23/03/2016
 23792                              <1> 
 23793                              <1> 	; TRDOS 386 (TRDOS v2.0)
 23794                              <1> 	; Allocate contiguous memory block for loading the file
 23795                              <1> 	
 23796                              <1> 	;mov	ecx, [SourceFile_DirEntry+DirEntry_FileSize]
 23797                              <1> 	
 23798                              <1> 	;sub	eax, eax ; First free memory aperture
 23799                              <1> 	
 23800                              <1> 	; eax = 0 (Allocate memory from the beginning)
 23801                              <1> 	; ecx = File (Allocation) size in bytes
 23802                              <1> 	
 23803 00008269 E885B6FFFF          <1> 	call	allocate_memory_block
 23804 0000826E 7304                <1> 	jnc	short loc_check_sf_save_loading_parms
 23805                              <1> 
 23806 00008270 29C0                <1> 	sub	eax, eax
 23807 00008272 29C9                <1> 	sub	ecx, ecx
 23808                              <1> 	
 23809                              <1> loc_check_sf_save_loading_parms:
 23810 00008274 A3[C2CA0000]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
 23811 00008279 890D[C6CA0000]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
 23812                              <1> ; ///   
 23813                              <1> 	; 19/03/2016
 23814 0000827F 8B35[E6CA0000]      <1> 	mov	esi, [csftdf_sf_drv_dt] ; logical dos drv desc. tbl.
 23815                              <1> 
 23816                              <1> 	; 17/03/2016
 23817 00008285 09C0                <1> 	or	eax, eax ; contiguous free memory block address 
 23818 00008287 0F845B010000        <1>         jz      csftdf2_read_sf_cluster
 23819                              <1> 
 23820                              <1> 	; 18/03/2016
 23821 0000828D 8B1D[C2CA0000]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
 23822                              <1> 
 23823 00008293 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 23824 00008297 0F861C020000        <1>         jna     csftdf2_load_fs_file
 23825                              <1> 
 23826                              <1> csftdf2_load_fat_file:
 23827 0000829D 53                  <1> 	push	ebx ; *
 23828                              <1> 
 23829                              <1> csftdf2_load_fat_file_next:
 23830 0000829E BE[D5B40000]        <1> 	mov	esi, msg_reading
 23831 000082A3 E8E3BBFFFF          <1> 	call	print_msg
 23832                              <1> 
 23833 000082A8 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 23834 000082AF 7605                <1> 	jna	short csftdf2_load_fat_file_1
 23835                              <1> 	
 23836 000082B1 E87C000000          <1> 	call	csftdf2_print_percentage ; 19/03/2016
 23837                              <1> 
 23838                              <1> csftdf2_load_fat_file_1:
 23839 000082B6 8B35[E6CA0000]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
 23840 000082BC 5B                  <1> 	pop	ebx ; *
 23841                              <1> 
 23842                              <1> csftdf2_load_fat_file_2:
 23843 000082BD E8B8000000          <1> 	call	csftdf2_read_fat_file_sectors ; 19/03/2016
 23844 000082C2 0F8267040000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
 23845                              <1> 
 23846 000082C8 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 23847 000082CA 7520                <1> 	jnz	short csftdf2_load_fat_file_ok
 23848                              <1> 
 23849 000082CC 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 23850 000082D3 76E8                <1> 	jna	short csftdf2_load_fat_file_2
 23851                              <1> 
 23852 000082D5 53                  <1> 	push	ebx ; *	
 23853                              <1> 
 23854                              <1> 	; Set cursor position
 23855                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 23856 000082D6 8A1D[E3CA0000]      <1> 	mov	bl, [csftdf_videopage]
 23857 000082DC 668B15[E4CA0000]    <1> 	mov	dx, [csftdf_cursorpos]
 23858 000082E3 B402                <1> 	mov	ah, 2
 23859 000082E5 E85E91FFFF          <1> 	call	int10h
 23860 000082EA EBB2                <1> 	jmp	short csftdf2_load_fat_file_next
 23861                              <1> 	
 23862                              <1> csftdf2_load_fat_file_ok:
 23863 000082EC 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 23864 000082F3 0F8668020000        <1>         jna     csftdf2_save_file ; 25/03/2016
 23865                              <1> 	
 23866                              <1> 	; "Reading... 100%"
 23867 000082F9 BF[EDB40000]        <1> 	mov	edi, percentagestr
 23868 000082FE B031                <1> 	mov	al, '1'
 23869 00008300 AA                  <1> 	stosb
 23870 00008301 B030                <1> 	mov	al, '0'
 23871 00008303 AA                  <1> 	stosb
 23872 00008304 AA                  <1> 	stosb
 23873                              <1> 
 23874 00008305 8A1D[E3CA0000]      <1> 	mov	bl, [csftdf_videopage]
 23875 0000830B 668B15[E4CA0000]    <1> 	mov	dx, [csftdf_cursorpos]
 23876 00008312 B402                <1> 	mov	ah, 2
 23877 00008314 E82F91FFFF          <1> 	call	int10h
 23878                              <1> 
 23879 00008319 BE[D5B40000]        <1> 	mov	esi, msg_reading
 23880 0000831E E868BBFFFF          <1> 	call	print_msg
 23881                              <1> 	
 23882 00008323 BE[EDB40000]        <1> 	mov	esi, percentagestr
 23883 00008328 E85EBBFFFF          <1> 	call	print_msg
 23884                              <1> 
 23885 0000832D E92F020000          <1>         jmp     csftdf2_save_file ; 25/03/2016
 23886                              <1> 
 23887                              <1> csftdf2_print_percentage:
 23888                              <1> 	; 19/03/2016
 23889                              <1> 	; 18/03/2016
 23890 00008332 B020                <1> 	mov	al, 20h
 23891 00008334 BF[EDB40000]        <1> 	mov	edi, percentagestr
 23892 00008339 AA                  <1> 	stosb
 23893 0000833A AA                  <1> 	stosb
 23894 0000833B A1[DACA0000]        <1> 	mov	eax, [csftdf_sf_rbytes]
 23895 00008340 BA64000000          <1> 	mov	edx, 100
 23896 00008345 F7E2                <1> 	mul	edx
 23897 00008347 8B0D[BECA0000]      <1> 	mov	ecx, [csftdf_filesize]	
 23898 0000834D F7F1                <1> 	div	ecx
 23899 0000834F B10A                <1> 	mov	cl, 10
 23900 00008351 F6F1                <1> 	div	cl
 23901 00008353 80C430              <1> 	add	ah, '0'
 23902 00008356 8827                <1> 	mov	[edi], ah
 23903 00008358 20C0                <1> 	and	al, al
 23904 0000835A 740A                <1> 	jz	short csftdf2_print_percent_1
 23905 0000835C 4F                  <1> 	dec	edi
 23906 0000835D 6698                <1> 	cbw
 23907 0000835F F6F1                <1> 	div	cl
 23908 00008361 80C430              <1> 	add	ah, '0'
 23909 00008364 8827                <1> 	mov	[edi], ah
 23910                              <1> 	;and	al, al
 23911                              <1> 	;jz	short csftdf2_print_percent_1
 23912                              <1> 	;dec	edi
 23913                              <1> 	;mov	[edi], '1' ; 100%		
 23914                              <1> 
 23915                              <1> csftdf2_print_percent_1:
 23916 00008366 BE[EDB40000]        <1> 	mov	esi, percentagestr
 23917                              <1> 	;call	print_msg
 23918                              <1> 	;retn
 23919 0000836B E91BBBFFFF          <1> 	jmp	print_msg
 23920                              <1> 
 23921                              <1> csftdf2_read_file_sectors:
 23922                              <1> 	; 19/03/2016
 23923 00008370 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 23924 00008374 0F863E070000        <1>         jna     csftdf2_read_fs_file_sectors
 23925                              <1> 
 23926                              <1> csftdf2_read_fat_file_sectors:
 23927                              <1> 	; 19/03/2016
 23928                              <1> 	; 18/03/2016
 23929                              <1> 	; return:
 23930                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
 23931                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
 23932                              <1> 	;   CF = 1 -> read error (error code in AL)	
 23933                              <1> 
 23934                              <1> csftdf2_read_fat_file_secs_0:
 23935 0000837A 8B15[BECA0000]      <1> 	mov	edx, [csftdf_filesize]
 23936 00008380 2B15[DACA0000]      <1> 	sub	edx, [csftdf_sf_rbytes]
 23937 00008386 3B15[D2CA0000]      <1> 	cmp	edx, [csftdf_r_size]	
 23938 0000838C 7306                <1> 	jnb	short csftdf2_read_fat_file_secs_1
 23939 0000838E 8915[D2CA0000]      <1> 	mov	[csftdf_r_size], edx
 23940                              <1> 		
 23941                              <1> csftdf2_read_fat_file_secs_1:
 23942 00008394 A1[D2CA0000]        <1> 	mov	eax, [csftdf_r_size]
 23943 00008399 29D2                <1> 	sub	edx, edx
 23944 0000839B 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
 23945 0000839F 01C8                <1> 	add	eax, ecx
 23946 000083A1 48                  <1> 	dec	eax
 23947 000083A2 F7F1                <1> 	div	ecx
 23948 000083A4 89C1                <1> 	mov	ecx, eax ; sector count
 23949 000083A6 A1[CACA0000]        <1> 	mov	eax, [csftdf_sf_cluster]
 23950                              <1> 
 23951                              <1> 	; EBX = memory block address (current)
 23952                              <1> 	
 23953 000083AB E838090000          <1> 	call	read_fat_file_sectors
 23954 000083B0 7235                <1> 	jc	short csftdf2_read_fat_file_secs_3
 23955                              <1> 
 23956                              <1> 	; EBX = next memory address
 23957                              <1> 
 23958 000083B2 A1[DACA0000]        <1> 	mov	eax, [csftdf_sf_rbytes]
 23959 000083B7 0305[D2CA0000]      <1> 	add	eax, [csftdf_r_size]
 23960 000083BD 8B15[BECA0000]      <1> 	mov	edx, [csftdf_filesize]
 23961 000083C3 39D0                <1> 	cmp	eax, edx
 23962 000083C5 7320                <1> 	jnb	short csftdf2_read_fat_file_secs_3 ; edx > 0
 23963 000083C7 A3[DACA0000]        <1> 	mov	[csftdf_sf_rbytes], eax
 23964                              <1> 
 23965 000083CC 53                  <1> 	push	ebx ; *
 23966                              <1> 	; get next cluster (csftdf_r_size! bytes)
 23967 000083CD A1[CACA0000]        <1> 	mov	eax, [csftdf_sf_cluster]
 23968 000083D2 E8E3060000          <1> 	call	get_next_cluster
 23969 000083D7 5B                  <1> 	pop	ebx ; *
 23970 000083D8 7306                <1> 	jnc	short csftdf2_read_fat_file_secs_2
 23971                              <1> 
 23972 000083DA B815000000          <1> 	mov	eax, 15h ; Read error !
 23973 000083DF C3                  <1> 	retn
 23974                              <1> 
 23975                              <1> csftdf2_read_fat_file_secs_2:
 23976 000083E0 29D2                <1> 	sub	edx, edx ; 0
 23977 000083E2 A3[CACA0000]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
 23978                              <1> 
 23979                              <1> csftdf2_read_fat_file_secs_3:
 23980 000083E7 C3                  <1> 	retn
 23981                              <1> 
 23982                              <1> csftdf2_read_sf_cluster:
 23983                              <1> 	; 19/03/2016
 23984 000083E8 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
 23985                              <1> 
 23986 000083ED 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 23987 000083F4 760D                <1> 	jna	short csftdf2_read_sf_clust_2
 23988                              <1> 
 23989 000083F6 53                  <1> 	push	ebx ; *	
 23990                              <1> 
 23991                              <1> csftdf2_read_sf_clust_next:
 23992 000083F7 E836FFFFFF          <1> 	call	csftdf2_print_percentage
 23993                              <1> 
 23994                              <1> csftdf2_read_sf_clust_0:
 23995 000083FC 8B35[E6CA0000]      <1> 	mov	esi, [csftdf_sf_drv_dt]	
 23996                              <1> csftdf2_read_sf_clust_1:
 23997 00008402 5B                  <1> 	pop	ebx ; *
 23998                              <1> 
 23999                              <1> csftdf2_read_sf_clust_2:
 24000 00008403 89DA                <1> 	mov	edx, ebx
 24001 00008405 0315[D2CA0000]      <1> 	add	edx, [csftdf_r_size]
 24002 0000840B 81FA00000800        <1> 	cmp	edx, Cluster_Buffer + 65536
 24003 00008411 772F                <1> 	ja	short csftdf2_write_df_cluster
 24004                              <1> 
 24005 00008413 E858FFFFFF          <1> 	call	csftdf2_read_file_sectors ; 19/03/2016
 24006 00008418 0F8297020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
 24007                              <1> 
 24008 0000841E 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 24009 00008420 7520                <1> 	jnz	short csftdf2_write_df_cluster
 24010                              <1> 
 24011 00008422 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 24012 00008429 76D8                <1> 	jna	short csftdf2_read_sf_clust_2
 24013                              <1> 
 24014 0000842B 53                  <1> 	push	ebx ; *	
 24015                              <1> 
 24016                              <1> 	; Set cursor position
 24017                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 24018 0000842C 8A1D[E3CA0000]      <1> 	mov	bl, [csftdf_videopage]
 24019 00008432 668B15[E4CA0000]    <1> 	mov	dx, [csftdf_cursorpos]
 24020 00008439 B402                <1> 	mov	ah, 2
 24021 0000843B E80890FFFF          <1> 	call	int10h
 24022 00008440 EBB5                <1> 	jmp	short csftdf2_read_sf_clust_next
 24023                              <1> 
 24024                              <1> csftdf2_write_df_cluster:
 24025                              <1> 	; 19/03/2016
 24026 00008442 8B35[EACA0000]      <1> 	mov	esi, [csftdf_df_drv_dt]	
 24027 00008448 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
 24028                              <1> 
 24029                              <1> csftdf2_write_df_clust_next:
 24030 0000844D E86C000000          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016
 24031 00008452 0F825D020000        <1>         jc      csftdf2_save_fat_file_err2 ; eocc! or disk error! 
 24032                              <1> 
 24033 00008458 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 24034 0000845A 7521                <1> 	jnz	short csftdf2_rw_f_clust_ok
 24035                              <1> 
 24036 0000845C 81FB00000800        <1> 	cmp	ebx, Cluster_Buffer + 65536
 24037 00008462 72E9                <1> 	jb	short csftdf2_write_df_clust_next
 24038                              <1> 
 24039                              <1> 	; 05/04/2016
 24040                              <1> 	; Set cursor position
 24041                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 24042 00008464 8A1D[E3CA0000]      <1> 	mov	bl, [csftdf_videopage]
 24043 0000846A 668B15[E4CA0000]    <1> 	mov	dx, [csftdf_cursorpos]
 24044 00008471 B402                <1> 	mov	ah, 2
 24045 00008473 E8D08FFFFF          <1> 	call	int10h
 24046                              <1> 
 24047 00008478 E96BFFFFFF          <1>         jmp     csftdf2_read_sf_cluster
 24048                              <1>  
 24049                              <1> csftdf2_rw_f_clust_ok:
 24050 0000847D 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 24051 00008484 0F86B2010000        <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
 24052                              <1> 
 24053                              <1> 	; "100%"
 24054 0000848A BF[EDB40000]        <1> 	mov	edi, percentagestr
 24055 0000848F B031                <1> 	mov	al, '1'
 24056 00008491 AA                  <1> 	stosb
 24057 00008492 B030                <1> 	mov	al, '0'
 24058 00008494 AA                  <1> 	stosb
 24059 00008495 AA                  <1> 	stosb
 24060                              <1> 
 24061 00008496 8A1D[E3CA0000]      <1> 	mov	bl, [csftdf_videopage]
 24062 0000849C 668B15[E4CA0000]    <1> 	mov	dx, [csftdf_cursorpos]
 24063 000084A3 B402                <1> 	mov	ah, 2
 24064 000084A5 E89E8FFFFF          <1> 	call	int10h
 24065                              <1> 
 24066 000084AA BE[EDB40000]        <1> 	mov	esi, percentagestr
 24067 000084AF E8D7B9FFFF          <1> 	call	print_msg
 24068                              <1> 
 24069 000084B4 E983010000          <1>         jmp     csftdf2_save_fat_file_4
 24070                              <1> 
 24071                              <1> csftdf2_load_fs_file:
 24072                              <1> 	; temporary - 18/03/2016
 24073 000084B9 E96F020000          <1>         jmp     csftdf2_read_error
 24074                              <1> 
 24075                              <1> csftdf2_write_file_sectors:
 24076                              <1> 	; 19/03/2016
 24077 000084BE 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 24078 000084C2 0F86F1050000        <1>         jna     csftdf2_write_fs_file_sectors
 24079                              <1> 
 24080                              <1> csftdf2_write_fat_file_sectors:
 24081                              <1> 	; 19/03/2016
 24082                              <1> 	; 18/03/2016
 24083                              <1> 	; return:
 24084                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
 24085                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
 24086                              <1> 	;   CF = 1 -> write error (error code in AL)	
 24087                              <1> 
 24088                              <1> csftdf2_write_fat_file_secs_0:
 24089 000084C8 8B15[BECA0000]      <1> 	mov	edx, [csftdf_filesize]
 24090 000084CE 2B15[DECA0000]      <1> 	sub	edx, [csftdf_df_wbytes]
 24091 000084D4 3B15[D6CA0000]      <1> 	cmp	edx, [csftdf_w_size]	
 24092 000084DA 7306                <1> 	jnb	short csftdf2_write_fat_file_secs_1
 24093 000084DC 8915[D6CA0000]      <1> 	mov	[csftdf_w_size], edx		
 24094                              <1> 
 24095                              <1> csftdf2_write_fat_file_secs_1:
 24096 000084E2 A1[D6CA0000]        <1> 	mov	eax, [csftdf_w_size]
 24097 000084E7 29D2                <1> 	sub	edx, edx
 24098 000084E9 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
 24099 000084ED 01C8                <1> 	add	eax, ecx
 24100 000084EF 48                  <1> 	dec	eax
 24101 000084F0 F7F1                <1> 	div	ecx
 24102 000084F2 89C1                <1> 	mov	ecx, eax ; sector count
 24103 000084F4 A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster]
 24104                              <1> 
 24105                              <1> 	; EBX = memory block address (current)	
 24106                              <1> 
 24107 000084F9 E8A10F0000          <1> 	call	write_fat_file_sectors
 24108 000084FE 7259                <1> 	jc	short csftdf2_write_fat_file_secs_4
 24109                              <1> 
 24110                              <1> 	; EBX = next memory address
 24111                              <1> 
 24112 00008500 A1[DECA0000]        <1> 	mov	eax, [csftdf_df_wbytes]
 24113 00008505 0305[D6CA0000]      <1> 	add	eax, [csftdf_w_size]
 24114 0000850B 8B15[BECA0000]      <1> 	mov	edx, [csftdf_filesize]
 24115 00008511 39D0                <1> 	cmp	eax, edx
 24116 00008513 7344                <1> 	jnb	short csftdf2_write_fat_file_secs_4
 24117 00008515 A3[DECA0000]        <1> 	mov	[csftdf_df_wbytes], eax
 24118                              <1> 	;
 24119 0000851A A3[82CA0000]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
 24120                              <1> 
 24121 0000851F 53                  <1> 	push	ebx ; *
 24122                              <1> 
 24123 00008520 803D[BCCA0000]01    <1> 	cmp	byte [DestinationFileFound], 1
 24124 00008527 7210                <1> 	jb	short csftdf2_write_fat_file_secs_2
 24125                              <1> 
 24126                              <1> 	; get next cluster (csftdf_w_size! bytes)
 24127 00008529 A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster]
 24128 0000852E E887050000          <1> 	call	get_next_cluster
 24129 00008533 731C                <1> 	jnc	short csftdf2_write_fat_file_secs_3
 24130                              <1> 
 24131 00008535 21C0                <1> 	and	eax, eax ; end of cluster chain!?
 24132 00008537 7521                <1> 	jnz	short csftdf2_write_fat_file_secs_5 ; disk error !
 24133                              <1> 
 24134                              <1> csftdf2_write_fat_file_secs_2:
 24135 00008539 A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
 24136 0000853E E8700E0000          <1> 	call	add_new_cluster		
 24137 00008543 7215                <1> 	jc	short csftdf2_write_fat_file_secs_5
 24138                              <1> 
 24139                              <1> 	; NOTE: Destination file size may be bigger than
 24140                              <1> 	; source file size when the last reading fails after here.
 24141                              <1> 	; (The last -empty- cluster of destination file must be 
 24142                              <1> 	; truncated and LMDT must be current date&time for partial
 24143                              <1> 	; copy result!) 
 24144 00008545 8B15[D6CA0000]      <1> 	mov	edx, [csftdf_w_size] ; bytes per cluster
 24145 0000854B 0115[82CA0000]      <1> 	add	[DestinationFile_DirEntry+DirEntry_FileSize], edx
 24146                              <1> 
 24147                              <1> csftdf2_write_fat_file_secs_3:
 24148 00008551 5B                  <1> 	pop	ebx ; *
 24149 00008552 29D2                <1> 	sub	edx, edx ; 0
 24150 00008554 A3[CECA0000]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
 24151                              <1> 
 24152                              <1> csftdf2_write_fat_file_secs_4:
 24153 00008559 C3                  <1> 	retn
 24154                              <1> 
 24155                              <1> csftdf2_write_fat_file_secs_5:
 24156 0000855A 5B                  <1> 	pop	ebx ; *
 24157 0000855B B81D000000          <1> 	mov	eax, 1Dh ; Write error !
 24158 00008560 C3                  <1> 	retn
 24159                              <1> 
 24160                              <1> csftdf2_save_file:
 24161                              <1> 	; 25/03/2016
 24162                              <1> 	; 19/03/2016
 24163                              <1> 	; 18/03/2016
 24164 00008561 8B35[EACA0000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; logical dos drv desc. tbl.
 24165                              <1> 
 24166 00008567 8B1D[C2CA0000]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
 24167                              <1> 
 24168 0000856D 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 24169 00008571 0F86F4010000        <1>         jna     csftdf2_save_fs_file
 24170                              <1> 
 24171                              <1> csftdf2_save_fat_file:
 24172 00008577 53                  <1> 	push	ebx; *
 24173                              <1> 
 24174 00008578 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 24175 0000857F 7724                <1> 	ja	short csftdf2_save_fat_file_0
 24176                              <1> 
 24177                              <1> 	; Set cursor position
 24178                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 24179 00008581 8A1D[E3CA0000]      <1> 	mov	bl, [csftdf_videopage]
 24180 00008587 668B15[E4CA0000]    <1> 	mov	dx, [csftdf_cursorpos]
 24181 0000858E B402                <1> 	mov	ah, 2
 24182 00008590 E8B38EFFFF          <1> 	call	int10h
 24183                              <1> 	
 24184 00008595 BE[E1B40000]        <1> 	mov	esi, msg_writing
 24185 0000859A E8ECB8FFFF          <1> 	call	print_msg
 24186                              <1> 
 24187                              <1> csftdf2_save_fat_file_next:
 24188 0000859F 8B35[EACA0000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 25/03/2016
 24189                              <1> 
 24190                              <1> csftdf2_save_fat_file_0:
 24191 000085A5 5B                  <1> 	pop	ebx ; *
 24192                              <1> 
 24193                              <1> csftdf2_save_fat_file_1:
 24194 000085A6 E813FFFFFF          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016	
 24195 000085AB 0F827E010000        <1>         jc      csftdf2_rw_error ; eocc! or disk error! 
 24196                              <1> 
 24197 000085B1 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
 24198 000085B3 756D                <1>         jnz     short csftdf2_save_fat_file_3 ; 25/03/2016
 24199                              <1> 
 24200 000085B5 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 24201 000085BC 76E8                <1> 	jna	short csftdf2_save_fat_file_1
 24202                              <1> 
 24203 000085BE B020                <1> 	mov	al, 20h
 24204 000085C0 BF[EDB40000]        <1> 	mov	edi, percentagestr
 24205 000085C5 AA                  <1> 	stosb
 24206 000085C6 AA                  <1> 	stosb
 24207 000085C7 A1[DECA0000]        <1> 	mov	eax, [csftdf_df_wbytes]
 24208 000085CC BA64000000          <1> 	mov	edx, 100
 24209 000085D1 F7E2                <1> 	mul	edx
 24210 000085D3 8B0D[BECA0000]      <1> 	mov	ecx, [csftdf_filesize]	
 24211 000085D9 F7F1                <1> 	div	ecx
 24212 000085DB B10A                <1> 	mov	cl, 10
 24213 000085DD F6F1                <1> 	div	cl
 24214 000085DF 80C430              <1> 	add	ah, '0'
 24215 000085E2 8827                <1> 	mov	[edi], ah
 24216 000085E4 20C0                <1> 	and	al, al
 24217 000085E6 740A                <1> 	jz	short csftdf2_save_fat_file_2
 24218 000085E8 4F                  <1> 	dec	edi
 24219 000085E9 6698                <1> 	cbw
 24220 000085EB F6F1                <1> 	div	cl
 24221 000085ED 80C430              <1> 	add	ah, '0'
 24222 000085F0 8827                <1> 	mov	[edi], ah
 24223                              <1> 	;and	al, al
 24224                              <1> 	;jz	short csftdf2_save_fat_file_2
 24225                              <1> 	;dec	edi
 24226                              <1> 	;mov	[edi], '1' ; 100%		
 24227                              <1> 
 24228                              <1> csftdf2_save_fat_file_2:
 24229 000085F2 53                  <1> 	push	ebx ; *
 24230                              <1> 
 24231 000085F3 E802000000          <1> 	call	csftdf2_print_wr_percentage ; 25/03/2016
 24232                              <1> 
 24233 000085F8 EBA5                <1>         jmp     csftdf2_save_fat_file_next
 24234                              <1> 
 24235                              <1> csftdf2_print_wr_percentage:
 24236                              <1> 	; Set cursor position
 24237                              <1> 	; AH= 02h, BL= Page Number, DH= Row, DL= Column
 24238 000085FA 8A1D[E3CA0000]      <1> 	mov	bl, [csftdf_videopage]
 24239 00008600 668B15[E4CA0000]    <1> 	mov	dx, [csftdf_cursorpos]
 24240 00008607 B402                <1> 	mov	ah, 2
 24241 00008609 E83A8EFFFF          <1> 	call	int10h
 24242                              <1> 
 24243 0000860E BE[E1B40000]        <1> 	mov	esi, msg_writing
 24244 00008613 E873B8FFFF          <1> 	call	print_msg
 24245                              <1> 
 24246 00008618 BE[EDB40000]        <1> 	mov	esi, percentagestr
 24247                              <1> 	;call	print_msg
 24248                              <1> 	;retn
 24249 0000861D E969B8FFFF          <1> 	jmp	print_msg
 24250                              <1> 
 24251                              <1> csftdf2_save_fat_file_3:
 24252 00008622 803D[E2CA0000]00    <1> 	cmp	byte [csftdf_percentage], 0
 24253 00008629 7611                <1>         jna     csftdf2_save_fat_file_4 ; 25/03/2016
 24254                              <1> 
 24255                              <1> 	; "100%"
 24256 0000862B BF[EDB40000]        <1> 	mov	edi, percentagestr
 24257 00008630 B031                <1> 	mov	al, '1'
 24258 00008632 AA                  <1> 	stosb
 24259 00008633 B030                <1> 	mov	al, '0'
 24260 00008635 AA                  <1> 	stosb
 24261 00008636 AA                  <1> 	stosb
 24262                              <1> 
 24263 00008637 E8BEFFFFFF          <1> 	call	csftdf2_print_wr_percentage
 24264                              <1> 
 24265                              <1> csftdf2_save_fat_file_4:
 24266 0000863C 803D[BCCA0000]00    <1> 	cmp	byte [DestinationFileFound], 0
 24267 00008643 7647                <1> 	jna	short csftdf2_save_fat_file_6
 24268                              <1> 
 24269 00008645 8B35[EACA0000]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 31/03/2016	
 24270                              <1> 
 24271 0000864B A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
 24272 00008650 E865040000          <1> 	call	get_next_cluster
 24273 00008655 7235                <1> 	jc	short csftdf2_save_fat_file_6 ; eocc! or disk error!
 24274                              <1> 
 24275 00008657 A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
 24276                              <1> 	;xor	ecx, ecx
 24277                              <1> 	;mov	[FAT_ClusterCounter], ecx ; 0 ; reset
 24278                              <1> 	;dec	ecx ; 0FFFFFFFFh
 24279                              <1> 	;shr	ecx, 4 ; 28 bit ; 0FFFFFFFh
 24280 0000865C B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
 24281 00008661 E87E070000          <1> 	call	update_cluster
 24282 00008666 7224                <1> 	jc	short csftdf2_save_fat_file_6 ; really last cluster!?
 24283                              <1> 
 24284 00008668 A3[CECA0000]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
 24285                              <1> 	
 24286                              <1> 	; byte [FAT_BuffValidData] = 2 
 24287 0000866D E82F0A0000          <1> 	call	save_fat_buffer
 24288 00008672 730E                <1> 	jnc	short csftdf2_save_fat_file_5
 24289                              <1> 	
 24290 00008674 8B15[BECA0000]      <1> 	mov	edx, [csftdf_filesize]
 24291 0000867A 8915[82CA0000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
 24292 00008680 EB58                <1> 	jmp	short csftdf2_save_fat_file_err3
 24293                              <1> 
 24294                              <1> csftdf2_save_fat_file_5:
 24295 00008682 A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster]
 24296                              <1> 
 24297                              <1> 	; EAX = First cluster to be truncated/unlinked
 24298                              <1> 	; ESI = Logical dos drive description table address
 24299 00008687 E8480C0000          <1> 	call	truncate_cluster_chain
 24300                              <1> 
 24301                              <1> csftdf2_save_fat_file_6:
 24302                              <1> 	; 28/03/2016
 24303 0000868C BE[F1C90000]        <1> 	mov	esi, SourceFile_DirEntry+DirEntry_Attr ; +11 to + 18
 24304 00008691 BF[71CA0000]        <1> 	mov	edi, DestinationFile_DirEntry+DirEntry_Attr ; +11 to + 18
 24305 00008696 A4                  <1> 	movsb ; +11
 24306 00008697 A5                  <1> 	movsd ; +12 .. +15
 24307 00008698 66A5                <1> 	movsw ; +16 .. +17
 24308                              <1> 		; + 18
 24309 0000869A 83C604              <1> 	add	esi, 4
 24310 0000869D 83C704              <1> 	add	edi, 4
 24311 000086A0 A5                  <1> 	movsd	; DirEntry_WrtTime ; +22 .. +25
 24312                              <1> 
 24313 000086A1 8B15[BECA0000]      <1> 	mov	edx, [csftdf_filesize]
 24314 000086A7 8915[82CA0000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
 24315                              <1> 
 24316 000086AD E8C0F0FFFF          <1> 	call	convert_current_date_time
 24317                              <1> 	; DX = Date in dos dir entry format
 24318                              <1> 	; AX = Time in dos dir entry format
 24319 000086B2 EB4D                <1> 	jmp	short csftdf2_save_fat_file_7
 24320                              <1> 
 24321                              <1> csftdf2_save_fat_file_err1:
 24322 000086B4 5B                  <1> 	pop	ebx ; *	
 24323                              <1> csftdf2_save_fat_file_err2:
 24324 000086B5 A1[DECA0000]        <1> 	mov	eax, [csftdf_df_wbytes]
 24325 000086BA 8B15[82CA0000]      <1> 	mov	edx, [DestinationFile_DirEntry+DirEntry_FileSize]
 24326 000086C0 39C2                <1> 	cmp	edx, eax
 24327 000086C2 7616                <1> 	jna	short csftdf2_save_fat_file_err3
 24328 000086C4 A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster] ; last (empty) cluster
 24329                              <1> 	; ESI = Logical dos drive description table address
 24330 000086C9 E8060C0000          <1> 	call	truncate_cluster_chain
 24331 000086CE 720A                <1> 	jc	short csftdf2_save_fat_file_err3
 24332 000086D0 A1[DECA0000]        <1> 	mov	eax, [csftdf_df_wbytes]	
 24333 000086D5 A3[82CA0000]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
 24334                              <1> csftdf2_save_fat_file_err3:
 24335 000086DA E893F0FFFF          <1> 	call	convert_current_date_time
 24336                              <1> 	; DX = Date in dos dir entry format
 24337                              <1> 	; AX = Time in dos dir entry format
 24338 000086DF C605[73CA0000]00    <1> 	mov	byte [DestinationFile_DirEntry+DirEntry_CrtTimeTenth], 0
 24339 000086E6 66A3[74CA0000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtTime], ax
 24340 000086EC 668915[76CA0000]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtDate], dx		
 24341 000086F3 66A3[7CCA0000]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtTime], ax
 24342 000086F9 668915[7ECA0000]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtDate], dx
 24343 00008700 F9                  <1> 	stc
 24344                              <1> csftdf2_save_fat_file_7:
 24345 00008701 9C                  <1> 	pushf
 24346 00008702 668915[78CA0000]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_LastAccDate], dx
 24347 00008709 BE[66CA0000]        <1> 	mov	esi, DestinationFile_DirEntry
 24348 0000870E BF00000800          <1> 	mov	edi, Directory_Buffer
 24349 00008713 0FB70D[8ECA0000]    <1> 	movzx	ecx, word [DestinationFile_DirEntryNumber] ; (<2048)
 24350 0000871A 66C1E105            <1> 	shl	cx, 5 ; 32 * directory entry number
 24351 0000871E 01CF                <1> 	add	edi, ecx
 24352                              <1> 	;mov	ecx, 8
 24353 00008720 66B90800            <1> 	mov	cx, 8
 24354 00008724 F3A5                <1> 	rep	movsd
 24355 00008726 9D                  <1> 	popf
 24356 00008727 730B                <1> 	jnc	short csftdf2_write_file_OK
 24357                              <1> 	 		
 24358                              <1> csftdf2_write_error:
 24359                              <1> 	; 18/03/2016
 24360 00008729 B01D                <1> 	mov	al, 1Dh ; write error
 24361 0000872B EB02                <1> 	jmp	short csftdf2_rw_error
 24362                              <1> 
 24363                              <1> 	; 16/03/2016
 24364                              <1> csftdf2_read_error:
 24365 0000872D B015                <1> 	mov	al, 15h ; ; Drive not ready or read error!
 24366                              <1> csftdf2_rw_error:
 24367 0000872F A2[BBCA0000]        <1> 	mov	[csftdf_rw_err], al 
 24368                              <1> 
 24369                              <1> csftdf2_write_file_OK:
 24370                              <1> 	; 18/03/2016
 24371 00008734 C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 24372 0000873B E8D0F0FFFF          <1> 	call	save_directory_buffer
 24373                              <1> 
 24374                              <1>  	; Update last modification date&time of destination
 24375                              <1> 	; file's (parent) directory
 24376 00008740 E866F1FFFF          <1> 	call	update_parent_dir_lmdt
 24377                              <1> 	;
 24378 00008745 A1[C2CA0000]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
 24379                              <1> 
 24380 0000874A 21C0                <1> 	and	eax, eax
 24381 0000874C 750E                <1> 	jnz	short csftdf2_dealloc_mblock
 24382                              <1> 
 24383 0000874E 88C5                <1> 	mov	ch, al ; 0 (Cluster r/w, not full loading)
 24384                              <1> csftdf2_dealloc_retn:
 24385 00008750 8A0D[BBCA0000]      <1> 	mov	cl, [csftdf_rw_err]
 24386 00008756 A1[CECA0000]        <1> 	mov	eax, [csftdf_df_cluster]
 24387 0000875B C3                  <1> 	retn
 24388                              <1> 
 24389                              <1> csftdf2_dealloc_mblock:
 24390 0000875C 8B0D[C6CA0000]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size	
 24391 00008762 E85BB3FFFF          <1> 	call	deallocate_memory_block
 24392 00008767 B5FF                <1>         mov     ch, 0FFh ; (File was full loaded at memory)
 24393 00008769 EBE5                <1> 	jmp	short csftdf2_dealloc_retn
 24394                              <1> 
 24395                              <1> csftdf2_save_fs_file:
 24396                              <1> 	; temporary - (21/03/2016)
 24397 0000876B B81D000000          <1> 	mov	eax, 1Dh ; write error
 24398 00008770 F9                  <1> 	stc
 24399 00008771 C3                  <1> 	retn
 24400                              <1> 
 24401                              <1> create_file:
 24402                              <1> 	; 31/03/2016
 24403                              <1> 	; 24/03/2016
 24404                              <1> 	; 23/03/2016
 24405                              <1> 	; 21/03/2016
 24406                              <1> 	; 20/03/2016
 24407                              <1> 	; 19/03/2016 (TRDOS 396 = TRDOS v2.0)
 24408                              <1> 	; 03/09/2011 (FILE.ASM, 'proc_create_file')
 24409                              <1> 	; 09/08/2010
 24410                              <1> 	;
 24411                              <1> 	; INPUT ->
 24412                              <1> 	; 	EAX = File Size
 24413                              <1> 	; 	ESI = ASCIIZ File Name
 24414                              <1> 	; 	CL = File Attributes 
 24415                              <1> 	;	EBX = FFFFFFFFh -> create empty file 
 24416                              <1> 	;			 (only for FAT fs) 
 24417                              <1> 	; OUTPUT ->
 24418                              <1> 	;     CF = 0 ->
 24419                              <1> 	;	EAX = New file's first cluster
 24420                              <1> 	; 	ESI = Logical Dos Drv Descr. Table Addr.
 24421                              <1> 	; 	EBX = offset CreateFile_Size
 24422                              <1> 	; 	ECX = Sectors per cluster (<256) 
 24423                              <1> 	; 	EDX = Directory entry index/number (<65536)
 24424                              <1> 	;     CF = 1 -> error code in AL
 24425                              <1> 
 24426                              <1> ;	test	cl, 18h (directory or volume name)
 24427                              <1> ;	jnz	short loc_createfile_access_denied
 24428 00008772 80E107              <1> 	and	cl, 07h ; S, H, R
 24429 00008775 880D[0ACB0000]      <1>         mov     [createfile_attrib], cl 
 24430                              <1> 
 24431 0000877B 89D9                <1> 	mov	ecx, ebx
 24432 0000877D 89F3                <1> 	mov	ebx, esi ; ASCIIZ File Name address
 24433 0000877F 29D2                <1> 	sub	edx, edx
 24434 00008781 8A35[AEBE0000]      <1>         mov     dh, [Current_Drv]
 24435 00008787 BE00010900          <1>         mov     esi, Logical_DOSDisks
 24436 0000878C 01D6                <1> 	add	esi, edx
 24437                              <1> 
 24438 0000878E 8815[15CB0000]      <1> 	mov	[createfile_UpdatePDir], dl ; 0 ; 31/03/2016 
 24439                              <1> 
 24440                              <1> 	; LD_DiskType = 0 for write protection (read only) 
 24441 00008794 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
 24442 00008798 730A                <1> 	jnb	short loc_createfile_check_file_sytem
 24443 0000879A B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected 
 24444 0000879F 66BA0000            <1> 	mov	dx, 0
 24445                              <1> 	; err retn: EDX = 0, EBX = File name offset
 24446                              <1> 	; ESI -> Dos drive description table address	
 24447 000087A3 C3                  <1> 	retn
 24448                              <1> 
 24449                              <1> ;loc_createfile_access_denied:
 24450                              <1> ;	mov	eax, 05h ; access denied (invalid attributes input)
 24451                              <1> ;	stc
 24452                              <1> ;	retn
 24453                              <1> 
 24454                              <1> loc_createfile_check_file_sytem:
 24455 000087A4 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 24456 000087A8 730A                <1> 	jnb	short loc_createfile_chk_empty_FAT_file_sign1
 24457                              <1> 
 24458 000087AA A3[F6CA0000]        <1> 	mov	[createfile_size], eax
 24459                              <1> 	; ESI = Logical Dos Drive Description Table address
 24460                              <1> 	; EBX = ASCIIZ File Name address
 24461 000087AF E9FE020000          <1> 	jmp	create_fs_file
 24462                              <1> 
 24463                              <1> loc_createfile_chk_empty_FAT_file_sign1:
 24464                              <1> 	; ECX = FFFFFFFFh -> create empty file if drive has FAT fs
 24465 000087B4 41                  <1> 	inc	ecx
 24466 000087B5 7506                <1> 	jnz	short loc_createfile_chk_empty_FAT_file_sign2
 24467 000087B7 890D[F6CA0000]      <1> 	mov	[createfile_size], ecx ; 0 ; empty file
 24468                              <1> 
 24469                              <1> loc_createfile_chk_empty_FAT_file_sign2:
 24470                              <1> 	; 23/03/2016
 24471 000087BD 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec]
 24472 000087C1 66890D[12CB0000]    <1> 	mov	[createfile_BytesPerSec], cx
 24473                              <1> 	
 24474                              <1> 	; EBX = ASCIIZ File Name address
 24475 000087C8 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
 24476 000087CC 8815[0BCB0000]      <1> 	mov	[createfile_SecPerClust], dl
 24477 000087D2 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
 24478 000087D5 39D1                <1> 	cmp	ecx, edx ; byte [createfile_SecPerClust]
 24479 000087D7 7306                <1> 	jnb	short loc_create_fat_file
 24480                              <1> 	  
 24481                              <1> loc_createfile_insufficient_disk_space:
 24482 000087D9 B827000000          <1> 	mov	eax, 27h
 24483                              <1> loc_createfile_gffc_retn:
 24484 000087DE C3                  <1> 	retn
 24485                              <1> 
 24486                              <1> loc_create_fat_file:
 24487 000087DF 891D[EECA0000]      <1> 	mov	[createfile_Name_Offset], ebx
 24488 000087E5 890D[F2CA0000]      <1> 	mov	[createfile_FreeSectors], ecx
 24489                              <1> 
 24490                              <1> loc_createfile_gffc_1:
 24491 000087EB E821050000          <1> 	call	get_first_free_cluster
 24492 000087F0 72EC                <1> 	jc	short loc_createfile_gffc_retn
 24493                              <1> 
 24494 000087F2 A3[FACA0000]        <1> 	mov	[createfile_FFCluster], eax
 24495                              <1> 
 24496                              <1> loc_createfile_locate_ffe_on_directory:
 24497                              <1> 	; Current directory fcluster <> Directory buffer cluster
 24498                              <1> 	; Current directory will be reloaded by
 24499                              <1> 	; 'locate_current_dir_file' procedure
 24500                              <1> 	;
 24501                              <1> 	; ESI = Logical Dos Drv Desc. Table Adress
 24502 000087F7 56                  <1> 	push	esi ; *
 24503 000087F8 31C0                <1> 	xor	eax, eax
 24504                              <1> 
 24505 000087FA A3[CDC60000]        <1> 	mov	dword [FAT_ClusterCounter], eax ; 0
 24506                              <1> 	; 21/03/2016
 24507 000087FF A2[14CB0000]        <1> 	mov	byte [createfile_wfc], al ; 0 
 24508                              <1> 
 24509 00008804 89C1                <1>  	mov	ecx, eax
 24510 00008806 6649                <1> 	dec	cx ; FFFFh  
 24511                              <1> 	; CX = FFFFh -> find first deleted or free entry
 24512                              <1> 	; ESI would be ASCIIZ filename Address if the call
 24513                              <1> 	; would not be for first free or deleted dir entry  
 24514 00008808 E8DFE7FFFF          <1> 	call	locate_current_dir_file
 24515 0000880D 0F83EE000000        <1> 	jnc	loc_createfile_set_ff_dir_entry
 24516 00008813 5E                  <1> 	pop	esi ; *
 24517                              <1> 	 ; ESI = Logical DOS Drv. Description Table Address 
 24518 00008814 83F802              <1> 	cmp	eax, 2
 24519 00008817 7402                <1> 	je	short loc_createfile_add_new_cluster
 24520                              <1> loc_createfile_locate_file_stc_retn:
 24521 00008819 F9                  <1> 	stc
 24522 0000881A C3                  <1> 	retn
 24523                              <1> 
 24524                              <1> loc_createfile_add_new_cluster:
 24525 0000881B 803D[ADBE0000]02    <1> 	cmp	byte [Current_FATType], 2
 24526                              <1> 	;cmp	byte [esi+LD_FATType], 2
 24527 00008822 770C                <1> 	ja	short loc_createfile_add_new_cluster_check_fsc
 24528 00008824 803D[ACBE0000]01    <1> 	cmp	byte [Current_Dir_Level], 1
 24529                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
 24530 0000882B 7303                <1> 	jnb	short loc_createfile_add_new_cluster_check_fsc
 24531                              <1> 	
 24532                              <1> 	;mov	eax, 12
 24533 0000882D B00C                <1> 	mov	al, 12 ; No more files 
 24534                              <1> 
 24535                              <1> loc_createfile_anc_retn:
 24536 0000882F C3                  <1> 	retn
 24537                              <1> 
 24538                              <1> loc_createfile_add_new_cluster_check_fsc:
 24539 00008830 8B0D[F2CA0000]      <1> 	mov	ecx, [createfile_FreeSectors]
 24540 00008836 0FB605[0BCB0000]    <1> 	movzx	eax, byte [createfile_SecPerClust]
 24541 0000883D 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
 24542 00008840 39C1                <1> 	cmp	ecx, eax
 24543 00008842 7295                <1>         jb	short loc_createfile_insufficient_disk_space
 24544                              <1> 
 24545                              <1> loc_createfile_add_new_subdir_cluster:
 24546 00008844 8B15[DDC60000]      <1> 	mov	edx, [DirBuff_Cluster]
 24547 0000884A 8915[FECA0000]      <1> 	mov	[createfile_LastDirCluster], edx	
 24548                              <1> 
 24549 00008850 A1[FACA0000]        <1> 	mov	eax, [createfile_FFCluster]
 24550 00008855 E846040000          <1> 	call	load_FAT_sub_directory 
 24551 0000885A 72D3                <1> 	jc	short loc_createfile_anc_retn
 24552                              <1> 
 24553                              <1> pass_createfile_add_new_subdir_cluster:
 24554                              <1> 	;movzx	eax, word [esi+LD_BPB+BytesPerSec]
 24555 0000885C 0FB705[12CB0000]    <1> 	movzx	eax, word [createfile_BytesPerSec] ; 23/03/2016
 24556 00008863 F7E1                <1> 	mul	ecx ; ecx = directory buffer sector count
 24557 00008865 89C1                <1> 	mov	ecx, eax
 24558 00008867 C1E902              <1> 	shr	ecx, 2 ; dword count
 24559 0000886A 29C0                <1> 	sub	eax, eax ; 0
 24560 0000886C F3AB                <1> 	rep	stosd 
 24561                              <1> 	;
 24562 0000886E C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2 
 24563 00008875 E896EFFFFF          <1> 	call	save_directory_buffer
 24564 0000887A 72B3                <1> 	jc	short loc_createfile_anc_retn
 24565                              <1> 
 24566                              <1> loc_createfile_save_added_subdir_cluster:
 24567 0000887C A1[FECA0000]        <1> 	mov	eax, [createfile_LastDirCluster]
 24568 00008881 8B0D[FACA0000]      <1> 	mov	ecx, [createfile_FFCluster]
 24569 00008887 E858050000          <1> 	call	update_cluster
 24570 0000888C 7304                <1> 	jnc	short loc_createfile_save_fat_buffer_0
 24571 0000888E 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 24572 00008890 751A                <1> 	jnz	short loc_createfile_save_fat_buffer_stc_retn
 24573                              <1> 
 24574                              <1> loc_createfile_save_fat_buffer_0:
 24575 00008892 A1[FACA0000]        <1> 	mov	eax, [createfile_FFCluster]
 24576 00008897 A3[FECA0000]        <1> 	mov	[createfile_LastDirCluster], eax
 24577 0000889C B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh ; 28 bit
 24578 000088A1 E83E050000          <1> 	call	update_cluster
 24579 000088A6 7306                <1> 	jnc	short loc_createfile_save_fat_buffer_1
 24580 000088A8 09C0                <1> 	or	eax, eax ; Was it free cluster
 24581 000088AA 7402                <1> 	jz	short loc_createfile_save_fat_buffer_1
 24582                              <1> 
 24583                              <1> loc_createfile_save_fat_buffer_stc_retn:
 24584 000088AC F9                  <1> 	stc
 24585                              <1> loc_createfile_save_fat_buffer_retn:
 24586                              <1> loc_createfile_gffc_2_stc_retn:
 24587 000088AD C3                  <1> 	retn
 24588                              <1> 
 24589                              <1> loc_createfile_save_fat_buffer_1:
 24590                              <1> 	; byte [FAT_BuffValidData] = 2 
 24591 000088AE E8EE070000          <1> 	call	save_fat_buffer
 24592 000088B3 72F8                <1> 	jc	short loc_createfile_save_fat_buffer_retn
 24593                              <1> 
 24594 000088B5 803D[CDC60000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 24595 000088BC 7222                <1> 	jb	short loc_createfile_save_fat_buffer_2
 24596                              <1> 
 24597                              <1> 	; ESI = Logical DOS Drive Description Table address 
 24598 000088BE A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 24599                              <1> 
 24600 000088C3 C605[CDC60000]00    <1> 	mov	byte [FAT_ClusterCounter], 0 ; 21/03/2016
 24601                              <1> 
 24602 000088CA 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 24603 000088CE E863080000          <1> 	call	calculate_fat_freespace
 24604                              <1> 
 24605                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 24606                              <1> 	;jnz	short loc_createfile_save_fat_buffer_2
 24607                              <1> 
 24608                              <1> 	; ecx > 0 -> Recalculation is needed
 24609 000088D3 09C9                <1> 	or	ecx, ecx 
 24610 000088D5 7409                <1> 	jz	short loc_createfile_save_fat_buffer_2
 24611                              <1> 
 24612 000088D7 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
 24613 000088DB E856080000          <1> 	call	calculate_fat_freespace
 24614                              <1> 
 24615                              <1> loc_createfile_save_fat_buffer_2:
 24616                              <1> 	;call	update_parent_dir_lmdt
 24617                              <1> 
 24618                              <1> loc_createfile_gffc_2:
 24619 000088E0 E82C040000          <1> 	call	get_first_free_cluster
 24620 000088E5 72C6                <1> 	jc	short loc_createfile_gffc_2_stc_retn
 24621                              <1> 
 24622 000088E7 A3[FACA0000]        <1> 	mov	[createfile_FFCluster], eax
 24623                              <1> 
 24624 000088EC A1[FECA0000]        <1> 	mov	eax, [createfile_LastDirCluster]
 24625                              <1> 	
 24626 000088F1 E8AA030000          <1> 	call	load_FAT_sub_directory 
 24627 000088F6 72B5                <1> 	jc	short loc_createfile_gffc_2_stc_retn
 24628                              <1> 
 24629 000088F8 BF00000800          <1> 	mov	edi, Directory_Buffer
 24630                              <1> 
 24631 000088FD 6629DB              <1> 	sub	bx, bx ; directory entry index/number = 0
 24632                              <1> 
 24633 00008900 56                  <1> 	push	esi ; * ; 23/03/2016
 24634                              <1> 
 24635                              <1> loc_createfile_set_ff_dir_entry:
 24636 00008901 66891D[0CCB0000]    <1> 	mov	[createfile_DirIndex], bx
 24637                              <1> 
 24638                              <1>         ; EDI = Directory entry address
 24639 00008908 8B35[EECA0000]      <1> 	mov	esi, [createfile_Name_Offset]
 24640 0000890E A1[FACA0000]        <1> 	mov	eax, [createfile_FFCluster]
 24641 00008913 A3[02CB0000]        <1> 	mov	[createfile_Cluster], eax ; 24/03/2016
 24642 00008918 B5FF                <1> 	mov	ch, 0FFh
 24643 0000891A 8A0D[0ACB0000]      <1>         mov	cl, [createfile_attrib] ; file attributes
 24644                              <1> 	; CH > 0 -> File size is in EBX
 24645 00008920 BB[F6CA0000]        <1> 	mov	ebx, createfile_size
 24646                              <1>   
 24647 00008925 E809EEFFFF          <1> 	call	make_directory_entry
 24648                              <1> 	
 24649 0000892A 5E                  <1> 	pop	esi ; * ; ESI = Logical Dos Drv Desc. Table address
 24650                              <1> 
 24651 0000892B C605[D8C60000]02    <1> 	mov	byte [DirBuff_ValidData], 2 
 24652 00008932 E8D9EEFFFF          <1> 	call	save_directory_buffer
 24653 00008937 7221                <1> 	jc	short loc_createfile_set_ff_dir_entry_retn
 24654                              <1> 
 24655 00008939 C605[15CB0000]01    <1> 	mov	byte [createfile_UpdatePDir], 1 ; 31/03/2016 
 24656                              <1> 
 24657                              <1> loc_createfile_get_set_write_file_cluster:
 24658 00008940 A1[F6CA0000]        <1> 	mov	eax, [createfile_size]
 24659 00008945 09C0                <1> 	or	eax, eax
 24660 00008947 7570                <1> 	jnz	short loc_createfile_get_set_wfc_cont
 24661 00008949 40                  <1> 	inc	eax
 24662                              <1> 	; 23/03/2016
 24663 0000894A 0FB61D[0BCB0000]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
 24664                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512
 24665 00008951 0FB70D[12CB0000]    <1>         movzx   ecx, word [createfile_BytesPerSec] ; 512
 24666 00008958 EB7C                <1> 	jmp	loc_createfile_set_cluster_count 
 24667                              <1> 
 24668                              <1> loc_createfile_set_ff_dir_entry_retn:
 24669 0000895A C3                  <1> 	retn
 24670                              <1> 
 24671                              <1> loc_createfile_write_fcluster_to_disk:
 24672 0000895B 034668              <1> 	add	eax, [esi+LD_DATABegin] ; convert to physical address
 24673 0000895E BB00000700          <1> 	mov	ebx, Cluster_Buffer
 24674                              <1> 	; ESI = Logical DOS Drv. Desc. Tbl. address
 24675                              <1> 	; EAX = Disk address
 24676                              <1> 	; EBX = Sector Buffer
 24677                              <1> 	; ECX = sectors per cluster
 24678 00008963 E8CF210000          <1> 	call	disk_write
 24679 00008968 7211                <1> 	jc	short loc_createfile_dsk_wr_err
 24680                              <1> 
 24681                              <1> loc_createfile_update_fat_cluster:
 24682                              <1> 	; 21/03/2016	
 24683 0000896A 803D[14CB0000]00    <1> 	cmp	byte [createfile_wfc], 0 
 24684 00008971 7712                <1> 	ja	short loc_createfile_update_fat_cluster_n1
 24685                              <1> 
 24686 00008973 FE05[14CB0000]      <1> 	inc	byte [createfile_wfc] ; 1
 24687 00008979 EB24                <1> 	jmp	short loc_createfile_update_fat_cluster_n2
 24688                              <1> 
 24689                              <1> loc_createfile_dsk_wr_err:
 24690                              <1> 	; 23/03/2016
 24691 0000897B B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error !
 24692 00008980 E9BD000000          <1> 	jmp	loc_createfile_stc_retn
 24693                              <1> 
 24694                              <1> loc_createfile_update_fat_cluster_n1:
 24695 00008985 A1[06CB0000]        <1> 	mov	eax, [createfile_PCluster]
 24696 0000898A 8B0D[02CB0000]      <1> 	mov	ecx, [createfile_Cluster]
 24697 00008990 E84F040000          <1> 	call	update_cluster
 24698 00008995 7308                <1> 	jnc	short loc_createfile_update_fat_cluster_n2
 24699 00008997 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 24700 00008999 0F85A3000000        <1> 	jnz	loc_createfile_stc_retn
 24701                              <1> 
 24702                              <1> loc_createfile_update_fat_cluster_n2:
 24703 0000899F A1[02CB0000]        <1>         mov	eax, [createfile_Cluster]
 24704 000089A4 B9FFFFFF0F          <1> 	mov	ecx, 0FFFFFFFh
 24705 000089A9 E836040000          <1> 	call	update_cluster
 24706 000089AE 734E                <1> 	jnc	short loc_createfile_save_fat_buffer_3
 24707 000089B0 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 24708 000089B2 744A                <1> 	jz	short loc_createfile_save_fat_buffer_3
 24709                              <1> 
 24710                              <1> loc_createfile_upd_fat_fcluster_stc_retn:
 24711 000089B4 E989000000          <1> 	jmp	loc_createfile_stc_retn
 24712                              <1> 
 24713                              <1> loc_createfile_get_set_wfc_cont:
 24714                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512	
 24715 000089B9 0FB70D[12CB0000]    <1> 	movzx	ecx, word [createfile_BytesPerSec] ; 512
 24716 000089C0 01C8                <1> 	add	eax, ecx
 24717 000089C2 48                  <1> 	dec	eax  ; add eax, 511
 24718 000089C3 29D2                <1> 	sub	edx, edx
 24719 000089C5 F7F1                <1> 	div	ecx
 24720 000089C7 0FB61D[0BCB0000]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
 24721 000089CE 01D8                <1> 	add	eax, ebx
 24722 000089D0 48                  <1> 	dec	eax  ; add eax, SecPerClust - 1
 24723 000089D1 6631D2              <1> 	xor	dx, dx
 24724 000089D4 F7F3                <1> 	div	ebx
 24725                              <1> 
 24726                              <1> loc_createfile_set_cluster_count:
 24727 000089D6 A3[0ECB0000]        <1> 	mov 	[createfile_CCount], eax
 24728                              <1> 	
 24729 000089DB BF00000700          <1> 	mov	edi, Cluster_Buffer
 24730 000089E0 89C8                <1> 	mov	eax, ecx ; Bytes per Sector
 24731 000089E2 F7E3                <1> 	mul	ebx ; Sectors per Cluster 
 24732                              <1> 	; EAX = Bytes per Cluster
 24733 000089E4 89C1                <1> 	mov	ecx, eax
 24734 000089E6 C1E902              <1> 	shr	ecx, 2 ; dword count
 24735 000089E9 31C0                <1> 	xor	eax, eax
 24736 000089EB F3AB                <1> 	rep	stosd ; clear cluster buffer
 24737                              <1> 
 24738 000089ED A1[02CB0000]        <1> 	mov	eax, [createfile_Cluster] ; 24/03/2016
 24739                              <1> 
 24740 000089F2 89D9                <1> 	mov	ecx, ebx
 24741                              <1> 
 24742                              <1> loc_createfile_get_set_wf_fclust_cont:
 24743 000089F4 83E802              <1> 	sub	eax, 2
 24744 000089F7 F7E1                <1> 	mul	ecx
 24745                              <1> 	; EAX = Logical DOS disk address (offset)
 24746 000089F9 E95DFFFFFF          <1>         jmp     loc_createfile_write_fcluster_to_disk
 24747                              <1> 
 24748                              <1> loc_createfile_save_fat_buffer_3:
 24749                              <1> 	; byte [FAT_BuffValidData] = 2
 24750 000089FE E89E060000          <1> 	call	save_fat_buffer
 24751 00008A03 723D                <1> 	jc	loc_createfile_stc_retn
 24752                              <1> 
 24753                              <1> 	; 21/03/2016
 24754 00008A05 803D[CDC60000]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
 24755 00008A0C 721B                <1> 	jb	short loc_createfile_save_fat_buffer_4
 24756                              <1> 
 24757                              <1> 	; ESI = Logical DOS Drive Description Table address 
 24758 00008A0E A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 24759 00008A13 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
 24760 00008A17 E81A070000          <1> 	call	calculate_fat_freespace
 24761                              <1> 
 24762                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
 24763                              <1> 	;jnz	short loc_createfile_save_fat_buffer_4
 24764                              <1> 
 24765                              <1> 	; ecx > 0 -> Recalculation is needed
 24766 00008A1C 09C9                <1> 	or	ecx, ecx 
 24767 00008A1E 7409                <1> 	jz	short loc_createfile_save_fat_buffer_4
 24768                              <1> 
 24769 00008A20 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
 24770 00008A24 E80D070000          <1> 	call	calculate_fat_freespace
 24771                              <1> 
 24772                              <1> loc_createfile_save_fat_buffer_4:
 24773 00008A29 FF0D[0ECB0000]      <1> 	dec	dword [createfile_CCount]
 24774                              <1> 	;jz	short loc_createfile_upd_dir_modif_date_time
 24775 00008A2F 743F                <1> 	jz	short loc_createfile_stc_retn_cc ; 31/03/2016
 24776                              <1> 
 24777                              <1> loc_createfile_get_set_write_next_cluster:
 24778 00008A31 E8DB020000          <1> 	call	get_first_free_cluster
 24779 00008A36 720A                <1> 	jc	short loc_createfile_stc_retn
 24780                              <1> 
 24781                              <1> loc_createfile_get_set_write_next_cluster_1:
 24782 00008A38 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
 24783 00008A3B 7213                <1> 	jb	short loc_createfile_get_set_write_next_cluster_2
 24784                              <1> 
 24785                              <1> loc_createfile_wnc_insufficient_disk_space:	
 24786 00008A3D B827000000          <1> 	mov	eax, 27h ; Insufficient disk space
 24787                              <1> 
 24788                              <1> loc_createfile_stc_retn:
 24789 00008A42 803D[14CB0000]01    <1> 	cmp	byte [createfile_wfc], 1
 24790 00008A49 7324                <1> 	jnb	short loc_createfile_err_retn
 24791 00008A4B C3                  <1> 	retn
 24792                              <1> 
 24793                              <1> loc_createfile_wnc_inv_format_retn:
 24794                              <1> 	;mov	eax, 0Bh
 24795 00008A4C B00B                <1> 	mov	al, 0Bh ; Invalid format
 24796 00008A4E EBF2                <1> 	jmp	short loc_createfile_stc_retn
 24797                              <1> 	         
 24798                              <1> loc_createfile_get_set_write_next_cluster_2:
 24799 00008A50 83F802              <1> 	cmp	eax, 2
 24800 00008A53 72F7                <1> 	jb	short loc_createfile_wnc_inv_format_retn
 24801                              <1> 
 24802                              <1> loc_createfile_get_set_write_next_cluster_3:
 24803 00008A55 8B0D[02CB0000]      <1> 	mov	ecx, [createfile_Cluster]
 24804 00008A5B A3[02CB0000]        <1> 	mov	[createfile_Cluster], eax
 24805 00008A60 890D[06CB0000]      <1> 	mov	[createfile_PCluster], ecx
 24806 00008A66 0FB60D[0BCB0000]    <1> 	movzx	ecx, byte [createfile_SecPerClust]
 24807 00008A6D EB85                <1> 	jmp	short loc_createfile_get_set_wf_fclust_cont
 24808                              <1> 
 24809                              <1> loc_createfile_err_retn:
 24810 00008A6F F9                  <1> 	stc
 24811                              <1> 
 24812                              <1> ;loc_createfile_upd_dir_modif_date_time:
 24813                              <1> loc_createfile_stc_retn_cc: ; 31/03/2016
 24814 00008A70 9C                  <1> 	pushf	; cpu is here for an error return or completion 
 24815 00008A71 50                  <1> 	push	eax ; error code if cf = 1
 24816                              <1> 
 24817                              <1> 	;call	update_parent_dir_lmdt
 24818                              <1> 
 24819                              <1> ;loc_createfile_stc_retn_cc:
 24820 00008A72 A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 24821 00008A77 09C0                <1> 	or	eax, eax
 24822 00008A79 741A                <1> 	jz	short loc_createfile_stc_retn_pop_eax
 24823 00008A7B 8A3D[AEBE0000]      <1> 	mov	bh, [Current_Drv]
 24824 00008A81 B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
 24825                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
 24826                              <1> 	; (If EAX value is negative, Free Cluster Count will be decreased)
 24827 00008A83 E8AE060000          <1>   	call	calculate_fat_freespace
 24828                              <1>         ; ESI = Logical DOS Drive Description Table Address 
 24829                              <1>         ;jc	short loc_createfile_stc_retn_pop_eax_cf
 24830 00008A88 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
 24831 00008A8A 7409                <1> 	jz	short loc_createfile_stc_retn_pop_eax
 24832                              <1> 
 24833                              <1> loc_createfile_stc_retn_recalc_FAT_freespace:
 24834 00008A8C 66BB00FF            <1> 	mov	bx, 0FF00h ; bh = 0FFh -> 
 24835                              <1> 	; ESI = Logical DOS Drv DT Addr
 24836                              <1> 	; BL = 0 -> Recalculate 
 24837 00008A90 E8A1060000          <1> 	call	calculate_fat_freespace
 24838                              <1> 
 24839                              <1> loc_createfile_stc_retn_pop_eax:
 24840 00008A95 58                  <1> 	pop	eax
 24841 00008A96 9D                  <1> 	popf
 24842 00008A97 7218                <1> 	jc	short loc_createfile_retn
 24843                              <1> 
 24844                              <1> loc_createfile_retn_fcluster:
 24845 00008A99 A1[FACA0000]        <1> 	mov	eax, [createfile_FFCluster]
 24846 00008A9E BB[F6CA0000]        <1> 	mov	ebx, createfile_size
 24847                              <1> 	;movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 24848 00008AA3 0FB60D[0BCB0000]    <1> 	movzx	ecx, byte [createfile_SecPerClust] ; 23/03/2016
 24849 00008AAA 0FB715[0CCB0000]    <1> 	movzx	edx, word [createfile_DirIndex]
 24850                              <1> 
 24851                              <1> loc_createfile_retn:
 24852 00008AB1 C3                  <1> 	retn
 24853                              <1> 
 24854                              <1> create_fs_file:
 24855                              <1> 	; temporary (21/03/2016)
 24856 00008AB2 C3                  <1> 	retn
 24857                              <1> 
 24858                              <1> delete_fs_file:
 24859                              <1> 	; temporary (28/02/2016)
 24860 00008AB3 C3                  <1> 	retn
 24861                              <1> 
 24862                              <1> rename_fs_file_or_directory:
 24863 00008AB4 C3                  <1> 	retn
 24864                              <1> 
 24865                              <1> make_fs_directory:
 24866                              <1> 	; temporary (21/02/2016)
 24867 00008AB5 C3                  <1> 	retn
 24868                              <1> 
 24869                              <1> add_new_fs_section:
 24870                              <1> 	; temporary (11/03/2016)
 24871 00008AB6 C3                  <1> 	retn
 24872                              <1> 
 24873                              <1> delete_fs_directory_entry:
 24874                              <1> 	; temporary (11/03/2016)
 24875 00008AB7 C3                  <1> 	retn
 24876                              <1> 
 24877                              <1> csftdf2_read_fs_file_sectors:
 24878                              <1> 	; temporary (19/03/2016)
 24879 00008AB8 C3                  <1> 	retn
 24880                              <1> 
 24881                              <1> csftdf2_write_fs_file_sectors:
 24882                              <1> 	; temporary (19/03/2016)
 24883 00008AB9 C3                  <1> 	retn
 24884                                  %include 'trdosk5.s' ; 24/01/2016
 24885                              <1> ; ****************************************************************************
 24886                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - File System Procedures : trdosk5s
 24887                              <1> ; ----------------------------------------------------------------------------
 24888                              <1> ; Last Update: 24/03/2016
 24889                              <1> ; ----------------------------------------------------------------------------
 24890                              <1> ; Beginning: 24/01/2016
 24891                              <1> ; ----------------------------------------------------------------------------
 24892                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 24893                              <1> ; ----------------------------------------------------------------------------
 24894                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 24895                              <1> ; DRV_FAT.ASM (21/08/2011)
 24896                              <1> ; ****************************************************************************
 24897                              <1> ; DRV_FAT.ASM (c) 2005-2011 Erdogan TAN [ 07/07/2009 ] Last Update: 21/08/2011
 24898                              <1> 
 24899                              <1> get_next_cluster:
 24900                              <1> 	; 23/03/2016
 24901                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 24902                              <1> 	; 05/07/2011
 24903                              <1> 	; 07/07/2009
 24904                              <1> 	; 2005
 24905                              <1> 	; INPUT ->
 24906                              <1> 	;	EAX = Cluster Number (32 bit)
 24907                              <1> 	;	ESI = Logical DOS Drive Parameters Table
 24908                              <1> 	; OUTPUT ->
 24909                              <1> 	;	cf = 0 -> No Error, EAX valid
 24910                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
 24911                              <1> 	;	cf = 1 & EAX > 0 -> Error
 24912                              <1> 	;	ECX = Current/Previous cluster (if CF = 0)
 24913                              <1> 	;	EAX = Next Cluster Number (32 bit)
 24914                              <1> 	;
 24915                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 24916                              <1> 
 24917 00008ABA A3[C1C60000]        <1> 	mov	[FAT_CurrentCluster], eax
 24918                              <1> check_next_cluster_fat_type:
 24919 00008ABF 29D2                <1> 	sub	edx, edx ; 0
 24920 00008AC1 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
 24921 00008AC5 7250                <1> 	jb	short get_FAT12_next_cluster
 24922 00008AC7 0F87AF000000        <1>         ja      get_FAT32_next_cluster
 24923                              <1> get_FAT16_next_cluster:
 24924 00008ACD BB00030000          <1> 	mov	ebx, 300h ;768
 24925 00008AD2 F7F3                <1> 	div	ebx
 24926                              <1> 	; EAX = Count of 3 FAT sectors
 24927                              <1> 	; EDX = Cluster Offset (< 768)
 24928 00008AD4 66D1E2              <1> 	shl	dx, 1 ; Multiply by 2
 24929 00008AD7 89D3                <1> 	mov	ebx, edx ; Byte Offset
 24930 00008AD9 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 24931 00008ADF 66BA0300            <1> 	mov	dx, 3
 24932 00008AE3 F7E2                <1> 	mul	edx  
 24933                              <1> 	; EAX = FAT Sector (<= 256)
 24934                              <1> 	; EDX = 0
 24935 00008AE5 8A0E                <1> 	mov	cl, [esi+LD_Name]
 24936 00008AE7 803D[C5C60000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 24937 00008AEE 0F86CC000000        <1>         jna     load_FAT_sectors0
 24938 00008AF4 3A0D[C6C60000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 24939 00008AFA 0F85C0000000        <1>         jne     load_FAT_sectors0
 24940 00008B00 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 24941 00008B06 0F85BA000000        <1>         jne     load_FAT_sectors1
 24942                              <1> 	;movzx	eax, word [ebx]
 24943 00008B0C 668B03              <1> 	mov	ax, [ebx]
 24944                              <1> 	; 01/02/2016
 24945                              <1> 	; DRV_FAT.ASM (21/08/2011) had a FATal bug here !
 24946                              <1> 	; (cmp ah, 0Fh) ! (ax >= FF7h)
 24947                              <1> 	; (how can i do a such mistake!?)
 24948                              <1> 	;cmp	al, 0F7h
 24949                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 24950                              <1> 	;cmp	ah, 0FFh
 24951                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 24952 00008B0F 6683F8F7            <1> 	cmp	ax, 0FFF7h
 24953 00008B13 725A                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
 24954                              <1> 	; ax >= FFF7h (cluster 0002h to FFF6h is valid, in use)
 24955 00008B15 EB56                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
 24956                              <1> 
 24957                              <1> get_FAT12_next_cluster:
 24958 00008B17 BB00040000          <1> 	mov	ebx, 400h ;1024
 24959 00008B1C F7F3                <1> 	div	ebx
 24960                              <1> 	; EAX = Count of 3 FAT sectors
 24961                              <1> 	; EDX = Cluster Offset (< 1024)
 24962 00008B1E 6650                <1> 	push	ax
 24963 00008B20 66B80300            <1> 	mov	ax, 3	
 24964 00008B24 66F7E2              <1> 	mul	dx    	; Multiply by 3
 24965 00008B27 66D1E8              <1> 	shr	ax, 1	; Divide by 2
 24966 00008B2A 6689C3              <1>         mov	bx, ax 	; Byte Offset
 24967 00008B2D 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 24968 00008B33 6658                <1> 	pop	ax
 24969 00008B35 66BA0300            <1> 	mov	dx, 3
 24970 00008B39 F7E2                <1> 	mul	edx 
 24971                              <1> 	; EAX = FAT Sector (<= 12)
 24972                              <1> 	; EDX = 0
 24973 00008B3B 8A0E                <1> 	mov	cl, [esi+LD_Name]
 24974 00008B3D 803D[C5C60000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 24975 00008B44 767A                <1> 	jna	short load_FAT_sectors0
 24976 00008B46 3A0D[C6C60000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 24977 00008B4C 7572                <1> 	jne	short load_FAT_sectors0
 24978 00008B4E 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 24979 00008B54 7570                <1> 	jne	short load_FAT_sectors1
 24980 00008B56 A1[C1C60000]        <1> 	mov	eax, [FAT_CurrentCluster]
 24981 00008B5B 66D1E8              <1> 	shr	ax, 1
 24982                              <1> 	;movzx	eax, word [ebx]
 24983 00008B5E 668B03              <1> 	mov	ax, [ebx]
 24984 00008B61 7314                <1> 	jnc	short get_FAT12_nc_even
 24985 00008B63 66C1E804            <1> 	shr	ax, 4
 24986                              <1> loc_gnc_fat12_eoc_check:
 24987                              <1> 	;cmp	al, 0F7h
 24988                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 24989                              <1> 	;cmp	ah, 0Fh
 24990                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 24991 00008B67 663DF70F            <1> 	cmp	ax, 0FF7h
 24992 00008B6B 7202                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
 24993                              <1> 	; ax >= FF7h (cluster 0002h to FF6h is valid, in use)
 24994                              <1> 
 24995                              <1> loc_pass_gnc_FAT16_eoc_check_xor_eax:
 24996 00008B6D 31C0                <1> 	xor	eax, eax ; 0
 24997                              <1> loc_pass_gnc_FAT16_eoc_check:
 24998                              <1> loc_pass_gnc_FAT32_eoc_check:
 24999 00008B6F 8B0D[C1C60000]      <1> 	mov	ecx, [FAT_CurrentCluster]
 25000 00008B75 F5                  <1> 	cmc
 25001 00008B76 C3                  <1> 	retn
 25002                              <1> 
 25003                              <1> get_FAT12_nc_even:
 25004 00008B77 80E40F              <1> 	and	ah, 0Fh
 25005 00008B7A EBEB                <1> 	jmp	short loc_gnc_fat12_eoc_check
 25006                              <1> 
 25007                              <1> get_FAT32_next_cluster:
 25008 00008B7C BB80010000          <1> 	mov	ebx, 180h ;384
 25009 00008B81 F7F3                <1> 	div	ebx
 25010                              <1> 	; EAX = Count of 3 FAT sectors
 25011                              <1> 	; EDX = Cluster Offset (< 384)
 25012 00008B83 66C1E202            <1> 	shl	dx, 2	; Multiply by 4
 25013 00008B87 89D3                <1> 	mov	ebx, edx ; Byte Offset
 25014 00008B89 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 25015 00008B8F 66BA0300            <1> 	mov	dx, 3
 25016 00008B93 F7E2                <1> 	mul	edx	
 25017                              <1>         ; EAX = FAT Sector (<= 2097152) ; (FFFFFF7h * 4) / 512
 25018                              <1> 	; 	for 32KB cluster size:
 25019                              <1> 	;	EAX <= 1024 = (4GB / 32KB) * 4) / 512 	
 25020                              <1> 	; EDX = 0
 25021 00008B95 8A0E                <1> 	mov	cl, [esi+LD_Name]
 25022 00008B97 803D[C5C60000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 25023 00008B9E 7620                <1> 	jna	short load_FAT_sectors0
 25024 00008BA0 3A0D[C6C60000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 25025 00008BA6 7518                <1> 	jne	short load_FAT_sectors0
 25026 00008BA8 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector] ; 0, 3, 6, 9 ...
 25027 00008BAE 7516                <1> 	jne	short load_FAT_sectors1
 25028 00008BB0 8B03                <1> 	mov	eax, [ebx]
 25029 00008BB2 25FFFFFF0F          <1>  	and	eax, 0FFFFFFFh ; 28 bit Cluster
 25030 00008BB7 3DF7FFFF0F          <1> 	cmp	eax, 0FFFFFF7h
 25031 00008BBC 72B1                <1> 	jb	short loc_pass_gnc_FAT32_eoc_check
 25032                              <1> 	; eax >= FFFFFF7h (cluster 0002h to FFFFFF6h is valid)
 25033 00008BBE EBAD                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
 25034                              <1> 
 25035                              <1> load_FAT_sectors0:
 25036 00008BC0 880D[C6C60000]      <1> 	mov	[FAT_BuffDrvName], cl
 25037                              <1> load_FAT_sectors1:
 25038 00008BC6 A3[C9C60000]        <1> 	mov	[FAT_BuffSector], eax
 25039 00008BCB 89C3                <1> 	mov	ebx, eax
 25040 00008BCD 034660              <1>         add     eax, [esi+LD_FATBegin]
 25041 00008BD0 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 25042 00008BD4 7706                <1>         ja      short load_FAT_sectors3
 25043 00008BD6 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
 25044 00008BDA EB03                <1> 	jmp	short load_FAT_sectors4
 25045                              <1> load_FAT_sectors3:
 25046 00008BDC 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+BPB_FATSz32]
 25047                              <1> load_FAT_sectors4:
 25048 00008BDF 29D9                <1> 	sub	ecx, ebx ; [FAT_BuffSector]
 25049 00008BE1 83F903              <1>         cmp     ecx, 3
 25050 00008BE4 7605                <1>         jna     short load_FAT_sectors5
 25051 00008BE6 B903000000          <1> 	mov	ecx, 3
 25052                              <1> load_FAT_sectors5:
 25053 00008BEB BB001C0900          <1> 	mov	ebx, FAT_Buffer
 25054 00008BF0 E8511F0000          <1> 	call	disk_read
 25055 00008BF5 730D                <1> 	jnc	short load_FAT_sectors_ok
 25056                              <1> 	; 23/03/2016
 25057 00008BF7 B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
 25058 00008BFC C605[C5C60000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 25059 00008C03 C3                  <1> 	retn
 25060                              <1> load_FAT_sectors_ok:
 25061 00008C04 C605[C5C60000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 25062 00008C0B A1[C1C60000]        <1> 	mov	eax, [FAT_CurrentCluster]
 25063 00008C10 E9AAFEFFFF          <1>         jmp     check_next_cluster_fat_type
 25064                              <1> 
 25065                              <1> load_FAT_root_directory:
 25066                              <1> 	; 07/02/2016
 25067                              <1> 	; 02/02/2016
 25068                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25069                              <1> 	; 21/05/2011
 25070                              <1> 	; 22/08/2009
 25071                              <1> 	;
 25072                              <1> 	; INPUT ->
 25073                              <1> 	;	ESI = Logical DOS Drive Description Table
 25074                              <1> 	; OUTPUT ->
 25075                              <1> 	;	cf = 1 -> Root directory could not be loaded
 25076                              <1> 	;	    EAX > 0 -> Error number
 25077                              <1> 	;	cf = 0 -> EAX = 0
 25078                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 25079                              <1> 	;	EBX = Directory buffer address
 25080                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 25081                              <1> 	;
 25082                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 25083                              <1> 
 25084                              <1> 	; NOTE: Only for FAT12 and FAT16 file systems !
 25085                              <1> 	; (FAT32 fs root dir must be loaded as sub directory)
 25086                              <1> 
 25087 00008C15 8A1E                <1> 	mov	bl, [esi+LD_Name]
 25088 00008C17 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 25089                              <1> 
 25090                              <1> 	;mov	[DirBuff_DRV], bl
 25091                              <1> 	;mov	[DirBuff_FATType], bh
 25092 00008C1A 66891D[D6C60000]    <1> 	mov	[DirBuff_DRV], bx
 25093                              <1> 	
 25094                              <1> 	;cmp	bh, 2
 25095                              <1> 	;ja	short load_FAT32_root_dir0 ; FAT32 root dir
 25096                              <1> 
 25097 00008C21 0FB75617            <1> 	movzx	edx, word [esi+LD_BPB+RootDirEnts]
 25098                              <1> 
 25099                              <1> 	;or	dx, dx ; 0 for FAT32 file systems
 25100                              <1> 	;jz	short load_FAT32_root_dir0 ; FAT32 root dir
 25101                              <1> 
 25102 00008C25 6681FA0002          <1> 	cmp	dx, 512 ; Number of Root Dir Entries
 25103 00008C2A 7414                <1> 	je	short lrd_mov_ecx_32
 25104 00008C2C 89D0                <1> 	mov	eax, edx
 25105 00008C2E 6683C00F            <1> 	add	ax, 15 ; round up 
 25106 00008C32 66C1E804            <1> 	shr	ax, 4  ; 16 entries per sector (512/32)
 25107 00008C36 89C1                <1> 	mov	ecx, eax ; Root directory size in sectors
 25108 00008C38 66C1E009            <1> 	shl	ax, 9 ; Root directory size in bytes
 25109 00008C3C 664A                <1> 	dec	dx    ; Last entry number of root dir
 25110                              <1> 	; cx = Dir Buffer sector count             
 25111 00008C3E EB0B                <1> 	jmp	short lrd_check_dir_buffer
 25112                              <1> 
 25113                              <1> lrd_mov_ecx_32:
 25114 00008C40 B920000000          <1> 	mov	ecx, 32
 25115 00008C45 664A                <1> 	dec	dx ; 511
 25116 00008C47 66B80040            <1> 	mov	ax, 32*512 
 25117                              <1>  
 25118                              <1> lrd_check_dir_buffer:
 25119 00008C4B 29DB                <1> 	sub	ebx, ebx ; 0
 25120 00008C4D 881D[D8C60000]      <1> 	mov	[DirBuff_ValidData], bl ; 0
 25121 00008C53 668915[DBC60000]    <1> 	mov	[DirBuff_LastEntry], dx
 25122 00008C5A 891D[DDC60000]      <1> 	mov	[DirBuff_Cluster], ebx ; 0
 25123 00008C60 66A3[E1C60000]      <1> 	mov	[DirBuffer_Size], ax
 25124                              <1> 
 25125 00008C66 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin]
 25126                              <1> read_directory:
 25127 00008C69 BB00000800          <1> 	mov	ebx, Directory_Buffer
 25128 00008C6E 51                  <1> 	push	ecx ; Directory buffer sector count
 25129 00008C6F 53                  <1> 	push	ebx
 25130 00008C70 E8D11E0000          <1> 	call	disk_read
 25131 00008C75 5B                  <1> 	pop	ebx
 25132 00008C76 720B                <1> 	jc	short load_DirBuff_error
 25133                              <1> 
 25134                              <1> validate_DirBuff_and_return:
 25135 00008C78 59                  <1> 	pop	ecx ; Number of loaded sectors
 25136 00008C79 C605[D8C60000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 25137 00008C80 31C0                <1> 	xor	eax, eax ; 0 = no error
 25138 00008C82 C3                  <1> 	retn
 25139                              <1> 
 25140                              <1> load_DirBuff_error:
 25141 00008C83 89C8                <1> 	mov	eax, ecx ; remaining sectors
 25142 00008C85 59                  <1> 	pop	ecx ; sector count
 25143 00008C86 29C1                <1> 	sub	ecx, eax ; Number of loaded sectors
 25144 00008C88 B815000000          <1> 	mov	eax, 15h ; DRV NOT READY OR READ ERROR !
 25145 00008C8D F9                  <1> 	stc
 25146 00008C8E C3                  <1>         retn
 25147                              <1> 
 25148                              <1> load_FAT32_root_directory:
 25149                              <1> 	; 02/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25150                              <1> 	;
 25151                              <1> 	; INPUT ->
 25152                              <1> 	;	ESI = Logical DOS Drive Description Table
 25153                              <1> 	; OUTPUT ->
 25154                              <1> 	;	cf = 1 -> Root directory could not be loaded
 25155                              <1> 	;	    EAX > 0 -> Error number
 25156                              <1> 	;	cf = 0 -> EAX = 0
 25157                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 25158                              <1> 	;	EBX = Directory buffer address
 25159                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 25160                              <1> 	;
 25161                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 25162                              <1> 
 25163                              <1> 
 25164 00008C8F 8A1E                <1> 	mov	bl, [esi+LD_Name]
 25165 00008C91 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 25166                              <1> 
 25167                              <1> 	;mov	[DirBuff_DRV], bl
 25168                              <1> 	;mov	[DirBuff_FATType], bh
 25169 00008C94 66891D[D6C60000]    <1> 	mov	[DirBuff_DRV], bx
 25170                              <1> 
 25171                              <1> load_FAT32_root_dir0:
 25172 00008C9B 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
 25173 00008C9E EB0C                <1> 	jmp	short load_FAT_sub_dir0
 25174                              <1> 	
 25175                              <1> load_FAT_sub_directory:
 25176                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25177                              <1> 	; 05/07/2011
 25178                              <1> 	; 23/08/2009
 25179                              <1> 	;
 25180                              <1> 	; INPUT ->
 25181                              <1> 	;	ESI = Logical DOS Drive Description Table
 25182                              <1> 	;	EAX = Cluster Number
 25183                              <1> 	; OUTPUT ->
 25184                              <1> 	;	cf = 1 -> Sub directory could not be loaded
 25185                              <1> 	;	    EAX > 0 -> Error number
 25186                              <1> 	;	cf = 0 -> EAX = 0
 25187                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 25188                              <1> 	;	EBX = Directory buffer address
 25189                              <1> 	;
 25190                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 25191                              <1> 	;
 25192                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 25193                              <1> 
 25194 00008CA0 8A1E                <1> 	mov	bl, [esi+LD_Name]
 25195 00008CA2 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 25196                              <1> 
 25197                              <1> 	;mov	[DirBuff_DRV], bl
 25198                              <1> 	;mov	[DirBuff_FATType], bh
 25199 00008CA5 66891D[D6C60000]    <1> 	mov	[DirBuff_DRV], bx
 25200                              <1> 
 25201                              <1> load_FAT_sub_dir0:
 25202 00008CAC 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 25203                              <1> 
 25204 00008CB0 882D[D8C60000]      <1> 	mov	[DirBuff_ValidData], ch ; 0
 25205 00008CB6 A3[DDC60000]        <1> 	mov	[DirBuff_Cluster], eax
 25206                              <1> 
 25207 00008CBB 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
 25208 00008CBF F7E1                <1> 	mul	ecx
 25209 00008CC1 C1E805              <1> 	shr	eax, 5 ; directory entry count (dir size / 32)
 25210 00008CC4 6648                <1> 	dec	ax ; last entry
 25211 00008CC6 66A3[DBC60000]      <1> 	mov	[DirBuff_LastEntry], ax
 25212                              <1> 
 25213 00008CCC A1[DDC60000]        <1> 	mov	eax, [DirBuff_Cluster]
 25214 00008CD1 83E802              <1> 	sub	eax, 2
 25215 00008CD4 F7E1                <1> 	mul	ecx
 25216 00008CD6 034668              <1> 	add	eax, [esi+LD_DATABegin]
 25217                              <1> 	; ecx = sector per cluster (dir buffer size = 32 sectors)
 25218 00008CD9 EB8E                <1> 	jmp	short read_directory
 25219                              <1> 
 25220                              <1> ; DRV_FS.ASM
 25221                              <1> 
 25222                              <1> load_current_FS_directory:
 25223 00008CDB C3                  <1> 	retn
 25224                              <1> load_FS_root_directory:
 25225 00008CDC C3                  <1> 	retn
 25226                              <1> load_FS_sub_directory:
 25227 00008CDD C3                  <1> 	retn
 25228                              <1> 
 25229                              <1> read_cluster:
 25230                              <1> 	; 18/03/2016
 25231                              <1> 	; 16/03/2016
 25232                              <1> 	; 17/02/2016
 25233                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25234                              <1> 	;
 25235                              <1> 	; INPUT ->
 25236                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
 25237                              <1> 	;	ESI = Logical DOS Drive Description Table address
 25238                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
 25239                              <1> 	;	Only for SINGLIX FS:
 25240                              <1> 	;	EDX = File Number (The 1st FDT address) 
 25241                              <1> 	; OUTPUT ->
 25242                              <1> 	;	cf = 1 -> Cluster can not be loaded at the buffer
 25243                              <1> 	;	    EAX > 0 -> Error number
 25244                              <1> 	;	cf = 0 -> Cluster has been loaded at the buffer
 25245                              <1> 	;
 25246                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 25247                              <1> 	
 25248 00008CDE 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
 25249                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 25250                              <1> 
 25251                              <1> read_file_sectors: ; 16/03/2016
 25252 00008CE2 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 25253 00008CE6 761C                <1> 	jna	short read_fs_cluster
 25254                              <1> 
 25255                              <1> read_fat_file_sectors: ; 18/03/2016
 25256 00008CE8 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
 25257 00008CEB 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
 25258 00008CEF F7E2                <1> 	mul	edx
 25259 00008CF1 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
 25260                              <1> 
 25261                              <1> 	; EAX = Disk sector address
 25262                              <1> 	; ECX = Sector count
 25263                              <1> 	; EBX = Buffer address
 25264                              <1> 	; (EDX = 0)
 25265                              <1> 	; ESI = Logical DOS drive description table address	
 25266                              <1> 
 25267 00008CF4 E84D1E0000          <1> 	call	disk_read
 25268 00008CF9 7306                <1> 	jnc	short rclust_retn
 25269                              <1> 	
 25270 00008CFB B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
 25271 00008D00 C3                  <1> 	retn
 25272                              <1> 
 25273                              <1> rclust_retn:
 25274 00008D01 29C0                <1> 	sub	eax, eax ; 0
 25275 00008D03 C3                  <1> 	retn
 25276                              <1> 
 25277                              <1> read_fs_cluster:
 25278                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25279                              <1> 	; Singlix FS
 25280                              <1> 	
 25281                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
 25282                              <1> 	
 25283                              <1> 	; EDX = File number is the first File Descriptor Table address 
 25284                              <1> 	;	of the file. (Absolute address of the FDT).
 25285                              <1> 	
 25286                              <1> 	; eax = sector index (0 for the first sector)
 25287                              <1> 	; edx = FDT0 address
 25288                              <1> 		; 64 KB buffer = 128 sectors (limit) 
 25289 00008D04 B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
 25290 00008D09 E801000000          <1> 	call	read_fs_sectors
 25291 00008D0E C3                  <1> 	retn
 25292                              <1> 
 25293                              <1> read_fs_sectors:
 25294                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25295 00008D0F F9                  <1> 	stc
 25296 00008D10 C3                  <1> 	retn
 25297                              <1> 
 25298                              <1> get_first_free_cluster:
 25299                              <1> 	; 02/03/2016
 25300                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25301                              <1> 	; 26/10/2010 (DRV_FAT.ASM, 'proc_get_first_free_cluster')
 25302                              <1> 	; 10/07/2010
 25303                              <1> 	; INPUT ->
 25304                              <1> 	;	ESI = Logical DOS Drive Description Table address
 25305                              <1> 	; OUTPUT ->
 25306                              <1> 	;	cf = 1 -> Error code in AL (EAX)
 25307                              <1> 	;	cf = 0 -> 
 25308                              <1> 	;	  EAX = Cluster number 
 25309                              <1> 	;	  If EAX = FFFFFFFFh -> no free space
 25310                              <1> 	;	If the drive has FAT32 fs:
 25311                              <1> 	;	  EBX = FAT32 FSI sector buffer address (if > 0)
 25312                              <1> 
 25313 00008D11 8B4678              <1> 	mov	eax, [esi+LD_Clusters]
 25314 00008D14 40                  <1> 	inc	eax ; add eax, 1
 25315 00008D15 A3[60C90000]        <1> 	mov	[gffc_last_free_cluster], eax
 25316                              <1> 
 25317 00008D1A 31DB                <1> 	xor	ebx, ebx ; 0 ; 02/03/2016
 25318                              <1> 
 25319 00008D1C 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 25320 00008D20 760E                <1> 	jna	short loc_gffc_get_first_fat_free_cluster0
 25321                              <1> 
 25322                              <1> loc_gffc_get_first_fat32_free_cluster:
 25323                              <1> 	; 02/03/2016
 25324 00008D22 E834060000          <1> 	call	get_fat32_fsinfo_sector_parms
 25325 00008D27 7207                <1> 	jc	short loc_gffc_get_first_fat_free_cluster0 
 25326                              <1> 
 25327                              <1> loc_gffc_check_fsinfo_parms:
 25328                              <1> 	;;mov	ebx, DOSBootSectorBuff
 25329                              <1> 	;cmp	dword [ebx], 41615252h
 25330                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
 25331                              <1> 	;cmp	dword [ebx+484], 61417272h
 25332                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
 25333                              <1> 	;mov	eax, [ebx+492] ; FSI_Next_Free
 25334                              <1> 	;EAX = First free cluster 
 25335                              <1> 	;(from FAT32 FSInfo sector)
 25336 00008D29 89D0                <1> 	mov	eax, edx ; FSI_Next_Free (First Free Cluster)
 25337 00008D2B 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; invalid (unknown) !
 25338 00008D2E 7205                <1> 	jb	short loc_gffc_get_first_fat_free_cluster1
 25339                              <1> 
 25340                              <1> 	; Start from the 1st cluster of the FAT(32) file system
 25341                              <1> loc_gffc_get_first_fat_free_cluster0:
 25342 00008D30 B802000000          <1> 	mov	eax, 2
 25343                              <1> 	;xor	edx, edx
 25344                              <1> 
 25345                              <1> loc_gffc_get_first_fat_free_cluster1:
 25346 00008D35 53                  <1> 	push	ebx ; 02/03/2016 
 25347                              <1> 
 25348                              <1> loc_gffc_get_first_fat_free_cluster2:   
 25349 00008D36 A3[5CC90000]        <1> 	mov	[gffc_first_free_cluster], eax
 25350 00008D3B A3[58C90000]        <1> 	mov	[gffc_next_free_cluster], eax
 25351                              <1> 
 25352                              <1> 	; EBX = FAT32 FSINFO sector buffer address
 25353                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
 25354                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
 25355                              <1> 
 25356                              <1> loc_gffc_get_first_fat_free_cluster3:
 25357 00008D40 E875FDFFFF          <1> 	call	get_next_cluster
 25358 00008D45 7307                <1> 	jnc	short loc_gffc_get_first_fat_free_cluster4
 25359 00008D47 09C0                <1> 	or	eax, eax
 25360 00008D49 740B                <1> 	jz	short loc_gffc_first_free_fat_cluster_next
 25361 00008D4B 5B                  <1> 	pop	ebx ; 02/03/2016
 25362 00008D4C F5                  <1> 	cmc 	; stc
 25363 00008D4D C3                  <1> 	retn
 25364                              <1> 
 25365                              <1> loc_gffc_get_first_fat_free_cluster4:
 25366 00008D4E 21C0                <1> 	and	eax, eax ; next cluster value
 25367 00008D50 7504                <1> 	jnz	short loc_gffc_first_free_fat_cluster_next
 25368 00008D52 89C8                <1> 	mov	eax, ecx ; current (previous cluster) value
 25369 00008D54 EB22                <1> 	jmp	short loc_gffc_check_for_set
 25370                              <1>  
 25371                              <1> loc_gffc_first_free_fat_cluster_next:
 25372 00008D56 A1[58C90000]        <1> 	mov	eax, [gffc_next_free_cluster]
 25373 00008D5B 3B05[60C90000]      <1> 	cmp	eax, [gffc_last_free_cluster]
 25374 00008D61 7308                <1> 	jnb	short retn_stc_from_get_first_free_cluster
 25375                              <1> pass_gffc_last_cluster_eax_check:
 25376 00008D63 40                  <1> 	inc	eax ; add eax, 1
 25377 00008D64 A3[58C90000]        <1> 	mov	[gffc_next_free_cluster], eax
 25378 00008D69 EBD5                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster3
 25379                              <1> 
 25380                              <1> retn_stc_from_get_first_free_cluster:
 25381 00008D6B A1[5CC90000]        <1> 	mov	eax, [gffc_first_free_cluster]
 25382 00008D70 83F802              <1> 	cmp	eax, 2
 25383 00008D73 7709                <1> 	ja	short loc_gffc_check_previous_clusters
 25384 00008D75 29C0                <1> 	sub	eax, eax
 25385 00008D77 48                  <1> 	dec	eax ; FFFFFFFFh
 25386                              <1> 
 25387                              <1> loc_gffc_check_for_set:
 25388                              <1> 	; 02/03/2016
 25389 00008D78 5B                  <1> 	pop	ebx
 25390                              <1> 
 25391                              <1> 	; EBX = FAT32 FSINFO sector buffer address
 25392                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
 25393                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
 25394                              <1> 
 25395 00008D79 09DB                <1> 	or	ebx, ebx
 25396 00008D7B 750E                <1> 	jnz	short loc_gffc_set_ffree_fat32_cluster
 25397                              <1> 
 25398                              <1> 	;cmp	byte [esi+LD_FATType], 3
 25399                              <1> 	;jnb	short loc_gffc_set_ffree_fat32_cluster
 25400                              <1> 
 25401                              <1> 	;xor	ebx, ebx ; 0
 25402                              <1> 
 25403                              <1> loc_gffc_retn:
 25404 00008D7D C3                  <1> 	retn
 25405                              <1> 
 25406                              <1> loc_gffc_check_previous_clusters:
 25407 00008D7E 48                  <1> 	dec	eax ; sub eax, 1
 25408 00008D7F A3[60C90000]        <1> 	mov	[gffc_last_free_cluster], eax 
 25409 00008D84 B802000000          <1> 	mov	eax, 2
 25410                              <1> 	;xor	edx, edx
 25411 00008D89 EBAB                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster2
 25412                              <1> 
 25413                              <1> loc_gffc_set_ffree_fat32_cluster:
 25414                              <1> 	;call	set_first_free_cluster
 25415                              <1> 	;retn
 25416                              <1> 	;jmp	short set_first_free_cluster	
 25417                              <1> 
 25418                              <1> set_first_free_cluster:
 25419                              <1> 	; 23/03/2016
 25420                              <1> 	; 02/03/2016
 25421                              <1> 	; 29/02/2016
 25422                              <1> 	; 26/02/2016
 25423                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25424                              <1> 	; 21/08/2011 (DRV_FAT.ASM, 'proc_set_first_free_cluster')
 25425                              <1> 	; 11/07/2010
 25426                              <1> 	; INPUT -> 
 25427                              <1> 	;	ESI = Logical DOS Drive Description Table address
 25428                              <1> 	;	EAX = First free cluster
 25429                              <1> 	;	EBX = FSINFO sector buffer address
 25430                              <1> 	;  	;;If EBX > 0, it is FSINFO sector buffer address
 25431                              <1> 	;	;;EBX = 0, if FSINFO sector is not loaded
 25432                              <1> 	; OUTPUT->
 25433                              <1> 	;	ESI = Logical DOS Drive Description Table address
 25434                              <1> 	;  	If EBX > 0, it is FSINFO sector buffer address
 25435                              <1> 	;	EBX = 0, if FSINFO sector could not be loaded
 25436                              <1> 	; 	CF = 1 -> Error code in AL (EAX)
 25437                              <1> 	;	CF = 0 -> first free cluster is successfully updated 
 25438                              <1> 
 25439                              <1> 	;cmp	byte [esi+LD_FATType], 3
 25440                              <1> 	;jb	short loc_sffc_invalid_drive
 25441                              <1> 
 25442                              <1> 	; Save First Free Cluster value for 'update_cluster'
 25443 00008D8B 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First free Cluster	
 25444                              <1> 
 25445                              <1> 	;or	ebx, ebx
 25446                              <1> 	;jnz	short loc_sffc_read_fsinfo_sector
 25447                              <1> 
 25448 00008D8E 813B52526141        <1> 	cmp     dword [ebx], 41615252h
 25449 00008D94 7540                <1> 	jne	short loc_sffc_read_fsinfo_sector
 25450 00008D96 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 25451 00008D9F 61                  <1>
 25452 00008DA0 7534                <1> 	jne	short loc_sffc_read_fsinfo_sector
 25453                              <1> 
 25454 00008DA2 3B83EC010000        <1> 	cmp	eax, [ebx+492]  ; FSI_Next_Free
 25455 00008DA8 741F                <1> 	je	short loc_sffc_retn
 25456                              <1> 
 25457                              <1> loc_sffc_write_fsinfo_sector:
 25458                              <1> 	; EBX = FSINFO sector buffer
 25459                              <1> 	; [CFS_FAT32FSINFOSEC] is set in 'get_fat32_fsinfo_sector_parms'
 25460 00008DAA 8983EC010000        <1> 	mov	[ebx+492], eax
 25461 00008DB0 A1[70C90000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC] 
 25462 00008DB5 B901000000          <1> 	mov	ecx, 1
 25463 00008DBA 53                  <1> 	push	ebx
 25464 00008DBB E8771D0000          <1> 	call	disk_write
 25465 00008DC0 7208                <1> 	jc      short loc_sffc_read_fsinfo_sector_err1
 25466 00008DC2 5B                  <1> 	pop	ebx
 25467                              <1> 
 25468 00008DC3 8B83EC010000        <1> 	mov	eax, [ebx+492] ; First (Next) Free Cluster
 25469                              <1> 
 25470                              <1> loc_sffc_retn:
 25471 00008DC9 C3                  <1> 	retn
 25472                              <1> 
 25473                              <1> ;loc_sffc_invalid_drive:
 25474                              <1> ;	mov	eax, 0Fh ; MSDOS Error : Invalid drive
 25475                              <1> ;	push	edx
 25476                              <1> 
 25477                              <1> loc_sffc_read_fsinfo_sector_err1:
 25478 00008DCA BB00000000          <1> 	mov	ebx, 0
 25479                              <1> 	; 23/03/2016
 25480 00008DCF B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error
 25481                              <1> 
 25482                              <1> loc_sffc_read_fsinfo_sector_err2:
 25483 00008DD4 5A                  <1> 	pop	edx
 25484 00008DD5 C3                  <1> 	retn
 25485                              <1> 	
 25486                              <1> loc_sffc_read_fsinfo_sector:
 25487 00008DD6 50                  <1> 	push	eax
 25488                              <1> 
 25489 00008DD7 E87F050000          <1> 	call	get_fat32_fsinfo_sector_parms
 25490 00008DDC 72F6                <1> 	jc	short loc_sffc_read_fsinfo_sector_err2
 25491                              <1> 
 25492 00008DDE 58                  <1> 	pop	eax
 25493                              <1> 	; EDX = First (Next) Free Cluster value from FSINFO sector
 25494                              <1> 	; EAX = First Free Cluster value from 'get_next_cluster'
 25495                              <1> 	; (edx = old value)
 25496 00008DDF 39D0                <1> 	cmp	eax, edx ; First free Cluster (eax = new value) 
 25497 00008DE1 75C7                <1> 	jne	short loc_sffc_write_fsinfo_sector
 25498                              <1> 
 25499 00008DE3 C3                  <1> 	retn	
 25500                              <1> 
 25501                              <1> update_cluster:
 25502                              <1> 	; 02/03/2016
 25503                              <1> 	; 01/03/2016
 25504                              <1> 	; 29/02/2016
 25505                              <1> 	; 27/02/2016
 25506                              <1> 	; 26/02/2016
 25507                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25508                              <1> 	; 11/08/2011  
 25509                              <1> 	; 09/02/2005
 25510                              <1> 	; INPUT ->
 25511                              <1> 	;	EAX = Cluster Number
 25512                              <1> 	;	ECX = New Cluster Value
 25513                              <1> 	;	ESI = Logical Dos Drive Parameters Table
 25514                              <1> 	;
 25515                              <1> 	;	/// dword [FAT_ClusterCounter] ///
 25516                              <1> 	;
 25517                              <1> 	; OUTPUT ->
 25518                              <1> 	;	cf = 0 -> No Error, EAX is valid
 25519                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
 25520                              <1> 	; 	cf = 1 & EAX > 0 -> Error
 25521                              <1> 	;		(ECX -> any value)
 25522                              <1> 	; 	EAX = Next Cluster
 25523                              <1> 	;	ECX = New Cluster Value
 25524                              <1> 	;
 25525                              <1> 	;	/// [FAT_ClusterCounter] is updated,
 25526                              <1> 	;	/// decreased when a free cluster is assigned,
 25527                              <1> 	;	/// increased if an assigned cluster is freed.	
 25528                              <1> 	;		
 25529                              <1> 	;
 25530                              <1> 	; (Modified registers: EAX, EBX, -ECX-, EDX)
 25531                              <1> 	
 25532 00008DE4 A3[C1C60000]        <1> 	mov	[FAT_CurrentCluster], eax
 25533 00008DE9 890D[64C90000]      <1> 	mov	[ClusterValue], ecx
 25534                              <1> 
 25535                              <1> loc_update_cluster_check_fat_buffer:
 25536 00008DEF 8A1E                <1> 	mov	bl, [esi+LD_Name]
 25537 00008DF1 381D[C6C60000]      <1> 	cmp	[FAT_BuffDrvName], bl
 25538 00008DF7 741A                <1> 	je	short loc_update_cluster_check_fat_type
 25539 00008DF9 803D[C5C60000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 25540 00008E00 0F84C2000000        <1>         je      loc_uc_save_fat_buffer
 25541                              <1> 
 25542                              <1> loc_uc_reset_fat_buffer_validation:
 25543 00008E06 C605[C5C60000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 25544                              <1> 
 25545                              <1> loc_uc_check_fat_type_reset_drvname:
 25546 00008E0D 881D[C6C60000]      <1> 	mov	[FAT_BuffDrvName], bl
 25547                              <1> 
 25548                              <1> loc_update_cluster_check_fat_type:
 25549 00008E13 29D2                <1> 	sub	edx, edx ; 26/02/2016
 25550 00008E15 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
 25551 00008E18 83F802              <1> 	cmp	eax, 2
 25552 00008E1B 0F82BE000000        <1>         jb      update_cluster_inv_data
 25553 00008E21 80FB02              <1> 	cmp	bl, 2 
 25554 00008E24 0F877A010000        <1>         ja      update_fat32_cluster
 25555                              <1> 	;cmp	bl, 1
 25556                              <1> 	;jb	short update_cluster_inv_data
 25557 00008E2A 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
 25558 00008E2D 41                  <1> 	inc	ecx  
 25559 00008E2E 890D[D1C60000]      <1> 	mov	[LastCluster], ecx
 25560 00008E34 39C8                <1> 	cmp	eax, ecx ; dword [LastCluster]
 25561 00008E36 0F87A6000000        <1>         ja      return_uc_fat_stc
 25562                              <1> 	; TRDOS v1 has a FATal bug here ! 
 25563                              <1> 		; or bl, bl ; cmp bl, 0
 25564                              <1> 		; jz short update_fat12_cluster
 25565                              <1> 	; !! It would destroy FAT12 floppy disk fs here !!
 25566                              <1> 	; ('A:' disks of TRDOS v1 operating system project
 25567                              <1> 	; had 'singlix fs', so, I could not differ this mistake
 25568                              <1> 	; on a drive 'A:')
 25569 00008E3C 80FB01              <1> 	cmp	bl, 1 ; correct comparison is this !
 25570 00008E3F 0F86A2000000        <1>         jna     update_fat12_cluster 
 25571                              <1> 
 25572                              <1> update_fat16_cluster:
 25573                              <1> pass_uc_fat16_errc:
 25574                              <1> 	;sub	edx, edx
 25575 00008E45 BB00030000          <1> 	mov	ebx, 300h ;768
 25576 00008E4A F7F3                <1> 	div	ebx
 25577                              <1> 	; EAX = Count of 3 FAT sectors
 25578                              <1> 	; DX = Cluster offset in FAT buffer
 25579 00008E4C 6689D3              <1> 	mov	bx, dx  
 25580 00008E4F 66D1E3              <1> 	shl	bx, 1 ; Multiply by 2
 25581 00008E52 66BA0300            <1> 	mov	dx, 3
 25582 00008E56 F7E2                <1> 	mul	edx  
 25583                              <1> 	; EAX = FAT Sector
 25584                              <1> 	; EDX = 0
 25585                              <1> 	; EBX = Byte offset in FAT buffer
 25586 00008E58 8A0D[C5C60000]      <1> 	mov	cl, [FAT_BuffValidData]
 25587 00008E5E 80F902              <1> 	cmp	cl, 2
 25588 00008E61 750A                <1> 	jne	short loc_uc_check_fat16_buff_sector_load
 25589                              <1> 
 25590                              <1> loc_uc_check_fat16_buff_sector_save:
 25591 00008E63 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 25592 00008E69 755D                <1> 	jne	short loc_uc_save_fat_buffer
 25593 00008E6B EB15                <1> 	jmp	short loc_update_fat16_cell
 25594                              <1> 
 25595                              <1> loc_uc_check_fat16_buff_sector_load:
 25596 00008E6D 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
 25597 00008E70 0F85FB010000        <1>         jne     loc_uc_load_fat_sectors
 25598 00008E76 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 25599 00008E7C 0F85EF010000        <1>         jne     loc_uc_load_fat_sectors
 25600                              <1> 
 25601                              <1> loc_update_fat16_cell:
 25602                              <1> loc_update_fat16_buffer:
 25603 00008E82 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 25604                              <1> 	;movzx	eax, word [ebx]
 25605 00008E88 668B03              <1> 	mov	ax, [ebx]
 25606                              <1> 	; 01/03/2016
 25607 00008E8B 89C2                <1> 	mov	edx, eax ; old value of the cluster
 25608 00008E8D A3[C1C60000]        <1> 	mov	[FAT_CurrentCluster], eax
 25609 00008E92 8B0D[64C90000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 25610 00008E98 66890B              <1> 	mov	[ebx], cx ; 16 bits !
 25611                              <1> 
 25612 00008E9B C605[C5C60000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 25613                              <1> 	
 25614 00008EA2 6683F802            <1> 	cmp	ax, 2
 25615 00008EA6 723A                <1> 	jb	short return_uc_fat_stc
 25616 00008EA8 3B05[D1C60000]      <1> 	cmp	eax, [LastCluster]
 25617 00008EAE 7732                <1> 	ja	short return_uc_fat_stc
 25618                              <1> 
 25619                              <1> loc_fat_buffer_updated:
 25620                              <1> 	; 01/03/2016
 25621 00008EB0 F8                  <1> 	clc
 25622                              <1> loc_fat_buffer_stc_1:
 25623 00008EB1 9C                  <1> 	pushf
 25624 00008EB2 21C9                <1> 	and	ecx, ecx
 25625 00008EB4 7506                <1> 	jnz	short loc_fat_buffer_updated_1
 25626                              <1> 
 25627                              <1> 	; 01/03/2016 
 25628                              <1> 	; new value of the cluster = 0 (free)
 25629                              <1> 	; increase free(d) cluster count
 25630 00008EB6 FF05[CDC60000]      <1> 	inc	dword [FAT_ClusterCounter]
 25631                              <1> 
 25632                              <1> loc_fat_buffer_updated_1: ; new value of the cluster > 0
 25633 00008EBC 09D2                <1> 	or	edx, edx ; 02/03/2016
 25634 00008EBE 7506                <1> 	jnz	short loc_fat_buffer_updated_2
 25635                              <1> 	; old value of the cluster = 0 (it was free cluster)
 25636                              <1> 	; decrease free(d) cluster count
 25637 00008EC0 FF0D[CDC60000]      <1> 	dec	dword [FAT_ClusterCounter] ; it may be negative number
 25638                              <1> 
 25639                              <1> loc_fat_buffer_updated_2:
 25640 00008EC6 9D                  <1> 	popf
 25641 00008EC7 C3                  <1> 	retn
 25642                              <1> 
 25643                              <1> loc_uc_save_fat_buffer:
 25644                              <1> 	; byte [FAT_BuffValidData] = 2 
 25645 00008EC8 E8D4010000          <1> 	call	save_fat_buffer
 25646 00008ECD 0F8297010000        <1>         jc      loc_fat_sectors_rw_error2
 25647                              <1> 	;mov	byte [FAT_BuffValidData], 1
 25648 00008ED3 A1[C1C60000]        <1> 	mov	eax, [FAT_CurrentCluster]
 25649                              <1> 	;mov	ecx, [ClusterValue]
 25650                              <1> 	;jmp	short loc_update_cluster_check_fat_buffer
 25651 00008ED8 8A1E                <1> 	mov	bl, [esi+LD_Name] ; 01/03/2016
 25652 00008EDA E927FFFFFF          <1>         jmp     loc_uc_reset_fat_buffer_validation
 25653                              <1> 
 25654                              <1> update_cluster_inv_data:
 25655                              <1> 	;mov	eax, 0Dh
 25656 00008EDF B00D                <1> 	mov	al, 0Dh  ; Invalid Data
 25657 00008EE1 C3                  <1> 	retn 
 25658                              <1> 
 25659                              <1> return_uc_fat_stc:
 25660                              <1> 	; 01/03/2016
 25661 00008EE2 31C0                <1> 	xor	eax, eax
 25662 00008EE4 F9                  <1> 	stc
 25663 00008EE5 EBCA                <1> 	jmp	short loc_fat_buffer_stc_1
 25664                              <1> 
 25665                              <1> update_fat12_cluster:
 25666                              <1> pass_uc_fat12_errc:
 25667                              <1> 	;sub	edx, edx
 25668 00008EE7 BB00040000          <1> 	mov	ebx, 400h ;1024
 25669 00008EEC F7F3                <1> 	div	ebx
 25670                              <1> 	; EAX = Count of 3 FAT sectors
 25671                              <1> 	; DX = Cluster offset in FAT buffer
 25672 00008EEE 66B90300            <1> 	mov	cx, 3
 25673 00008EF2 6689C3              <1> 	mov	bx, ax
 25674 00008EF5 6689C8              <1> 	mov	ax, cx ; 3
 25675 00008EF8 66F7E2              <1> 	mul	dx     ; Multiply by 3
 25676 00008EFB 66D1E8              <1> 	shr	ax, 1  ; Divide by 2
 25677 00008EFE 6693                <1> 	xchg	bx, ax
 25678                              <1> 	; EAX = Count of 3 FAT sectors
 25679                              <1> 	; EBX = Byte Offset in FAT buffer   
 25680 00008F00 66F7E1              <1> 	mul	cx  ; 3 * AX
 25681                              <1> 	; EAX = FAT Beginning Sector
 25682                              <1> 	; EDX = 0
 25683 00008F03 8A0D[C5C60000]      <1> 	mov	cl, [FAT_BuffValidData]
 25684                              <1> 	; TRDOS v1 has a FATal bug here ! 
 25685                              <1> 	; (it does not have 'cmp cl, 2' instruction here !
 25686                              <1> 	;  while 'jne' is existing !)
 25687 00008F09 80F902              <1> 	cmp	cl, 2 ; 2 = dirty buffer (must be written to disk)
 25688 00008F0C 750A                <1> 	jne	short loc_uc_check_fat12_buff_sector_load
 25689                              <1> 
 25690                              <1> loc_uc_check_fat12_buff_sector_save:
 25691 00008F0E 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 25692 00008F14 75B2                <1>         jne     short loc_uc_save_fat_buffer
 25693 00008F16 EB15                <1> 	jmp	short loc_update_fat12_cell
 25694                              <1> 
 25695                              <1> loc_uc_check_fat12_buff_sector_load:
 25696 00008F18 80F901              <1> 	cmp	cl, 1 ; byte ptr [FAT_BuffValidData]
 25697 00008F1B 0F8550010000        <1>         jne     loc_uc_load_fat_sectors
 25698 00008F21 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 25699 00008F27 0F8544010000        <1>         jne     loc_uc_load_fat_sectors
 25700                              <1> 
 25701                              <1> loc_update_fat12_cell:
 25702 00008F2D 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 25703 00008F33 668B0D[C1C60000]    <1> 	mov	cx, [FAT_CurrentCluster]
 25704 00008F3A 66D1E9              <1> 	shr	cx, 1
 25705 00008F3D 668B03              <1> 	mov	ax, [ebx]
 25706 00008F40 6689C2              <1> 	mov	dx, ax
 25707 00008F43 7344                <1> 	jnc	short uc_fat12_nc_even
 25708                              <1> 
 25709 00008F45 6683E00F            <1> 	and	ax, 0Fh
 25710 00008F49 8B0D[64C90000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 25711 00008F4F 66C1E104            <1> 	shl	cx, 4
 25712 00008F53 6609C1              <1> 	or	cx, ax
 25713 00008F56 6689D0              <1> 	mov	ax, dx
 25714 00008F59 66890B              <1> 	mov	[ebx], cx  ; 16 bits !
 25715 00008F5C 66C1E804            <1> 	shr	ax, 4 ; al(bit4..7)+ah(bit0..7)
 25716                              <1> 
 25717                              <1> update_fat12_buffer:
 25718 00008F60 A3[C1C60000]        <1> 	mov	[FAT_CurrentCluster], eax
 25719 00008F65 89C2                <1> 	mov	edx, eax ; 01/03/2016
 25720 00008F67 C605[C5C60000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 25721 00008F6E 6683F802            <1> 	cmp	ax, 2
 25722 00008F72 0F826AFFFFFF        <1>         jb      return_uc_fat_stc
 25723 00008F78 3B05[D1C60000]      <1> 	cmp	eax, [LastCluster]
 25724 00008F7E 0F875EFFFFFF        <1>         ja      return_uc_fat_stc
 25725 00008F84 E927FFFFFF          <1>         jmp     loc_fat_buffer_updated
 25726                              <1> 
 25727                              <1> uc_fat12_nc_even:
 25728 00008F89 662500F0            <1> 	and	ax, 0F000h
 25729 00008F8D 8B0D[64C90000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 25730 00008F93 80E50F              <1> 	and	ch, 0Fh
 25731 00008F96 6609C1              <1> 	or	cx, ax
 25732 00008F99 6689D0              <1> 	mov	ax, dx
 25733 00008F9C 66890B              <1> 	mov	[ebx], cx ; 16 bits !
 25734 00008F9F 80E40F              <1> 	and	ah, 0Fh ; al(bit0..7)+ah(bit0..3)
 25735 00008FA2 EBBC                <1> 	jmp	short update_fat12_buffer
 25736                              <1> 
 25737                              <1> update_fat32_cluster:
 25738 00008FA4 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
 25739 00008FA7 41                  <1> 	inc	ecx
 25740 00008FA8 890D[D1C60000]      <1> 	mov	[LastCluster], ecx
 25741                              <1> 
 25742 00008FAE 39C8                <1> 	cmp	eax, ecx
 25743 00008FB0 0F872CFFFFFF        <1>         ja      return_uc_fat_stc
 25744                              <1> 
 25745                              <1> pass_uc_fat32_errc:
 25746                              <1> 	;sub	edx, edx
 25747 00008FB6 BB80010000          <1> 	mov	ebx, 180h ;384
 25748 00008FBB F7F3                <1> 	div	ebx
 25749                              <1> 	; EAX = Count of 3 FAT sectors
 25750                              <1> 	; DX = Cluster offset in FAT buffer
 25751 00008FBD 89D3                <1> 	mov	ebx, edx
 25752 00008FBF C1E302              <1> 	shl	ebx, 2 ; Multiply by 4
 25753 00008FC2 BA03000000          <1> 	mov	edx, 3	
 25754 00008FC7 F7E2                <1> 	mul	edx
 25755                              <1> 	; EBX = Cluster Offset in FAT buffer
 25756                              <1> 	; EAX = FAT Sector
 25757                              <1> 	; EDX = 0
 25758 00008FC9 8A0D[C5C60000]      <1> 	mov	cl, [FAT_BuffValidData]
 25759 00008FCF 80F902              <1> 	cmp	cl, 2
 25760 00008FD2 750E                <1> 	jne	short loc_uc_check_fat32_buff_sector_load
 25761                              <1> 
 25762                              <1> loc_uc_check_fat32_buff_sector_save:
 25763 00008FD4 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 25764 00008FDA 0F85E8FEFFFF        <1>         jne     loc_uc_save_fat_buffer
 25765 00008FE0 EB11                <1> 	jmp	short loc_update_fat32_cell
 25766                              <1> 
 25767                              <1> loc_uc_check_fat32_buff_sector_load:
 25768 00008FE2 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
 25769 00008FE5 0F8586000000        <1>         jne     loc_uc_load_fat_sectors
 25770 00008FEB 3B05[C9C60000]      <1> 	cmp	eax, [FAT_BuffSector]
 25771 00008FF1 757E                <1>         jne     loc_uc_load_fat_sectors
 25772                              <1> 
 25773                              <1> loc_update_fat32_cell:
 25774                              <1> loc_update_fat32_buffer:
 25775 00008FF3 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 25776 00008FF9 8B03                <1> 	mov	eax, [ebx]
 25777 00008FFB 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh ; 28 bit cluster value
 25778                              <1> 	
 25779 00009000 8B15[C1C60000]      <1> 	mov	edx, [FAT_CurrentCluster] ; 01/03/2016
 25780                              <1> 
 25781 00009006 A3[C1C60000]        <1> 	mov 	[FAT_CurrentCluster], eax
 25782 0000900B 8B0D[64C90000]      <1> 	mov	ecx, [ClusterValue]
 25783 00009011 890B                <1> 	mov	[ebx], ecx ; 29/02/2016 
 25784                              <1> 
 25785 00009013 C605[C5C60000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 25786                              <1> 
 25787                              <1> 	; 01/03/2016
 25788 0000901A 21C0                <1> 	and	eax, eax ; was it free cluster ?
 25789 0000901C 7514                <1> 	jnz	short loc_upd_fat32_c0
 25790                              <1> 
 25791                              <1> 	;or	ecx, ecx ; it will be left free ?!
 25792                              <1> 	;jz	short loc_upd_fat32_c3
 25793                              <1> 
 25794 0000901E 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
 25795 00009021 7520                <1> 	jne	short loc_upd_fat32_c3
 25796                              <1> 
 25797 00009023 3B15[D1C60000]      <1> 	cmp	edx, [LastCluster]
 25798 00009029 7207                <1> 	jb	short loc_upd_fat32_c0
 25799                              <1> 
 25800 0000902B BA02000000          <1> 	mov	edx, 2 ; rewind !
 25801 00009030 EB0E                <1> 	jmp	short loc_upd_fat32_c2
 25802                              <1> 
 25803                              <1> loc_upd_fat32_c0:
 25804 00009032 FF463E              <1> 	inc	dword [esi+LD_BPB+BPB_Reserved+4] ; set it to next cluster		
 25805 00009035 EB0C                <1> 	jmp	short loc_upd_fat32_c3
 25806                              <1> 
 25807                              <1> loc_upd_fat32_c1:
 25808 00009037 09C9                <1> 	or	ecx, ecx ; will it be free cluster ?
 25809 00009039 7508                <1> 	jnz	short loc_upd_fat32_c3
 25810                              <1> 
 25811 0000903B 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
 25812 0000903E 7303                <1> 	jnb	short loc_upd_fat32_c3
 25813                              <1> 
 25814                              <1> loc_upd_fat32_c2:	
 25815 00009040 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx			
 25816                              <1> 
 25817                              <1> loc_upd_fat32_c3:
 25818 00009043 89C2                <1> 	mov	edx, eax
 25819                              <1> 
 25820                              <1> loc_upd_fat32_c4:
 25821 00009045 83F802              <1> 	cmp	eax, 2
 25822 00009048 0F8294FEFFFF        <1>         jb      return_uc_fat_stc
 25823                              <1> 
 25824                              <1> pass_uc_fat32_c_zero_check_2:
 25825 0000904E 3B05[D1C60000]      <1> 	cmp	eax, [LastCluster]
 25826 00009054 0F8788FEFFFF        <1>         ja      return_uc_fat_stc
 25827                              <1> 	
 25828 0000905A E951FEFFFF          <1> 	jmp     loc_fat_buffer_updated
 25829                              <1> 
 25830                              <1> loc_fat_sectors_rw_error1:
 25831                              <1> 	;mov	byte [FAT_BuffValidData], 0
 25832                              <1> 	; 23/03/2016
 25833 0000905F B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
 25834 00009064 8825[C5C60000]      <1> 	mov	[FAT_BuffValidData], ah ; 0
 25835                              <1> 
 25836                              <1> loc_fat_sectors_rw_error2:
 25837                              <1> 	;mov	eax, error code
 25838                              <1> 	;mov	edx, 0
 25839 0000906A 8B0D[64C90000]      <1> 	mov	ecx, [ClusterValue]
 25840 00009070 C3                  <1> 	retn
 25841                              <1> 
 25842                              <1> loc_uc_load_fat_sectors:
 25843 00009071 A3[C9C60000]        <1> 	mov	[FAT_BuffSector], eax
 25844                              <1> 
 25845                              <1> load_uc_fat_sectors_zero:
 25846 00009076 034660              <1> 	add	eax, [esi+LD_FATBegin]
 25847 00009079 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 25848 0000907E B903000000          <1> 	mov	ecx, 3
 25849 00009083 E8BE1A0000          <1> 	call	disk_read
 25850 00009088 72D5                <1> 	jc	short loc_fat_sectors_rw_error1
 25851                              <1> 
 25852 0000908A C605[C5C60000]01    <1>         mov     byte [FAT_BuffValidData], 1
 25853 00009091 A1[C1C60000]        <1> 	mov 	eax, [FAT_CurrentCluster]
 25854 00009096 8B0D[64C90000]      <1> 	mov	ecx, [ClusterValue]
 25855 0000909C E972FDFFFF          <1>         jmp     loc_update_cluster_check_fat_type
 25856                              <1> 
 25857                              <1> save_fat_buffer:
 25858                              <1> 	; 01/03/2016
 25859                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25860                              <1> 	; 11/08/2011
 25861                              <1> 	; 09/02/2005 
 25862                              <1> 	; INPUT ->
 25863                              <1> 	;	None
 25864                              <1> 	; OUTPUT ->
 25865                              <1> 	;	cf = 0 -> OK.
 25866                              <1> 	;	cf = 1 -> error code in AL (EAX)
 25867                              <1> 	;
 25868                              <1> 	;	EBX = FAT_Buffer address
 25869                              <1> 	;
 25870                              <1> 	; (EAX, EDX, ECX will be modified)
 25871                              <1> 
 25872                              <1> 	;cmp	byte [FAT_BuffValidData], 2 
 25873                              <1> 	;je	short loc_save_fat_buff
 25874                              <1> 
 25875                              <1> ;loc_save_fat_buffer_retn:
 25876                              <1> ;	xor	eax, eax
 25877                              <1> ;	retn
 25878                              <1> 
 25879                              <1> loc_save_fat_buff:
 25880 000090A1 31D2                <1> 	xor	edx, edx
 25881 000090A3 8A35[C6C60000]      <1> 	mov	dh, [FAT_BuffDrvName]
 25882 000090A9 80FE41              <1> 	cmp	dh, 'A'
 25883 000090AC 722E                <1> 	jb	short loc_save_fat_buffer_inv_data_retn
 25884 000090AE 80EE41              <1> 	sub	dh, 'A'
 25885 000090B1 56                  <1> 	push	esi ; *
 25886 000090B2 BE00010900          <1>         mov     esi, Logical_DOSDisks
 25887 000090B7 01D6                <1> 	add	esi, edx
 25888                              <1> 	
 25889 000090B9 8A5603              <1> 	mov	dl, [esi+LD_FATType]
 25890 000090BC 20D2                <1> 	and	dl, dl
 25891 000090BE 741B                <1> 	jz	short loc_save_fat_buffer_inv_data_pop_retn 
 25892                              <1> 
 25893 000090C0 A1[C9C60000]        <1> 	mov	eax, [FAT_BuffSector]
 25894 000090C5 80FA02              <1> 	cmp	dl, 2
 25895 000090C8 770A                <1> 	ja	short loc_save_fat32_buff
 25896                              <1> 
 25897                              <1> loc_save_fat_12_16_buff:
 25898                              <1> 	; 01/03/2016
 25899                              <1> 	; TRDOS v1 has a FATal bug here!
 25900                              <1> 	; Correct code: mov dx, word ptr [FAT_BuffSector]+2
 25901                              <1> 	; (DX:AX in TRDOS v1 -> EAX in TRDOS v2)
 25902                              <1> 	;
 25903 000090CA 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+FATSecs] 
 25904 000090CE 29C1                <1> 	sub	ecx, eax
 25905                              <1> 	; TRDOS v1 has a bug here... ('pop esi' was forgotten!)
 25906                              <1> 	;jna	short loc_save_fat_buffer_inv_data_retn ; wrong addr!
 25907 000090D0 7609                <1> 	jna	short loc_save_fat_buffer_inv_data_pop_retn ; correct addr.
 25908 000090D2 EB15                <1> 	jmp	short loc_save_fat_buffer_check_rs3
 25909                              <1> 
 25910                              <1> loc_save_fat32_buff:
 25911 000090D4 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+FAT32_FAT_Size]
 25912 000090D7 29C1                <1> 	sub	ecx, eax
 25913 000090D9 770E                <1> 	ja	short loc_save_fat_buffer_check_rs3
 25914                              <1> 
 25915                              <1> loc_save_fat_buffer_inv_data_pop_retn:
 25916 000090DB 5E                  <1> 	pop	esi ; *
 25917                              <1> loc_save_fat_buffer_inv_data_retn:
 25918 000090DC B80D000000          <1> 	mov	eax, 0Dh ; Invalid DATA
 25919 000090E1 C3                  <1> 	retn
 25920                              <1> 
 25921                              <1> loc_save_fat_buff_remain_sectors_3:
 25922 000090E2 B903000000          <1> 	mov	ecx, 3
 25923 000090E7 EB05                <1> 	jmp	short loc_save_fat_buff_continue
 25924                              <1> 
 25925                              <1> loc_save_fat_buffer_check_rs3:
 25926 000090E9 83F903              <1> 	cmp	ecx, 3
 25927 000090EC 77F4                <1> 	ja	short loc_save_fat_buff_remain_sectors_3
 25928                              <1> 
 25929                              <1> loc_save_fat_buff_continue:
 25930 000090EE BB001C0900          <1> 	mov	ebx, FAT_Buffer
 25931 000090F3 034660              <1> 	add	eax, [esi+LD_FATBegin]
 25932 000090F6 51                  <1> 	push	ecx
 25933 000090F7 E83B1A0000          <1> 	call	disk_write
 25934 000090FC 59                  <1> 	pop	ecx
 25935 000090FD 722B                <1> 	jc	short loc_save_FAT_buff_write_err
 25936                              <1> 	
 25937 000090FF 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 25938 00009103 7605                <1> 	jna	short loc_calc_2nd_fat12_16_addr
 25939                              <1> 
 25940                              <1> loc_calc_2nd_fat32_addr:
 25941 00009105 8B462A              <1> 	mov	eax, [esi+LD_BPB+FAT32_FAT_Size]
 25942 00009108 EB04                <1> 	jmp	short loc_calc_2nd_fat_addr
 25943                              <1> 
 25944                              <1> loc_calc_2nd_fat12_16_addr:
 25945 0000910A 0FB7461C            <1> 	movzx	eax, word [esi+LD_BPB+FATSecs]
 25946                              <1> 
 25947                              <1> loc_calc_2nd_fat_addr:
 25948 0000910E 034660              <1> 	add	eax, [esi+LD_FATBegin]
 25949 00009111 0305[C9C60000]      <1> 	add	eax, [FAT_BuffSector]
 25950 00009117 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 25951                              <1> 	; ecx = 1 to 3
 25952 0000911C E8161A0000          <1> 	call	disk_write
 25953 00009121 7207                <1> 	jc	short loc_save_FAT_buff_write_err
 25954                              <1>  	; Valid  buffer (1 = valid but do not save)
 25955 00009123 C605[C5C60000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 25956                              <1> 
 25957                              <1> loc_save_FAT_buff_write_err:
 25958 0000912A 5E                  <1> 	pop	esi ; *
 25959 0000912B BB001C0900          <1> 	mov	ebx, FAT_Buffer
 25960                              <1> 	; 23/03/2016
 25961 00009130 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error
 25962 00009135 C3                  <1> 	retn
 25963                              <1> 
 25964                              <1> calculate_fat_freespace:
 25965                              <1> 	; 23/03/2016
 25966                              <1> 	; 02/03/2016
 25967                              <1> 	; 01/03/2016
 25968                              <1> 	; 29/02/2016
 25969                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 25970                              <1> 	; 30/04/2011
 25971                              <1> 	; 03/04/2010
 25972                              <1> 	; 2005
 25973                              <1> 	; INPUT ->
 25974                              <1> 	;	EAX = Cluster count to be added or subtracted
 25975                              <1> 	; 	If BH = FFh, ESI = TR-DOS Logical Drive Description Table
 25976                              <1> 	; 	If BH < FFh, BH = TR-DOS Logical Drive Number
 25977                              <1> 	; 	BL: 
 25978                              <1> 	;	0 = Calculate, 1 = Add, 2 = Subtract, 3 = Get (Not Set/Calc)
 25979                              <1> 	; OUTPUT ->
 25980                              <1> 	;	EAX = Free Space in sectors
 25981                              <1> 	;	ESI = Logical Dos Drive Description Table address
 25982                              <1> 	;	BH = Logical Dos Drive Number (same with input value of BH)
 25983                              <1> 	;	BL = Type of operation (same with input value of BL)
 25984                              <1> 	;	ECX = 0 -> valid
 25985                              <1> 	;	ECX > 0 -> error or invalid
 25986                              <1> 	;	If EAX = FFFFFFFFh, it is 're-calculation needed'
 25987                              <1> 	;			          sign due to r/w error   
 25988                              <1> 
 25989 00009136 66891D[6AC90000]    <1> 	mov	[CFS_OPType], bx
 25990 0000913D A3[6CC90000]        <1> 	mov	[CFS_CC], eax
 25991                              <1> 	
 25992 00009142 80FFFF              <1> 	cmp	bh, 0FFh
 25993 00009145 740B                <1> 	je	short pass_calculate_freespace_get_drive_dt_offset
 25994                              <1> 
 25995                              <1> loc_calculate_freespace_get_drive_dt_offset:     
 25996 00009147 31C0                <1> 	xor	eax, eax
 25997 00009149 88FC                <1>         mov     ah, bh
 25998 0000914B BE00010900          <1> 	mov	esi, Logical_DOSDisks
 25999 00009150 01C6                <1>         add     esi, eax
 26000                              <1> 
 26001                              <1> pass_calculate_freespace_get_drive_dt_offset:
 26002 00009152 08DB                <1> 	or	bl, bl
 26003 00009154 7435                <1> 	jz	short loc_reset_fcc
 26004                              <1> 	
 26005                              <1> loc_get_free_sectors:
 26006 00009156 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
 26007                              <1> 
 26008                              <1> 	;xor	ecx, ecx
 26009                              <1> 	;dec	ecx ; 0FFFFFFFFh
 26010                              <1> 	;cmp	eax, ecx ; 29/02/2016
 26011                              <1> 	;je	short loc_get_free_sectors_retn ; recalculation is needed!
 26012                              <1> 	
 26013                              <1> 	; 23/03/2016
 26014 00009159 8B4E70              <1> 	mov	ecx, [esi+LD_TotalSectors]
 26015 0000915C 39C1                <1> 	cmp	ecx, eax ; Total sectors must be greater than Free sectors !
 26016 0000915E 7707                <1> 	ja	short loc_get_free_sectors_check_optype
 26017                              <1> 	
 26018 00009160 31C0                <1> 	xor	eax, eax
 26019 00009162 48                  <1> 	dec	eax ; 0FFFFFFFFh  ; recalculation is needed!
 26020 00009163 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; reset (for recalculation)
 26021                              <1> 		
 26022                              <1> loc_get_free_sectors_retn:
 26023 00009166 C3                  <1> 	retn
 26024                              <1> 	
 26025                              <1> loc_get_free_sectors_check_optype:
 26026 00009167 80FB03              <1> 	cmp	bl, 3
 26027 0000916A 7203                <1> 	jb	short loc_set_fcc
 26028                              <1> 
 26029 0000916C 29C9                <1> 	sub	ecx, ecx ; 0
 26030                              <1> 
 26031 0000916E C3                  <1> 	retn	
 26032                              <1> 
 26033                              <1> loc_set_fcc:
 26034 0000916F 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 26035 00009173 0F87DF000000        <1>         ja      loc_update_FAT32_fs_info_fcc
 26036                              <1> 
 26037                              <1> 	;mov	eax, [esi+LD_FreeSectors]
 26038 00009179 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 26039 0000917D 29D2                <1> 	sub	edx, edx
 26040 0000917F F7F1                <1> 	div	ecx
 26041                              <1> 	;or	dx, dx 
 26042                              <1> 	;	; DX -> Remain sectors < SecPerClust
 26043                              <1> 	;	; DX > 0 -> invalid free sector count
 26044                              <1> 	;jnz	short loc_reset_fcc 
 26045                              <1> 
 26046                              <1> ;pass_set_fcc_div32:
 26047 00009181 A3[E3C60000]        <1> 	mov	[FreeClusterCount], eax
 26048 00009186 E988000000          <1>         jmp     loc_set_free_sectors_FAT12_FAT16
 26049                              <1> 
 26050                              <1> loc_reset_fcc:
 26051 0000918B 31C0                <1> 	xor	eax, eax
 26052 0000918D A3[E3C60000]        <1> 	mov	[FreeClusterCount], eax ; 0
 26053 00009192 8B5678              <1> 	mov	edx, [esi+LD_Clusters]
 26054 00009195 42                  <1> 	inc	edx
 26055 00009196 8915[D1C60000]      <1> 	mov	[LastCluster], edx
 26056                              <1> 
 26057 0000919C 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 26058 000091A0 7647                <1> 	jna	short loc_count_free_fat_clusters_0  
 26059                              <1> 
 26060 000091A2 48                  <1> 	dec	eax ; FFFFFFFFh
 26061 000091A3 A3[74C90000]        <1> 	mov	[CFS_FAT32FC], eax
 26062                              <1> 
 26063                              <1> 	; 29/02/2016
 26064 000091A8 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; reset
 26065 000091AB 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; reset
 26066                              <1> 	
 26067 000091AE B802000000          <1> 	mov 	eax, 2
 26068                              <1> 
 26069                              <1> loc_count_fc_next_cluster_0:
 26070 000091B3 50                  <1> 	push	eax
 26071 000091B4 E801F9FFFF          <1> 	call	get_next_cluster
 26072 000091B9 7310                <1> 	jnc	short loc_check_fat32_ff_cluster
 26073 000091BB 09C0                <1> 	or	eax, eax
 26074 000091BD 741E                <1> 	jz	short pass_inc_cfs_fcc_0
 26075                              <1> 
 26076                              <1> loc_put_fcc_unknown_sign:
 26077 000091BF 58                  <1> 	pop	eax
 26078                              <1> 	; "Free count is Unknown" sign
 26079                              <1> 	;mov	dword [FreeClusterCount], 0FFFFFFFFh
 26080                              <1> 
 26081                              <1> 	; 29/02/2016
 26082                              <1> 	; Save Free Cluster Count value in FAT32 'BPB_Reserved' area
 26083                              <1> 	;mov	[esi+LD_BPB+BPB_Reserved], 0FFFFFFFFh ; unknown!
 26084 000091C0 8B15[74C90000]      <1> 	mov	edx, [CFS_FAT32FC] ; First Free Cluster
 26085                              <1> 	; Save First Free Cluster value in FAT32 'BPB_Reserved+4' area
 26086 000091C6 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
 26087                              <1> 	
 26088 000091C9 EB7D                <1>         jmp     loc_put_fcc_invalid_sign
 26089                              <1> 
 26090                              <1> loc_check_fat32_ff_cluster:
 26091 000091CB 09C0                <1> 	or	eax, eax
 26092 000091CD 750E                <1> 	jnz	short pass_inc_cfs_fcc_0
 26093 000091CF 58                  <1> 	pop	eax
 26094 000091D0 A3[74C90000]        <1> 	mov	[CFS_FAT32FC], eax
 26095                              <1> 	;mov	dword [FreeClusterCount], 1
 26096 000091D5 FF05[E3C60000]      <1> 	inc	dword [FreeClusterCount]
 26097 000091DB EB27                <1> 	jmp	short pass_inc_cfs_fcc_1
 26098                              <1> 
 26099                              <1> pass_inc_cfs_fcc_0:
 26100 000091DD 58                  <1> 	pop	eax
 26101                              <1> 
 26102                              <1> pass_inc_cfs_fcc_0c:
 26103 000091DE 40                  <1> 	inc	eax ; add eax, 1
 26104 000091DF 3B05[D1C60000]      <1> 	cmp	eax, [LastCluster]
 26105 000091E5 76CC                <1> 	jna 	short loc_count_fc_next_cluster_0
 26106 000091E7 EB6F                <1> 	jmp	short loc_update_FAT32_fs_info_fcc
 26107                              <1> 
 26108                              <1> loc_count_free_fat_clusters_0:
 26109                              <1> 	;mov	eax, 2
 26110 000091E9 B002                <1> 	mov	al, 2
 26111                              <1> 
 26112                              <1> loc_count_fc_next_cluster:
 26113 000091EB 50                  <1> 	push	eax
 26114 000091EC E8C9F8FFFF          <1> 	call	get_next_cluster
 26115 000091F1 720C                <1> 	jc	short loc_count_fcc_stc
 26116                              <1> 
 26117                              <1> loc_count_free_clusters_1:
 26118 000091F3 21C0                <1> 	and	eax, eax
 26119 000091F5 750C                <1> 	jnz	short pass_inc_cfs_fcc
 26120                              <1> 
 26121 000091F7 FF05[E3C60000]      <1> 	inc	dword [FreeClusterCount]
 26122 000091FD EB04                <1> 	jmp	short pass_inc_cfs_fcc
 26123                              <1> 
 26124                              <1> loc_count_fcc_stc:
 26125 000091FF 09C0                <1> 	or	eax, eax
 26126 00009201 75BC                <1> 	jnz	short loc_put_fcc_unknown_sign ; 29/02/2016
 26127                              <1> 
 26128                              <1> pass_inc_cfs_fcc:
 26129 00009203 58                  <1> 	pop	eax
 26130                              <1> 
 26131                              <1> pass_inc_cfs_fcc_1:
 26132 00009204 40                  <1> 	inc	eax ; add eax, 1
 26133 00009205 3B05[D1C60000]      <1> 	cmp	eax, [LastCluster]
 26134 0000920B 76DE                <1> 	jna	short loc_count_fc_next_cluster
 26135                              <1> 
 26136                              <1> loc_set_free_sectors:
 26137 0000920D 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 26138 00009211 7745                <1> 	ja	short loc_update_FAT32_fs_info_fcc
 26139                              <1> 
 26140                              <1> loc_set_free_sectors_FAT12_FAT16:
 26141 00009213 803D[6AC90000]00    <1> 	cmp	byte [CFS_OPType], 0
 26142 0000921A 761C                <1> 	jna	short pass_FAT_add_sub_fcc
 26143 0000921C A1[6CC90000]        <1> 	mov	eax, [CFS_CC]
 26144 00009221 803D[6AC90000]01    <1> 	cmp	byte [CFS_OPType], 1
 26145 00009228 7708                <1> 	ja	short pass_FAT_add_fcc
 26146 0000922A 0105[E3C60000]      <1> 	add 	[FreeClusterCount], eax
 26147 00009230 EB06                <1> 	jmp	short pass_FAT_add_sub_fcc
 26148                              <1> 
 26149                              <1> pass_FAT_add_fcc:
 26150 00009232 2905[E3C60000]      <1> 	sub	[FreeClusterCount], eax
 26151                              <1> 
 26152                              <1> pass_FAT_add_sub_fcc:
 26153 00009238 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
 26154 0000923C 8B15[E3C60000]      <1> 	mov	edx, [FreeClusterCount]
 26155 00009242 F7E2                <1> 	mul	edx
 26156                              <1> 
 26157 00009244 31C9                <1> 	xor	ecx, ecx 
 26158 00009246 EB05                <1> 	jmp	short loc_cfs_retn_params
 26159                              <1> 
 26160                              <1> loc_put_fcc_invalid_sign:
 26161 00009248 29C0                <1>        	sub	eax, eax ; 0
 26162 0000924A 48                  <1> 	dec	eax ; FFFFFFFFh
 26163                              <1> loc_fat32_ffc_recalc_needed:
 26164 0000924B 89C1                <1> 	mov	ecx, eax
 26165                              <1> 
 26166                              <1> loc_cfs_retn_params:
 26167 0000924D 894674              <1> 	mov 	[esi+LD_FreeSectors], eax
 26168 00009250 0FB71D[6AC90000]    <1> 	movzx	ebx, word [CFS_OPType]
 26169 00009257 C3                  <1> 	retn
 26170                              <1> 
 26171                              <1> loc_update_FAT32_fs_info_fcc:
 26172                              <1> loc_check_fcc_FSINFO_op:
 26173                              <1> 	; 29/02/2016
 26174                              <1> 	; EAX = Free cluster count (before this update) ; value from disk
 26175                              <1> 	; EDX = First Free Cluster (before this update) ; value from disk
 26176 00009258 803D[6AC90000]01    <1> 	cmp	byte [CFS_OPType], 1
 26177 0000925F 7221                <1> 	jb	short loc_cfs_FAT32_get_rcalc_parms ; 0 = recalculated
 26178 00009261 7406                <1> 	je	short loc_check_fcc_FSINFO_op1 ; 1 = add
 26179                              <1> loc_check_fcc_FSINFO_op2: ; subtract
 26180 00009263 F71D[6CC90000]      <1> 	neg	dword [CFS_CC] ; prepare to subtract ; 2 = sub (add negative)
 26181                              <1> loc_check_fcc_FSINFO_op1:
 26182                              <1> 	; 01/03/2016
 26183 00009269 31D2                <1> 	xor	edx, edx ; 0
 26184 0000926B 4A                  <1> 	dec	edx ; 0FFFFFFFFh
 26185 0000926C 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved]
 26186 0000926F 39D0                <1> 	cmp	eax, edx
 26187 00009271 73D5                <1> 	jnb	short loc_put_fcc_invalid_sign
 26188 00009273 0305[6CC90000]      <1>         add     eax, [CFS_CC] ; free cluster count on disk + current count
 26189 00009279 72CD                <1> 	jc	short loc_put_fcc_invalid_sign
 26190                              <1> 	
 26191 0000927B A3[E3C60000]        <1> 	mov	[FreeClusterCount], eax
 26192 00009280 EB0E                <1> 	jmp	short loc_cfs_write_FSINFO_sector
 26193                              <1> 
 26194                              <1> loc_cfs_FAT32_get_rcalc_parms:
 26195 00009282 8B15[74C90000]      <1> 	mov	edx, [CFS_FAT32FC]
 26196 00009288 A1[E3C60000]        <1> 	mov	eax, [FreeClusterCount]
 26197 0000928D 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free Cluster
 26198                              <1> loc_cfs_write_FSINFO_sector:
 26199 00009290 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
 26200                              <1> 	; 01/03/2016
 26201 00009293 E89A000000          <1> 	call	set_fat32_fsinfo_sector_parms
 26202 00009298 72AE                <1>         jc      short loc_put_fcc_invalid_sign
 26203                              <1> 
 26204                              <1> loc_set_FAT32_free_sectors:
 26205                              <1> 	; 29/02/2016
 26206                              <1> 	;mov	eax, [FreeClusterCount]
 26207                              <1> 	;mov	ecx, eax
 26208                              <1> 	;cmp	eax, 0FFFFFFFFh ; Invalid !
 26209                              <1> 	;je	short loc_cfs_retn_params
 26210                              <1> 	;
 26211 0000929A 8B0D[E3C60000]      <1> 	mov	ecx, [FreeClusterCount]
 26212 000092A0 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
 26213 000092A4 F7E1                <1> 	mul	ecx
 26214                              <1> 	; 29/02/2016
 26215 000092A6 31C9                <1> 	xor	ecx, ecx ; 0
 26216 000092A8 09D2                <1> 	or	edx, edx ; 0 ?
 26217 000092AA 759C                <1>         jnz     loc_put_fcc_invalid_sign
 26218 000092AC 394670              <1> 	cmp	[esi+LD_TotalSectors], eax ; Volume size in sectors
 26219 000092AF 7697                <1>         jna     short loc_put_fcc_invalid_sign
 26220                              <1> 	;
 26221                              <1> loc_set_FAT32_free_sectors_ok:
 26222 000092B1 31D2                <1> 	xor	edx, edx ; 0
 26223 000092B3 EB98                <1>         jmp     short loc_cfs_retn_params 
 26224                              <1> 	;
 26225                              <1> 
 26226                              <1> get_last_cluster:
 26227                              <1> 	; 27/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26228                              <1> 	; 12/06/2010 (DRV_FAT.ASM, 'proc_get_last_custer')
 26229                              <1> 	; 06/06/2010
 26230                              <1> 	; INPUT ->
 26231                              <1> 	;	EAX = First Cluster Number
 26232                              <1> 	; 	ESI = Logical Dos Drive Parameters Table
 26233                              <1> 	; OUTPUT ->
 26234                              <1> 	;	cf = 0 -> No Error, EAX is valid
 26235                              <1> 	;	cf = 1 -> EAX > 0 -> Error
 26236                              <1> 	;	EAX = Last Cluster Number
 26237                              <1> 	;       ECX = Previous Cluster -just before the last cluster-
 26238                              <1> 	;
 26239                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 26240                              <1> 
 26241 000092B5 89C1                <1> 	mov	ecx, eax	
 26242                              <1> 
 26243                              <1> loc_glc_get_next_cluster_1:
 26244 000092B7 890D[78C90000]      <1> 	mov	[glc_prevcluster], ecx
 26245                              <1> 
 26246                              <1> loc_glc_get_next_cluster_2:
 26247 000092BD E8F8F7FFFF          <1> 	call	get_next_cluster
 26248                              <1> 	; ecx = current/previous cluster 
 26249                              <1> 	; eax = next/last cluster
 26250 000092C2 73F3                <1> 	jnc	short loc_glc_get_next_cluster_1
 26251                              <1> 
 26252 000092C4 09C0                <1> 	or	eax, eax
 26253 000092C6 7509                <1> 	jnz	short loc_glc_stc_retn
 26254                              <1> 
 26255                              <1> 	; ecx = previous cluster
 26256 000092C8 89C8                <1>         mov	eax, ecx
 26257                              <1> 
 26258                              <1> 	; previous cluster becomes last cluster (ecx -> eax)
 26259                              <1> 	; previous of previous cluster becomes previous cluster (ecx)
 26260                              <1> 
 26261                              <1> loc_glc_prev_cluster_retn:
 26262 000092CA 8B0D[78C90000]      <1> 	mov	ecx, [glc_prevcluster] 
 26263 000092D0 C3                  <1> 	retn
 26264                              <1> 
 26265                              <1> loc_glc_stc_retn:
 26266 000092D1 F5                  <1> 	cmc	;stc
 26267 000092D2 EBF6                <1>         jmp	short loc_glc_prev_cluster_retn
 26268                              <1> 
 26269                              <1> truncate_cluster_chain:
 26270                              <1> 	; 01/03/2016
 26271                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26272                              <1> 	; 22/01/2011 (DRV_FAT.ASM, 'proc_truncate_cluster_chain')
 26273                              <1> 	; 11/09/2010
 26274                              <1> 	; INPUT ->
 26275                              <1> 	;	ESI = Logical dos drive description table address
 26276                              <1> 	;	EAX = First cluster to be truncated/unlinked 
 26277                              <1> 	; OUTPUT ->
 26278                              <1> 	;	ESI = Logical dos drive description table address
 26279                              <1> 	; 	ECX = Count of truncated/removed clusters
 26280                              <1> 	; 	CF = 0 -> EAX = Free sectors
 26281                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
 26282                              <1> 
 26283                              <1> 	; NOTE: This procedure does not update lm date&time ! 
 26284                              <1> 
 26285                              <1> loc_truncate_cc:	
 26286 000092D4 31C9                <1> 	xor	ecx, ecx ; mov ecx, 0
 26287                              <1> 	;mov	byte [FAT_BuffValidData], 0
 26288 000092D6 890D[CDC60000]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
 26289                              <1> 
 26290                              <1> loc_tcc_unlink_clusters:
 26291 000092DC E803FBFFFF          <1> 	call	update_cluster
 26292                              <1> 	; EAX = Next Cluster
 26293                              <1> 	; ECX = Cluster Value
 26294                              <1> 	; Note:
 26295                              <1> 	; Returns count of unlinked clusters in
 26296                              <1> 	; dword ptr FAT_ClusterCounter
 26297 000092E1 73F9                <1> 	jnc short loc_tcc_unlink_clusters
 26298                              <1> 
 26299                              <1> pass_tcc_unlink_clusters:
 26300 000092E3 A2[7FC90000]        <1> 	mov	byte [TCC_FATErr], al
 26301 000092E8 803D[C5C60000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 26302 000092EF 750E                <1> 	jne	short loc_tcc_calculate_FAT_freespace
 26303 000092F1 E8ABFDFFFF          <1> 	call	save_fat_buffer
 26304 000092F6 7307                <1> 	jnc	short loc_tcc_calculate_FAT_freespace
 26305 000092F8 A2[7FC90000]        <1> 	mov	byte [TCC_FATErr], al ; Error
 26306                              <1> 	;mov	byte [FAT_BuffValidData], 0
 26307                              <1> 
 26308                              <1> 	; 01/03/2016
 26309 000092FD EB12                <1> 	jmp	short loc_tcc_recalculate_FAT_freespace
 26310                              <1> 
 26311                              <1> loc_tcc_calculate_FAT_freespace:
 26312 000092FF A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter] ; signed (+-) number
 26313 00009304 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI = Dos drv desc. table
 26314                              <1> 			   ; BL = 1 -> add cluster
 26315 00009308 E829FEFFFF          <1> 	call	calculate_fat_freespace
 26316 0000930D 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
 26317 0000930F 7409                <1> 	jz	short pass_truncate_cc_recalc_FAT_freespace
 26318                              <1> 
 26319                              <1> loc_tcc_recalculate_FAT_freespace:
 26320 00009311 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate !
 26321 00009315 E81CFEFFFF          <1> 	call	calculate_fat_freespace
 26322                              <1>               
 26323                              <1> loc_tcc_calculate_FAT_freespace_err:
 26324                              <1> pass_truncate_cc_recalc_FAT_freespace:
 26325 0000931A 8B0D[CDC60000]      <1> 	mov	ecx, [FAT_ClusterCounter]
 26326                              <1> 
 26327 00009320 803D[7FC90000]00    <1> 	cmp	byte [TCC_FATErr], 0
 26328 00009327 7608                <1> 	jna	short loc_tcc_unlink_clusters_retn
 26329                              <1> 
 26330                              <1> loc_tcc_unlink_clusters_error:
 26331 00009329 0FB605[7FC90000]    <1> 	movzx	eax, byte [TCC_FATErr]
 26332 00009330 F9                  <1> 	stc
 26333                              <1> loc_tcc_unlink_clusters_retn:
 26334 00009331 C3                  <1> 	retn
 26335                              <1> 
 26336                              <1> set_fat32_fsinfo_sector_parms:
 26337                              <1> 	; 23/03/2016
 26338                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26339                              <1> 	; INPUT ->
 26340                              <1> 	;	ESI = Logical dos drive description table address
 26341                              <1> 	;	[esi+LD_BPB+BPB_Reserved] = Free Cluster Count
 26342                              <1> 	;	[esi+LD_BPB+BPB_Reserved+4] = First Free Cluster 
 26343                              <1> 	; OUTPUT ->
 26344                              <1> 	;	ESI = Logical dos drive description table address
 26345                              <1> 	; 	CF = 0 -> OK..
 26346                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
 26347                              <1> 	;
 26348                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 26349                              <1> 
 26350 00009332 E824000000          <1> 	call	get_fat32_fsinfo_sector_parms
 26351 00009337 7221                <1> 	jc	short update_fat32_fsinfo_sector_retn
 26352                              <1> 
 26353 00009339 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved] ; Free Cluster Count
 26354 0000933C 8B563E              <1> 	mov	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free Cluster	
 26355                              <1> 
 26356                              <1>         ;mov	ebx, DOSBootSectorBuff
 26357 0000933F 8983E8010000        <1> 	mov	[ebx+488], eax
 26358 00009345 8993EC010000        <1> 	mov	[ebx+492], edx	
 26359                              <1> 
 26360 0000934B A1[70C90000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
 26361 00009350 B901000000          <1> 	mov	ecx, 1
 26362 00009355 E8DD170000          <1> 	call	disk_write
 26363                              <1> 	;jnc     short update_fat32_fsinfo_sector_retn
 26364                              <1> 
 26365                              <1> 	; 23/03/2016
 26366                              <1> 	;mov	eax, 1Dh ; Drive not ready or write error
 26367                              <1> 
 26368                              <1> update_fat32_fsinfo_sector_retn:
 26369 0000935A C3                  <1> 	retn
 26370                              <1> 
 26371                              <1> get_fat32_fsinfo_sector_parms:
 26372                              <1> 	; 23/03/2016
 26373                              <1> 	; 01/03/2016
 26374                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
 26375                              <1> 	; INPUT ->
 26376                              <1> 	;	ESI = Logical dos drive description table address
 26377                              <1> 	; OUTPUT ->
 26378                              <1> 	;	ESI = Logical dos drive description table address
 26379                              <1> 	;	EBX = FSINFO sector buffer address (DOSBootSectorBuff)	
 26380                              <1> 	;	CF = 0 -> OK..
 26381                              <1> 	;	   EAX = FsInfo sector address
 26382                              <1> 	;	   ECX = Free cluster count
 26383                              <1> 	;	   EDX = First free cluster 	
 26384                              <1> 	;	CF = 1 -> Error code in AL (EAX)
 26385                              <1> 	;	   EBX = 0
 26386                              <1> 	;	
 26387                              <1> 	;	[CFS_FAT32FSINFOSEC] = FAT32 FSINFO sector address
 26388                              <1>         ;
 26389                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 26390                              <1> 
 26391 0000935B 0FB74636            <1> 	movzx	eax, word [esi+LD_BPB+FAT32_FSInfoSec]
 26392 0000935F 03466C              <1> 	add	eax, [esi+LD_StartSector]
 26393 00009362 A3[70C90000]        <1> 	mov	[CFS_FAT32FSINFOSEC], eax
 26394                              <1> 	
 26395 00009367 BB[C1C40000]        <1>         mov     ebx, DOSBootSectorBuff
 26396 0000936C B901000000          <1> 	mov	ecx, 1
 26397 00009371 E8D0170000          <1> 	call	disk_read
 26398 00009376 7232                <1> 	jc	short loc_read_FAT32_fsinfo_sec_err
 26399                              <1> 
 26400 00009378 BB[C1C40000]        <1> 	mov	ebx, DOSBootSectorBuff
 26401                              <1> 
 26402 0000937D 813B52526141        <1> 	cmp	dword [ebx], 41615252h
 26403 00009383 751E                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
 26404                              <1> 
 26405 00009385 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 26406 0000938E 61                  <1>
 26407 0000938F 7512                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
 26408                              <1> 
 26409 00009391 A1[70C90000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
 26410 00009396 8B8BE8010000        <1> 	mov	ecx, [ebx+488] ; free cluster count
 26411 0000939C 8B93EC010000        <1> 	mov	edx, [ebx+492] ; first (next) free cluster	
 26412                              <1> 
 26413 000093A2 C3                  <1> 	retn
 26414                              <1> 
 26415                              <1> loc_read_FAT32_fsinfo_sec_stc:
 26416 000093A3 B80B000000          <1> 	mov	eax, 0Bh ; Invalid format!
 26417 000093A8 EB05                <1> 	jmp	short loc_read_FAT32_fsinfo_sec_stc_retn
 26418                              <1> 
 26419                              <1> loc_read_FAT32_fsinfo_sec_err:
 26420                              <1> 	; 23/03/2016
 26421 000093AA B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error
 26422                              <1> 
 26423                              <1> loc_read_FAT32_fsinfo_sec_stc_retn:
 26424 000093AF 29DB                <1> 	sub	ebx, ebx ; 0
 26425 000093B1 F9                  <1> 	stc
 26426 000093B2 C3                  <1> 	retn
 26427                              <1> 
 26428                              <1> add_new_cluster:
 26429                              <1> 	; 24/03/2016
 26430                              <1> 	; 18/03/2016
 26431                              <1> 	; 11/03/2016 (TRDOS 386 =  TRDOS v2.0)
 26432                              <1> 	; 30/07/2011 (DRV_FAT.ASM)
 26433                              <1> 	; 11/09/2010
 26434                              <1> 	; INPUT ->
 26435                              <1> 	;	ESI = Logical dos drv desc. table address
 26436                              <1> 	;	EAX = Last cluster
 26437                              <1> 	; OUTPUT ->
 26438                              <1> 	;	ESI = Logical dos drv desc. table address
 26439                              <1> 	;	EAX = New Last cluster (next cluster)
 26440                              <1> 	;	cf = 1 -> error code in EAX (AL)
 26441                              <1> 	;	cf = 1 -> DX = sectors per cluster
 26442                              <1> 	;	ECX = Free sectors
 26443                              <1> 	; NOTE:
 26444                              <1> 	; This procedure does not update lm date&time !
 26445                              <1> 	;
 26446                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, EDI)
 26447                              <1> 	;
 26448                              <1> 
 26449 000093B3 A3[9ACA0000]        <1> 	mov	[FAT_anc_LCluster], eax
 26450                              <1> 	
 26451 000093B8 E854F9FFFF          <1> 	call	get_first_free_cluster
 26452 000093BD 720B                <1> 	jc	short loc_add_new_cluster_retn
 26453                              <1> 	; EAX >= 2 and EAX < FFFFFFFFh is valid
 26454                              <1> 
 26455 000093BF 89C2                <1> 	mov	edx, eax
 26456                              <1> 
 26457 000093C1 42                  <1> 	inc	edx
 26458                              <1> 	;jnz	short loc_add_new_cluster_check_ffc_eax
 26459 000093C2 7516                <1> 	jnz	short loc_add_new_cluster_save_fcc
 26460                              <1> 
 26461                              <1> loc_add_new_cluster_no_disk_space_retn:
 26462 000093C4 B827000000          <1> 	mov	eax, 27h ; MSDOS err => insufficient disk space
 26463                              <1> loc_add_new_cluster_stc_retn:
 26464 000093C9 F9                  <1> 	stc
 26465                              <1> loc_add_new_cluster_retn:
 26466 000093CA 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
 26467 000093CE 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
 26468                              <1> 	;xor	edx, edx
 26469                              <1> 	;stc
 26470 000093D1 C3                  <1> 	retn
 26471                              <1> 
 26472                              <1> loc_anc_invalid_format_stc_retn:
 26473 000093D2 F9                  <1> 	stc
 26474                              <1> loc_add_new_cluster_invalid_format_retn:
 26475 000093D3 B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 26476 000093D8 EBF0                <1> 	jmp	short loc_add_new_cluster_retn 
 26477                              <1> 
 26478                              <1> ;loc_add_new_cluster_check_ffc_eax:
 26479                              <1> ;	cmp	eax, 2
 26480                              <1> ;	jb	short loc_add_new_cluster_invalid_format_retn
 26481                              <1> 
 26482                              <1> loc_add_new_cluster_save_fcc:  
 26483 000093DA A3[9ECA0000]        <1> 	mov	[FAT_anc_FFCluster], eax
 26484                              <1> 
 26485 000093DF 83E802              <1> 	sub	eax, 2
 26486 000093E2 0FB65E13            <1>         movzx   ebx, byte [esi+LD_BPB+SecPerClust]
 26487 000093E6 F7E3                <1> 	mul	ebx
 26488 000093E8 09D2                <1> 	or	edx, edx
 26489 000093EA 75E6                <1> 	jnz	short loc_anc_invalid_format_stc_retn
 26490                              <1> 
 26491                              <1> loc_add_new_cluster_allocate_cluster:
 26492                              <1> 	; 18/03/2016
 26493 000093EC 92                  <1> 	xchg	edx, eax ; eax = 0
 26494 000093ED 3805[D5C60000]      <1> 	cmp	[ClusterBuffer_Valid], al ; 0
 26495 000093F3 7607                <1> 	jna	short loc_anc_clear_cluster_buffer
 26496                              <1> 	; 'copy' command, 
 26497                              <1> 	; writing destination file clust after reading source file clust
 26498 000093F5 A2[D5C60000]        <1> 	mov	[ClusterBuffer_Valid], al ; 0 ; reset
 26499 000093FA EB0C                <1> 	jmp	short loc_add_new_cluster_write_nc_to_disk
 26500                              <1> 
 26501                              <1> loc_anc_clear_cluster_buffer:
 26502                              <1> 	; 11/03/2016
 26503                              <1> 	; Clear buffer
 26504 000093FC BF00000700          <1> 	mov	edi, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
 26505 00009401 89D9                <1> 	mov	ecx, ebx ; sector count
 26506 00009403 C1E107              <1> 	shl	ecx, 7 ; 1 sector = 512 bytes -> 128 double words
 26507                              <1> 	;xor	eax, eax ; 0
 26508 00009406 F3AB                <1> 	rep	stosd
 26509                              <1> 
 26510                              <1> loc_add_new_cluster_write_nc_to_disk:
 26511                              <1> 	; 11/03/2016
 26512                              <1> 	;xchg	eax, edx ; edx = 0, eax = sector offset
 26513 00009408 89D0                <1> 	mov	eax, edx
 26514 0000940A 034668              <1>         add     eax, [esi+LD_DATABegin]
 26515 0000940D 72C4                <1> 	jc	short loc_add_new_cluster_invalid_format_retn 
 26516                              <1> 		
 26517 0000940F 89D9                <1> 	mov	ecx, ebx ; ECX = sectors per cluster (<256)
 26518 00009411 BB00000700          <1> 	mov	ebx, Cluster_Buffer
 26519 00009416 E81C170000          <1> 	call	disk_write
 26520 0000941B 7307                <1> 	jnc	short loc_add_new_cluster_update_fat_nlc
 26521                              <1> 	
 26522 0000941D B81D000000          <1> 	mov	eax, 1Dh ; Write Error
 26523 00009422 EBA5                <1> 	jmp	short loc_add_new_cluster_stc_retn
 26524                              <1> 
 26525                              <1> loc_add_new_cluster_update_fat_nlc:
 26526 00009424 A1[9ECA0000]        <1> 	mov	eax, [FAT_anc_FFCluster]
 26527 00009429 31C9                <1> 	xor	ecx, ecx
 26528 0000942B 890D[CDC60000]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
 26529 00009431 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 26530 00009432 E8ADF9FFFF          <1> 	call	update_cluster
 26531 00009437 7304                <1> 	jnc	short loc_add_new_cluster_update_fat_plc
 26532 00009439 09C0                <1> 	or	eax, eax ;EAX = 0 -> cluster value is 0 or eocc
 26533 0000943B 758C                <1> 	jnz	short loc_add_new_cluster_stc_retn
 26534                              <1> 
 26535                              <1> loc_add_new_cluster_update_fat_plc:
 26536 0000943D A1[9ACA0000]        <1> 	mov	eax, [FAT_anc_LCluster]
 26537 00009442 8B0D[9ECA0000]      <1> 	mov	ecx, [FAT_anc_FFCluster]
 26538 00009448 E897F9FFFF          <1> 	call	update_cluster
 26539 0000944D 7314                <1> 	jnc	short loc_add_new_cluster_save_fat_buffer
 26540 0000944F 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 26541 00009451 7410                <1> 	jz	short loc_add_new_cluster_save_fat_buffer
 26542                              <1> 
 26543                              <1> loc_anc_save_fat_buffer_err_retn:
 26544                              <1> 	;cmp	byte [FAT_ClusterCounter], 1
 26545                              <1> 	;jb	short loc_add_new_cluster_retn
 26546                              <1> 
 26547 00009453 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
 26548                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
 26549 00009457 50                  <1> 	push	eax
 26550 00009458 E8D9FCFFFF          <1> 	call	calculate_fat_freespace
 26551 0000945D 58                  <1> 	pop	eax
 26552 0000945E E966FFFFFF          <1>         jmp     loc_add_new_cluster_stc_retn
 26553                              <1> 
 26554                              <1> loc_add_new_cluster_save_fat_buffer:
 26555                              <1> 	;cmp	byte [FAT_BuffValidData], 2
 26556                              <1> 	;jne	short loc_add_new_cluster_calc_FAT_freespace 
 26557                              <1> 	;Byte [FAT_BuffValidData] =  2 
 26558 00009463 E839FCFFFF          <1> 	call	save_fat_buffer
 26559 00009468 72E9                <1> 	jc	short loc_anc_save_fat_buffer_err_retn
 26560                              <1> 
 26561                              <1> loc_add_new_cluster_calc_FAT_freespace:
 26562                              <1> 	;mov	eax, 1 ; Only one Cluster
 26563 0000946A A1[CDC60000]        <1> 	mov	eax, [FAT_ClusterCounter]
 26564 0000946F 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI -> Dos drv desc. table
 26565                              <1> 		; BL = 1 -> add cluster
 26566 00009473 B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
 26567                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
 26568                              <1> 	; (Free Cluster Count is decreased when EAX value is negative)
 26569 00009475 E8BCFCFFFF          <1>         call    calculate_fat_freespace
 26570                              <1> 	;ECX = 0 -> no error, ECX > 0 -> error or invalid return
 26571 0000947A 21C9                <1> 	and	ecx, ecx ; ECX = 0 -> valid free sector count
 26572 0000947C 7409                <1> 	jz	short loc_add_new_cluster_return_cluster_number
 26573                              <1> 
 26574                              <1> loc_add_new_cluster_recalc_FAT_freespace:
 26575 0000947E 66BB00FF            <1> 	mov	bx, 0FF00h  ; recalculate free space
 26576 00009482 E8AFFCFFFF          <1>         call    calculate_fat_freespace
 26577                              <1> 	; cf = 0
 26578                              <1> loc_add_new_cluster_return_cluster_number:
 26579 00009487 89C1                <1> 	mov	ecx, eax ; Free sector count
 26580 00009489 A1[9ECA0000]        <1> 	mov	eax, [FAT_anc_FFCluster]
 26581 0000948E 0FB65E13            <1> 	movzx	ebx, byte [esi+LD_BPB+SecPerClust]
 26582                              <1> 	;mov	edi, Cluster_Buffer
 26583 00009492 31D2                <1> 	xor	edx, edx
 26584 00009494 C3                  <1>         retn
 26585                              <1> 
 26586                              <1> write_cluster:
 26587                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
 26588                              <1> 	;
 26589                              <1> 	; INPUT ->
 26590                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
 26591                              <1> 	;	ESI = Logical DOS Drive Description Table address
 26592                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
 26593                              <1> 	;	Only for SINGLIX FS:
 26594                              <1> 	;	EDX = File Number (The 1st FDT address) 
 26595                              <1> 	; OUTPUT ->
 26596                              <1> 	;	cf = 1 -> Cluster can not be written onto disk
 26597                              <1> 	;	    EAX > 0 -> Error number
 26598                              <1> 	;	cf = 0 -> Cluster has been written successfully
 26599                              <1> 	;
 26600                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 26601                              <1> 	
 26602 00009495 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
 26603                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 26604                              <1> 
 26605                              <1> write_file_sectors: ; 16/03/2016
 26606 00009499 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 26607 0000949D 761C                <1> 	jna	short write_fs_cluster
 26608                              <1> 
 26609                              <1> write_fat_file_sectors: 
 26610 0000949F 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
 26611 000094A2 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
 26612 000094A6 F7E2                <1> 	mul	edx
 26613 000094A8 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
 26614                              <1> 
 26615                              <1> 	; EAX = Disk sector address
 26616                              <1> 	; ECX = Sector count
 26617                              <1> 	; EBX = Buffer address
 26618                              <1> 	; (EDX = 0)
 26619                              <1> 	; ESI = Logical DOS drive description table address	
 26620                              <1> 
 26621 000094AB E887160000          <1> 	call	disk_write
 26622 000094B0 7306                <1> 	jnc	short wclust_retn
 26623                              <1> 	
 26624 000094B2 B81D000000          <1> 	mov	eax, 1Dh ; Drive not ready or write error !
 26625 000094B7 C3                  <1> 	retn
 26626                              <1> 
 26627                              <1> wclust_retn:
 26628 000094B8 29C0                <1> 	sub	eax, eax ; 0
 26629 000094BA C3                  <1> 	retn
 26630                              <1> 
 26631                              <1> write_fs_cluster:
 26632                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
 26633                              <1> 	; Singlix FS
 26634                              <1> 	
 26635                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
 26636                              <1> 	
 26637                              <1> 	; EDX = File number is the first File Descriptor Table address 
 26638                              <1> 	;	of the file. (Absolute address of the FDT).
 26639                              <1> 	
 26640                              <1> 	; eax = sector index (0 for the first sector)
 26641                              <1> 	; edx = FDT0 address
 26642                              <1> 		; 64 KB buffer = 128 sectors (limit) 
 26643 000094BB B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
 26644 000094C0 E801000000          <1> 	call	write_fs_sectors
 26645 000094C5 C3                  <1> 	retn
 26646                              <1> 
 26647                              <1> write_fs_sectors:
 26648                              <1> 	; 21/03/2016 (TRDOS 386 =  TRDOS v2.0)
 26649 000094C6 F9                  <1> 	stc
 26650 000094C7 C3                  <1> 	retn
 26651                                  %include 'trdosk6.s' ; 24/01/2016
 26652                              <1> ; ****************************************************************************
 26653                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk6.s
 26654                              <1> ; ----------------------------------------------------------------------------
 26655                              <1> ; Last Update: 24/01/2016
 26656                              <1> ; ----------------------------------------------------------------------------
 26657                              <1> ; Beginning: 24/01/2016
 26658                              <1> ; ----------------------------------------------------------------------------
 26659                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 26660                              <1> ; ----------------------------------------------------------------------------
 26661                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 26662                              <1> ; XXXXXXXX.ASM (XX/XX/2011)
 26663                              <1> ;
 26664                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 26665                              <1> ; u1.s (27/17/2015)
 26666                              <1> ; ****************************************************************************
 26667                              <1> 
 26668                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u1.s
 26669                              <1> ; Last Modification: 27/12/2015
 26670                              <1> 
 26671                              <1> sysent: ; < enter to system call >
 26672                              <1> 	 ;19/10/2015
 26673                              <1> 	; 21/09/2015
 26674                              <1> 	; 01/07/2015
 26675                              <1> 	; 19/05/2015
 26676                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 26677                              <1> 	; 10/04/2013 - 18/01/2014 (Retro UNIX 8086 v1)
 26678                              <1> 	;
 26679                              <1> 	; 'unkni' or 'sysent' is sytem entry from various traps. 
 26680                              <1> 	; The trap type is determined and an indirect jump is made to 
 26681                              <1> 	; the appropriate system call handler. If there is a trap inside
 26682                              <1> 	; the system a jump to panic is made. All user registers are saved 
 26683                              <1> 	; and u.sp points to the end of the users stack. The sys (trap)
 26684                              <1> 	; instructor is decoded to get the the system code part (see
 26685                              <1> 	; trap instruction in the PDP-11 handbook) and from this 
 26686                              <1> 	; the indirect jump address is calculated. If a bad system call is
 26687                              <1> 	; made, i.e., the limits of the jump table are exceeded, 'badsys'
 26688                              <1> 	; is called. If the call is legitimate control passes to the
 26689                              <1> 	; appropriate system routine.
 26690                              <1> 	;
 26691                              <1> 	; Calling sequence:
 26692                              <1> 	;	Through a trap caused by any sys call outside the system.
 26693                              <1> 	; Arguments:
 26694                              <1> 	;	Arguments of particular system call.	
 26695                              <1> 	; ...............................................................
 26696                              <1> 	;	
 26697                              <1> 	; Retro UNIX 8086 v1 modification: 
 26698                              <1> 	;       System call number is in EAX register.
 26699                              <1> 	;
 26700                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
 26701                              <1> 	;	registers depending of function details.
 26702                              <1>   	;
 26703                              <1> 	; 16/04/2015
 26704 000094C8 368925[38CE0000]    <1>         mov     [ss:u.sp], esp ; Kernel stack points to return address
 26705                              <1> 	; save user registers
 26706 000094CF 1E                  <1> 	push	ds
 26707 000094D0 06                  <1> 	push	es
 26708 000094D1 0FA0                <1> 	push	fs
 26709 000094D3 0FA8                <1> 	push	gs
 26710 000094D5 60                  <1> 	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
 26711                              <1> 	;
 26712                              <1> 	; ESPACE = esp - [ss:u.sp] ; 4*12 = 48 ; 17/09/2015
 26713                              <1> 	; 	(ESPACE is size of space in kernel stack 
 26714                              <1> 	;	for saving/restoring user registers.)
 26715                              <1> 	;
 26716 000094D6 50                  <1> 	push	eax ; 01/07/2015
 26717 000094D7 66B81000            <1> 	mov     ax, KDATA
 26718 000094DB 8ED8                <1>         mov     ds, ax
 26719 000094DD 8EC0                <1>         mov     es, ax
 26720 000094DF 8EE0                <1>         mov     fs, ax
 26721 000094E1 8EE8                <1>         mov     gs, ax
 26722 000094E3 A1[E8BD0000]        <1> 	mov	eax, [k_page_dir]
 26723 000094E8 0F22D8              <1> 	mov	cr3, eax
 26724 000094EB 58                  <1> 	pop	eax ; 01/07/2015
 26725                              <1> 	; 19/10/2015
 26726 000094EC FC                  <1> 	cld
 26727                              <1> 	;
 26728 000094ED FE05[37CE0000]      <1> 	inc	byte [sysflg]
 26729                              <1> 		; incb sysflg / indicate a system routine is in progress
 26730 000094F3 FB                  <1>         sti 	; 18/01/2014
 26731 000094F4 0F85E4A9FFFF        <1> 	jnz     panic ; 24/05/2013
 26732                              <1> 		; beq 1f
 26733                              <1> 		; jmp panic ; / called if trap inside system
 26734                              <1> ;1:
 26735                              <1> 	; 16/04/2015
 26736 000094FA A3[40CE0000]        <1> 	mov	[u.r0], eax
 26737 000094FF 8925[3CCE0000]      <1> 	mov	[u.usp], esp ; kernel stack points to user's registers
 26738                              <1> 	;
 26739                              <1> 		; mov $s.syst+2,clockp
 26740                              <1> 		; mov r0,-(sp) / save user registers 
 26741                              <1> 		; mov sp,u.r0 / pointer to bottom of users stack 
 26742                              <1> 			   ; / in u.r0
 26743                              <1> 		; mov r1,-(sp)
 26744                              <1> 		; mov r2,-(sp)
 26745                              <1> 		; mov r3,-(sp)
 26746                              <1> 		; mov r4,-(sp)
 26747                              <1> 		; mov r5,-(sp)
 26748                              <1> 		; mov ac,-(sp) / "accumulator" register for extended
 26749                              <1> 		             ; / arithmetic unit
 26750                              <1> 		; mov mq,-(sp) / "multiplier quotient" register for the
 26751                              <1> 		             ; / extended arithmetic unit
 26752                              <1> 		; mov sc,-(sp) / "step count" register for the extended
 26753                              <1> 		             ; / arithmetic unit
 26754                              <1> 		; mov sp,u.sp / u.sp points to top of users stack
 26755                              <1> 		; mov 18.(sp),r0 / store pc in r0
 26756                              <1> 		; mov -(r0),r0 / sys inst in r0      10400xxx
 26757                              <1> 		; sub $sys,r0 / get xxx code
 26758 00009505 C1E002              <1> 	shl	eax, 2
 26759                              <1> 		; asl r0 / multiply by 2 to jump indirect in bytes
 26760 00009508 3D94000000          <1> 	cmp	eax, end_of_syscalls - syscalls
 26761                              <1> 		; cmp r0,$2f-1f / limit of table (35) exceeded
 26762                              <1> 	;jnb	short badsys
 26763                              <1> 		; bhis badsys / yes, bad system call
 26764 0000950D F5                  <1> 	cmc
 26765 0000950E 9C                  <1> 	pushf	
 26766 0000950F 50                  <1> 	push	eax
 26767 00009510 8B2D[38CE0000]      <1>  	mov 	ebp, [u.sp] ; Kernel stack at the beginning of sys call
 26768 00009516 B0FE                <1> 	mov	al, 0FEh ; 11111110b
 26769 00009518 1400                <1> 	adc	al, 0 ; al = al + cf
 26770 0000951A 204508              <1> 	and	[ebp+8], al ; flags (reset carry flag)
 26771                              <1> 		; bic $341,20.(sp) / set users processor priority to 0 
 26772                              <1> 				 ; / and clear carry bit
 26773 0000951D 5D                  <1> 	pop	ebp ; eax
 26774 0000951E 9D                  <1> 	popf
 26775 0000951F 0F8248010000        <1>         jc      badsys
 26776 00009525 A1[40CE0000]        <1> 	mov	eax, [u.r0]
 26777                              <1> 	; system call registers: EAX, EDX, ECX, EBX, ESI, EDI
 26778 0000952A FFA5[30950000]      <1> 	jmp	dword [ebp+syscalls]
 26779                              <1> 		; jmp *1f(r0) / jump indirect thru table of addresses
 26780                              <1> 		            ; / to proper system routine.
 26781                              <1> syscalls: ; 1:
 26782                              <1> 	; 21/09/2015
 26783                              <1> 	; 01/07/2015
 26784                              <1> 	; 16/04/2015 (32 bit address modification) 
 26785 00009530 [37960000]          <1> 	dd sysrele	; / 0
 26786 00009534 [DD960000]          <1> 	dd sysexit 	; / 1
 26787 00009538 [02980000]          <1> 	dd sysfork 	; / 2
 26788 0000953C [15990000]          <1> 	dd sysread 	; / 3
 26789 00009540 [30990000]          <1> 	dd syswrite 	; / 4
 26790 00009544 [9A990000]          <1> 	dd sysopen 	; / 5
 26791 00009548 [D49A0000]          <1> 	dd sysclose 	; / 6
 26792 0000954C [84970000]          <1> 	dd syswait 	; / 7
 26793 00009550 [4A9A0000]          <1> 	dd syscreat 	; / 8
 26794 00009554 [FB9D0000]          <1> 	dd syslink 	; / 9
 26795 00009558 [BD9E0000]          <1> 	dd sysunlink 	; / 10
 26796 0000955C [909F0000]          <1> 	dd sysexec 	; / 11
 26797 00009560 [F7A50000]          <1> 	dd syschdir 	; / 12
 26798 00009564 [DBA60000]          <1> 	dd systime 	; / 13
 26799 00009568 [8B9A0000]          <1> 	dd sysmkdir 	; / 14
 26800 0000956C [49A60000]          <1> 	dd syschmod 	; / 15
 26801 00009570 [ABA60000]          <1> 	dd syschown 	; / 16
 26802 00009574 [0EA70000]          <1> 	dd sysbreak 	; / 17
 26803 00009578 [68A30000]          <1> 	dd sysstat 	; / 18
 26804 0000957C [D3A70000]          <1> 	dd sysseek 	; / 19
 26805 00009580 [E5A70000]          <1> 	dd systell 	; / 20
 26806 00009584 [E6A80000]          <1> 	dd sysmount 	; / 21
 26807 00009588 [98A90000]          <1> 	dd sysumount 	; / 22
 26808 0000958C [63A80000]          <1> 	dd syssetuid 	; / 23
 26809 00009590 [94A80000]          <1> 	dd sysgetuid 	; / 24
 26810 00009594 [EAA60000]          <1> 	dd sysstime 	; / 25
 26811 00009598 [57A80000]          <1> 	dd sysquit 	; / 26
 26812 0000959C [4BA80000]          <1> 	dd sysintr 	; / 27
 26813 000095A0 [44A30000]          <1> 	dd sysfstat 	; / 28
 26814 000095A4 [F09A0000]          <1> 	dd sysemt 	; / 29
 26815 000095A8 [1E9B0000]          <1> 	dd sysmdate 	; / 30
 26816 000095AC [699B0000]          <1> 	dd sysstty 	; / 31
 26817 000095B0 [E89C0000]          <1> 	dd sysgtty 	; / 32
 26818 000095B4 [199B0000]          <1> 	dd sysilgins 	; / 33
 26819 000095B8 [F3A90000]          <1> 	dd syssleep 	; 34 ; Retro UNIX 8086 v1 feature only !
 26820                              <1> 			     ; 11/06/2014
 26821 000095BC [22AA0000]          <1> 	dd sysmsg	; 35 ; Retro UNIX 386 v1 feature only !
 26822                              <1> 			     ; 01/07/2015
 26823 000095C0 [F9AA0000]          <1> 	dd sysgeterr	; 36 ; Retro UNIX 386 v1 feature only !
 26824                              <1> 			     ; 21/09/2015 - get last error number
 26825                              <1> end_of_syscalls:
 26826                              <1> 
 26827                              <1> error:
 26828                              <1> 	; 17/09/2015
 26829                              <1> 	; 03/09/2015
 26830                              <1> 	; 01/09/2015
 26831                              <1> 	; 09/06/2015
 26832                              <1> 	; 13/05/2015
 26833                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 26834                              <1> 	; 10/04/2013 - 07/08/2013 (Retro UNIX 8086 v1)
 26835                              <1> 	;
 26836                              <1> 	; 'error' merely sets the error bit off the processor status (c-bit)
 26837                              <1> 	; then falls right into the 'sysret', 'sysrele' return sequence.
 26838                              <1> 	;
 26839                              <1> 	; INPUTS -> none
 26840                              <1> 	; OUTPUTS ->
 26841                              <1> 	;	processor status - carry (c) bit is set (means error)
 26842                              <1> 	;
 26843                              <1> 	; 26/05/2013 (Stack pointer must be reset here! 
 26844                              <1> 	; 	      Because, jumps to error procedure
 26845                              <1> 	;	      disrupts push-pop nesting balance)
 26846                              <1> 	;
 26847 000095C4 8B2D[38CE0000]      <1> 	mov	ebp, [u.sp] ; interrupt (system call) return (iretd) address
 26848 000095CA 804D0801            <1> 	or	byte [ebp+8], 1  ; set carry bit of flags register
 26849                              <1> 				 ; (system call will return with cf = 1)
 26850                              <1> 		; bis $1,20.(r1) / set c bit in processor status word below
 26851                              <1> 		               ; / users stack
 26852                              <1> 	; 17/09/2015
 26853 000095CE 83ED30              <1> 	sub	ebp, ESPACE ; 48 ; total size of stack frame ('sysdefs.inc')
 26854                              <1> 				 ; for saving/restoring user registers	
 26855                              <1> 	;cmp	ebp, [u.usp]
 26856                              <1> 	;je	short err0	
 26857 000095D1 892D[3CCE0000]      <1> 	mov	[u.usp], ebp
 26858                              <1> ;err0:
 26859                              <1> 	; 01/09/2015
 26860 000095D7 8B25[3CCE0000]      <1> 	mov	esp, [u.usp] 	    ; Retro Unix 8086 v1 modification!
 26861                              <1> 				    ; 10/04/2013
 26862                              <1> 				    ; (If an I/O error occurs during disk I/O,
 26863                              <1> 				    ; related procedures will jump to 'error'
 26864                              <1> 				    ; procedure directly without returning to 
 26865                              <1> 				    ; the caller procedure. So, stack pointer
 26866                              <1>                                     ; must be restored here.)
 26867                              <1> 	; 13/05/2015
 26868                              <1> 	; NOTE: (The last) error code is in 'u.error', it can be retrieved by
 26869                              <1> 	;	'get last error' system call later. 	
 26870                              <1> 
 26871                              <1> 	; 03/09/2015 - 09/06/2015 - 07/08/2013
 26872 000095DD C605[A7CE0000]00    <1> 	mov 	byte [u.kcall], 0 ; namei_r, mkdir_w reset
 26873                              <1> 
 26874                              <1> sysret: ; < return from system call>
 26875                              <1> 	; 10/09/2015
 26876                              <1> 	; 29/07/2015
 26877                              <1> 	; 25/06/2015
 26878                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 26879                              <1> 	; 10/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
 26880                              <1> 	;
 26881                              <1> 	; 'sysret' first checks to see if process is about to be 
 26882                              <1> 	; terminated (u.bsys). If it is, 'sysexit' is called.
 26883                              <1> 	; If not, following happens:	 
 26884                              <1> 	; 	1) The user's stack pointer is restored.
 26885                              <1> 	;	2) r1=0 and 'iget' is called to see if last mentioned
 26886                              <1> 	;	   i-node has been modified. If it has, it is written out
 26887                              <1> 	;	   via 'ppoke'.
 26888                              <1> 	;	3) If the super block has been modified, it is written out
 26889                              <1> 	;	   via 'ppoke'.				
 26890                              <1> 	;	4) If the dismountable file system's super block has been
 26891                              <1> 	;	   modified, it is written out to the specified device
 26892                              <1> 	;	   via 'ppoke'.
 26893                              <1> 	;	5) A check is made if user's time quantum (uquant) ran out
 26894                              <1> 	;	   during his execution. If so, 'tswap' is called to give
 26895                              <1> 	;	   another user a chance to run.
 26896                              <1> 	;	6) 'sysret' now goes into 'sysrele'. 
 26897                              <1> 	;	    (See 'sysrele' for conclusion.)		
 26898                              <1> 	;
 26899                              <1> 	; Calling sequence:
 26900                              <1> 	;	jump table or 'br sysret'
 26901                              <1> 	; Arguments: 
 26902                              <1> 	;	-	
 26903                              <1> 	; ...............................................................
 26904                              <1> 	;	
 26905                              <1> 	; ((AX=r1 for 'iget' input))
 26906                              <1> 	;	
 26907 000095E4 6631C0              <1> 	xor	ax, ax ; 04/05/2013
 26908                              <1> sysret0: ; 29/07/2015 (eax = 0, jump from sysexec)
 26909 000095E7 FEC0                <1> 	inc	al ; 04/05/2013
 26910 000095E9 3805[8ECE0000]      <1> 	cmp	[u.bsys], al ; 1
 26911                              <1> 		; tstb u.bsys / is a process about to be terminated because
 26912 000095EF 0F83E8000000        <1>         jnb     sysexit ; 04/05/2013
 26913                              <1> 		; bne sysexit / of an error? yes, go to sysexit
 26914                              <1> 	;mov	esp, [u.usp] ; 24/05/2013 (that is not needed here)
 26915                              <1> 		; mov u.sp,sp / no point stack to users stack
 26916 000095F5 FEC8                <1> 	dec 	al ; mov ax, 0
 26917                              <1> 		; clr r1 / zero r1 to check last mentioned i-node
 26918 000095F7 E820150000          <1> 	call	iget
 26919                              <1> 		; jsr r0,iget / if last mentioned i-node has been modified
 26920                              <1> 		            ; / it is written out
 26921 000095FC 6631C0              <1> 	xor 	ax, ax ; 0
 26922 000095FF 3805[35CE0000]      <1> 	cmp	[smod], al ; 0
 26923                              <1> 		; tstb	smod / has the super block been modified
 26924 00009605 7614                <1> 	jna	short sysret1
 26925                              <1> 		; beq	1f / no, 1f
 26926 00009607 A2[35CE0000]        <1> 	mov	[smod], al ; 0
 26927                              <1> 		; clrb smod / yes, clear smod
 26928 0000960C BB[E5D60000]        <1> 	mov	ebx, sb0 ;; 07/08//2013
 26929 00009611 66810B0002          <1>    	or	word [ebx], 200h ;;
 26930                              <1> 	;or	word [sb0], 200h ; write bit, bit 9
 26931                              <1> 		; bis $1000,sb0 / set write bit in I/O queue for super block
 26932                              <1> 		      	      ; / output
 26933                              <1> 	; AX = 0
 26934 00009616 E802150000          <1> 	call 	poke ; 07/08/2013
 26935                              <1> 	; call	ppoke
 26936                              <1> 	; AX = 0
 26937                              <1> 		; jsr r0,ppoke / write out modified super block to disk
 26938                              <1> sysret1: ;1:
 26939 0000961B 3805[36CE0000]      <1> 	cmp	[mmod], al ; 0
 26940                              <1> 		; tstb	mmod / has the super block for the dismountable file
 26941                              <1> 		           ; / system
 26942 00009621 7614                <1> 	jna	short sysrel0
 26943                              <1> 		; beq 1f / been modified?  no, 1f
 26944 00009623 A2[36CE0000]        <1> 	mov	[mmod], al ; 0	
 26945                              <1> 		; clrb	mmod / yes, clear mmod
 26946                              <1>         ;mov    ax, [mntd]
 26947                              <1>         ;;mov   al, [mdev] ; 26/04/2013
 26948 00009628 BB[EDD80000]        <1> 	mov	ebx, sb1 ;; 07/08//2013
 26949                              <1>         ;;mov	[ebx], al
 26950                              <1> 	;mov    [sb1], al
 26951                              <1> 		; movb	mntd,sb1 / set the I/O queue
 26952 0000962D 66810B0002          <1> 	or	word [ebx], 200h
 26953                              <1> 	;or	word [sb1], 200h ; write bit, bit 9
 26954                              <1> 		; bis $1000,sb1 / set write bit in I/O queue for detached sb
 26955 00009632 E8E6140000          <1> 	call	poke ; 07/08/2013
 26956                              <1> 	;call	ppoke 
 26957                              <1> 		; jsr r0,ppoke / write it out to its device
 26958                              <1>         ;xor    al, al ; 26/04/2013       
 26959                              <1> ;1:
 26960                              <1> 		; tstb uquant / is the time quantum 0?
 26961                              <1> 		; bne 1f / no, don't swap it out
 26962                              <1> 
 26963                              <1> sysrele: ; < release >
 26964                              <1> 	; 14/10/2015
 26965                              <1> 	; 01/09/2015
 26966                              <1> 	; 24/07/2015
 26967                              <1> 	; 14/05/2015
 26968                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 26969                              <1> 	; 10/04/2013 - 07/03/2014 (Retro UNIX 8086 v1)
 26970                              <1> 	;
 26971                              <1> 	; 'sysrele' first calls 'tswap' if the time quantum for a user is
 26972                              <1> 	;  zero (see 'sysret'). It then restores the user's registers and
 26973                              <1> 	; turns off the system flag. It then checked to see if there is
 26974                              <1> 	; an interrupt from the user by calling 'isintr'. If there is, 
 26975                              <1> 	; the output gets flashed (see isintr) and interrupt action is
 26976                              <1> 	; taken by a branch to 'intract'. If there is no interrupt from
 26977                              <1> 	; the user, a rti is made.
 26978                              <1> 	;
 26979                              <1> 	; Calling sequence:
 26980                              <1> 	;	Fall through a 'bne' in 'sysret' & ?
 26981                              <1> 	; Arguments:
 26982                              <1> 	;	-	
 26983                              <1> 	; ...............................................................
 26984                              <1> 	;	
 26985                              <1> 	; 23/02/2014 (swapret)
 26986                              <1> 	; 22/09/2013
 26987                              <1> sysrel0: ;1:
 26988 00009637 803D[82CE0000]00    <1> 	cmp	byte [u.quant], 0 ; 16/05/2013
 26989                              <1> 		; tstb uquant / is the time quantum 0?
 26990 0000963E 7705                <1>         ja      short swapret
 26991                              <1> 		; bne 1f / no, don't swap it out
 26992                              <1> sysrelease: ; 07/12/2013 (jump from 'clock')
 26993 00009640 E8D9140000          <1> 	call	tswap
 26994                              <1> 		; jsr r0,tswap / yes, swap it out
 26995                              <1> ;
 26996                              <1> ; Retro Unix 8086 v1 feature: return from 'swap' to 'swapret' address.
 26997                              <1> swapret: ;1:
 26998                              <1> 	; 10/09/2015
 26999                              <1> 	; 01/09/2015
 27000                              <1> 	; 14/05/2015
 27001                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit, pm modifications)
 27002                              <1> 	; 26/05/2013 (Retro UNIX 8086 v1)
 27003                              <1> 	; cli
 27004                              <1> 	; 24/07/2015
 27005                              <1> 	;
 27006                              <1> 	;; 'esp' must be already equal to '[u.usp]' here ! 
 27007                              <1> 	;; mov	esp, [u.usp]
 27008                              <1> 
 27009                              <1> 	; 22/09/2013
 27010 00009645 E8D5140000          <1> 	call	isintr
 27011                              <1> 	; 20/10/2013
 27012 0000964A 7405                <1> 	jz	short sysrel1
 27013 0000964C E875000000          <1> 	call	intract
 27014                              <1> 		; jsr r0,isintr / is there an interrupt from the user
 27015                              <1> 		;     br intract / yes, output gets flushed, take interrupt
 27016                              <1> 		               ; / action
 27017                              <1> sysrel1:
 27018 00009651 FA                  <1> 	cli ; 14/10/2015
 27019 00009652 FE0D[37CE0000]      <1> 	dec	byte [sysflg]
 27020                              <1> 		; decb sysflg / turn system flag off
 27021 00009658 A1[99CE0000]        <1> 	mov     eax, [u.pgdir]
 27022 0000965D 0F22D8              <1> 	mov	cr3, eax  ; 1st PDE points to Kernel Page Table 0 (1st 4 MB)
 27023                              <1> 			  ; (others are different than kernel page tables) 
 27024                              <1> 	; 10/09/2015
 27025 00009660 61                  <1> 	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
 27026                              <1> 		; mov (sp)+,sc / restore user registers
 27027                              <1> 		; mov (sp)+,mq
 27028                              <1> 		; mov (sp)+,ac
 27029                              <1> 		; mov (sp)+,r5
 27030                              <1> 		; mov (sp)+,r4
 27031                              <1> 		; mov (sp)+,r3
 27032                              <1> 		; mov (sp)+,r2
 27033                              <1> 	;
 27034 00009661 A1[40CE0000]        <1> 	mov	eax, [u.r0]  ; ((return value in EAX))
 27035 00009666 0FA9                <1> 	pop	gs
 27036 00009668 0FA1                <1> 	pop	fs
 27037 0000966A 07                  <1> 	pop	es
 27038 0000966B 1F                  <1> 	pop	ds
 27039 0000966C CF                  <1> 	iretd	
 27040                              <1> 		; rti / no, return from interrupt
 27041                              <1> 
 27042                              <1> badsys:
 27043                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 27044                              <1> 	; (Major Modification: 'core' dumping procedure in
 27045                              <1>         ;       original UNIX v1 and Retro UNIX 8086 v1
 27046                              <1> 	;	has been changed to print 'Invalid System Call !'
 27047                              <1> 	;	message on the user's console tty.)
 27048                              <1> 	; (EIP, EAX values will be shown on screen with error message)
 27049                              <1> 	; (EIP = Return address just after the system call -INT 30h-)
 27050                              <1> 	; (EAX = Function number)  
 27051                              <1> 	;
 27052 0000966D FE05[8ECE0000]      <1> 	inc	byte [u.bsys]
 27053                              <1> 	;
 27054 00009673 8B1D[38CE0000]      <1> 	mov	ebx, [u.sp] ; esp at the beginning of 'sysent'
 27055 00009679 8B03                <1> 	mov	eax, [ebx] ; EIP (return address, not 'INT 30h' address)
 27056 0000967B E86783FFFF          <1> 	call	dwordtohex
 27057 00009680 8915[13BB0000]      <1> 	mov	[bsys_msg_eip], edx
 27058 00009686 A3[17BB0000]        <1> 	mov	[bsys_msg_eip+4], eax
 27059 0000968B A1[40CE0000]        <1> 	mov	eax, [u.r0]
 27060 00009690 E85283FFFF          <1> 	call	dwordtohex
 27061 00009695 8915[03BB0000]      <1> 	mov	[bsys_msg_eax], edx
 27062 0000969B A3[07BB0000]        <1> 	mov	[bsys_msg_eax+4], eax
 27063 000096A0 31C0                <1> 	xor	eax, eax
 27064 000096A2 C705[60CE0000]-     <1>         mov     dword [u.base], badsys_msg ; "Invalid System call !"
 27065 000096A8 [E4BA0000]          <1>
 27066 000096AC 8B1D[50CE0000]      <1> 	mov	ebx, [u.fofp]
 27067 000096B2 8903                <1> 	mov	[ebx], eax
 27068                              <1> 	;mov	eax, 1 ; inode number of console tty (for user)	
 27069 000096B4 40                  <1> 	inc	eax
 27070 000096B5 C705[64CE0000]3B00- <1> 	mov	dword [u.count], BSYS_M_SIZE
 27071 000096BD 0000                <1>
 27072                              <1> 		; writei
 27073                              <1> 		; INPUTS ->
 27074                              <1> 		;    r1 - inode number
 27075                              <1> 		;    u.count - byte count to be written
 27076                              <1> 		;    u.base - points to user buffer
 27077                              <1> 		;    u.fofp - points to word with current file offset
 27078                              <1> 		; OUTPUTS ->
 27079                              <1> 		;    u.count - cleared
 27080                              <1> 		;    u.nread - accumulates total bytes passed back	
 27081                              <1> 		;
 27082                              <1> 		; ((Modified registers: EDX, EBX, ECX, ESI, EDI, EBP)) 	
 27083 000096BF E85C140000          <1> 	call	writei
 27084                              <1> 	;mov	eax, 1
 27085 000096C4 EB17                <1> 	jmp	sysexit
 27086                              <1> 
 27087                              <1> 		; incb u.bsys / turn on the user's bad-system flag
 27088                              <1> 		; mov $3f,u.namep / point u.namep to "core\0\0"
 27089                              <1> 		; jsr r0,namei / get the i-number for the core image file
 27090                              <1> 		; br 1f / error
 27091                              <1> 		; neg r1 / negate the i-number to open the core image file
 27092                              <1> 		       ; / for writing
 27093                              <1> 		; jsr r0,iopen / open the core image file
 27094                              <1> 		; jsr r0,itrunc / free all associated blocks
 27095                              <1> 		; br 2f
 27096                              <1> ;1:
 27097                              <1> 		; mov $17,r1 / put i-node mode (17) in r1
 27098                              <1> 		; jsr r0,maknod / make an i-node
 27099                              <1> 		; mov u.dirbuf,r1 / put i-node number in r1
 27100                              <1> ;2:
 27101                              <1> 		; mov $core,u.base / move address core to u.base
 27102                              <1> 		; mov $ecore-core,u.count / put the byte count in u.count
 27103                              <1> 		; mov $u.off,u.fofp / more user offset to u.fofp
 27104                              <1> 		; clr u.off / clear user offset
 27105                              <1> 		; jsr r0,writei / write out the core image to the user
 27106                              <1> 		; mov $user,u.base / pt. u.base to user
 27107                              <1> 		; mov $64.,u.count / u.count = 64
 27108                              <1> 		; jsr r0,writei / write out all the user parameters
 27109                              <1> 		; neg r1 / make i-number positive
 27110                              <1> 		; jsr r0,iclose / close the core image file
 27111                              <1> 		; br sysexit /
 27112                              <1> ;3:
 27113                              <1> 		; <core\0\0>
 27114                              <1> 
 27115                              <1> intract: ; / interrupt action
 27116                              <1> 	; 14/10/2015
 27117                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 27118                              <1> 	; 09/05/2013 - 07/12/2013 (Retro UNIX 8086 v1)
 27119                              <1> 	;
 27120                              <1> 	; Retro UNIX 8086 v1 modification !
 27121                              <1> 	; (Process/task switching and quit routine by using
 27122                              <1> 	; Retro UNIX 8086 v1 keyboard interrupt output.))
 27123                              <1> 	;
 27124                              <1> 	; input -> 'u.quit'  (also value of 'u.intr' > 0)
 27125                              <1> 	; output -> If value of 'u.quit' = FFFFh ('ctrl+brk' sign)
 27126                              <1> 	;		'intract' will jump to 'sysexit'.
 27127                              <1> 	;	    Intract will return to the caller 
 27128                              <1> 	;		if value of 'u.quit' <> FFFFh. 	 
 27129                              <1> 	; 14/10/2015
 27130 000096C6 FB                  <1> 	sti
 27131                              <1> 	; 07/12/2013	
 27132 000096C7 66FF05[86CE0000]    <1> 	inc 	word [u.quit]
 27133 000096CE 7408                <1> 	jz	short intrct0 ; FFFFh -> 0
 27134 000096D0 66FF0D[86CE0000]    <1> 	dec	word [u.quit]
 27135                              <1> 	; 16/04/2015
 27136 000096D7 C3                  <1> 	retn
 27137                              <1> intrct0:	
 27138 000096D8 58                  <1> 	pop	eax ; call intract -> retn
 27139                              <1> 	;
 27140 000096D9 31C0                <1> 	xor 	eax, eax
 27141 000096DB FEC0                <1> 	inc	al  ; mov ax, 1
 27142                              <1> ;;;
 27143                              <1> 	; UNIX v1 original 'intract' routine... 
 27144                              <1> 	; / interrupt action
 27145                              <1> 		;cmp *(sp),$rti / are you in a clock interrupt?
 27146                              <1> 		; bne 1f / no, 1f
 27147                              <1> 		; cmp (sp)+,(sp)+ / pop clock pointer
 27148                              <1> 	; 1: / now in user area
 27149                              <1> 		; mov r1,-(sp) / save r1
 27150                              <1> 		; mov u.ttyp,r1 
 27151                              <1> 			; / pointer to tty buffer in control-to r1
 27152                              <1> 		; cmpb 6(r1),$177
 27153                              <1> 			; / is the interrupt char equal to "del"
 27154                              <1> 		; beq 1f / yes, 1f
 27155                              <1> 		; clrb 6(r1) 
 27156                              <1> 		        ; / no, clear the byte 
 27157                              <1> 			; / (must be a quit character)
 27158                              <1> 		; mov (sp)+,r1 / restore r1
 27159                              <1> 		; clr u.quit / clear quit flag
 27160                              <1> 		; bis $20,2(sp) 
 27161                              <1> 		    	; / set trace for quit (sets t bit of 
 27162                              <1> 			; / ps-trace trap)
 27163                              <1> 		; rti   ;  / return from interrupt
 27164                              <1> 	; 1: / interrupt char = del
 27165                              <1> 		; clrb 6(r1) / clear the interrupt byte 
 27166                              <1> 			   ; / in the buffer
 27167                              <1> 		; mov (sp)+,r1 / restore r1
 27168                              <1> 		; cmp u.intr,$core / should control be 
 27169                              <1> 				; / transferred to loc core?
 27170                              <1> 		; blo 1f
 27171                              <1> 		; jmp *u.intr / user to do rti yes, 
 27172                              <1> 				; / transfer to loc core
 27173                              <1> 	; 1:
 27174                              <1> 		; sys 1 / exit
 27175                              <1> 
 27176                              <1> sysexit: ; <terminate process>
 27177                              <1> 	; 01/09/2015
 27178                              <1> 	; 31/08/2015
 27179                              <1> 	; 14/05/2015
 27180                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 27181                              <1> 	; 19/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
 27182                              <1> 	;
 27183                              <1> 	; 'sysexit' terminates a process. First each file that
 27184                              <1> 	; the process has opened is closed by 'flose'. The process
 27185                              <1> 	; status is then set to unused. The 'p.pid' table is then
 27186                              <1> 	; searched to find children of the dying process. If any of
 27187                              <1> 	; children are zombies (died by not waited for), they are
 27188                              <1> 	; set free. The 'p.pid' table is then searched to find the
 27189                              <1> 	; dying process's parent. When the parent is found, it is
 27190                              <1> 	; checked to see if it is free or it is a zombie. If it is
 27191                              <1> 	; one of these, the dying process just dies. If it is waiting
 27192                              <1> 	; for a child process to die, it notified that it doesn't 
 27193                              <1> 	; have to wait anymore by setting it's status from 2 to 1
 27194                              <1> 	; (waiting to active). It is awakened and put on runq by
 27195                              <1> 	; 'putlu'. The dying process enters a zombie state in which
 27196                              <1> 	; it will never be run again but stays around until a 'wait'
 27197                              <1> 	; is completed by it's parent process. If the parent is not
 27198                              <1> 	; found, process just dies. This means 'swap' is called with
 27199                              <1> 	; 'u.uno=0'. What this does is the 'wswap' is not called
 27200                              <1> 	; to write out the process and 'rswap' reads the new process
 27201                              <1> 	; over the one that dies..i.e., the dying process is 
 27202                              <1> 	; overwritten and destroyed.	
 27203                              <1>  	;
 27204                              <1> 	; Calling sequence:
 27205                              <1> 	;	sysexit or conditional branch.
 27206                              <1> 	; Arguments:
 27207                              <1> 	;	-	
 27208                              <1> 	; ...............................................................
 27209                              <1> 	;	
 27210                              <1> 	; Retro UNIX 8086 v1 modification: 
 27211                              <1> 	;       System call number (=1) is in EAX register.
 27212                              <1> 	;
 27213                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
 27214                              <1> 	;       registers depending of function details.
 27215                              <1> 	;
 27216                              <1> 	; ('swap' procedure is mostly different than original UNIX v1.)
 27217                              <1> 	;
 27218                              <1> ; / terminate process
 27219                              <1> 	; AX = 1
 27220 000096DD 6648                <1> 	dec 	ax ; 0
 27221 000096DF 66A3[84CE0000]      <1> 	mov	[u.intr], ax ; 0
 27222                              <1> 		; clr u.intr / clear interrupt control word
 27223                              <1> 		; clr r1 / clear r1
 27224                              <1> 	; AX = 0
 27225                              <1> sysexit_1: ; 1:
 27226                              <1> 	; AX = File descriptor
 27227                              <1> 		; / r1 has file descriptor (index to u.fp list)
 27228                              <1> 		; / Search the whole list
 27229 000096E5 E8140D0000          <1> 	call	fclose
 27230                              <1> 		; jsr r0,fclose / close all files the process opened
 27231                              <1> 	;; ignore error return
 27232                              <1> 		; br .+2 / ignore error return
 27233                              <1> 	;inc	ax
 27234 000096EA FEC0                <1> 	inc	al
 27235                              <1> 		; inc r1 / increment file descriptor
 27236                              <1> 	;cmp	ax, 10
 27237 000096EC 3C0A                <1> 	cmp	al, 10
 27238                              <1> 		; cmp r1,$10. / end of u.fp list?
 27239 000096EE 72F5                <1> 	jb	short sysexit_1
 27240                              <1> 		; blt 1b / no, go back
 27241 000096F0 0FB61D[8FCE0000]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
 27242                              <1> 		; movb	u.uno,r1 / yes, move dying process's number to r1
 27243 000096F7 88A3[C5CB0000]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE, 05/02/2014
 27244                              <1> 		; clrb p.stat-1(r1) / free the process
 27245                              <1> 	;shl	bx, 1
 27246 000096FD D0E3                <1> 	shl	bl, 1
 27247                              <1> 		; asl r1 / use r1 for index into the below tables
 27248 000096FF 668B8B[34CB0000]    <1> 	mov	cx, [ebx+p.pid-2]
 27249                              <1> 		; mov p.pid-2(r1),r3 / move dying process's name to r3
 27250 00009706 668B93[54CB0000]    <1> 	mov	dx, [ebx+p.ppid-2]
 27251                              <1> 		; mov p.ppid-2(r1),r4 / move its parents name to r4
 27252                              <1> 	; xor 	bx, bx ; 0
 27253 0000970D 30DB                <1> 	xor	bl, bl ; 0
 27254                              <1> 		; clr r2
 27255 0000970F 31F6                <1> 	xor	esi, esi ; 0
 27256                              <1> 		; clr r5 / initialize reg
 27257                              <1> sysexit_2: ; 1:
 27258                              <1> 	        ; / find children of this dying process, 
 27259                              <1> 		; / if they are zombies, free them
 27260                              <1> 	;add	bx, 2
 27261 00009711 80C302              <1> 	add	bl, 2
 27262                              <1> 		; add $2,r2 / search parent process table 
 27263                              <1> 		          ; / for dying process's name
 27264 00009714 66398B[54CB0000]    <1> 	cmp	[ebx+p.ppid-2], cx
 27265                              <1> 		; cmp p.ppid-2(r2),r3 / found it?
 27266 0000971B 7513                <1> 	jne	short sysexit_4
 27267                              <1> 		; bne 3f / no
 27268                              <1> 	;shr	bx, 1
 27269 0000971D D0EB                <1> 	shr	bl, 1
 27270                              <1> 		; asr r2 / yes, it is a parent
 27271 0000971F 80BB[C5CB0000]03    <1> 	cmp	byte [ebx+p.stat-1], 3 ; SZOMB, 05/02/2014
 27272                              <1> 		; cmpb p.stat-1(r2),$3 / is the child of this 
 27273                              <1> 				     ; / dying process a zombie
 27274 00009726 7506                <1> 	jne	short sysexit_3 
 27275                              <1> 		; bne 2f / no
 27276 00009728 88A3[C5CB0000]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE, 05/02/2014
 27277                              <1> 		; clrb p.stat-1(r2) / yes, free the child process
 27278                              <1> sysexit_3: ; 2:
 27279                              <1> 	;shr	bx, 1
 27280 0000972E D0E3                <1> 	shl	bl, 1
 27281                              <1> 		; asl r2
 27282                              <1> sysexit_4: ; 3:
 27283                              <1> 		; / search the process name table 
 27284                              <1> 		; / for the dying process's parent
 27285 00009730 663993[34CB0000]    <1> 	cmp	[ebx+p.pid-2], dx ; 17/09/2013	
 27286                              <1> 		; cmp p.pid-2(r2),r4 / found it?
 27287 00009737 7502                <1> 	jne	short sysexit_5
 27288                              <1> 		; bne 3f / no
 27289 00009739 89DE                <1> 	mov	esi, ebx
 27290                              <1> 		; mov r2,r5 / yes, put index to p.pid table (parents
 27291                              <1> 		          ; / process # x2) in r5
 27292                              <1> sysexit_5: ; 3:
 27293                              <1> 	;cmp	bx, nproc + nproc
 27294 0000973B 80FB20              <1> 	cmp	bl, nproc + nproc
 27295                              <1> 		; cmp r2,$nproc+nproc / has whole table been searched?
 27296 0000973E 72D1                <1> 	jb	short sysexit_2
 27297                              <1> 		; blt 1b / no, go back
 27298                              <1> 		; mov r5,r1 / yes, r1 now has parents process # x2
 27299 00009740 21F6                <1> 	and	esi, esi ; r5=r1
 27300 00009742 7431                <1> 	jz	short sysexit_6
 27301                              <1> 		; beq 2f / no parent has been found. 
 27302                              <1> 		       ; / The process just dies
 27303 00009744 66D1EE              <1> 	shr	si, 1
 27304                              <1> 		; asr r1 / set up index to p.stat
 27305 00009747 8A86[C5CB0000]      <1> 	mov	al, [esi+p.stat-1]
 27306                              <1> 		; movb p.stat-1(r1),r2 / move status of parent to r2
 27307 0000974D 20C0                <1> 	and	al, al
 27308 0000974F 7424                <1> 	jz	short sysexit_6
 27309                              <1> 		; beq 2f / if its been freed, 2f
 27310 00009751 3C03                <1> 	cmp	al, 3
 27311                              <1> 		; cmp r2,$3 / is parent a zombie?
 27312 00009753 7420                <1> 	je	short sysexit_6
 27313                              <1> 		; beq 2f / yes, 2f
 27314                              <1> 	; BH = 0
 27315 00009755 8A1D[8FCE0000]      <1> 	mov	bl, [u.uno]
 27316                              <1> 		; movb u.uno,r3 / move dying process's number to r3
 27317 0000975B C683[C5CB0000]03    <1> 	mov	byte [ebx+p.stat-1], 3  ; SZOMB, 05/02/2014
 27318                              <1> 		; movb $3,p.stat-1(r3) / make the process a zombie
 27319                              <1> 	; 05/02/2014
 27320 00009762 3C01                <1> 	cmp	al, 1 ; SRUN
 27321 00009764 740F                <1> 	je	short sysexit_6
 27322                              <1> 	;cmp	al, 2
 27323                              <1> 		; cmp r2,$2 / is the parent waiting for 
 27324                              <1> 			  ; / this child to die
 27325                              <1> 	;jne	short sysexit_6	
 27326                              <1> 		; bne 2f / yes, notify parent not to wait any more
 27327                              <1> 	; 05/02/2014
 27328                              <1> 	; p.stat = 2 --> waiting
 27329                              <1> 	; p.stat = 4 --> sleeping
 27330 00009766 C686[C5CB0000]01    <1> 	mov	byte [esi+p.stat-1], 1 ; SRUN ; 05/02/2014
 27331                              <1> 	;dec	byte [esi+p.stat-1]
 27332                              <1> 		; decb	p.stat-1(r1) / awaken it by putting it (parent)
 27333 0000976D 6689F0              <1> 	mov	ax, si ; r1  (process number in AL)
 27334                              <1> 	; 
 27335                              <1> 	;mov	ebx, runq + 4
 27336                              <1> 		; mov $runq+4,r2 / on the runq
 27337 00009770 E8AD130000          <1> 	call	putlu
 27338                              <1> 		; jsr r0, putlu
 27339                              <1> sysexit_6: ; 2:
 27340                              <1> 	; 31/08/2015
 27341                              <1> 		; / the process dies
 27342 00009775 C605[8FCE0000]00    <1> 	mov	byte [u.uno], 0
 27343                              <1> 		; clrb u.uno / put zero as the process number, 
 27344                              <1> 	           ; / so "swap" will
 27345 0000977C E8A2130000          <1> 	call	swap
 27346                              <1> 		; jsr r0,swap / overwrite process with another process
 27347                              <1> hlt_sys:
 27348                              <1> 	;sti ; 18/01/2014
 27349                              <1> hlts0:
 27350 00009781 F4                  <1> 	hlt
 27351 00009782 EBFD                <1> 	jmp	short hlts0
 27352                              <1> 		; 0 / and thereby kill it; halt?
 27353                              <1> 
 27354                              <1> 
 27355                              <1> syswait: ; < wait for a processs to die >
 27356                              <1> 	; 17/09/2015
 27357                              <1> 	; 02/09/2015
 27358                              <1> 	; 01/09/2015
 27359                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 27360                              <1> 	; 24/05/2013 - 05/02/2014 (Retro UNIX 8086 v1)
 27361                              <1> 	;
 27362                              <1> 	; 'syswait' waits for a process die. 
 27363                              <1> 	; It works in following way:
 27364                              <1> 	;    1) From the parent process number, the parent's 
 27365                              <1> 	; 	process name is found. The p.ppid table of parent
 27366                              <1> 	;	names is then searched for this process name.
 27367                              <1> 	;	If a match occurs, r2 contains child's process
 27368                              <1> 	;	number. The child status is checked to see if it is
 27369                              <1> 	;	a zombie, i.e; dead but not waited for (p.stat=3)
 27370                              <1> 	;	If it is, the child process is freed and it's name
 27371                              <1> 	;	is put in (u.r0). A return is then made via 'sysret'.
 27372                              <1> 	;	If the child is not a zombie, nothing happens and
 27373                              <1> 	;	the search goes on through the p.ppid table until
 27374                              <1> 	;	all processes are checked or a zombie is found.
 27375                              <1> 	;    2) If no zombies are found, a check is made to see if
 27376                              <1> 	;	there are any children at all. If there are none,
 27377                              <1> 	;	an error return is made. If there are, the parent's
 27378                              <1> 	;	status is set to 2 (waiting for child to die),
 27379                              <1> 	;	the parent is swapped out, and a branch to 'syswait'
 27380                              <1> 	;	is made to wait on the next process.
 27381                              <1> 	;
 27382                              <1> 	; Calling sequence:
 27383                              <1> 	;	?
 27384                              <1> 	; Arguments:
 27385                              <1> 	;	-
 27386                              <1> 	; Inputs: - 
 27387                              <1> 	; Outputs: if zombie found, it's name put in u.r0.	
 27388                              <1> 	; ...............................................................
 27389                              <1> 	;				
 27390                              <1> 	
 27391                              <1> ; / wait for a process to die
 27392                              <1> 
 27393                              <1> syswait_0:
 27394 00009784 0FB61D[8FCE0000]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
 27395                              <1> 		; movb u.uno,r1 / put parents process number in r1
 27396 0000978B D0E3                <1> 	shl	bl, 1
 27397                              <1> 	;shl	bx, 1
 27398                              <1> 		; asl r1 / x2 to get index into p.pid table
 27399 0000978D 668B83[34CB0000]    <1> 	mov	ax, [ebx+p.pid-2]
 27400                              <1> 		; mov p.pid-2(r1),r1 / get the name of this process
 27401 00009794 31F6                <1> 	xor	esi, esi
 27402                              <1> 		; clr r2
 27403 00009796 31C9                <1> 	xor	ecx, ecx ; 30/10/2013
 27404                              <1> 	;xor 	cl, cl
 27405                              <1> 		; clr r3 / initialize reg 3
 27406                              <1> syswait_1: ; 1:
 27407 00009798 6683C602            <1> 	add	si, 2
 27408                              <1> 		; add $2,r2 / use r2 for index into p.ppid table
 27409                              <1> 			  ; / search table of parent processes 
 27410                              <1> 			  ; / for this process name
 27411 0000979C 663B86[54CB0000]    <1> 	cmp	ax, [esi+p.ppid-2]
 27412                              <1> 		; cmp p.ppid-2(r2),r1 / r2 will contain the childs 
 27413                              <1> 			            ; / process number
 27414 000097A3 7535                <1> 	jne	short syswait_3
 27415                              <1> 		;bne 3f / branch if no match of parent process name
 27416                              <1> 	;inc	cx
 27417 000097A5 FEC1                <1> 	inc	cl
 27418                              <1> 		;inc r3 / yes, a match, r3 indicates number of children
 27419 000097A7 66D1EE              <1> 	shr	si, 1
 27420                              <1> 		; asr r2 / r2/2 to get index to p.stat table
 27421                              <1> 	; The possible states ('p.stat' values) of a process are:
 27422                              <1> 	;	0 = free or unused
 27423                              <1> 	;	1 = active
 27424                              <1> 	;	2 = waiting for a child process to die
 27425                              <1> 	;	3 = terminated, but not yet waited for (zombie).	
 27426 000097AA 80BE[C5CB0000]03    <1> 	cmp	byte [esi+p.stat-1], 3 ; SZOMB, 05/02/2014
 27427                              <1> 		; cmpb p.stat-1(r2),$3 / is the child process a zombie?
 27428 000097B1 7524                <1> 	jne	short syswait_2
 27429                              <1> 		; bne 2f / no, skip it
 27430 000097B3 88BE[C5CB0000]      <1> 	mov	[esi+p.stat-1], bh ; 0
 27431                              <1> 		; clrb p.stat-1(r2) / yes, free it
 27432 000097B9 66D1E6              <1> 	shl	si, 1
 27433                              <1> 		; asl r2 / r2x2 to get index into p.pid table
 27434 000097BC 0FB786[34CB0000]    <1> 	movzx	eax, word [esi+p.pid-2]
 27435 000097C3 A3[40CE0000]        <1> 	mov	[u.r0], eax
 27436                              <1> 		; mov p.pid-2(r2),*u.r0 
 27437                              <1> 			      ; / put childs process name in (u.r0)
 27438                              <1> 	;
 27439                              <1> 	; Retro UNIX 386 v1 modification ! (17/09/2015)
 27440                              <1> 	;
 27441                              <1> 	; Parent process ID -p.ppid- field (of the child process)
 27442                              <1> 	; must be cleared in order to prevent infinitive 'syswait'
 27443                              <1> 	; system call loop from the application/program if it calls
 27444                              <1> 	; 'syswait' again (mistakenly) while there is not a zombie
 27445                              <1> 	; or running child process to wait. ('forktest.s', 17/09/2015)
 27446                              <1> 	;
 27447                              <1> 	; Note: syswait will return with error if there is not a
 27448                              <1> 	;       zombie or running process to wait.	
 27449                              <1> 	;
 27450 000097C8 6629C0              <1> 	sub	ax, ax
 27451 000097CB 668986[54CB0000]    <1> 	mov 	[esi+p.ppid-2], ax ; 0 ; 17/09/2015
 27452 000097D2 E910FEFFFF          <1> 	jmp	sysret0 ; ax = 0
 27453                              <1> 	;
 27454                              <1> 	;jmp	sysret
 27455                              <1> 		; br sysret1 / return cause child is dead
 27456                              <1> syswait_2: ; 2:
 27457 000097D7 66D1E6              <1> 	shl	si, 1
 27458                              <1> 		; asl r2 / r2x2 to get index into p.ppid table
 27459                              <1> syswait_3: ; 3:
 27460 000097DA 6683FE20            <1> 	cmp	si, nproc+nproc
 27461                              <1> 		; cmp r2,$nproc+nproc / have all processes been checked?
 27462 000097DE 72B8                <1> 	jb	short syswait_1
 27463                              <1> 		; blt 1b / no, continue search
 27464                              <1> 	;and	cx, cx
 27465 000097E0 20C9                <1> 	and	cl, cl
 27466                              <1> 		; tst r3 / one gets here if there are no children 
 27467                              <1> 		       ; / or children that are still active
 27468                              <1> 	; 30/10/2013
 27469 000097E2 750B                <1> 	jnz	short syswait_4
 27470                              <1> 	;jz	error
 27471                              <1> 		; beq error1 / there are no children, error
 27472 000097E4 890D[40CE0000]      <1> 	mov	[u.r0], ecx ; 0
 27473 000097EA E9D5FDFFFF          <1> 	jmp	error
 27474                              <1> syswait_4:
 27475 000097EF 8A1D[8FCE0000]      <1> 	mov	bl, [u.uno]
 27476                              <1> 		; movb u.uno,r1 / there are children so put 
 27477                              <1> 			      ; / parent process number in r1
 27478 000097F5 FE83[C5CB0000]      <1> 	inc	byte [ebx+p.stat-1] ; 2, SWAIT, 05/02/2014
 27479                              <1> 		; incb p.stat-1(r1) / it is waiting for 
 27480                              <1> 				  ; / other children to die
 27481                              <1> 	; 04/11/2013
 27482 000097FB E823130000          <1> 	call	swap
 27483                              <1> 		; jsr r0,swap / swap it out, because it's waiting
 27484 00009800 EB82                <1> 	jmp	syswait_0
 27485                              <1> 		; br syswait / wait on next process
 27486                              <1> 
 27487                              <1> sysfork: ; < create a new process >
 27488                              <1> 	; 18/09/2015
 27489                              <1> 	; 04/09/2015
 27490                              <1> 	; 02/09/2015
 27491                              <1> 	; 01/09/2015
 27492                              <1> 	; 28/08/2015
 27493                              <1> 	; 14/05/2015
 27494                              <1> 	; 10/05/2015
 27495                              <1> 	; 09/05/2015
 27496                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 - Beginning)
 27497                              <1> 	; 24/05/2013 - 14/02/2014 (Retro UNIX 8086 v1)
 27498                              <1> 	;
 27499                              <1> 	; 'sysfork' creates a new process. This process is referred
 27500                              <1> 	; to as the child process. This new process core image is
 27501                              <1> 	; a copy of that of the caller of 'sysfork'. The only
 27502                              <1> 	; distinction is the return location and the fact that (u.r0)
 27503                              <1> 	; in the old process (parent) contains the process id (p.pid)
 27504                              <1> 	; of the new process (child). This id is used by 'syswait'.
 27505                              <1> 	; 'sysfork' works in the following manner: 	
 27506                              <1> 	;    1) The process status table (p.stat) is searched to find
 27507                              <1> 	;	a process number that is unused. If none are found
 27508                              <1> 	;	an error occurs.
 27509                              <1> 	;    2) when one is found, it becomes the child process number
 27510                              <1> 	;	and it's status (p.stat) is set to active.
 27511                              <1> 	;    3) If the parent had a control tty, the interrupt 
 27512                              <1> 	;	character in that tty buffer is cleared.
 27513                              <1> 	;    4) The child process is put on the lowest priority run 
 27514                              <1> 	;	queue via 'putlu'.
 27515                              <1> 	;    5) A new process name is gotten from 'mpid' (actually 
 27516                              <1> 	;	it is a unique number) and is put in the child's unique
 27517                              <1> 	;	identifier; process id (p.pid).
 27518                              <1> 	;    6) The process name of the parent is then obtained and
 27519                              <1> 	;	placed in the unique identifier of the parent process
 27520                              <1> 	;	name is then put in 'u.r0'.	
 27521                              <1> 	;    7) The child process is then written out on disk by
 27522                              <1> 	;	'wswap',i.e., the parent process is copied onto disk
 27523                              <1> 	;	and the child is born. (The child process is written 
 27524                              <1> 	;	out on disk/drum with 'u.uno' being the child process
 27525                              <1> 	;	number.)
 27526                              <1> 	;    8) The parent process number is then restored to 'u.uno'.
 27527                              <1> 	;    9) The child process name is put in 'u.r0'.
 27528                              <1> 	;   10) The pc on the stack sp + 18 is incremented by 2 to
 27529                              <1> 	;	create the return address for the parent process.
 27530                              <1> 	;   11) The 'u.fp' list as then searched to see what files
 27531                              <1> 	;	the parent has opened. For each file the parent has
 27532                              <1> 	;	opened, the corresponding 'fsp' entry must be updated
 27533                              <1> 	;	to indicate that the child process also has opened
 27534                              <1> 	;	the file. A branch to 'sysret' is then made.	 			 				
 27535                              <1> 	;
 27536                              <1> 	; Calling sequence:
 27537                              <1> 	;	from shell ?
 27538                              <1> 	; Arguments:
 27539                              <1> 	;	-
 27540                              <1> 	; Inputs: -
 27541                              <1> 	; Outputs: *u.r0 - child process name
 27542                              <1> 	; ...............................................................
 27543                              <1> 	;	
 27544                              <1> 	; Retro UNIX 8086 v1 modification: 
 27545                              <1> 	;	AX = r0 = PID (>0) (at the return of 'sysfork')
 27546                              <1> 	;	= process id of child a parent process returns
 27547                              <1> 	;	= process id of parent when a child process returns
 27548                              <1> 	;
 27549                              <1> 	;       In original UNIX v1, sysfork is called and returns as
 27550                              <1> 	;	in following manner: (with an example: c library, fork)
 27551                              <1> 	;	
 27552                              <1> 	;	1:
 27553                              <1> 	;		sys	fork
 27554                              <1> 	;			br 1f  / child process returns here
 27555                              <1> 	;		bes	2f     / parent process returns here
 27556                              <1> 	;		/ pid of new process in r0
 27557                              <1> 	;		rts	pc
 27558                              <1> 	;	2: / parent process condionally branches here
 27559                              <1> 	;		mov	$-1,r0 / pid = -1 means error return
 27560                              <1> 	;		rts	pc
 27561                              <1> 	;
 27562                              <1> 	;	1: / child process brances here
 27563                              <1> 	;		clr	r0   / pid = 0 in child process
 27564                              <1> 	;		rts	pc
 27565                              <1> 	;
 27566                              <1> 	;	In UNIX v7x86 (386) by Robert Nordier (1999)
 27567                              <1> 	;		// pid = fork();
 27568                              <1> 	;		//
 27569                              <1> 	;		// pid == 0 in child process; 
 27570                              <1> 	;		// pid == -1 means error return
 27571                              <1> 	;		// in child, 
 27572                              <1> 	;		//	parents id is in par_uid if needed
 27573                              <1> 	;		
 27574                              <1> 	;		_fork:
 27575                              <1> 	;			mov	$.fork,eax
 27576                              <1> 	;			int	$0x30
 27577                              <1> 	;			jmp	1f
 27578                              <1> 	;			jnc	2f
 27579                              <1> 	;			jmp	cerror
 27580                              <1> 	;		1:
 27581                              <1> 	;			mov	eax,_par_uid
 27582                              <1> 	;			xor	eax,eax
 27583                              <1> 	;		2:
 27584                              <1> 	;			ret
 27585                              <1> 	;
 27586                              <1> 	;	In Retro UNIX 8086 v1,
 27587                              <1> 	;	'sysfork' returns in following manner:
 27588                              <1> 	;	
 27589                              <1> 	;		mov	ax, sys_fork
 27590                              <1> 	;		mov	bx, offset @f ; routine for child
 27591                              <1> 	;		int	20h
 27592                              <1> 	;		jc	error
 27593                              <1> 	;		
 27594                              <1> 	;	; Routine for parent process here (just after 'jc')
 27595                              <1> 	;		mov	word ptr [pid_of_child], ax
 27596                              <1> 	;		jmp	next_routine_for_parent	
 27597                              <1> 	;
 27598                              <1> 	;	@@: ; routine for child process here				
 27599                              <1> 	;		....	
 27600                              <1> 	;	NOTE: 'sysfork' returns to specified offset
 27601                              <1> 	;	       for child process by using BX input.
 27602                              <1> 	;	      (at first, parent process will return then 
 27603                              <1> 	;	      child process will return -after swapped in-
 27604                              <1> 	;	      'syswait' is needed in parent process
 27605                              <1> 	;	      if return from child process will be waited for.)
 27606                              <1> 	;	  				
 27607                              <1> 	
 27608                              <1> ; / create a new process
 27609                              <1> 	; EBX = return address for child process 
 27610                              <1> 	     ; (Retro UNIX 8086 v1 modification !)
 27611 00009802 31F6                <1> 	xor 	esi, esi
 27612                              <1> 		; clr r1
 27613                              <1> sysfork_1: ; 1: / search p.stat table for unused process number
 27614 00009804 46                  <1> 	inc	esi
 27615                              <1> 		; inc r1
 27616 00009805 80BE[C5CB0000]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE, 05/02/2014
 27617                              <1> 		; tstb p.stat-1(r1) / is process active, unused, dead
 27618 0000980C 760B                <1> 	jna	short sysfork_2	
 27619                              <1> 		; beq 1f / it's unused so branch
 27620 0000980E 6683FE10            <1> 	cmp	si, nproc
 27621                              <1> 		; cmp r1,$nproc / all processes checked
 27622 00009812 72F0                <1> 	jb	short sysfork_1
 27623                              <1> 		; blt 1b / no, branch back
 27624                              <1> 	;
 27625                              <1> 	; Retro UNIX 8086 v1. modification:
 27626                              <1> 	;	Parent process returns from 'sysfork' to address 
 27627                              <1> 	;	which is just after 'sysfork' system call in parent
 27628                              <1> 	;	process. Child process returns to address which is put
 27629                              <1> 	;	in BX register by parent process for 'sysfork'. 
 27630                              <1> 	;
 27631                              <1> 		;add $2,18.(sp) / add 2 to pc when trap occured, points
 27632                              <1> 		             ; / to old process return
 27633                              <1> 		; br error1 / no room for a new process
 27634 00009814 E9ABFDFFFF          <1> 	jmp	error
 27635                              <1> sysfork_2: ; 1:
 27636 00009819 E8E998FFFF          <1> 	call	allocate_page
 27637 0000981E 0F82A0FDFFFF        <1> 	jc	error
 27638 00009824 50                  <1> 	push	eax   ; UPAGE (user structure page) address
 27639                              <1> 	; Retro UNIX 386 v1 modification!
 27640 00009825 E8E69AFFFF          <1> 	call	duplicate_page_dir
 27641                              <1> 		; EAX = New page directory 
 27642 0000982A 730B                <1> 	jnc	short sysfork_3
 27643 0000982C 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
 27644 0000982D E8AD9AFFFF          <1> 	call 	deallocate_page
 27645 00009832 E98DFDFFFF          <1> 	jmp	error
 27646                              <1> sysfork_3:
 27647                              <1> 	; Retro UNIX 386 v1 modification !
 27648 00009837 56                  <1> 	push	esi
 27649 00009838 E8E7120000          <1> 	call	wswap ; save current user (u) structure, user registers
 27650                              <1> 		      ; and interrupt return components (for IRET)
 27651 0000983D 8705[99CE0000]      <1> 	xchg	eax, [u.pgdir] ; page directory of the child process
 27652 00009843 A3[9DCE0000]        <1> 	mov	[u.ppgdir], eax ; page directory of the parent process
 27653 00009848 5E                  <1> 	pop	esi
 27654 00009849 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
 27655                              <1> 		; [u.usp] = esp
 27656 0000984A 89F7                <1> 	mov	edi, esi
 27657 0000984C 66C1E702            <1> 	shl	di, 2
 27658 00009850 8987[D2CB0000]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
 27659 00009856 A3[90CE0000]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
 27660                              <1> 	; 28/08/2015
 27661 0000985B 0FB605[8FCE0000]    <1> 	movzx	eax, byte [u.uno] ; parent process number
 27662                              <1> 		; movb u.uno,-(sp) / save parent process number
 27663 00009862 89C7                <1> 	mov	edi, eax
 27664 00009864 50                  <1>         push	eax ; ** 
 27665 00009865 8A87[95CB0000]      <1> 	mov     al, [edi+p.ttyc-1] ; console tty (parent)
 27666                              <1> 	; 18/09/2015
 27667                              <1> 	;mov     [esi+p.ttyc-1], al ; set child's console tty
 27668                              <1> 	;mov     [esi+p.waitc-1], ah ; 0 ; reset child's wait channel
 27669 0000986B 668986[95CB0000]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
 27670                              <1> 				   ; ah - reset child's wait channel	
 27671 00009872 89F0                <1> 	mov	eax, esi
 27672 00009874 A2[8FCE0000]        <1> 	mov	[u.uno], al ; child process number
 27673                              <1> 		;movb r1,u.uno / set child process number to r1
 27674 00009879 FE86[C5CB0000]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN, 05/02/2014
 27675                              <1> 		; incb p.stat-1(r1) / set p.stat entry for child 
 27676                              <1> 				; / process to active status
 27677                              <1> 		; mov u.ttyp,r2 / put pointer to parent process' 
 27678                              <1> 			      ; / control tty buffer in r2
 27679                              <1>                 ; beq 2f / branch, if no such tty assigned
 27680                              <1> 		; clrb 6(r2) / clear interrupt character in tty buffer
 27681                              <1> 	; 2:
 27682 0000987F 53                  <1> 	push	ebx  ; * return address for the child process
 27683                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
 27684                              <1> 	; (Retro UNIX 8086 v1 modification!)
 27685                              <1> 		; mov $runq+4,r2
 27686 00009880 E89D120000          <1> 	call	putlu 
 27687                              <1>  		; jsr r0,putlu / put child process on lowest priority 
 27688                              <1> 			   ; / run queue
 27689 00009885 66D1E6              <1> 	shl	si, 1
 27690                              <1> 		; asl r1 / multiply r1 by 2 to get index 
 27691                              <1> 		       ; / into p.pid table
 27692 00009888 66FF05[2ECE0000]    <1> 	inc	word [mpid]
 27693                              <1> 		; inc mpid / increment m.pid; get a new process name
 27694 0000988F 66A1[2ECE0000]      <1> 	mov	ax, [mpid]
 27695 00009895 668986[34CB0000]    <1> 	mov	[esi+p.pid-2], ax
 27696                              <1> 		;mov mpid,p.pid-2(r1) / put new process name 
 27697                              <1> 				    ; / in child process' name slot
 27698 0000989C 5A                  <1> 	pop	edx  ; * return address for the child process
 27699                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
 27700 0000989D 5B                  <1>   	pop	ebx  ; **
 27701                              <1> 	;mov	ebx, [esp] ; ** parent process number
 27702                              <1> 		; movb (sp),r2 / put parent process number in r2
 27703 0000989E 66D1E3              <1> 	shl 	bx, 1
 27704                              <1> 		;asl r2 / multiply by 2 to get index into below tables
 27705                              <1> 	;movzx eax, word [ebx+p.pid-2]
 27706 000098A1 668B83[34CB0000]    <1> 	mov	ax, [ebx+p.pid-2]
 27707                              <1> 		; mov p.pid-2(r2),r2 / get process name of parent
 27708                              <1> 				   ; / process
 27709 000098A8 668986[54CB0000]    <1> 	mov	[esi+p.ppid-2], ax
 27710                              <1> 		; mov r2,p.ppid-2(r1) / put parent process name 
 27711                              <1> 			  ; / in parent process slot for child
 27712 000098AF A3[40CE0000]        <1> 	mov	[u.r0], eax	
 27713                              <1> 		; mov r2,*u.r0 / put parent process name on stack 
 27714                              <1> 			     ; / at location where r0 was saved
 27715 000098B4 8B2D[38CE0000]      <1> 	mov 	ebp, [u.sp] ; points to return address (EIP for IRET)
 27716 000098BA 895500              <1> 	mov	[ebp], edx ; *, CS:EIP -> EIP
 27717                              <1> 			   ; * return address for the child process
 27718                              <1> 		; mov $sysret1,-(sp) /
 27719                              <1> 		; mov sp,u.usp / contents of sp at the time when 
 27720                              <1> 			      ; / user is swapped out
 27721                              <1> 		; mov $sstack,sp / point sp to swapping stack space
 27722                              <1> 	; 04/09/2015 - 01/09/2015
 27723                              <1> 	; [u.usp] = esp
 27724 000098BD 68[E4950000]        <1> 	push	sysret ; ***
 27725 000098C2 8925[3CCE0000]      <1> 	mov	[u.usp], esp ; points to 'sysret' address (***)
 27726                              <1> 			     ; (for child process)	
 27727 000098C8 31C0                <1> 	xor 	eax, eax
 27728 000098CA 66A3[70CE0000]      <1> 	mov 	[u.ttyp], ax ; 0
 27729                              <1> 	;
 27730 000098D0 E84F120000          <1> 	call	wswap ; Retro UNIX 8086 v1 modification !
 27731                              <1> 		;jsr r0,wswap / put child process out on drum
 27732                              <1> 		;jsr r0,unpack / unpack user stack
 27733                              <1> 		;mov u.usp,sp / restore user stack pointer
 27734                              <1> 		; tst (sp)+ / bump stack pointer
 27735                              <1> 	; Retro UNIX 386 v1 modification !
 27736 000098D5 58                  <1> 	pop	eax ; ***
 27737 000098D6 66D1E3              <1> 	shl	bx, 1
 27738 000098D9 8B83[D2CB0000]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address ; 14/05/2015
 27739 000098DF E841120000          <1> 	call	rswap ; restore parent process 'u' structure, 
 27740                              <1> 		      ; registers and return address (for IRET)
 27741                              <1> 		;movb (sp)+,u.uno / put parent process number in u.uno
 27742 000098E4 0FB705[2ECE0000]    <1>         movzx   eax, word [mpid]
 27743 000098EB A3[40CE0000]        <1> 	mov	[u.r0], eax
 27744                              <1> 		; mov mpid,*u.r0 / put child process name on stack 
 27745                              <1> 			       ; / where r0 was saved
 27746                              <1> 		; add $2,18.(sp) / add 2 to pc on stack; gives parent
 27747                              <1> 			          ; / process return
 27748                              <1> 	;xor	ebx, ebx
 27749 000098F0 31F6                <1> 	xor     esi, esi
 27750                              <1> 		;clr r1
 27751                              <1> sysfork_4: ; 1: / search u.fp list to find the files 
 27752                              <1> 	      ; / opened by the parent process
 27753                              <1> 	; 01/09/2015
 27754                              <1> 	;xor	bh, bh
 27755                              <1> 	;mov 	bl, [esi+u.fp]
 27756 000098F2 8A86[46CE0000]      <1> 	mov 	al, [esi+u.fp]
 27757                              <1> 		; movb u.fp(r1),r2 / get an open file for this process
 27758                              <1>         ;or      bl, bl
 27759 000098F8 08C0                <1> 	or	al, al
 27760 000098FA 740D                <1> 	jz	short sysfork_5	
 27761                              <1> 		; beq 2f / file has not been opened by parent, 
 27762                              <1> 		       ; / so branch
 27763 000098FC B40A                <1> 	mov	ah, 10 ; Retro UNIX 386 v1 fsp structure size = 10 bytes
 27764 000098FE F6E4                <1> 	mul	ah
 27765                              <1> 	;movzx	ebx, ax
 27766 00009900 6689C3              <1> 	mov	bx, ax
 27767                              <1> 	;shl     bx, 3
 27768                              <1> 		; asl r2 / multiply by 8
 27769                              <1>        		; asl r2 / to get index into fsp table
 27770                              <1>        		; asl r2
 27771 00009903 FE83[14CC0000]      <1>   	inc     byte [ebx+fsp-2]
 27772                              <1> 		; incb fsp-2(r2) / increment number of processes
 27773                              <1> 			     ; / using file, because child will now be
 27774                              <1> 			     ; / using this file
 27775                              <1> sysfork_5: ; 2:
 27776 00009909 46                  <1>         inc     esi
 27777                              <1> 		; inc r1 / get next open file
 27778 0000990A 6683FE0A            <1>         cmp     si, 10
 27779                              <1> 		; cmp r1,$10. / 10. files is the maximum number which
 27780                              <1> 			  ; / can be opened
 27781 0000990E 72E2                <1> 	jb	short sysfork_4	
 27782                              <1> 		; blt 1b / check next entry
 27783 00009910 E9CFFCFFFF          <1> 	jmp	sysret
 27784                              <1> 		; br sysret1
 27785                              <1> 
 27786                              <1> sysread: ; < read from file >
 27787                              <1> 	; 13/05/2015
 27788                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 27789                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
 27790                              <1> 	;
 27791                              <1> 	; 'sysread' is given a buffer to read into and the number of
 27792                              <1> 	; characters to be read. If finds the file from the file
 27793                              <1> 	; descriptor located in *u.r0 (r0). This file descriptor
 27794                              <1> 	; is returned from a successful open call (sysopen).
 27795                              <1> 	; The i-number of file is obtained via 'rw1' and the data
 27796                              <1> 	; is read into core via 'readi'.
 27797                              <1> 	;
 27798                              <1> 	; Calling sequence:
 27799                              <1> 	;	sysread; buffer; nchars
 27800                              <1> 	; Arguments:
 27801                              <1> 	;	buffer - location of contiguous bytes where 
 27802                              <1> 	;		 input will be placed.
 27803                              <1> 	;	nchars - number of bytes or characters to be read.
 27804                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
 27805                              <1> 	; Outputs: *u.r0 - number of bytes read.	
 27806                              <1> 	; ...............................................................
 27807                              <1> 	;				
 27808                              <1> 	; Retro UNIX 8086 v1 modification: 
 27809                              <1> 	;       'sysread' system call has three arguments; so,
 27810                              <1> 	;	* 1st argument, file descriptor is in BX register
 27811                              <1> 	;	* 2nd argument, buffer address/offset in CX register
 27812                              <1> 	;	* 3rd argument, number of bytes is in DX register
 27813                              <1> 	;
 27814                              <1> 	;	AX register (will be restored via 'u.r0') will return
 27815                              <1> 	;	to the user with number of bytes read. 
 27816                              <1> 	;
 27817 00009915 E83D000000          <1> 	call	rw1
 27818 0000991A 0F82A4FCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
 27819                              <1> 		; jsr r0,rw1 / get i-number of file to be read into r1
 27820 00009920 F6C480              <1> 	test	ah, 80h
 27821                              <1> 		; tst r1 / negative i-number?
 27822 00009923 0F859BFCFFFF        <1> 	jnz	error
 27823                              <1> 		; ble error1 / yes, error 1 to read
 27824                              <1> 			   ; / it should be positive
 27825 00009929 E8F3110000          <1> 	call	readi
 27826                              <1> 		; jsr r0,readi / read data into core
 27827 0000992E EB18                <1> 	jmp	short rw0
 27828                              <1> 		; br 1f
 27829                              <1> syswrite: ; < write to file >
 27830                              <1> 	; 13/05/2015
 27831                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 27832                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
 27833                              <1> 	;
 27834                              <1> 	; 'syswrite' is given a buffer to write onto an output file
 27835                              <1> 	; and the number of characters to write. If finds the file
 27836                              <1> 	; from the file descriptor located in *u.r0 (r0). This file 
 27837                              <1> 	; descriptor is returned from a successful open or create call
 27838                              <1> 	; (sysopen or syscreat). The i-number of file is obtained via
 27839                              <1> 	; 'rw1' and buffer is written on the output file via 'write'.
 27840                              <1> 	;
 27841                              <1> 	; Calling sequence:
 27842                              <1> 	;	syswrite; buffer; nchars
 27843                              <1> 	; Arguments:
 27844                              <1> 	;	buffer - location of contiguous bytes to be writtten.
 27845                              <1> 	;	nchars - number of characters to be written.
 27846                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
 27847                              <1> 	; Outputs: *u.r0 - number of bytes written.	
 27848                              <1> 	; ...............................................................
 27849                              <1> 	;				
 27850                              <1> 	; Retro UNIX 8086 v1 modification: 
 27851                              <1> 	;       'syswrite' system call has three arguments; so,
 27852                              <1> 	;	* 1st argument, file descriptor is in BX register
 27853                              <1> 	;	* 2nd argument, buffer address/offset in CX register
 27854                              <1> 	;	* 3rd argument, number of bytes is in DX register
 27855                              <1> 	;
 27856                              <1> 	;	AX register (will be restored via 'u.r0') will return
 27857                              <1> 	;	to the user with number of bytes written. 
 27858                              <1> 	;
 27859 00009930 E822000000          <1> 	call	rw1
 27860 00009935 0F8289FCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
 27861                              <1> 		; jsr r0,rw1 / get i-number in r1 of file to write
 27862 0000993B F6C480              <1>         test	ah, 80h
 27863                              <1> 		; tst r1 / positive i-number ?
 27864 0000993E 744E                <1>         jz	short rw3 ; 13/05/2015
 27865                              <1> 	;jz	error
 27866                              <1> 		; bge error1 / yes, error 1 
 27867                              <1> 			   ; / negative i-number means write
 27868 00009940 66F7D8              <1>         neg	ax
 27869                              <1> 		; neg r1 / make it positive
 27870 00009943 E8D8110000          <1> 	call	writei
 27871                              <1>         	; jsr r0,writei / write data
 27872                              <1> rw0: ; 1:
 27873 00009948 A1[68CE0000]        <1>         mov	eax, [u.nread]
 27874 0000994D A3[40CE0000]        <1> 	mov	[u.r0], eax
 27875                              <1> 		; mov u.nread,*u.r0 / put no. of bytes transferred
 27876                              <1> 				  ; / into (u.r0)
 27877 00009952 E98DFCFFFF          <1> 	jmp	sysret
 27878                              <1>         	; br sysret1
 27879                              <1> rw1:	
 27880                              <1> 	; 14/05/2015
 27881                              <1> 	; 13/05/2015
 27882                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 27883                              <1> 	; 23/05/2013 - 24/05/2013 (Retro UNIX 8086 v1)
 27884                              <1> 	; System call registers: bx, cx, dx (through 'sysenter')
 27885                              <1> 	;
 27886                              <1> 	;mov	[u.base], ecx 	; buffer address/offset 
 27887                              <1> 				;(in the user's virtual memory space)
 27888                              <1> 	;mov	[u.count], edx 
 27889                              <1> 		; jsr r0,arg; u.base / get buffer pointer
 27890                              <1>         	; jsr r0,arg; u.count / get no. of characters
 27891                              <1> 	;;mov	eax, ebx ; file descriptor
 27892                              <1> 		; mov *u.r0,r1 / put file descriptor 
 27893                              <1> 		             ; / (index to u.fp table) in r1
 27894                              <1> 	; 13/05/2015
 27895 00009957 C705[40CE0000]0000- <1> 	mov	dword [u.r0], 0 ; r/w transfer count = 0 (reset)
 27896 0000995F 0000                <1>
 27897                              <1> 	;
 27898                              <1> 	;; call	getf
 27899                              <1>         ; eBX = File descriptor
 27900 00009961 E8E30A0000          <1> 	call	getf1 ; calling point in 'getf' from 'rw1'
 27901                              <1> 		; jsr r0,getf / get i-number of the file in r1
 27902                              <1> 	; AX = I-number of the file ; negative i-number means write
 27903                              <1> 	; 13/05/2015
 27904 00009966 6683F801            <1> 	cmp 	ax, 1
 27905 0000996A 7217                <1> 	jb	short rw2
 27906                              <1> 	;
 27907 0000996C 890D[60CE0000]      <1> 	mov	[u.base], ecx 	; buffer address/offset 
 27908                              <1> 				;(in the user's virtual memory space)
 27909 00009972 8915[64CE0000]      <1> 	mov	[u.count], edx 
 27910                              <1> 	; 14/05/2015
 27911 00009978 C705[95CE0000]0000- <1>         mov     dword [u.error], 0 ; reset the last error code
 27912 00009980 0000                <1>
 27913 00009982 C3                  <1> 	retn
 27914                              <1>         	; rts r0
 27915                              <1> rw2:
 27916                              <1> 	; 13/05/2015
 27917 00009983 C705[95CE0000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
 27918 0000998B 0000                <1>
 27919 0000998D C3                  <1> 	retn
 27920                              <1> rw3: 
 27921                              <1> 	; 13/05/2015
 27922 0000998E C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 27923 00009996 0000                <1>
 27924 00009998 F9                  <1> 	stc
 27925 00009999 C3                  <1> 	retn
 27926                              <1> 
 27927                              <1> sysopen: ;<open file>
 27928                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 27929                              <1> 	; 22/05/2013 - 27/05/2013 (Retro UNIX 8086 v1)
 27930                              <1> 	;
 27931                              <1> 	; 'sysopen' opens a file in following manner:
 27932                              <1> 	;    1) The second argument in a sysopen says whether to
 27933                              <1> 	;	open the file ro read (0) or write (>0).
 27934                              <1> 	;    2) I-node of the particular file is obtained via 'namei'.
 27935                              <1> 	;    3) The file is opened by 'iopen'.
 27936                              <1> 	;    4) Next housekeeping is performed on the fsp table
 27937                              <1> 	;	and the user's open file list - u.fp.
 27938                              <1> 	;	a) u.fp and fsp are scanned for the next available slot.
 27939                              <1> 	;	b) An entry for the file is created in the fsp table.
 27940                              <1> 	;	c) The number of this entry is put on u.fp list.
 27941                              <1> 	;	d) The file descriptor index to u.fp list is pointed
 27942                              <1> 	;	   to by u.r0.
 27943                              <1> 	;
 27944                              <1> 	; Calling sequence:
 27945                              <1> 	;	sysopen; name; mode
 27946                              <1> 	; Arguments:
 27947                              <1> 	;	name - file name or path name
 27948                              <1> 	;	mode - 0 to open for reading
 27949                              <1> 	;	       1 to open for writing
 27950                              <1> 	; Inputs: (arguments)
 27951                              <1> 	; Outputs: *u.r0 - index to u.fp list (the file descriptor)
 27952                              <1> 	;		  is put into r0's location on the stack.	
 27953                              <1> 	; ...............................................................
 27954                              <1> 	;				
 27955                              <1> 	; Retro UNIX 8086 v1 modification: 
 27956                              <1> 	;       'sysopen' system call has two arguments; so,
 27957                              <1> 	;	* 1st argument, name is pointed to by BX register
 27958                              <1> 	;	* 2nd argument, mode is in CX register
 27959                              <1> 	;
 27960                              <1> 	;	AX register (will be restored via 'u.r0') will return
 27961                              <1> 	;	to the user with the file descriptor/number 
 27962                              <1> 	;	(index to u.fp list).
 27963                              <1> 	;
 27964                              <1> 	;call	arg2
 27965                              <1> 	; * name - 'u.namep' points to address of file/path name
 27966                              <1> 	;          in the user's program segment ('u.segmnt')
 27967                              <1> 	;          with offset in BX register (as sysopen argument 1).
 27968                              <1> 	; * mode - sysopen argument 2 is in CX register 
 27969                              <1> 	;          which is on top of stack.
 27970                              <1> 	;
 27971                              <1> 	; jsr r0,arg2 / get sys args into u.namep and on stack
 27972                              <1> 	;
 27973                              <1>        	; system call registers: ebx, ecx (through 'sysenter')
 27974                              <1> 
 27975 0000999A 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 27976 000099A0 6651                <1> 	push	cx
 27977 000099A2 E8D90A0000          <1> 	call	namei
 27978                              <1> 		; jsr r0,namei / i-number of file in r1
 27979                              <1>      	;and	ax, ax
 27980                              <1> 	;jz	error ; File not found
 27981 000099A7 723B                <1> 	jc	short fnotfound ; 14/05/2015
 27982                              <1> 	;jc	error ; 27/05/2013
 27983                              <1> 		; br  error2 / file not found
 27984 000099A9 665A                <1>    	pop	dx ; mode
 27985 000099AB 6652                <1> 	push	dx
 27986                              <1> 	;or	dx, dx
 27987 000099AD 08D2                <1> 	or	dl, dl
 27988                              <1> 		; tst (sp) / is mode = 0 (2nd arg of call; 
 27989                              <1> 		         ; / 0 means, open for read)
 27990 000099AF 7403                <1> 	jz	short sysopen_0
 27991                              <1> 		; beq 1f / yes, leave i-number positive
 27992                              <1> syscreat_0: ; 27/12/2015
 27993 000099B1 66F7D8              <1> 	neg	ax
 27994                              <1>         	; neg r1 / open for writing so make i-number negative
 27995                              <1> sysopen_0: ;1:
 27996 000099B4 E86D110000          <1> 	call	iopen
 27997                              <1> 		;jsr r0,iopen / open file whose i-number is in r1
 27998 000099B9 665A                <1> 	pop	dx
 27999                              <1> 	;and	dx, dx
 28000 000099BB 20D2                <1> 	and	dl, dl
 28001                              <1>         	; tst (sp)+ / pop the stack and test the mode
 28002 000099BD 7403                <1> 	jz	short sysopen_2
 28003                              <1>         	; beq op1 / is open for read op1
 28004                              <1> sysopen_1: ;op0:
 28005 000099BF 66F7D8              <1> 	neg	ax
 28006                              <1>         	; neg r1 
 28007                              <1> 		     ;/ make i-number positive if open for writing [???]
 28008                              <1> 	;; NOTE: iopen always make i-number positive.
 28009                              <1> 	;; Here i-number becomes negative again. [22/05/2013]
 28010                              <1> sysopen_2: ;op1:
 28011 000099C2 31F6                <1>         xor     esi, esi
 28012                              <1>         	; clr r2 / clear registers
 28013 000099C4 31DB                <1>         xor     ebx, ebx
 28014                              <1> 		; clr r3
 28015                              <1> sysopen_3: ;1: / scan the list of entries in fsp table
 28016 000099C6 389E[46CE0000]      <1>         cmp     [esi+u.fp], bl ; 0
 28017                              <1> 		; tstb u.fp(r2) / test the entry in the u.fp list
 28018 000099CC 7625                <1>         jna      short sysopen_4
 28019                              <1> 		; beq 1f / if byte in list is 0 branch
 28020 000099CE 46                  <1>         inc     esi
 28021                              <1> 		; inc r2 / bump r2 so next byte can be checked
 28022 000099CF 6683FE0A            <1>         cmp     si, 10
 28023                              <1> 		; cmp r2,$10. / reached end of list?
 28024 000099D3 72F1                <1> 	jb	short sysopen_3
 28025                              <1> 		; blt 1b / no, go back
 28026                              <1> toomanyf:
 28027                              <1> 	; 14/05/2015
 28028 000099D5 C705[95CE0000]0D00- <1> 	mov	dword [u.error], ERR_TOO_MANY_FILES ; too many open files !
 28029 000099DD 0000                <1>
 28030 000099DF E9E0FBFFFF          <1> 	jmp	error
 28031                              <1>         	; br error2 / yes, error (no files open)
 28032                              <1> fnotfound: 
 28033                              <1> 	; 14/05/2015
 28034 000099E4 C705[95CE0000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; file not found !
 28035 000099EC 0000                <1>
 28036 000099EE E9D1FBFFFF          <1> 	jmp	error
 28037                              <1> 
 28038                              <1> sysopen_4: ; 1:
 28039 000099F3 6683BB[16CC0000]00  <1>         cmp     word [ebx+fsp], 0
 28040                              <1> 		; tst fsp(r3) / scan fsp entries
 28041 000099FB 7610                <1>         jna     short sysopen_5
 28042                              <1> 		; beq 1f / if 0 branch
 28043                              <1> 	; 14/05/2015 - Retro UNIX 386 v1 modification !
 28044 000099FD 6683C30A            <1>         add     bx, 10 ; fsp structure size = 10 bytes/entry
 28045                              <1> 		; add $8.,r3 / add 8 to r3 
 28046                              <1> 			; / to bump it to next entry mfsp table
 28047 00009A01 6681FBF401          <1>         cmp     bx, nfiles*10
 28048                              <1> 		; cmp r3,$[nfiles*8.] / done scanning
 28049 00009A06 72EB                <1> 	jb	short sysopen_4
 28050                              <1>        		; blt 1b / no, back
 28051 00009A08 E9B7FBFFFF          <1> 	jmp	error
 28052                              <1>         	; br error2 / yes, error
 28053                              <1> sysopen_5: ; 1: / r2 has index to u.fp list; r3, has index to fsp table
 28054 00009A0D 668983[16CC0000]    <1>         mov     [ebx+fsp], ax
 28055                              <1> 		; mov r1,fsp(r3) / put i-number of open file 
 28056                              <1> 			; / into next available entry in fsp table,
 28057 00009A14 668B3D[26CE0000]    <1> 	mov	di, [cdev] ; word ? byte ?
 28058 00009A1B 6689BB[18CC0000]    <1>         mov     [ebx+fsp+2], di ; device number
 28059                              <1> 		; mov cdev,fsp+2(r3) / put # of device in next word
 28060 00009A22 31FF                <1>         xor	edi, edi
 28061 00009A24 89BB[1ACC0000]      <1>         mov     [ebx+fsp+4], edi ; offset pointer (0)
 28062                              <1> 		; clr fsp+4(r3)
 28063 00009A2A 6689BB[1ECC0000]    <1>         mov     [ebx+fsp+8], di ; open count (0), deleted flag (0)
 28064                              <1>        		; clr fsp+6(r3) / clear the next two words
 28065 00009A31 89D8                <1>   	mov	eax, ebx
 28066 00009A33 B30A                <1> 	mov	bl, 10
 28067 00009A35 F6F3                <1> 	div	bl 
 28068                              <1> 		; asr r3
 28069                              <1> 		; asr r3 / divide by 8 
 28070                              <1> 		; asr r3 ; / to get number of the fsp entry-1
 28071 00009A37 FEC0                <1> 	inc	al
 28072                              <1>         	; inc r3 / add 1 to get fsp entry number
 28073 00009A39 8886[46CE0000]      <1>         mov     [esi+u.fp], al
 28074                              <1> 		; movb r3,u.fp(r2) / move entry number into 
 28075                              <1> 			; / next available slot in u.fp list
 28076 00009A3F 8935[40CE0000]      <1>         mov     [u.r0], esi
 28077                              <1> 		; mov r2,*u.r0 / move index to u.fp list 
 28078                              <1> 			     ; / into r0 loc on stack
 28079 00009A45 E99AFBFFFF          <1>         jmp	sysret
 28080                              <1> 		; br sysret2
 28081                              <1> 
 28082                              <1> 	;
 28083                              <1> 	; 'fsp' table (10 bytes/entry)
 28084                              <1> 	; bit 15				   bit 0
 28085                              <1> 	; ---|-------------------------------------------
 28086                              <1> 	; r/w|		i-number of open file
 28087                              <1> 	; ---|-------------------------------------------
 28088                              <1> 	;		   device number
 28089                              <1> 	; -----------------------------------------------
 28090                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
 28091                              <1> 	; -----------------------------------------------
 28092                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
 28093                              <1> 	; ----------------------|------------------------
 28094                              <1> 	;  flag that says file 	| number of processes
 28095                              <1> 	;   has been deleted	| that have file open 
 28096                              <1> 	; ----------------------|------------------------
 28097                              <1> 	;
 28098                              <1> 
 28099                              <1> syscreat: ; < create file >
 28100                              <1> 	; 27/12/2015 (Retro UNIX 386 v1.1)
 28101                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 28102                              <1> 	; 27/05/2013 (Retro UNIX 8086 v1)
 28103                              <1> 	;
 28104                              <1> 	; 'syscreat' called with two arguments; name and mode.
 28105                              <1> 	; u.namep points to name of the file and mode is put
 28106                              <1> 	; on the stack. 'namei' is called to get i-number of the file.		
 28107                              <1> 	; If the file aready exists, it's mode and owner remain 
 28108                              <1> 	; unchanged, but it is truncated to zero length. If the file
 28109                              <1> 	; did not exist, an i-node is created with the new mode via
 28110                              <1> 	; 'maknod' whether or not the file already existed, it is
 28111                              <1> 	; open for writing. The fsp table is then searched for a free
 28112                              <1> 	; entry. When a free entry is found, proper data is placed
 28113                              <1> 	; in it and the number of this entry is put in the u.fp list.
 28114                              <1> 	; The index to the u.fp (also know as the file descriptor)
 28115                              <1> 	; is put in the user's r0. 			
 28116                              <1> 	;
 28117                              <1> 	; Calling sequence:
 28118                              <1> 	;	syscreate; name; mode
 28119                              <1> 	; Arguments:
 28120                              <1> 	;	name - name of the file to be created
 28121                              <1> 	;	mode - mode of the file to be created
 28122                              <1> 	; Inputs: (arguments)
 28123                              <1> 	; Outputs: *u.r0 - index to u.fp list 
 28124                              <1> 	;		   (the file descriptor of new file)
 28125                              <1> 	; ...............................................................
 28126                              <1> 	;				
 28127                              <1> 	; Retro UNIX 8086 v1 modification: 
 28128                              <1> 	;       'syscreate' system call has two arguments; so,
 28129                              <1> 	;	* 1st argument, name is pointed to by BX register
 28130                              <1> 	;	* 2nd argument, mode is in CX register
 28131                              <1> 	;
 28132                              <1> 	;	AX register (will be restored via 'u.r0') will return
 28133                              <1> 	;	to the user with the file descriptor/number 
 28134                              <1> 	;	(index to u.fp list).
 28135                              <1> 	;
 28136                              <1> 	;call	arg2
 28137                              <1> 	; * name - 'u.namep' points to address of file/path name
 28138                              <1> 	;          in the user's program segment ('u.segmnt')
 28139                              <1> 	;          with offset in BX register (as sysopen argument 1).
 28140                              <1> 	; * mode - sysopen argument 2 is in CX register 
 28141                              <1> 	;          which is on top of stack.
 28142                              <1> 	;
 28143                              <1>         	; jsr r0,arg2 / put file name in u.namep put mode 
 28144                              <1> 			    ; / on stack
 28145 00009A4A 891D[58CE0000]      <1> 	mov	[u.namep], ebx ; file name address
 28146 00009A50 6651                <1> 	push	cx ; mode
 28147 00009A52 E8290A0000          <1> 	call 	namei        	
 28148                              <1> 		; jsr r0,namei / get the i-number
 28149                              <1>         ;and	ax, ax
 28150                              <1> 	;jz	short syscreat_1	       	
 28151 00009A57 721E                <1> 	jc	short syscreat_1
 28152                              <1> 		; br  2f / if file doesn't exist 2f
 28153                              <1> 	; 27/12/2015
 28154 00009A59 6683F829            <1> 	cmp	ax, 41 ; device inode ?
 28155 00009A5D 0F824EFFFFFF        <1>         jb      syscreat_0 ; yes
 28156                              <1> 	;
 28157 00009A63 66F7D8              <1> 	neg 	ax
 28158                              <1>         	; neg r1 / if file already exists make i-number 
 28159                              <1> 		       ; / negative (open for writing)
 28160 00009A66 E8BB100000          <1> 	call	iopen
 28161                              <1>         	; jsr r0,iopen /
 28162 00009A6B E8B8100000          <1> 	call	itrunc
 28163                              <1>         	; jsr r0,itrunc / truncate to 0 length
 28164 00009A70 6659                <1> 	pop	cx ; pop mode (did not exist in original Unix v1 !?)
 28165 00009A72 E948FFFFFF          <1>         jmp     sysopen_1
 28166                              <1>         	; br op0
 28167                              <1> syscreat_1: ; 2: / file doesn't exist
 28168 00009A77 6658                <1> 	pop	ax
 28169                              <1>         	; mov (sp)+,r1 / put the mode in r1
 28170 00009A79 30E4                <1> 	xor	ah, ah	
 28171                              <1>         	; bic $!377,r1 / clear upper byte
 28172 00009A7B E8D30C0000          <1> 	call 	maknod
 28173                              <1>         	; jsr r0,maknod / make an i-node for this file
 28174 00009A80 66A1[72CE0000]      <1> 	mov	ax, [u.dirbuf]
 28175                              <1>         	; mov u.dirbuf,r1 / put i-number 
 28176                              <1> 			        ; / for this new file in r1
 28177 00009A86 E934FFFFFF          <1>         jmp     sysopen_1
 28178                              <1>         	; br op0 / open the file
 28179                              <1> 
 28180                              <1> sysmkdir: ; < make directory >
 28181                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 28182                              <1> 	; 27/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 28183                              <1> 	;
 28184                              <1> 	; 'sysmkdir' creates an empty directory whose name is
 28185                              <1> 	; pointed to by arg 1. The mode of the directory is arg 2.	
 28186                              <1> 	; The special entries '.' and '..' are not present.
 28187                              <1> 	; Errors are indicated if the directory already exists or		
 28188                              <1> 	; user is not the super user. 
 28189                              <1> 	;
 28190                              <1> 	; Calling sequence:
 28191                              <1> 	;	sysmkdir; name; mode
 28192                              <1> 	; Arguments:
 28193                              <1> 	;	name - points to the name of the directory
 28194                              <1> 	;	mode - mode of the directory
 28195                              <1> 	; Inputs: (arguments)
 28196                              <1> 	; Outputs: -
 28197                              <1> 	;    (sets 'directory' flag to 1; 
 28198                              <1> 	;    'set user id on execution' and 'executable' flags to 0)
 28199                              <1> 	; ...............................................................
 28200                              <1> 	;				
 28201                              <1> 	; Retro UNIX 8086 v1 modification: 
 28202                              <1> 	;       'sysmkdir' system call has two arguments; so,
 28203                              <1> 	;	* 1st argument, name is pointed to by BX register
 28204                              <1> 	;	* 2nd argument, mode is in CX register
 28205                              <1> 	;
 28206                              <1> 		
 28207                              <1> ; / make a directory
 28208                              <1> 
 28209                              <1> 	;call	arg2
 28210                              <1> 	; * name - 'u.namep' points to address of file/path name
 28211                              <1> 	;          in the user's program segment ('u.segmnt')
 28212                              <1> 	;          with offset in BX register (as sysopen argument 1).
 28213                              <1> 	; * mode - sysopen argument 2 is in CX register 
 28214                              <1> 	;          which is on top of stack.
 28215                              <1> 
 28216                              <1> 		; jsr r0,arg2 / put file name in u.namep put mode 
 28217                              <1> 			    ; / on stack
 28218 00009A8B 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 28219 00009A91 6651                <1> 	push	cx ; mode
 28220 00009A93 E8E8090000          <1> 	call	namei
 28221                              <1>         	; jsr r0,namei / get the i-number
 28222                              <1>         	;     br .+4 / if file not found branch around error
 28223                              <1>         ;xor 	ax, ax
 28224                              <1> 	;jnz	error
 28225 00009A98 731C                <1> 	jnc	short dir_exists ; 14/05/2015
 28226                              <1> 	;jnc	error	
 28227                              <1> 		; br  error2 / directory already exists (error)
 28228 00009A9A 803D[8CCE0000]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
 28229                              <1>         	;tstb u.uid / is user the super user
 28230 00009AA1 7622                <1> 	jna	short dir_access_err ; 14/05/2015
 28231                              <1> 	;jna	error
 28232                              <1>         	;bne error2 / no, not allowed
 28233 00009AA3 6658                <1> 	pop	ax
 28234                              <1>         	;mov (sp)+,r1 / put the mode in r1
 28235 00009AA5 6683E0CF            <1> 	and	ax, 0FFCFh ; 1111111111001111b
 28236                              <1>         	;bic $!317,r1 / all but su and ex
 28237                              <1> 	;or	ax , 4000h ; 1011111111111111b
 28238 00009AA9 80CC40              <1> 	or	ah, 40h ; Set bit 14 to 1
 28239                              <1>         	;bis $40000,r1 / directory flag
 28240 00009AAC E8A20C0000          <1> 	call	maknod
 28241                              <1>         	;jsr r0,maknod / make the i-node for the directory
 28242 00009AB1 E92EFBFFFF          <1> 	jmp	sysret
 28243                              <1>         	;br sysret2 /
 28244                              <1> dir_exists:
 28245                              <1> 	; 14/05/2015
 28246 00009AB6 C705[95CE0000]0E00- <1> 	mov	dword [u.error], ERR_DIR_EXISTS ; dir. already exists !
 28247 00009ABE 0000                <1>
 28248 00009AC0 E9FFFAFFFF          <1> 	jmp	error
 28249                              <1> dir_access_err:
 28250                              <1> 	; 14/05/2015
 28251 00009AC5 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_DIR_ACCESS ; permission denied !
 28252 00009ACD 0000                <1>
 28253 00009ACF E9F0FAFFFF          <1> 	jmp	error
 28254                              <1> 
 28255                              <1> sysclose: ;<close file>
 28256                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 28257                              <1> 	; 22/05/2013 - 26/05/2013 (Retro UNIX 8086 v1)
 28258                              <1> 	;
 28259                              <1> 	; 'sysclose', given a file descriptor in 'u.r0', closes the
 28260                              <1> 	; associated file. The file descriptor (index to 'u.fp' list)
 28261                              <1> 	; is put in r1 and 'fclose' is called.
 28262                              <1> 	;
 28263                              <1> 	; Calling sequence:
 28264                              <1> 	;	sysclose
 28265                              <1> 	; Arguments:
 28266                              <1> 	;	-  
 28267                              <1> 	; Inputs: *u.r0 - file descriptor
 28268                              <1> 	; Outputs: -
 28269                              <1> 	; ...............................................................
 28270                              <1> 	;				
 28271                              <1> 	; Retro UNIX 8086 v1 modification:
 28272                              <1> 	;	 The user/application program puts file descriptor
 28273                              <1> 	;        in BX register as 'sysclose' system call argument.
 28274                              <1> 	; 	 (argument transfer method 1)
 28275                              <1> 
 28276                              <1> 	; / close the file
 28277                              <1> 	
 28278 00009AD4 89D8                <1> 	mov 	eax, ebx
 28279 00009AD6 E823090000          <1> 	call 	fclose
 28280                              <1> 		; mov *u.r0,r1 / move index to u.fp list into r1
 28281                              <1> 		; jsr r0,fclose / close the file
 28282                              <1>                	; br error2 / unknown file descriptor
 28283                              <1> 		; br sysret2
 28284                              <1> 	; 14/05/2015
 28285 00009ADB 0F8303FBFFFF        <1> 	jnc	sysret
 28286 00009AE1 C705[95CE0000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
 28287 00009AE9 0000                <1>
 28288 00009AEB E9D4FAFFFF          <1> 	jmp	error
 28289                              <1> 
 28290                              <1> sysemt:
 28291                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 28292                              <1> 	; 10/12/2013 - 20/04/2014 (Retro UNIX 8086 v1)
 28293                              <1> 	;
 28294                              <1> 	; Retro UNIX 8086 v1 modification: 
 28295                              <1> 	;	'Enable Multi Tasking'  system call instead 
 28296                              <1> 	;	of 'Emulator Trap' in original UNIX v1 for PDP-11.
 28297                              <1> 	;
 28298                              <1> 	; Retro UNIX 8086 v1 feature only!
 28299                              <1> 	;	Using purpose: Kernel will start without time-out
 28300                              <1> 	;	(internal clock/timer) functionality.
 28301                              <1> 	;	Then etc/init will enable clock/timer for
 28302                              <1> 	;	multi tasking. (Then it will not be disabled again
 28303                              <1> 	;	except hardware reset/restart.)
 28304                              <1> 	;
 28305                              <1> 
 28306 00009AF0 803D[8CCE0000]00    <1> 	cmp	byte [u.uid], 0 ; root ?
 28307                              <1> 	;ja	error
 28308 00009AF7 0F8770FBFFFF        <1> 	ja	badsys ; 14/05/2015
 28309                              <1> emt_0:
 28310 00009AFD FA                  <1> 	cli
 28311 00009AFE 21DB                <1> 	and	ebx, ebx
 28312 00009B00 7410                <1> 	jz	short emt_2
 28313                              <1> 	; Enable multi tasking -time sharing-
 28314 00009B02 B8[29AB0000]        <1> 	mov	eax, clock
 28315                              <1> emt_1:
 28316 00009B07 A3[C2070000]        <1> 	mov	[x_timer], eax
 28317 00009B0C FB                  <1> 	sti
 28318 00009B0D E9D2FAFFFF          <1> 	jmp	sysret
 28319                              <1> emt_2:
 28320                              <1> 	; Disable multi tasking -time sharing-
 28321 00009B12 B8[CA070000]        <1> 	mov	eax, u_timer
 28322 00009B17 EBEE                <1> 	jmp	short emt_1
 28323                              <1> 
 28324                              <1> 	; Original UNIX v1 'sysemt' routine
 28325                              <1> ;sysemt:
 28326                              <1>         ;
 28327                              <1> 	;jsr    r0,arg; 30 / put the argument of the sysemt call 
 28328                              <1> 			 ; / in loc 30
 28329                              <1>         ;cmp    30,$core / was the argument a lower address 
 28330                              <1> 			; / than core
 28331                              <1>         ;blo    1f / yes, rtssym
 28332                              <1>         ;cmp    30,$ecore / no, was it higher than "core" 
 28333                              <1> 			; / and less than "ecore"
 28334                              <1>         ;blo    2f / yes, sysret2
 28335                              <1> ;1:
 28336                              <1>         ;mov    $rtssym,30
 28337                              <1> ;2:
 28338                              <1>         ;br     sysret2
 28339                              <1> 
 28340                              <1> sysilgins:
 28341                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 28342                              <1> 	; 03/06/2013
 28343                              <1> 	; Retro UNIX 8086 v1 modification: 
 28344                              <1> 	;	not a valid system call ! (not in use)
 28345                              <1> 	;
 28346 00009B19 E94FFBFFFF          <1> 	jmp	badsys
 28347                              <1> 	;jmp	error
 28348                              <1> 	;;jmp 	sysret
 28349                              <1> 
 28350                              <1> 	; Original UNIX v1 'sysemt' routine
 28351                              <1> ;sysilgins: / calculate proper illegal instruction trap address
 28352                              <1>         ;jsr    r0,arg; 10 / take address from sysilgins call
 28353                              <1> 			  ;/ put it in loc 8.,
 28354                              <1>         ;cmp    10,$core / making it the illegal instruction 
 28355                              <1> 		       ; / trap address
 28356                              <1>         ;blo    1f / is the address a user core address?  
 28357                              <1> 		; / yes, go to 2f
 28358                              <1>         ;cmp    10,$ecore
 28359                              <1>         ;blo    2f
 28360                              <1> ;1:
 28361                              <1>         ;mov    $fpsym,10 / no, make 'fpsum' the illegal 
 28362                              <1> 		    ; / instruction trap address for the system
 28363                              <1> ;2:
 28364                              <1>         ;br     sysret2 / return to the caller via 'sysret'
 28365                              <1> 
 28366                              <1> sysmdate: ; < change the modification time of a file >
 28367                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 28368                              <1> 	; 03/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 28369                              <1> 	;
 28370                              <1> 	; 'sysmdate' is given a file name. It gets inode of this 
 28371                              <1> 	; file into core. The user is checked if he is the owner 
 28372                              <1> 	; or super user. If he is neither an error occurs.
 28373                              <1> 	; 'setimod' is then called to set the i-node modification
 28374                              <1> 	; byte and the modification time, but the modification time
 28375                              <1> 	; is overwritten by whatever get put on the stack during
 28376                              <1> 	; a 'systime' system call. This calls are restricted to
 28377                              <1> 	; the super user.		
 28378                              <1> 	;
 28379                              <1> 	; Calling sequence:
 28380                              <1> 	;	sysmdate; name
 28381                              <1> 	; Arguments:
 28382                              <1> 	;	name - points to the name of file
 28383                              <1> 	; Inputs: (arguments)
 28384                              <1> 	; Outputs: -
 28385                              <1> 	; ...............................................................
 28386                              <1> 	;				
 28387                              <1> 	; Retro UNIX 8086 v1 modification: 
 28388                              <1> 	;	 The user/application program puts address 
 28389                              <1> 	;	 of the file name in BX register 
 28390                              <1> 	;	 as 'sysmdate' system call argument.
 28391                              <1> 	;
 28392                              <1> ; / change the modification time of a file
 28393                              <1> 		; jsr r0,arg; u.namep / point u.namep to the file name
 28394 00009B1E 891D[58CE0000]      <1>         mov	[u.namep], ebx
 28395 00009B24 E857090000          <1> 	call	namei
 28396                              <1> 		; jsr r0,namei / get its i-number
 28397 00009B29 0F82B5FEFFFF        <1>         jc	fnotfound ; file not found !
 28398                              <1> 	;jc	error       
 28399                              <1> 		; br error2 / no, such file
 28400 00009B2F E8E80F0000          <1> 	call	iget
 28401                              <1> 		; jsr r0,iget / get i-node into core
 28402 00009B34 A0[8CCE0000]        <1> 	mov	al, [u.uid]
 28403 00009B39 3A05[19CB0000]      <1> 	cmp	al, [i.uid]
 28404                              <1>         	; cmpb u.uid,i.uid / is user same as owner
 28405 00009B3F 7413                <1> 	je	short mdate_1
 28406                              <1>         	; beq 1f / yes
 28407 00009B41 20C0                <1> 	and	al, al
 28408                              <1> 		; tstb u.uid / no, is user the super user
 28409                              <1> 	;jnz	error
 28410                              <1> 		; bne error2 / no, error
 28411 00009B43 740F                <1> 	jz	short mdate_1
 28412 00009B45 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 28413 00009B4D 0000                <1>
 28414 00009B4F E970FAFFFF          <1> 	jmp	error
 28415                              <1> mdate_1: ;1:
 28416 00009B54 E8D10F0000          <1> 	call	setimod
 28417                              <1>         	; jsr r0,setimod / fill in modification data,
 28418                              <1> 		               ; / time etc.
 28419 00009B59 BE[32BE0000]        <1> 	mov	esi, p_time
 28420 00009B5E BF[30CB0000]        <1> 	mov	edi, i.mtim
 28421 00009B63 A5                  <1> 	movsd
 28422                              <1> 		; mov 4(sp),i.mtim / move present time to
 28423                              <1>         	; mov 2(sp),i.mtim+2 / modification time
 28424 00009B64 E97BFAFFFF          <1>         jmp	sysret
 28425                              <1> 		; br sysret2
 28426                              <1> 
 28427                              <1> sysstty: ; < set tty status and mode >
 28428                              <1> 	; 17/11/2015
 28429                              <1> 	; 12/11/2015
 28430                              <1> 	; 29/10/2015
 28431                              <1> 	; 17/10/2015
 28432                              <1> 	; 13/10/2015
 28433                              <1> 	; 29/06/2015
 28434                              <1> 	; 27/06/2015 (Retro UNIX 386 v1 - Beginning)
 28435                              <1> 	; 02/06/2013 - 12/07/2014 (Retro UNIX 8086 v1)
 28436                              <1> 	;
 28437                              <1> 	; 'sysstty' sets the status and mode of the typewriter 
 28438                              <1> 	; whose file descriptor is in (u.r0).
 28439                              <1> 	;
 28440                              <1> 	; Calling sequence:
 28441                              <1> 	;	sysstty; arg
 28442                              <1> 	; Arguments:
 28443                              <1> 	;	arg - address of 3 consequitive words that contain
 28444                              <1> 	;	      the source of status data	
 28445                              <1> 	; Inputs: ((*u.r0 - file descriptor & argument))
 28446                              <1> 	; Outputs: ((status in address which is pointed to by arg))
 28447                              <1> 	; ...............................................................
 28448                              <1> 	;	
 28449                              <1> 	; Retro UNIX 8086 v1 modification: 
 28450                              <1> 	;	'sysstty' system call will set the tty
 28451                              <1> 	;	(clear keyboard buffer and set cursor position)
 28452                              <1> 	;	 in following manner:
 28453                              <1> 	;   NOTE: All of tty setting functions are here (16/01/2014)
 28454                              <1> 	;
 28455                              <1> 	; Inputs:
 28456                              <1> 	;	BX = 0 --> means
 28457                              <1> 	;	   If CL = FFh
 28458                              <1> 	;	      set cursor position for console tty, only 
 28459                              <1> 	;	      CH will be ignored (char. will not be written)	
 28460                              <1> 	;	   If CH = 0 (CL < FFh)
 28461                              <1> 	;	      set console tty for (current) process
 28462                              <1> 	;	      CL = tty number (0 to 9)
 28463                              <1> 	;	      (If CH = 0, character will not be written)			
 28464                              <1> 	;          If CH > 0 (CL < FFh)	
 28465                              <1> 	;             CL = tty number (0 to 9)
 28466                              <1> 	;	      CH = character will be written
 28467                              <1> 	;	        at requested cursor position (in DX)	
 28468                              <1> 	;	   DX = cursor position for tty number 0 to 7.	
 28469                              <1>   	;		(only tty number 0 to 7) 
 28470                              <1> 	;          DL = communication parameters (for serial ports) 
 28471                              <1> 	;	        (only for COM1 and COM2 serial ports)
 28472                              <1> 	;	   DH < 0FFh -> DL is valid, initialize serial port
 28473                              <1> 	;			or set cursor position	
 28474                              <1> 	;	   DH = 0FFh -> DL is not valid
 28475                              <1> 	;		do not set serial port parameters 
 28476                              <1> 	;		or do not set cursor position
 28477                              <1> 	;
 28478                              <1> 	;	BX > 0 --> points to name of tty
 28479                              <1> 	;    	   CH > 0 -->
 28480                              <1> 	;		CH = character will be written in current 
 28481                              <1> 	;            	cursor position (for tty number from 0 to 7)
 28482                              <1> 	;	     	or character will be sent to serial port
 28483                              <1> 	;	     	(for tty number 8 or 9)
 28484                              <1> 	;		CL = color of the character if tty number < 8.
 28485                              <1> 	;    	   CH = 0 --> Do not write a character, 
 28486                              <1> 	;		set mode (tty 8 to 9) or 
 28487                              <1> 	;		set current cursor positions (tty 0 to 7) only. 
 28488                              <1> 	;   	   DX = cursor position for tty number 0 to 7.
 28489                              <1> 	;    	   DH = FFh --> Do not set cursor pos (or comm. params.)
 28490                              <1> 	;		(DL is not valid)
 28491                              <1> 	;	   DL = communication parameters 
 28492                              <1> 	;		for tty number 8 or 9 (COM1 or COM2).
 28493                              <1> 	; Outputs:
 28494                              <1> 	;	cf = 0 -> OK
 28495                              <1> 	;	     AL = tty number (0 to 9)
 28496                              <1> 	;	     AH = line status if tty number is 8 or 9
 28497                              <1> 	;	     AH = process number (of the caller) 	
 28498                              <1> 	;	cf = 1 means error (requested tty is not ready)
 28499                              <1> 	;	     AH = FFh if the tty is locked 
 28500                              <1> 	;		  (owned by another process)
 28501                              <1> 	;	        = process number (of the caller) 
 28502                              <1> 	;		  (if < FFh and tty number < 8)
 28503                              <1> 	;	     AL = tty number (0FFh if it does not exist)
 28504                              <1> 	;	     AH = line status if tty number is 8 or 9
 28505                              <1> 	;	NOTE: Video page will be cleared if cf = 0.
 28506                              <1> 	;
 28507                              <1> 	; 27/06/2015 (32 bit modifications)
 28508                              <1> 	; 14/01/2014
 28509 00009B69 31C0                <1> 	xor 	eax, eax
 28510 00009B6B 6648                <1> 	dec	ax ; 17/10/2015
 28511 00009B6D A3[40CE0000]        <1> 	mov	[u.r0], eax ; 0FFFFh
 28512 00009B72 21DB                <1> 	and	ebx, ebx
 28513 00009B74 0F85CB000000        <1>         jnz     sysstty_6
 28514                              <1> ; set console tty
 28515                              <1> 	; 29/10/2015
 28516                              <1> 	; 17/01/2014 
 28517 00009B7A 80F909              <1> 	cmp	cl, 9
 28518 00009B7D 7613                <1> 	jna	short sysstty_0
 28519                              <1> 	; 17/11/2015
 28520 00009B7F 80F9FF              <1> 	cmp	cl, 0FFh
 28521 00009B82 7202                <1> 	jb	short sysstty_13
 28522 00009B84 88CD                <1> 	mov	ch, cl ; force CH value to FFh 
 28523                              <1> sysstty_13:
 28524 00009B86 8A1D[8FCE0000]      <1> 	mov	bl, [u.uno] ; process number
 28525 00009B8C 8A8B[95CB0000]      <1> 	mov	cl, [ebx+p.ttyc-1] ; current/console tty
 28526                              <1> sysstty_0:
 28527                              <1> 	; 29/06/2015
 28528 00009B92 6652                <1> 	push	dx
 28529 00009B94 6651                <1> 	push	cx
 28530 00009B96 30D2                <1> 	xor 	dl, dl	; sysstty call sign
 28531 00009B98 88C8                <1> 	mov	al, cl
 28532 00009B9A A2[40CE0000]        <1> 	mov	[u.r0], al ; tyy number (0 to 9)
 28533 00009B9F E8870F0000          <1> 	call	ottyp
 28534 00009BA4 6659                <1> 	pop	cx
 28535 00009BA6 665A                <1> 	pop	dx
 28536                              <1> 	;
 28537 00009BA8 7257                <1> 	jc	short sysstty_pd_err
 28538                              <1> 	;
 28539 00009BAA 80F908              <1> 	cmp	cl, 8
 28540 00009BAD 7222                <1> 	jb	short sysstty_2
 28541                              <1> 	;
 28542 00009BAF 80FEFF              <1> 	cmp	dh, 0FFh
 28543 00009BB2 741D                <1> 	je	short sysstty_2
 28544                              <1> 		; set communication parameters for serial ports
 28545                              <1> 	; 29/10/2015
 28546 00009BB4 88D4                <1> 	mov	ah, dl ; communication parameters
 28547                              <1> 		; ah = 0E3h = 11100011b = 115200 baud,
 28548                              <1> 		;			 THRE int + RDA int 
 28549                              <1> 		; ah = 23h = 00100011b = 9600 baud,
 28550                              <1> 		;			 THRE int + RDA int 
 28551 00009BB6 28C0                <1> 	sub	al, al ; 0
 28552                              <1> 	; 12/07/2014
 28553 00009BB8 80F909              <1> 	cmp	cl, 9
 28554 00009BBB 7202                <1> 	jb	short sysstty_1
 28555 00009BBD FEC0                <1> 	inc	al
 28556                              <1> sysstty_1:
 28557 00009BBF 6651                <1> 	push	cx
 28558                              <1> 	; 29/06/2015	
 28559 00009BC1 E821120000          <1> 	call 	sp_setp ; Set serial port communication parameters
 28560 00009BC6 66890D[41CE0000]    <1> 	mov	[u.r0+1], cx ; Line status (ah)
 28561                              <1> 			     ; Modem status (EAX bits 16 to 23)
 28562 00009BCD 6659                <1> 	pop	cx
 28563 00009BCF 7265                <1>         jc      short sysstty_tmout_err ; 29/10/2015
 28564                              <1> sysstty_2:
 28565                              <1> 	; 17/01/2014
 28566 00009BD1 20ED                <1> 	and	ch, ch 	; set cursor position 
 28567                              <1> 			; or comm. parameters ONLY
 28568 00009BD3 750D                <1> 	jnz	short sysstty_3
 28569 00009BD5 0FB61D[8FCE0000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 28570 00009BDC 888B[95CB0000]      <1> 	mov	[ebx+p.ttyc-1], cl ; console tty
 28571                              <1> sysstty_3:
 28572                              <1> 	; 16/01/2014
 28573 00009BE2 88E8                <1> 	mov	al, ch ; character  ; 0 to FFh
 28574                              <1> 	; 17/11/2015
 28575 00009BE4 B507                <1> 	mov 	ch, 7  ; Default color (light gray)
 28576 00009BE6 38E9                <1> 	cmp	cl, ch ; 7 (tty number)
 28577 00009BE8 0F86C5000000        <1>         jna     sysstty_9
 28578                              <1> sysstty_12:
 28579                              <1> 	;; BX = 0, CL = 8 or CL = 9
 28580                              <1> 	; (Set specified serial port as console tty port)
 28581                              <1> 	; CH = character to be written
 28582                              <1> 	; 15/04/2014
 28583                              <1> 	; CH = 0 --> initialization only
 28584                              <1> 	; AL = character
 28585                              <1> 	; 26/06/2014
 28586 00009BEE 880D[94CE0000]      <1> 	mov	[u.ttyn], cl
 28587                              <1> 	; 12/07/2014
 28588 00009BF4 88CC                <1> 	mov	ah, cl ; tty number (8 or 9)
 28589 00009BF6 20C0                <1> 	and	al, al
 28590 00009BF8 7416                <1> 	jz	short sysstty_4 ; al = ch = 0
 28591                              <1>  	; 04/07/2014
 28592 00009BFA E82E0F0000          <1> 	call 	sndc
 28593                              <1> 	; 12/07/2014
 28594 00009BFF EB1B                <1> 	jmp	short sysstty_5
 28595                              <1> sysstty_pd_err: ; 29/06/2015
 28596                              <1> 	; 'permission denied !' error
 28597 00009C01 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_NOT_OWNER
 28598 00009C09 0000                <1>
 28599 00009C0B E9B4F9FFFF          <1> 	jmp	error
 28600                              <1> sysstty_4:
 28601                              <1> 	; 12/07/2014
 28602                              <1> 	;xchg 	ah, al	; al = 0 -> al = ah, ah = 0
 28603 00009C10 88E0                <1> 	mov	al, ah ; 29/06/2015
 28604 00009C12 2C08                <1> 	sub	al, 8
 28605                              <1> 	; 27/06/2015
 28606 00009C14 E8C6110000          <1> 	call	sp_status ; get serial port status
 28607                              <1> 	; AL = Line status, AH = Modem status
 28608                              <1> 	; 12/11/2015
 28609 00009C19 3C80                <1> 	cmp	al, 80h
 28610 00009C1B F5                  <1> 	cmc
 28611                              <1> sysstty_5:
 28612 00009C1C 66A3[41CE0000]      <1> 	mov	[u.r0+1], ax ; ah = line status
 28613                              <1> 		     ; EAX bits 16-23 = modem status	
 28614 00009C22 9C                  <1> 	pushf
 28615 00009C23 30D2                <1> 	xor	dl, dl ; sysstty call sign
 28616 00009C25 A0[94CE0000]        <1> 	mov	al, [u.ttyn] ; 26/06/2014
 28617 00009C2A E8FD0E0000          <1> 	call	cttyp
 28618 00009C2F 9D                  <1> 	popf
 28619 00009C30 0F83AEF9FFFF        <1> 	jnc	sysret	; time out error 
 28620                              <1> 
 28621                              <1> sysstty_tmout_err:
 28622 00009C36 C705[95CE0000]1900- <1> 	mov	dword [u.error], ERR_TIME_OUT
 28623 00009C3E 0000                <1>
 28624 00009C40 E97FF9FFFF          <1> 	jmp	error
 28625                              <1> sysstty_6:
 28626 00009C45 6652                <1> 	push	dx
 28627 00009C47 6651                <1> 	push	cx
 28628 00009C49 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 28629 00009C4F E82C080000          <1> 	call	namei
 28630 00009C54 6659                <1> 	pop	cx
 28631 00009C56 665A                <1> 	pop	dx
 28632 00009C58 720E                <1> 	jc	short sysstty_inv_dn
 28633                              <1> 	;
 28634 00009C5A 6683F813            <1> 	cmp	ax, 19  ; inode number of /dev/COM2
 28635 00009C5E 7708                <1> 	ja	short sysstty_inv_dn ; 27/06/2015
 28636                              <1> 	;
 28637 00009C60 3C0A                <1> 	cmp	al, 10 ; /dev/tty0 .. /dev/tty7
 28638                              <1> 		       ; /dev/COM1, /dev/COM2
 28639 00009C62 7213                <1> 	jb	short sysstty_7
 28640 00009C64 2C0A                <1> 	sub	al, 10
 28641 00009C66 EB20                <1> 	jmp	short sysstty_8
 28642                              <1> sysstty_inv_dn: 
 28643                              <1> 	; 27/06/2015
 28644                              <1> 	; Invalid device name (not a tty) ! error
 28645                              <1> 	; (Device is not a tty or device name not found)
 28646 00009C68 C705[95CE0000]1800- <1> 	mov	dword [u.error], ERR_INV_DEV_NAME
 28647 00009C70 0000                <1>
 28648 00009C72 E94DF9FFFF          <1> 	jmp	error 
 28649                              <1> sysstty_7:
 28650 00009C77 3C01                <1> 	cmp	al, 1 ; /dev/tty
 28651 00009C79 75ED                <1> 	jne	short sysstty_inv_dn ; 27/06/2015
 28652 00009C7B 0FB61D[8FCE0000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 28653 00009C82 8A83[95CB0000]      <1> 	mov	al, [ebx+p.ttyc-1] ; console tty
 28654                              <1> sysstty_8:	
 28655 00009C88 A2[40CE0000]        <1> 	mov	[u.r0], al
 28656 00009C8D 6652                <1> 	push	dx
 28657 00009C8F 6650                <1> 	push	ax
 28658 00009C91 6651                <1> 	push	cx	
 28659 00009C93 E8930E0000          <1> 	call	ottyp
 28660 00009C98 6659                <1> 	pop	cx
 28661 00009C9A 6658                <1> 	pop	ax
 28662 00009C9C 665A                <1> 	pop	dx
 28663 00009C9E 0F825DFFFFFF        <1>         jc      sysstty_pd_err ; 'permission denied !'
 28664                              <1> 	; 29/10/2015
 28665 00009CA4 86E9                <1> 	xchg 	ch, cl
 28666                              <1> 		; cl = character, ch = color code
 28667 00009CA6 86C1                <1> 	xchg	al, cl
 28668                              <1> 		; al = character, cl = tty number
 28669 00009CA8 80F907              <1> 	cmp	cl, 7
 28670 00009CAB 0F873DFFFFFF        <1>         ja      sysstty_12
 28671                              <1> 	;
 28672                              <1> 	; 16/01/2014
 28673 00009CB1 30FF                <1> 	xor	bh, bh
 28674                              <1> 	;
 28675                              <1> sysstty_9: 	; tty 0 to tty 7
 28676                              <1> 	; al = character
 28677 00009CB3 80FEFF              <1> 	cmp	dh, 0FFh ; Do not set cursor position
 28678 00009CB6 740F                <1> 	je	short sysstty_10
 28679 00009CB8 6651                <1> 	push	cx
 28680 00009CBA 6650                <1> 	push	ax	
 28681                              <1> 	; movzx, ebx, cl
 28682 00009CBC 88CB                <1> 	mov	bl, cl ; (tty number = video page number)
 28683 00009CBE E8887BFFFF          <1> 	call	_set_cpos
 28684 00009CC3 6658                <1> 	pop	ax
 28685 00009CC5 6659                <1> 	pop	cx
 28686                              <1> sysstty_10: 
 28687                              <1> 	; 29/10/2015
 28688 00009CC7 08C0                <1> 	or	al, al ; character
 28689 00009CC9 740F                <1> 	jz      short sysstty_11 ; al = 0
 28690                              <1> 	; 17/11/2015
 28691 00009CCB 3CFF                <1> 	cmp	al, 0FFh
 28692 00009CCD 730B                <1> 	jnb	short sysstty_11
 28693                              <1> 		; ch > 0 and ch < FFh
 28694                              <1> 	; write a character at current cursor position
 28695 00009CCF 88EC                <1> 	mov	ah, ch ; color/attribute
 28696                              <1> 	; 12/07/2014
 28697 00009CD1 6651                <1> 	push	cx
 28698 00009CD3 E8AE7AFFFF          <1> 	call	_write_c_current
 28699 00009CD8 6659                <1> 	pop	cx
 28700                              <1> sysstty_11:
 28701                              <1> 	; 14/01/2014
 28702 00009CDA 30D2                <1> 	xor	dl, dl ; sysstty call sign
 28703                              <1> 	; 18/01/2014
 28704                              <1> 	;movzx	eax, cl ; 27/06/2015
 28705 00009CDC 88C8                <1> 	mov	al, cl
 28706 00009CDE E8490E0000          <1> 	call	cttyp
 28707 00009CE3 E9FCF8FFFF          <1> 	jmp	sysret
 28708                              <1> 
 28709                              <1> ; Original UNIX v1 'sysstty' routine:
 28710                              <1> ; gtty:
 28711                              <1> ;sysstty: / set mode of typewriter; 3 consequtive word arguments
 28712                              <1>         ;jsr    r0,gtty / r1 will have offset to tty block, 
 28713                              <1> 	; 		/ r2 has source
 28714                              <1>         ;mov    r2,-(sp)
 28715                              <1>         ;mov    r1,-(sp) / put r1 and r2 on the stack
 28716                              <1> ;1: / flush the clist wait till typewriter is quiescent
 28717                              <1>         ;mov    (sp),r1 / restore r1 to tty block offset
 28718                              <1>         ;movb   tty+3(r1),0f / put cc offset into getc argument
 28719                              <1>         ;mov    $240,*$ps / set processor priority to 5
 28720                              <1>         ;jsr    r0,getc; 0:../ put character from clist in r1
 28721                              <1>         ;       br .+4 / list empty, skip branch
 28722                              <1>         ;br     1b / get another character until list is empty
 28723                              <1>         ;mov    0b,r1 / move cc offset to r1
 28724                              <1>         ;inc    r1 / bump it for output clist
 28725                              <1>         ;tstb   cc(r1) / is it 0
 28726                              <1>         ;beq    1f / yes, no characters to output
 28727                              <1>  	;mov    r1,0f / no, put offset in sleep arg
 28728                              <1>         ;jsr    r0,sleep; 0:.. / put tty output process to sleep
 28729                              <1>         ;br     1b / try to calm it down again
 28730                              <1> ;1:
 28731                              <1>         ;mov    (sp)+,r1
 28732                              <1>         ;mov    (sp)+,r2 / restore registers
 28733                              <1> 	;mov    (r2)+,r3 / put reader control status in r3
 28734                              <1>         ;beq    1f / if 0, 1f
 28735                              <1>         ;mov    r3,rcsr(r1) / move r.c. status to reader
 28736                              <1>         ;                   / control status register
 28737                              <1> ;1:
 28738                              <1>         ;mov    (r2)+,r3 / move pointer control status to r3
 28739                              <1>         ;beq    1f / if 0 1f
 28740                              <1>         ;mov    r3,tcsr(r1) / move p.c. status to printer 
 28741                              <1> 	;		    / control status reg
 28742                              <1> ;1:
 28743                              <1>         ;mov    (r2)+,tty+4(r1) / move to flag byte of tty block
 28744                              <1>         ;jmp     sysret2 / return to user
 28745                              <1> 
 28746                              <1> sysgtty: ; < get tty status >
 28747                              <1> 	; 23/11/2015
 28748                              <1> 	; 29/10/2015
 28749                              <1> 	; 17/10/2015
 28750                              <1> 	; 28/06/2015 (Retro UNIX 386 v1 - Beginning)
 28751                              <1> 	; 30/05/2013 - 12/07/2014 (Retro UNIX 8086 v1)
 28752                              <1> 	;
 28753                              <1> 	; 'sysgtty' gets the status of tty in question. 
 28754                              <1> 	; It stores in the three words addressed by it's argument
 28755                              <1> 	; the status of the typewriter whose file descriptor
 28756                              <1> 	; in (u.r0).
 28757                              <1> 	;
 28758                              <1> 	; Calling sequence:
 28759                              <1> 	;	sysgtty; arg
 28760                              <1> 	; Arguments:
 28761                              <1> 	;	arg - address of 3 words destination of the status
 28762                              <1> 	; Inputs: ((*u.r0 - file descriptor))
 28763                              <1> 	; Outputs: ((status in address which is pointed to by arg))
 28764                              <1> 	; ...............................................................
 28765                              <1> 	;	
 28766                              <1> 	; Retro UNIX 8086 v1 modification: 
 28767                              <1> 	;	'sysgtty' system call will return status of tty
 28768                              <1> 	;	(keyboard, serial port and video page status)
 28769                              <1> 	;	 in following manner:
 28770                              <1> 	;
 28771                              <1> 	; Inputs:
 28772                              <1> 	;	BX = 0 --> means 
 28773                              <1> 	;	     CH = 0 -->	'return status of the console tty' 
 28774                              <1> 	;	                 for (current) process
 28775                              <1> 	;	     CL = 0 --> return keyboard status (tty 0 to 9)
 28776                              <1> 	;	     CL = 1 --> return video page status (tty 0 to 7)
 28777                              <1> 	;	     CL = 1 --> return serial port status (tty 8 & 9)		
 28778                              <1> 	;	     CH > 0 -->	tty number + 1
 28779                              <1> 	;
 28780                              <1> 	;	BX > 0 --> points to name of tty
 28781                              <1> 	;	     CL = 0 --> return keyboard status
 28782                              <1> 	;	     CL = 1 --> return video page status
 28783                              <1> 	;	     CH = undefined		 
 28784                              <1> 	;
 28785                              <1> 	; Outputs:
 28786                              <1> 	;	cf = 0 ->
 28787                              <1> 	;
 28788                              <1> 	;	     AL = tty number from 0 to 9
 28789                              <1> 	;		  (0 to 7 is also the video page of the tty)	
 28790                              <1> 	;	     AH = 0 if the tty is free/unused
 28791                              <1> 	;	     AH = the process number of the caller 
 28792                              <1>  	;	     AH = FFh if the tty is locked by another process
 28793                              <1> 	;
 28794                              <1> 	;	  (if calling is for serial port status)
 28795                              <1> 	;	     BX = serial port status if tty number is 8 or 9
 28796                              <1> 	;		  (BH = modem status, BL = Line status)
 28797                              <1> 	;	     CX = 0FFFFh (if data is ready)
 28798                              <1> 	;	     CX = 0 (if data is not ready or undefined)		
 28799                              <1> 	;
 28800                              <1> 	;	  (if calling is for keyboard status)
 28801                              <1> 	;	     BX = current character in tty/keyboard buffer
 28802                              <1> 	;		  (BH = scan code, BL = ascii code)
 28803                              <1> 	;		  (BX=0 if there is not a waiting character)
 28804                              <1> 	;	     CX  is undefined
 28805                              <1> 	;
 28806                              <1> 	;	  (if calling is for video page status)	
 28807                              <1> 	;	     BX = cursor position on the video page
 28808                              <1> 	;		  if tty number < 8
 28809                              <1> 	;		  (BH = row, BL = column)
 28810                              <1> 	;	     CX = current character (in cursor position)
 28811                              <1> 	;		  on the video page of the tty 
 28812                              <1> 	;		  if tty number < 8
 28813                              <1> 	;		  (CH = color, CL = character)
 28814                              <1> 	;	
 28815                              <1> 	;	cf = 1 means error (requested tty is not ready)
 28816                              <1> 	;
 28817                              <1> 	;	     AH = FFh if the caller is not owner of
 28818                              <1> 	;		  specified tty or console tty
 28819                              <1> 	;	     AL = tty number (0FFh if it does not exist)
 28820                              <1> 	;	     BX, CX are undefined if cf = 1
 28821                              <1> 	;
 28822                              <1> 	;	  (If tty number is 8 or 9)
 28823                              <1> 	;	     AL = tty number 
 28824                              <1> 	;	     AH = the process number of the caller 
 28825                              <1> 	;	     BX = serial port status
 28826                              <1> 	;  		 (BH = modem status, BL = Line status)
 28827                              <1> 	;	     CX = 0
 28828                              <1> 	;
 28829                              <1> 		
 28830                              <1> gtty:   ; get (requested) tty number
 28831                              <1> 	; 17/10/2015
 28832                              <1> 	; 28/06/2015 (Retro UNIX 386 v1 - 32 bit modifications)
 28833                              <1> 	; 30/05/2013 - 12/07/2014
 28834                              <1> 	; Retro UNIX 8086 v1 modification ! 
 28835                              <1> 	;
 28836                              <1> 	; ((Modified regs: eAX, eBX, eCX, eDX, eSI, eDI, eBP))
 28837                              <1> 	;
 28838                              <1> 	; 28/06/2015 (32 bit modifications)
 28839                              <1> 	; 16/01/2014
 28840 00009CE8 31C0                <1> 	xor 	eax, eax
 28841 00009CEA 6648                <1> 	dec	ax ; 17/10/2015
 28842 00009CEC A3[40CE0000]        <1> 	mov 	[u.r0], eax ; 0FFFFh
 28843 00009CF1 80F901              <1> 	cmp	cl, 1
 28844 00009CF4 760F                <1> 	jna	short sysgtty_0
 28845                              <1> sysgtty_invp:
 28846                              <1> 	; 28/06/2015
 28847 00009CF6 C705[95CE0000]1700- <1>         mov     dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
 28848 00009CFE 0000                <1>
 28849 00009D00 E9BFF8FFFF          <1> 	jmp	error
 28850                              <1> sysgtty_0:	
 28851 00009D05 21DB                <1> 	and	ebx, ebx
 28852 00009D07 7430                <1> 	jz	short sysgtty_1
 28853                              <1> 	;
 28854 00009D09 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 28855 00009D0F 6651                <1> 	push	cx ; 23/11/2015
 28856 00009D11 E86A070000          <1> 	call	namei
 28857 00009D16 6659                <1> 	pop	cx ; 23/11/2015
 28858 00009D18 7210                <1> 	jc 	short sysgtty_inv_dn ; 28/06/2015
 28859                              <1> 	;
 28860 00009D1A 6683F801            <1> 	cmp	ax, 1
 28861 00009D1E 7622                <1> 	jna	short sysgtty_2
 28862 00009D20 6683E80A            <1> 	sub	ax, 10
 28863 00009D24 6683F809            <1> 	cmp	ax, 9
 28864                              <1> 	;ja	short sysgtty_inv_dn
 28865                              <1> 	;mov	ch, al
 28866                              <1> 	;jmp	short sysgtty_4
 28867                              <1> 	; 23/11/2015
 28868 00009D28 7629                <1> 	jna	short sysgtty_4
 28869                              <1> sysgtty_inv_dn: 
 28870                              <1> 	; 28/06/2015
 28871                              <1> 	; Invalid device name (not a tty) ! error
 28872                              <1> 	; (Device is not a tty or device name not found)
 28873 00009D2A C705[95CE0000]1800- <1> 	mov	dword [u.error], ERR_INV_DEV_NAME
 28874 00009D32 0000                <1>
 28875 00009D34 E98BF8FFFF          <1> 	jmp	error 
 28876                              <1> sysgtty_1:
 28877                              <1> 	; 16/01/2014
 28878 00009D39 80FD0A              <1> 	cmp	ch, 10
 28879 00009D3C 77B8                <1> 	ja	short sysgtty_invp ; 28/06/2015
 28880 00009D3E FECD                <1> 	dec	ch ; 0 -> FFh (negative)
 28881 00009D40 790F                <1> 	jns	short sysgtty_3 ; not negative
 28882                              <1> 	;
 28883                              <1> sysgtty_2:
 28884                              <1> 	; get tty number of console tty
 28885 00009D42 8A25[8FCE0000]      <1> 	mov	ah, [u.uno]
 28886                              <1>  	; 28/06/2015
 28887 00009D48 0FB6DC              <1> 	movzx 	ebx, ah
 28888 00009D4B 8AAB[95CB0000]      <1> 	mov	ch, [ebx+p.ttyc-1]
 28889                              <1> sysgtty_3:
 28890 00009D51 88E8                <1> 	mov	al, ch
 28891                              <1> sysgtty_4:
 28892 00009D53 A2[40CE0000]        <1> 	mov	[u.r0], al
 28893                              <1>  	; 28/06/2015
 28894                              <1> 	;cmp	al, 9
 28895                              <1> 	;ja	short sysgtty_invp
 28896 00009D58 8B2D[3CCE0000]      <1> 	mov	ebp, [u.usp]
 28897                              <1> 	; 23/11/2015
 28898 00009D5E 20C9                <1> 	and	cl, cl
 28899 00009D60 7436                <1> 	jz	short sysgtty_6 ; keyboard status
 28900 00009D62 3C08                <1> 	cmp	al, 8 ; cmp ch, 8
 28901 00009D64 7232                <1> 	jb	short sysgtty_6 ; video page status
 28902                              <1> 	; serial port status
 28903                              <1> 	; 12/07/2014
 28904                              <1> 	;mov	dx, 0
 28905                              <1> 	;je	short sysgtty_5
 28906                              <1> 	;inc	dl
 28907                              <1> ;sysgtty_5:
 28908                              <1> 	; 28/06/2015
 28909 00009D66 2C08                <1> 	sub	al, 8
 28910 00009D68 E872100000          <1> 	call	sp_status ; serial (COM) port (line) status
 28911                              <1> 	; AL = Line status, AH = Modem status
 28912 00009D6D 66894510            <1> 	mov	[ebp+16], ax ; serial port status (in EBX)
 28913 00009D71 8A25[8FCE0000]      <1> 	mov	ah, [u.uno]
 28914 00009D77 8825[41CE0000]      <1>         mov     [u.r0+1], ah
 28915 00009D7D 66C745180000        <1> 	mov	word [ebp+24], 0 ; data status (0 = not ready)	
 28916                              <1> 				; (in ECX)
 28917 00009D83 A880                <1> 	test	al, 80h
 28918 00009D85 7565                <1> 	jnz	short sysgtty_dnr_err ; 29/06/2015
 28919 00009D87 A801                <1> 	test	al, 1
 28920 00009D89 0F8455F8FFFF        <1> 	jz	sysret
 28921 00009D8F 66FF4D18            <1> 	dec	word [ebp+24] ; data status (FFFFh = ready)	
 28922 00009D93 E94CF8FFFF          <1> 	jmp	sysret
 28923                              <1> sysgtty_6:
 28924 00009D98 A2[94CE0000]        <1> 	mov	[u.ttyn], al ; tty number
 28925                              <1> 	;movzx	ebx, al
 28926 00009D9D 88C3                <1> 	mov 	bl, al ; tty number (0 to 9)
 28927 00009D9F D0E3                <1> 	shl 	bl, 1  ; aligned to word
 28928                              <1> 	; 22/04/2014 - 29/06/2015
 28929 00009DA1 81C3[36BE0000]      <1>         add     ebx, ttyl
 28930 00009DA7 8A23                <1>  	mov	ah, [ebx]
 28931 00009DA9 3A25[8FCE0000]      <1> 	cmp	ah, [u.uno]
 28932 00009DAF 7404                <1> 	je	short sysgtty_7
 28933 00009DB1 20E4                <1> 	and	ah, ah
 28934                              <1> 	;jz	short sysgtty_7
 28935 00009DB3 7506                <1> 	jnz	short sysgtty_8
 28936                              <1> 	;mov	ah, 0FFh
 28937                              <1> sysgtty_7:
 28938 00009DB5 8825[41CE0000]      <1>         mov     [u.r0+1], ah
 28939                              <1> sysgtty_8:
 28940 00009DBB 08C9                <1> 	or	cl, cl
 28941 00009DBD 7510                <1> 	jnz	short sysgtty_9
 28942 00009DBF B401                <1> 	mov	ah, 1  ; test a key is available
 28943 00009DC1 E8216EFFFF          <1> 	call	int16h ; 24/01/2016
 28944 00009DC6 66894510            <1> 	mov	[ebp+16], ax ; bx, character
 28945 00009DCA E915F8FFFF          <1> 	jmp	sysret
 28946                              <1> sysgtty_9:
 28947 00009DCF 8A1D[94CE0000]      <1> 	mov	bl, [u.ttyn]
 28948                              <1> 	; bl = video page number
 28949 00009DD5 E8A377FFFF          <1> 	call 	get_cpos
 28950                              <1> 	; dx = cursor position
 28951 00009DDA 66895510            <1> 	mov	[ebp+16], dx ; bx
 28952                              <1> 	;mov	bl, [u.ttyn]
 28953                              <1> 	; bl = video page number
 28954 00009DDE E85979FFFF          <1> 	call	_read_ac_current ; 24/01/2016
 28955                              <1> 	; ax = character and attribute/color
 28956 00009DE3 66894518            <1> 	mov	[ebp+24], ax ; cx
 28957 00009DE7 E9F8F7FFFF          <1> 	jmp	sysret
 28958                              <1> sysgtty_dnr_err:
 28959                              <1> 	; 'device not responding !' error	
 28960                              <1> 	;mov 	dword [u.error], ERR_TIME_OUT ; 25
 28961 00009DEC C705[95CE0000]1900- <1> 	mov 	dword [u.error], ERR_DEV_NOT_RESP ;  25				
 28962 00009DF4 0000                <1>
 28963 00009DF6 E9C9F7FFFF          <1> 	jmp	error	
 28964                              <1> 
 28965                              <1> ; Original UNIX v1 'sysgtty' routine:
 28966                              <1> ; sysgtty:
 28967                              <1>         ;jsr    r0,gtty / r1 will have offset to tty block,
 28968                              <1> 	;	       / r2 has destination
 28969                              <1>         ;mov    rcsr(r1),(r2)+ / put reader control status 
 28970                              <1> 	;                     / in 1st word of dest
 28971                              <1>         ;mov    tcsr(r1),(r2)+ / put printer control status
 28972                              <1> 	;                     / in 2nd word of dest
 28973                              <1>         ;mov    tty+4(r1),(r2)+ / put mode in 3rd word
 28974                              <1>         ;jmp    sysret2 / return to user
 28975                              <1> 	
 28976                              <1> ; Original UNIX v1 'gtty' routine:
 28977                              <1> ; gtty:
 28978                              <1>         ;jsr    r0,arg; u.off / put first arg in u.off
 28979                              <1>         ;mov    *u.r0,r1 / put file descriptor in r1
 28980                              <1>         ;jsr    r0,getf / get the i-number of the file
 28981                              <1>         ;tst    r1 / is it open for reading
 28982                              <1>         ;bgt    1f / yes
 28983                              <1>         ;neg    r1 / no, i-number is negative, 
 28984                              <1> 	;          / so make it positive
 28985                              <1> ;1:
 28986                              <1>         ;sub    $14.,r1 / get i-number of tty0
 28987                              <1>         ;cmp    r1,$ntty-1 / is there such a typewriter
 28988                              <1>         ;bhis   error9 / no, error
 28989                              <1>         ;asl    r1 / 0%2
 28990                              <1>         ;asl    r1 / 0%4 / yes
 28991                              <1>         ;asl    r1 / 0%8 / multiply by 8 so r1 points to 
 28992                              <1> 	;	       ; / tty block
 28993                              <1>         ;mov    u.off,r2 / put argument in r2
 28994                              <1>         ;rts    r0 / return
 28995                              <1> 
 28996                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u2.s
 28997                              <1> ; Last Modification: 03/01/2016
 28998                              <1> 
 28999                              <1> syslink:
 29000                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 29001                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 29002                              <1> 	;
 29003                              <1> 	; 'syslink' is given two arguments, name 1 and name 2.
 29004                              <1> 	; name 1 is a file that already exists. name 2 is the name
 29005                              <1> 	; given to the entry that will go in the current directory.
 29006                              <1> 	; name2 will then be a link to the name 1 file. The i-number
 29007                              <1> 	; in the name 2 entry of current directory is the same
 29008                              <1> 	; i-number for the name 1 file.
 29009                              <1> 	;
 29010                              <1> 	; Calling sequence:
 29011                              <1> 	;	syslink; name 1; name 2
 29012                              <1> 	; Arguments:
 29013                              <1> 	;	name 1 - file name to which link will be created.
 29014                              <1> 	;	name 2 - name of entry in current directory that
 29015                              <1> 	;		 links to name 1.
 29016                              <1> 	; Inputs: -
 29017                              <1> 	; Outputs: -
 29018                              <1> 	; ...............................................................
 29019                              <1> 	;	
 29020                              <1> 	; Retro UNIX 8086 v1 modification: 
 29021                              <1> 	;       'syslink' system call has two arguments; so,
 29022                              <1> 	;	* 1st argument, name 1 is pointed to by BX register
 29023                              <1> 	;	* 2nd argument, name 2 is pointed to by CX register
 29024                              <1> 	;
 29025                              <1> 		; / name1, name2
 29026                              <1> 		;jsr r0,arg2 / u.namep has 1st arg u.off has 2nd
 29027 00009DFB 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 29028 00009E01 51                  <1> 	push	ecx
 29029 00009E02 E879060000          <1> 	call	namei
 29030                              <1> 		; jsr r0,namei / find the i-number associated with
 29031                              <1> 			     ; / the 1st path name
 29032                              <1>      	;;and	ax, ax
 29033                              <1> 	;;jz	error ; File not found
 29034                              <1> 	;jc	error 
 29035                              <1> 		; br error9 / cannot be found
 29036 00009E07 730F                <1> 	jnc	short syslink0
 29037                              <1> 	;pop 	ecx
 29038                              <1> 	; 'file not found !' error
 29039 00009E09 C705[95CE0000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 29040 00009E11 0000                <1>
 29041 00009E13 E9ACF7FFFF          <1> 	jmp	error
 29042                              <1> syslink0:
 29043 00009E18 E8FF0C0000          <1> 	call	iget
 29044                              <1> 		; jsr r0,iget / get the i-node into core
 29045 00009E1D 8F05[58CE0000]      <1> 	pop	dword [u.namep] ; ecx
 29046                              <1> 		; mov (sp)+,u.namep / u.namep points to 2nd name
 29047 00009E23 6650                <1> 	push	ax
 29048                              <1> 		; mov r1,-(sp) / put i-number of name1 on the stack
 29049                              <1> 			    ; / (a link to this file is to be created)
 29050 00009E25 66FF35[26CE0000]    <1> 	push	word [cdev]
 29051                              <1> 		; mov cdev,-(sp) / put i-nodes device on the stack
 29052 00009E2C E855000000          <1> 	call	isdir
 29053                              <1> 		; jsr r0,isdir / is it a directory
 29054 00009E31 E84A060000          <1> 	call	namei
 29055                              <1> 		; jsr r0,namei / no, get i-number of name2
 29056                              <1> 	;jnc	error
 29057                              <1> 		; br .+4   / not found 
 29058                              <1> 			 ; / so r1 = i-number of current directory
 29059                              <1> 			 ; / ii = i-number of current directory
 29060                              <1> 		; br error9 / file already exists., error
 29061 00009E36 720F                <1> 	jc	short syslink1
 29062                              <1> 	; pop ax
 29063                              <1> 	; pop ax
 29064                              <1> 	; 'file exists !' error
 29065 00009E38 C705[95CE0000]0E00- <1> 	mov	dword [u.error], ERR_FILE_EXISTS ; 14
 29066 00009E40 0000                <1>
 29067 00009E42 E97DF7FFFF          <1> 	jmp	error
 29068                              <1> syslink1:
 29069 00009E47 6659                <1> 	pop	cx
 29070                              <1> 	;cmp	cx, [cdev]
 29071 00009E49 3A0D[26CE0000]      <1> 	cmp	cl, [cdev]
 29072                              <1> 	;jne	error
 29073                              <1> 		; cmp (sp)+,cdev / u.dirp now points to 
 29074                              <1> 			       ; / end of current directory
 29075                              <1> 	        ; bne error9
 29076 00009E4F 740F                <1> 	je	short syslink2
 29077                              <1> 	; 'not same drive !' error
 29078 00009E51 C705[95CE0000]1500- <1> 	mov	dword [u.error],  ERR_DRV_NOT_SAME ; 21
 29079 00009E59 0000                <1>
 29080 00009E5B E964F7FFFF          <1> 	jmp	error
 29081                              <1> syslink2:
 29082 00009E60 6658                <1> 	pop	ax
 29083 00009E62 6650                <1> 	push	ax
 29084 00009E64 66A3[72CE0000]      <1> 	mov	[u.dirbuf], ax
 29085                              <1> 		; mov (sp),u.dirbuf / i-number of name1 into u.dirbuf
 29086 00009E6A E8A8000000          <1> 	call	mkdir
 29087                              <1> 		; jsr r0,mkdir / make directory entry for name2 
 29088                              <1> 		 	     ; / in current directory
 29089 00009E6F 6658                <1> 	pop	ax
 29090                              <1> 		; mov (sp)+,r1 / r1 has i-number of name1
 29091 00009E71 E8A60C0000          <1> 	call	iget
 29092                              <1> 		; jsr r0,iget / get i-node into core
 29093 00009E76 FE05[18CB0000]      <1> 	inc	byte [i.nlks]
 29094                              <1> 		; incb i.nlks / add 1 to its number of links
 29095 00009E7C E8A90C0000          <1> 	call	setimod
 29096                              <1> 		; jsr r0,setimod / set the i-node modified flag
 29097 00009E81 E95EF7FFFF          <1> 	jmp	sysret
 29098                              <1> 
 29099                              <1> isdir:
 29100                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 29101                              <1> 	; 04/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 29102                              <1> 	;
 29103                              <1> 	; 'isdir' check to see if the i-node whose i-number is in r1
 29104                              <1> 	;  is a directory. If it is, an error occurs, because 'isdir'
 29105                              <1> 	;  called by syslink and sysunlink to make sure directories
 29106                              <1> 	;  are not linked. If the user is the super user (u.uid=0),
 29107                              <1> 	; 'isdir' does not bother checking. The current i-node
 29108                              <1> 	;  is not disturbed.			
 29109                              <1> 	;		
 29110                              <1> 	; INPUTS ->
 29111                              <1> 	;    r1 - contains the i-number whose i-node is being checked.
 29112                              <1> 	;    u.uid - user id
 29113                              <1> 	; OUTPUTS ->
 29114                              <1> 	;    r1 - contains current i-number upon exit
 29115                              <1> 	;    	 (current i-node back in core) 
 29116                              <1> 	;	
 29117                              <1> 	; ((AX = R1))
 29118                              <1> 	;
 29119                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 29120                              <1> 	;
 29121                              <1> 
 29122                              <1> 	; / if the i-node whose i-number is in r1 is a directory 
 29123                              <1> 	; / there is an error unless super user made the call
 29124                              <1> 	
 29125 00009E86 803D[8CCE0000]00    <1> 	cmp	byte [u.uid], 0 
 29126                              <1> 		; tstb u.uid / super user
 29127 00009E8D 762D                <1> 	jna	short isdir1
 29128                              <1> 		; beq 1f / yes, don't care
 29129 00009E8F 66FF35[22CE0000]    <1> 	push	word [ii]
 29130                              <1> 		; mov ii,-(sp) / put current i-number on stack
 29131 00009E96 E8810C0000          <1> 	call	iget
 29132                              <1> 		; jsr r0,iget / get i-node into core (i-number in r1)
 29133 00009E9B 66F705[16CB0000]00- <1> 	test 	word [i.flgs], 4000h ; Bit 14 : Directory flag
 29134 00009EA3 40                  <1>
 29135                              <1> 		; bit $40000,i.flgs / is it a directory
 29136                              <1> 	;jnz	error
 29137                              <1> 		; bne error9 / yes, error
 29138 00009EA4 740F                <1> 	jz	short isdir0
 29139 00009EA6 C705[95CE0000]0B00- <1> 	mov 	dword [u.error], ERR_NOT_FILE  ; 11 ; ERR_DIR_ACCESS 
 29140 00009EAE 0000                <1>
 29141                              <1> 				; 'permission denied !' error
 29142                              <1> 	; pop	ax
 29143 00009EB0 E90FF7FFFF          <1> 	jmp	error	
 29144                              <1> isdir0:	
 29145 00009EB5 6658                <1> 	pop	ax
 29146                              <1> 		; mov (sp)+,r1 / no, put current i-number in r1 (ii)
 29147 00009EB7 E8600C0000          <1> 	call	iget
 29148                              <1> 		; jsr r0,iget / get it back in
 29149                              <1> isdir1: ; 1:
 29150 00009EBC C3                  <1> 	retn
 29151                              <1> 		; rts r0
 29152                              <1> 
 29153                              <1> sysunlink:
 29154                              <1> 	; 04/12/2015 (14 byte file names)
 29155                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 29156                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 29157                              <1> 	;
 29158                              <1> 	; 'sysunlink' removes the entry for the file pointed to by
 29159                              <1> 	; name from its directory. If this entry was the last link
 29160                              <1> 	; to the file, the contents of the file are freed and the
 29161                              <1> 	; file is destroyed. If, however, the file was open in any
 29162                              <1> 	; process, the actual destruction is delayed until it is 
 29163                              <1> 	; closed, even though the directory entry has disappeared.
 29164                              <1> 	; 
 29165                              <1> 	; The error bit (e-bit) is set to indicate that the file	
 29166                              <1> 	; does not exist or that its directory can not be written.
 29167                              <1> 	; Write permission is not required on the file itself.
 29168                              <1> 	; It is also illegal to unlink a directory (except for
 29169                              <1> 	; the superuser).
 29170                              <1> 	;
 29171                              <1> 	; Calling sequence:
 29172                              <1> 	;	sysunlink; name
 29173                              <1> 	; Arguments:
 29174                              <1> 	;	name - name of directory entry to be removed 
 29175                              <1> 	; Inputs: -
 29176                              <1> 	; Outputs: -
 29177                              <1> 	; ...............................................................
 29178                              <1> 	;				
 29179                              <1> 	; Retro UNIX 8086 v1 modification:
 29180                              <1> 	;	 The user/application program puts address of the name
 29181                              <1> 	;        in BX register as 'sysunlink' system call argument.
 29182                              <1> 
 29183                              <1> 	; / name - remove link name
 29184 00009EBD 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 29185                              <1> 		;jsr r0,arg; u.namep / u.namep points to name
 29186 00009EC3 E8B8050000          <1> 	call	namei
 29187                              <1> 		; jsr r0,namei / find the i-number associated 
 29188                              <1> 			     ; / with the path name
 29189                              <1> 	;jc	error
 29190                              <1> 		; br error9 / not found
 29191 00009EC8 730F                <1> 	jnc	short sysunlink1
 29192                              <1> 	; 'file not found !' error
 29193 00009ECA C705[95CE0000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 29194 00009ED2 0000                <1>
 29195 00009ED4 E9EBF6FFFF          <1> 	jmp	error
 29196                              <1> sysunlink1:
 29197 00009ED9 6650                <1> 	push	ax
 29198                              <1> 		; mov r1,-(sp) / put its i-number on the stack
 29199 00009EDB E8A6FFFFFF          <1> 	call	isdir
 29200                              <1> 		; jsr r0,isdir / is it a directory
 29201 00009EE0 6631C0              <1> 	xor 	ax, ax
 29202 00009EE3 66A3[72CE0000]      <1> 	mov	[u.dirbuf], ax ; 0
 29203                              <1> 		; clr u.dirbuf / no, clear the location that will
 29204                              <1> 			   ; / get written into the i-number portion
 29205                              <1> 			 ; / of the entry
 29206 00009EE9 832D[5CCE0000]10    <1> 	sub	dword [u.off], 16 ; 04/12/2015 (10 -> 16) 
 29207                              <1> 		; sub $10.,u.off / move u.off back 1 directory entry
 29208 00009EF0 E86E000000          <1> 	call	wdir
 29209                              <1> 		; jsr r0,wdir / free the directory entry
 29210 00009EF5 6658                <1> 	pop	ax
 29211                              <1> 		; mov (sp)+,r1 / get i-number back
 29212 00009EF7 E8200C0000          <1> 	call	iget
 29213                              <1> 		; jsr r0,iget / get i-node
 29214 00009EFC E8290C0000          <1> 	call	setimod
 29215                              <1> 		; jsr r0,setimod / set modified flag
 29216 00009F01 FE0D[18CB0000]      <1> 	dec	byte [i.nlks]
 29217                              <1> 		; decb i.nlks / decrement the number of links
 29218 00009F07 0F85D7F6FFFF        <1> 	jnz	sysret
 29219                              <1> 		; bgt sysret9 / if this was not the last link
 29220                              <1> 			    ; / to file return
 29221                              <1> 	; AX = r1 = i-number
 29222 00009F0D E893090000          <1> 	call	anyi
 29223                              <1> 		; jsr r0,anyi / if it was, see if anyone has it open.
 29224                              <1> 			 ; / Then free contents of file and destroy it.
 29225 00009F12 E9CDF6FFFF          <1> 	jmp	sysret
 29226                              <1> 		; br sysret9
 29227                              <1> 
 29228                              <1> mkdir:
 29229                              <1> 	; 04/12/2015 (14 byte directory names)
 29230                              <1> 	; 12/10/2015
 29231                              <1> 	; 17/06/2015 (Retro UNIX 386 v1 - Beginning)
 29232                              <1> 	; 29/04/2013 - 01/08/2013 (Retro UNIX 8086 v1)
 29233                              <1> 	;
 29234                              <1> 	; 'mkdir' makes a directory entry from the name pointed to
 29235                              <1> 	; by u.namep into the current directory.
 29236                              <1> 	;
 29237                              <1> 	; INPUTS ->
 29238                              <1> 	;    u.namep - points to a file name 
 29239                              <1> 	;	           that is about to be a directory entry.
 29240                              <1> 	;    ii - current directory's i-number.	
 29241                              <1> 	; OUTPUTS ->
 29242                              <1> 	;    u.dirbuf+2 - u.dirbuf+10 - contains file name. 
 29243                              <1> 	;    u.off - points to entry to be filled 
 29244                              <1> 	;	     in the current directory		
 29245                              <1> 	;    u.base - points to start of u.dirbuf.
 29246                              <1> 	;    r1 - contains i-number of current directory 
 29247                              <1> 	;	
 29248                              <1> 	; ((AX = R1)) output
 29249                              <1> 	;
 29250                              <1> 	;    (Retro UNIX Prototype : 11/11/2012, UNIXCOPY.ASM)
 29251                              <1>         ;    ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 29252                              <1> 	;
 29253                              <1> 
 29254                              <1> 	; 17/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 29255 00009F17 31C0                <1> 	xor 	eax, eax
 29256 00009F19 BF[74CE0000]        <1> 	mov     edi, u.dirbuf+2
 29257 00009F1E 89FE                <1> 	mov	esi, edi
 29258 00009F20 AB                  <1> 	stosd
 29259 00009F21 AB                  <1> 	stosd
 29260                              <1> 	; 04/12/2015 (14 byte directory names)
 29261 00009F22 AB                  <1> 	stosd
 29262 00009F23 66AB                <1> 	stosw
 29263                              <1> 		; jsr r0,copyz; u.dirbuf+2; u.dirbuf+10. / clear this
 29264 00009F25 89F7                <1> 	mov	edi, esi ; offset to u.dirbuf
 29265                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 29266                              <1> 	;mov 	ebp, [u.namep]
 29267 00009F27 E899060000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
 29268                              <1> 		; esi = physical address (page start + offset)
 29269                              <1> 		; ecx = byte count in the page (1 - 4096)
 29270                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 29271                              <1> 		; mov u.namep,r2 / r2 points to name of directory entry
 29272                              <1> 		; mov $u.dirbuf+2,r3 / r3 points to u.dirbuf+2
 29273                              <1> mkdir_1: ; 1: 
 29274 00009F2C 45                  <1> 	inc	ebp ; 12/10/2015
 29275                              <1> 	;
 29276                              <1> 	; / put characters in the directory name in u.dirbuf+2 - u.dirbuf+10
 29277                              <1> 	 ; 01/08/2013
 29278 00009F2D AC                  <1> 	lodsb
 29279                              <1> 		; movb (r2)+,r1 / move character in name to r1
 29280 00009F2E 20C0                <1> 	and 	al, al
 29281 00009F30 7427                <1> 	jz 	short mkdir_3 	  
 29282                              <1> 		; beq 1f / if null, done
 29283 00009F32 3C2F                <1> 	cmp	al, '/'
 29284                              <1> 		; cmp r1,$'/ / is it a "/"?
 29285 00009F34 7414                <1> 	je	short mkdir_err
 29286                              <1> 	;je	error
 29287                              <1> 		; beq error9 / yes, error
 29288                              <1> 	; 12/10/2015
 29289 00009F36 6649                <1> 	dec	cx
 29290 00009F38 7505                <1> 	jnz	short mkdir_2
 29291                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 29292 00009F3A E88C060000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 29293                              <1> 		; esi = physical address (page start + offset)
 29294                              <1> 		; ecx = byte count in the page
 29295                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 29296                              <1> mkdir_2:
 29297 00009F3F 81FF[82CE0000]      <1> 	cmp     edi, u.dirbuf+16 ; ; 04/12/2015 (10 -> 16) 
 29298                              <1> 		; cmp r3,$u.dirbuf+10. / have we reached the last slot for
 29299                              <1> 				     ; / a char?
 29300 00009F45 74E5                <1> 	je	short mkdir_1
 29301                              <1> 		; beq 1b / yes, go back
 29302 00009F47 AA                  <1> 	stosb
 29303                              <1> 		; movb r1,(r3)+ / no, put the char in the u.dirbuf
 29304 00009F48 EBE2                <1> 	jmp 	short mkdir_1
 29305                              <1> 		; br 1b / get next char
 29306                              <1> mkdir_err:
 29307                              <1> 	; 17/06/2015
 29308 00009F4A C705[95CE0000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
 29309 00009F52 0000                <1>
 29310 00009F54 E96BF6FFFF          <1> 	jmp	error
 29311                              <1> 
 29312                              <1> mkdir_3: ; 1:
 29313 00009F59 A1[54CE0000]        <1> 	mov	eax, [u.dirp]
 29314 00009F5E A3[5CCE0000]        <1> 	mov	[u.off], eax
 29315                              <1> 		; mov u.dirp,u.off / pointer to empty current directory
 29316                              <1> 				 ; / slot to u.off
 29317                              <1> wdir: ; 29/04/2013
 29318 00009F63 C705[60CE0000]-     <1>         mov     dword [u.base], u.dirbuf
 29319 00009F69 [72CE0000]          <1>
 29320                              <1> 		; mov $u.dirbuf,u.base / u.base points to created file name
 29321 00009F6D C705[64CE0000]1000- <1>         mov     dword [u.count], 16 ; 04/12/2015 (10 -> 16) 
 29322 00009F75 0000                <1>
 29323                              <1> 		; mov $10.,u.count / u.count = 10
 29324 00009F77 66A1[22CE0000]      <1> 	mov	ax, [ii] 
 29325                              <1> 		; mov ii,r1 / r1 has i-number of current directory
 29326 00009F7D B201                <1> 	mov	dl, 1 ; owner flag mask ; RETRO UNIX 8086 v1 modification !
 29327 00009F7F E8AA0B0000          <1> 	call 	access
 29328                              <1> 		; jsr r0,access; 1 / get i-node and set its file up 
 29329                              <1> 				 ; / for writing
 29330                              <1> 	; AX = i-number of current directory
 29331                              <1> 	; 01/08/2013
 29332 00009F84 FE05[A7CE0000]      <1> 	inc     byte [u.kcall] ; the caller is 'mkdir' sign	
 29333 00009F8A E8910B0000          <1> 	call	writei
 29334                              <1> 		; jsr r0,writei / write into directory
 29335 00009F8F C3                  <1> 	retn	
 29336                              <1> 		; rts r0
 29337                              <1> 
 29338                              <1> sysexec:
 29339                              <1> 	; 23/10/2015
 29340                              <1> 	; 19/10/2015
 29341                              <1> 	; 18/10/2015
 29342                              <1> 	; 10/10/2015
 29343                              <1> 	; 26/08/2015
 29344                              <1> 	; 05/08/2015
 29345                              <1> 	; 29/07/2015
 29346                              <1> 	; 25/07/2015
 29347                              <1> 	; 24/07/2015
 29348                              <1> 	; 21/07/2015
 29349                              <1> 	; 20/07/2015
 29350                              <1> 	; 02/07/2015
 29351                              <1> 	; 01/07/2015
 29352                              <1> 	; 25/06/2015
 29353                              <1> 	; 24/06/2015
 29354                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 29355                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
 29356                              <1> 	;
 29357                              <1> 	; 'sysexec' initiates execution of a file whose path name if
 29358                              <1> 	; pointed to by 'name' in the sysexec call. 
 29359                              <1> 	; 'sysexec' performs the following operations:
 29360                              <1> 	;    1. obtains i-number of file to be executed via 'namei'.
 29361                              <1> 	;    2. obtains i-node of file to be exceuted via 'iget'.
 29362                              <1> 	;    3. sets trap vectors to system routines.
 29363                              <1> 	;    4. loads arguments to be passed to executing file into
 29364                              <1> 	;	highest locations of user's core
 29365                              <1> 	;    5. puts pointers to arguments in locations immediately
 29366                              <1> 	;	following arguments.
 29367                              <1> 	;    6.	saves number of arguments in next location.
 29368                              <1> 	;    7. intializes user's stack area so that all registers
 29369                              <1> 	;	will be zeroed and the PS is cleared and the PC set
 29370                              <1> 	;	to core when 'sysret' restores registers 
 29371                              <1> 	;	and does an rti.
 29372                              <1> 	;    8. inializes u.r0 and u.sp
 29373                              <1> 	;    9. zeros user's core down to u.r0
 29374                              <1> 	;   10.	reads executable file from storage device into core
 29375                              <1> 	;	starting at location 'core'.
 29376                              <1> 	;   11.	sets u.break to point to end of user's code with
 29377                              <1> 	;	data area appended.
 29378                              <1> 	;   12.	calls 'sysret' which returns control at location
 29379                              <1> 	;	'core' via 'rti' instruction. 		  		
 29380                              <1> 	;
 29381                              <1> 	; Calling sequence:
 29382                              <1> 	;	sysexec; namep; argp
 29383                              <1> 	; Arguments:
 29384                              <1> 	;	namep - points to pathname of file to be executed
 29385                              <1> 	;	argp  - address of table of argument pointers
 29386                              <1> 	;	argp1... argpn - table of argument pointers
 29387                              <1> 	;	argp1:<...0> ... argpn:<...0> - argument strings
 29388                              <1> 	; Inputs: (arguments)
 29389                              <1> 	; Outputs: -	
 29390                              <1> 	; ...............................................................
 29391                              <1> 	;
 29392                              <1> 	; Retro UNIX 386 v1 modification: 
 29393                              <1> 	;	User application runs in it's own virtual space 
 29394                              <1> 	;	which is izolated from kernel memory (and other
 29395                              <1> 	;	memory pages) via 80386	paging in ring 3 
 29396                              <1> 	;	privilige mode. Virtual start address is always 0.
 29397                              <1> 	;	User's core memory starts at linear address 400000h
 29398                              <1> 	;	(the end of the 1st 4MB).
 29399                              <1> 	;
 29400                              <1> 	; Retro UNIX 8086 v1 modification: 
 29401                              <1> 	;	user/application segment and system/kernel segment
 29402                              <1> 	;	are different and sysenter/sysret/sysrele routines
 29403                              <1> 	;	are different (user's registers are saved to 
 29404                              <1> 	;	and then restored from system's stack.)
 29405                              <1> 	;
 29406                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
 29407                              <1> 	;	      arguments which were in these registers;
 29408                              <1> 	;	      but, it returns by putting the 1st argument
 29409                              <1> 	;	      in 'u.namep' and the 2nd argument
 29410                              <1> 	;	      on top of stack. (1st argument is offset of the
 29411                              <1> 	;	      file/path name in the user's program segment.)		 	
 29412                              <1> 	
 29413                              <1> 	;call	arg2
 29414                              <1> 	; * name - 'u.namep' points to address of file/path name
 29415                              <1> 	;          in the user's program segment ('u.segmnt')
 29416                              <1> 	;          with offset in BX register (as sysopen argument 1).
 29417                              <1> 	; * argp - sysexec argument 2 is in CX register 
 29418                              <1> 	;          which is on top of stack.
 29419                              <1> 	;
 29420                              <1> 		; jsr r0,arg2 / arg0 in u.namep,arg1 on top of stack
 29421                              <1> 
 29422                              <1> 	; 23/06/2015 (32 bit modifications)
 29423                              <1> 
 29424 00009F90 891D[58CE0000]      <1> 	mov	[u.namep], ebx ; argument 1
 29425                              <1>         ; 18/10/2015
 29426 00009F96 890D[C0CE0000]      <1> 	mov     [argv], ecx  ; * ; argument 2
 29427 00009F9C E8DF040000          <1> 	call	namei
 29428                              <1> 		; jsr r0,namei / namei returns i-number of file 
 29429                              <1> 			     ; / named in sysexec call in r1
 29430                              <1> 	;jc	error
 29431                              <1> 		; br error9
 29432 00009FA1 731E                <1> 	jnc	short sysexec_0
 29433                              <1> 	;
 29434                              <1> 	; 'file not found !' error
 29435 00009FA3 C705[95CE0000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND
 29436 00009FAB 0000                <1>
 29437 00009FAD E912F6FFFF          <1> 	jmp	error 
 29438                              <1> sysexec_not_exf:
 29439                              <1> 	; 'not executable file !' error
 29440 00009FB2 C705[95CE0000]1600- <1> 	mov	dword [u.error], ERR_NOT_EXECUTABLE
 29441 00009FBA 0000                <1>
 29442 00009FBC E903F6FFFF          <1> 	jmp	error 
 29443                              <1> sysexec_0:
 29444 00009FC1 E8560B0000          <1> 	call	iget
 29445                              <1> 		; jsr r0,iget / get i-node for file to be executed
 29446 00009FC6 66F705[16CB0000]10- <1>         test    word [i.flgs], 10h
 29447 00009FCE 00                  <1>
 29448                              <1> 		; bit $20,i.flgs / is file executable
 29449 00009FCF 74E1                <1> 	jz	short sysexec_not_exf
 29450                              <1> 	;jz	error
 29451                              <1> 		; beq error9
 29452                              <1> 	;;
 29453 00009FD1 E8500B0000          <1> 	call	iopen
 29454                              <1> 		; jsr r0,iopen / gets i-node for file with i-number
 29455                              <1> 			     ; / given in r1 (opens file)
 29456                              <1> 	; AX = i-number of the file
 29457 00009FD6 66F705[16CB0000]20- <1> 	test	word [i.flgs], 20h
 29458 00009FDE 00                  <1>
 29459                              <1> 		; bit $40,i.flgs / test user id on execution bit
 29460 00009FDF 7415                <1> 	jz	short sysexec_1
 29461                              <1> 		; beq 1f
 29462 00009FE1 803D[8CCE0000]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013
 29463                              <1> 		; tstb u.uid / test user id
 29464 00009FE8 760C                <1> 	jna	short sysexec_1
 29465                              <1> 		; beq 1f / super user
 29466 00009FEA 8A0D[19CB0000]      <1> 	mov	cl, [i.uid]
 29467 00009FF0 880D[8CCE0000]      <1> 	mov	[u.uid], cl ; 02/08/2013
 29468                              <1> 		; movb i.uid,u.uid / put user id of owner of file
 29469                              <1> 				 ; / as process user id
 29470                              <1> sysexec_1:
 29471                              <1> 	; 18/10/2215
 29472                              <1> 	; 10/10/2015
 29473                              <1> 	; 24/07/2015
 29474                              <1> 	; 21/07/2015
 29475                              <1> 	; 25/06/2015
 29476                              <1> 	; 24/06/2015
 29477                              <1>         ; Moving arguments to the end of [u.upage]
 29478                              <1> 	; (by regarding page borders in user's memory space)
 29479                              <1> 	;
 29480                              <1> 	; 10/10/2015
 29481                              <1> 	; 21/07/2015
 29482 00009FF6 89E5                <1> 	mov	ebp, esp ; (**)
 29483                              <1> 	; 18/10/2015
 29484 00009FF8 89EF                <1> 	mov 	edi, ebp
 29485 00009FFA B900010000          <1> 	mov 	ecx, MAX_ARG_LEN ; 256
 29486                              <1> 	;sub	edi, MAX_ARG_LEN ; 256
 29487 00009FFF 29CF                <1> 	sub	edi, ecx
 29488 0000A001 89FC                <1> 	mov	esp, edi
 29489 0000A003 31C0                <1> 	xor	eax, eax
 29490 0000A005 A3[68CE0000]        <1> 	mov 	[u.nread], eax ; 0
 29491 0000A00A 49                  <1> 	dec	ecx ; 256 - 1
 29492 0000A00B 890D[64CE0000]      <1> 	mov 	[u.count], ecx ; MAX_ARG_LEN - 1 ; 255
 29493                              <1> 	;mov 	dword [u.count], MAX_ARG_LEN - 1 ; 255
 29494                              <1> sysexec_2:
 29495 0000A011 8B35[C0CE0000]      <1> 	mov	esi, [argv] ; 18/10/2015 
 29496 0000A017 E873020000          <1> 	call	get_argp
 29497 0000A01C B904000000          <1> 	mov	ecx, 4 ; mov ecx, 4
 29498                              <1> sysexec_3:
 29499 0000A021 21C0                <1> 	and	eax, eax
 29500 0000A023 7456                <1> 	jz	short sysexec_6
 29501                              <1> 	; 18/10/2015
 29502 0000A025 010D[C0CE0000]      <1> 	add	[argv], ecx ; 4
 29503 0000A02B 66FF05[BECE0000]    <1> 	inc	word [argc]
 29504                              <1> 	;
 29505 0000A032 A3[60CE0000]        <1> 	mov	[u.base], eax
 29506                              <1>  	; 23/10/2015
 29507 0000A037 66C705[A5CE0000]00- <1> 	mov	word [u.pcount], 0
 29508 0000A03F 00                  <1>
 29509                              <1> sysexec_4:
 29510 0000A040 E8EA0A0000          <1> 	call	cpass ; get a character from user's core memory
 29511 0000A045 750B                <1>         jnz      short sysexec_5
 29512                              <1> 		; (max. 255 chars + null)
 29513                              <1> 	; 18/10/2015
 29514 0000A047 28C0                <1> 	sub 	al, al
 29515 0000A049 AA                  <1> 	stosb
 29516 0000A04A FF05[68CE0000]      <1> 	inc	dword [u.nread]
 29517 0000A050 EB29                <1> 	jmp	short sysexec_6
 29518                              <1> sysexec_5:
 29519 0000A052 AA                  <1> 	stosb
 29520 0000A053 20C0                <1> 	and 	al, al
 29521 0000A055 75E9                <1> 	jnz	short sysexec_4
 29522 0000A057 B904000000          <1> 	mov	ecx, 4
 29523 0000A05C 390D[BCCE0000]      <1> 	cmp	[ncount], ecx ; 4
 29524 0000A062 72AD                <1> 	jb	short sysexec_2
 29525 0000A064 8B35[B8CE0000]      <1> 	mov	esi, [nbase]
 29526 0000A06A 010D[B8CE0000]      <1> 	add	[nbase], ecx ; 4	
 29527 0000A070 66290D[BCCE0000]    <1> 	sub	[ncount], cx 
 29528 0000A077 8B06                <1> 	mov	eax, [esi]
 29529 0000A079 EBA6                <1> 	jmp	short sysexec_3
 29530                              <1> sysexec_6:
 29531                              <1> 	; 18/10/2015
 29532                              <1> 	; argument list transfer from user's core memory to
 29533                              <1> 	; kernel stack frame is OK here.
 29534                              <1> 	; [u.nread] = ; argument list length
 29535                              <1> 	;mov	[argv], esp ; start address of argument list 	
 29536                              <1> 	;
 29537                              <1> 	; 18/10/2015
 29538                              <1> 	; 24/07/2015
 29539                              <1>         ; 21/07/2015
 29540                              <1> 	; 02/07/2015
 29541                              <1> 	; 25/06/2015
 29542                              <1> 	; 24/06/2015
 29543                              <1> 	; 23/06/2015
 29544                              <1> 	;
 29545 0000A07B 8B1D[9DCE0000]      <1> 	mov	ebx, [u.ppgdir] ; parent's page directory
 29546 0000A081 21DB                <1> 	and 	ebx, ebx  ; /etc/init ? (u.ppgdir = 0)	
 29547 0000A083 740A                <1> 	jz	short sysexec_7
 29548 0000A085 A1[99CE0000]        <1> 	mov	eax, [u.pgdir] ; physical address of page directory
 29549 0000A08A E8B191FFFF          <1> 	call	deallocate_page_dir
 29550                              <1> sysexec_7:
 29551 0000A08F E8E190FFFF          <1> 	call	make_page_dir
 29552                              <1> 	;jc	short sysexec_14
 29553 0000A094 0F82449EFFFF        <1> 	jc	panic  ; allocation error 
 29554                              <1> 		       ; after a deallocation would be nonsence !?
 29555                              <1> 	; 24/07/2015
 29556                              <1> 	; map kernel pages (1st 4MB) to PDE 0
 29557                              <1> 	;     of the user's page directory
 29558                              <1> 	;     (It is needed for interrupts!)
 29559                              <1> 	; 18/10/2015
 29560 0000A09A 8B15[E8BD0000]      <1> 	mov	edx, [k_page_dir] ; Kernel's page directory
 29561 0000A0A0 8B02                <1> 	mov	eax, [edx] ; physical address of
 29562                              <1> 			   ; kernel's first page table (1st 4 MB)
 29563                              <1> 			   ; (PDE 0 of kernel's page directory)
 29564 0000A0A2 8B15[99CE0000]      <1> 	mov 	edx, [u.pgdir]
 29565 0000A0A8 8902                <1> 	mov	[edx], eax ; PDE 0 (1st 4MB)
 29566                              <1> 	;
 29567                              <1> 	; 20/07/2015
 29568 0000A0AA BB00004000          <1> 	mov	ebx, CORE ; start address = 0 (virtual) + CORE
 29569                              <1> 	; 18/10/2015
 29570 0000A0AF BE[B0CE0000]        <1> 	mov	esi, pcore ; physical start address
 29571                              <1> sysexec_8:	
 29572 0000A0B4 B907000000          <1> 	mov	ecx, PDE_A_USER + PDE_A_WRITE + PDE_A_PRESENT
 29573 0000A0B9 E8D590FFFF          <1> 	call	make_page_table
 29574 0000A0BE 0F821A9EFFFF        <1> 	jc	panic
 29575                              <1> 	;mov	ecx, PTE_A_USER + PTE_A_WRITE + PTE_A_PRESENT
 29576 0000A0C4 E8D890FFFF          <1> 	call	make_page ; make new page, clear and set the pte 
 29577 0000A0C9 0F820F9EFFFF        <1> 	jc	panic
 29578                              <1> 	;
 29579 0000A0CF 8906                <1> 	mov	[esi], eax ; 24/06/2015
 29580                              <1> 	; ebx = virtual address (24/07/2015)
 29581 0000A0D1 E8EE95FFFF          <1> 	call 	add_to_swap_queue
 29582                              <1> 	; 18/10/2015
 29583 0000A0D6 81FE[B4CE0000]      <1> 	cmp	esi, ecore ; user's stack (last) page ?
 29584 0000A0DC 740C                <1> 	je	short sysexec_9 ; yes
 29585 0000A0DE BE[B4CE0000]        <1> 	mov	esi, ecore  ; physical address of the last page 
 29586                              <1> 	; 20/07/2015
 29587 0000A0E3 BB00F0FFFF          <1> 	mov	ebx, (ECORE - PAGE_SIZE) + CORE
 29588                              <1> 	; ebx = virtual end address + segment base address - 4K
 29589 0000A0E8 EBCA                <1>         jmp     short sysexec_8
 29590                              <1> 
 29591                              <1> sysexec_9:
 29592                              <1> 	; 18/10/2015
 29593                              <1> 	; 26/08/2015
 29594                              <1> 	; 25/06/2015
 29595                              <1> 	; move arguments from kernel stack to [ecore]
 29596                              <1> 	; (argument list/line will be copied from kernel stack
 29597                              <1> 	; frame to the last (stack) page of user's core memory)
 29598                              <1> 	; 18/10/2015
 29599 0000A0EA 8B3D[B4CE0000]      <1> 	mov	edi, [ecore]
 29600 0000A0F0 81C700100000        <1> 	add	edi, PAGE_SIZE
 29601 0000A0F6 0FB705[BECE0000]    <1> 	movzx	eax, word [argc]
 29602 0000A0FD 09C0                <1> 	or	eax, eax
 29603 0000A0FF 7509                <1> 	jnz	short sysexec_10
 29604 0000A101 89FB                <1> 	mov 	ebx, edi
 29605 0000A103 83EB04              <1> 	sub	ebx, 4 
 29606 0000A106 8903                <1> 	mov	[ebx], eax ; 0
 29607 0000A108 EB40                <1> 	jmp 	short sysexec_13
 29608                              <1> sysexec_10:
 29609 0000A10A 8B0D[68CE0000]      <1> 	mov	ecx, [u.nread]
 29610                              <1> 	;mov 	esi, [argv}
 29611 0000A110 89E6                <1> 	mov	esi, esp ; start address of argument list
 29612 0000A112 29CF                <1> 	sub	edi, ecx ; page end address - argument list length
 29613 0000A114 89C2                <1> 	mov	edx, eax
 29614 0000A116 FEC2                <1> 	inc	dl ; argument count + 1 for argc value  
 29615 0000A118 C0E202              <1> 	shl 	dl, 2  ; 4 * (argument count + 1)
 29616 0000A11B 89FB                <1> 	mov	ebx, edi
 29617 0000A11D 80E3FC              <1> 	and	bl, 0FCh ; 32 bit (dword) alignment
 29618 0000A120 29D3                <1> 	sub 	ebx, edx
 29619 0000A122 89FA                <1> 	mov	edx, edi
 29620 0000A124 F3A4                <1> 	rep	movsb
 29621 0000A126 89D6                <1> 	mov 	esi, edx
 29622 0000A128 89DF                <1> 	mov 	edi, ebx
 29623 0000A12A BA00F0BFFF          <1> 	mov	edx, ECORE - PAGE_SIZE ; virtual addr. of the last page
 29624 0000A12F 2B15[B4CE0000]      <1> 	sub 	edx, [ecore] ; difference (virtual - physical) 
 29625 0000A135 AB                  <1> 	stosd	; eax = argument count	
 29626                              <1> sysexec_11:
 29627 0000A136 89F0                <1> 	mov	eax, esi
 29628 0000A138 01D0                <1> 	add	eax, edx
 29629 0000A13A AB                  <1> 	stosd  ; eax = virtual address
 29630 0000A13B FE0D[BECE0000]      <1> 	dec	byte [argc]
 29631 0000A141 7407                <1> 	jz	short sysexec_13
 29632                              <1> sysexec_12:
 29633 0000A143 AC                  <1> 	lodsb
 29634 0000A144 20C0                <1> 	and	al, al
 29635 0000A146 75FB                <1> 	jnz	short sysexec_12
 29636 0000A148 EBEC                <1> 	jmp	short sysexec_11
 29637                              <1> 	;
 29638                              <1> 	; 1:
 29639                              <1> 		; mov (sp)+,r5 / r5 now contains address of list of 
 29640                              <1> 			     ; / pointers to arguments to be passed
 29641                              <1> 		; mov $1,u.quit / u.quit determines handling of quits;
 29642                              <1> 			      ; / u.quit = 1 take quit
 29643                              <1> 		; mov $1,u.intr / u.intr determines handling of 
 29644                              <1> 			     ; / interrupts; u.intr = 1 take interrupt
 29645                              <1> 		; mov $rtssym,30 / emt trap vector set to take 
 29646                              <1> 			       ; / system routine
 29647                              <1> 		; mov $fpsym,*10 / reserved instruction trap vector 
 29648                              <1> 			       ; / set to take system routine
 29649                              <1> 		; mov $sstack,sp / stack space used during swapping
 29650                              <1> 		; mov r5,-(sp) / save arguments pointer on stack
 29651                              <1> 		; mov $ecore,r5 / r5 has end of core
 29652                              <1> 		; mov $core,r4 / r4 has start of users core
 29653                              <1> 		; mov r4,u.base / u.base has start of users core
 29654                              <1> 		; mov (sp),r2 / move arguments list pointer into r2
 29655                              <1> 	; 1:
 29656                              <1> 		; tst (r2)+ / argument char = "nul"
 29657                              <1> 		; bne 1b
 29658                              <1> 		; tst -(r2) / decrement r2 by 2; r2 has addr of 
 29659                              <1> 			  ; / end of argument pointer list
 29660                              <1> 	; 1:
 29661                              <1> 	     ; / move arguments to bottom of users core
 29662                              <1> 		; mov -(r2),r3 / (r3) last non zero argument ptr
 29663                              <1> 		; cmp r2,(sp) / is r2 = beginning of argument
 29664                              <1> 			    ; / ptr list
 29665                              <1> 		; blo 1f / branch to 1f when all arguments
 29666                              <1> 		       ; / are moved
 29667                              <1> 		; mov -(r2),r3 / (r3) last non zero argument ptr
 29668                              <1> 	; 2:
 29669                              <1> 		; tstb (r3)+
 29670                              <1> 		; bne 2b / scan argument for \0 (nul)
 29671                              <1> 
 29672                              <1> 	; 2:
 29673                              <1> 		; movb -(r3),-(r5) / move argument char 
 29674                              <1> 				 ; / by char starting at "ecore"
 29675                              <1> 		; cmp r3,(r2) / moved all characters in 
 29676                              <1> 			    ; / this argument
 29677                              <1> 		; bhi 2b / branch 2b if not
 29678                              <1> 		; mov r5,(r4)+ / move r5 into top of users core;
 29679                              <1> 			     ; / r5 has pointer to nth arg
 29680                              <1> 		; br 1b / string
 29681                              <1> 	; 1:
 29682                              <1> 		; clrb -(r5)
 29683                              <1> 		; bic $1,r5 / make r5 even, r5 points to 
 29684                              <1> 			; / last word of argument strings
 29685                              <1> 		; mov $core,r2
 29686                              <1> 	
 29687                              <1> 	; 1: / move argument pointers into core following 
 29688                              <1> 	      ; / argument strings
 29689                              <1> 		; cmp r2,r4
 29690                              <1> 		; bhis 1f / branch to 1f when all pointers
 29691                              <1> 			; / are moved
 29692                              <1> 		; mov (r2)+,-(r5)
 29693                              <1> 		; br 1b
 29694                              <1> 	; 1:
 29695                              <1> 		; sub $core,r4 / gives number of arguments *2
 29696                              <1> 		; asr r4 / divide r4 by 2 to calculate 
 29697                              <1> 		       ; / the number of args stored
 29698                              <1> 		; mov r4,-(r5) / save number of arguments ahead
 29699                              <1> 			     ; / of the argument pointers
 29700                              <1> sysexec_13:
 29701                              <1> 	; 19/10/2015
 29702                              <1> 	; 18/10/2015
 29703                              <1> 	; 29/07/2015
 29704                              <1> 	; 25/07/2015
 29705                              <1> 	; 24/07/2015
 29706                              <1> 	; 20/07/2015
 29707                              <1> 	; 25/06/2015
 29708                              <1> 	; 24/06/2015
 29709                              <1> 	; 23/06/2015
 29710                              <1> 	;
 29711                              <1> 	; moving arguments to [ecore] is OK here..
 29712                              <1> 	; 18/10/2015
 29713 0000A14A 89EC                <1> 	mov 	esp, ebp ; (**) restore kernel stack pointer
 29714                              <1> 	; ebx = beginning addres of argument list pointers
 29715                              <1> 	;	in user's stack
 29716                              <1> 	; 19/10/2015
 29717 0000A14C 2B1D[B4CE0000]      <1> 	sub 	ebx, [ecore]
 29718 0000A152 81C300F0BFFF        <1> 	add     ebx, (ECORE - PAGE_SIZE)
 29719                              <1> 			; end of core - 4096 (last page)
 29720                              <1> 			; (virtual address)
 29721 0000A158 891D[C0CE0000]      <1> 	mov	[argv], ebx
 29722 0000A15E 891D[6CCE0000]      <1> 	mov	[u.break], ebx ; available user memory
 29723                              <1> 	;
 29724 0000A164 29C0                <1> 	sub	eax, eax
 29725 0000A166 C705[64CE0000]2000- <1> 	mov	dword [u.count], 32 ; Executable file header size
 29726 0000A16E 0000                <1>
 29727                              <1> 		; mov $14,u.count
 29728 0000A170 C705[50CE0000]-     <1> 	mov	dword [u.fofp], u.off
 29729 0000A176 [5CCE0000]          <1>
 29730                              <1> 		; mov $u.off,u.fofp
 29731 0000A17A A3[5CCE0000]        <1> 	mov	[u.off], eax ; 0
 29732                              <1> 		; clr u.off / set offset in file to be read to zero
 29733                              <1> 	; 25/07/2015
 29734 0000A17F A3[60CE0000]        <1> 	mov	[u.base], eax ; 0, start of user's core (virtual)
 29735                              <1> 	; 25/06/2015 
 29736 0000A184 66A1[22CE0000]      <1> 	mov	ax, [ii]
 29737                              <1> 	; AX = i-number of the executable file
 29738 0000A18A E892090000          <1> 	call	readi
 29739                              <1> 		; jsr r0,readi / read in first six words of 
 29740                              <1> 			; / user's file, starting at $core
 29741                              <1> 		; mov sp,r5 / put users stack address in r5
 29742                              <1> 		; sub $core+40.,r5 / subtract $core +40, 
 29743                              <1> 				; / from r5 (leaves number of words
 29744                              <1> 				; / less 26 available for
 29745                              <1> 			     	; / program in user core
 29746                              <1> 		; mov r5,u.count /
 29747                              <1> 	; 25/06/2015
 29748 0000A18F 8B0D[6CCE0000]      <1> 	mov	ecx, [u.break] ; top of user's stack (physical addr.)
 29749 0000A195 890D[64CE0000]      <1> 	mov	[u.count], ecx ; save for overrun check
 29750                              <1> 	;
 29751 0000A19B 8B0D[68CE0000]      <1> 	mov	ecx, [u.nread]
 29752 0000A1A1 890D[6CCE0000]      <1> 	mov	[u.break], ecx ; virtual address (offset from start)
 29753 0000A1A7 80F920              <1> 	cmp	cl, 32
 29754 0000A1AA 7540                <1>         jne     short sysexec_15
 29755                              <1> 	;:
 29756                              <1> 	; 25/06/2015
 29757                              <1> 	; Retro UNIX 386 v1 (32 bit) executable file header format
 29758                              <1> 	; 18/10/2015
 29759 0000A1AC 8B35[B0CE0000]      <1> 	mov	esi, [pcore] ; start address of user's core memory 
 29760                              <1> 		             ; (phys. start addr. of the exec. file)
 29761 0000A1B2 AD                  <1> 	lodsd
 29762 0000A1B3 663DEB1E            <1> 	cmp	ax, 1EEBh ; EBH, 1Eh -> jump to +32
 29763 0000A1B7 7533                <1> 	jne	short sysexec_15
 29764                              <1> 		; cmp core,$405 / br .+14 is first instruction 
 29765                              <1> 			      ; / if file is standard a.out format
 29766                              <1> 		; bne 1f / branch, if not standard format
 29767 0000A1B9 AD                  <1> 	lodsd
 29768 0000A1BA 89C1                <1> 	mov	ecx, eax ; text (code) section size
 29769 0000A1BC AD                  <1> 	lodsd
 29770 0000A1BD 01C1                <1> 	add	ecx, eax ; + data section size (initialized data)
 29771                              <1> 		; mov core+2,r5 / put 2nd word of users program in r5;
 29772                              <1> 		              ; / number of bytes in program text	
 29773                              <1> 		; sub $14,r5 / subtract 12
 29774 0000A1BF 89CB                <1> 	mov	ebx, ecx
 29775                              <1> 	;
 29776                              <1> 	; 25/06/2015
 29777                              <1> 	; NOTE: These are for next versions of Retro UNIX 386
 29778                              <1> 	;	and SINGLIX operating systems (as code template).
 29779                              <1> 	;	Current Retro UNIX 386 v1 files can be max. 64KB
 29780                              <1> 	;	due to RUFS (floppy disk file system) restriction...
 29781                              <1> 	;	Overrun is not possible for current version. 	
 29782                              <1> 	;
 29783 0000A1C1 AD                  <1> 	lodsd	
 29784 0000A1C2 01C3                <1> 	add	ebx, eax ; + bss section size (for overrun checking)
 29785 0000A1C4 3B1D[64CE0000]      <1> 	cmp	ebx, [u.count]
 29786 0000A1CA 7711                <1> 	ja	short sysexec_14  ; program overruns stack !
 29787                              <1> 	;
 29788                              <1> 	; 24/07/2015
 29789                              <1> 	; add bss section size to [u.break]
 29790 0000A1CC 0105[6CCE0000]      <1> 	add 	[u.break], eax
 29791                              <1> 	;
 29792 0000A1D2 83E920              <1> 	sub	ecx, 32  ; header size (already loaded)
 29793                              <1> 	;cmp	ecx, [u.count]
 29794                              <1> 	;jnb	short sysexec_16
 29795                              <1> 		; cmp r5,u.count /
 29796                              <1> 		; bgt 1f / branch if r5 greater than u.count
 29797 0000A1D5 890D[64CE0000]      <1> 	mov	[u.count], ecx ; required read count
 29798                              <1> 		; mov r5,u.count
 29799                              <1> 	;
 29800 0000A1DB EB2A                <1> 	jmp	short sysexec_16
 29801                              <1> 	;
 29802                              <1> sysexec_14:
 29803                              <1> 	; 23/06/2015
 29804                              <1> 	; insufficient (out of) memory
 29805 0000A1DD C705[95CE0000]0100- <1> 	mov	dword [u.error], ERR_MINOR_IM ; 1
 29806 0000A1E5 0000                <1>
 29807 0000A1E7 E9D8F3FFFF          <1> 	jmp	error
 29808                              <1> 	;
 29809                              <1> sysexec_15:
 29810                              <1> 	; 25/06/2015
 29811 0000A1EC 0FB715[1ACB0000]    <1>         movzx   edx, word [i.size] ; file size
 29812 0000A1F3 29CA                <1> 	sub	edx, ecx ; file size - loaded bytes
 29813 0000A1F5 7627                <1> 	jna	short sysexec_17 ; no need to next read
 29814 0000A1F7 01D1                <1> 	add	ecx, edx ; [i.size]
 29815 0000A1F9 3B0D[64CE0000]      <1> 	cmp	ecx, [u.count] ; overrun check (!)
 29816 0000A1FF 77DC                <1> 	ja	short sysexec_14
 29817 0000A201 8915[64CE0000]      <1> 	mov	[u.count], edx
 29818                              <1> sysexec_16:
 29819 0000A207 66A1[22CE0000]      <1> 	mov	ax, [ii] ; i-number
 29820 0000A20D E80F090000          <1> 	call	readi
 29821                              <1> 		; add core+10,u.nread / add size of user data area 
 29822                              <1> 		                    ; / to u.nread
 29823                              <1> 		; br 2f
 29824                              <1> 	; 1:
 29825                              <1> 		; jsr r0,readi / read in rest of file
 29826                              <1> 	; 2:
 29827 0000A212 8B0D[68CE0000]      <1> 	mov	ecx, [u.nread]
 29828 0000A218 010D[6CCE0000]      <1> 	add	[u.break], ecx
 29829                              <1> 		; mov u.nread,u.break / set users program break to end of 
 29830                              <1> 				    ; / user code
 29831                              <1> 		; add $core+14,u.break / plus data area
 29832                              <1> sysexec_17: ; 20/07/2015
 29833                              <1> 	;mov	ax, [ii] ;rgc i-number
 29834 0000A21E E804090000          <1> 	call	iclose
 29835                              <1> 		; jsr r0,iclose / does nothing
 29836 0000A223 31C0                <1>         xor     eax, eax
 29837 0000A225 FEC0                <1> 	inc	al
 29838 0000A227 66A3[84CE0000]      <1> 	mov	[u.intr], ax ; 1 (interrupt/time-out is enabled)
 29839 0000A22D 66A3[86CE0000]      <1> 	mov	[u.quit], ax ; 1 ('crtl+brk' signal is enabled) 
 29840                              <1> 	; 02/07/2015
 29841 0000A233 833D[9DCE0000]00    <1>         cmp	dword [u.ppgdir], 0  ; is the caller sys_init (kernel) ?
 29842 0000A23A 770C                <1> 	ja	short sysexec_18 ; no, the caller is user process
 29843                              <1> 	; If the caller is kernel (sys_init), 'sysexec' will come here
 29844 0000A23C 8B15[E8BD0000]      <1> 	mov	edx, [k_page_dir] ; kernel's page directory
 29845 0000A242 8915[9DCE0000]      <1> 	mov	[u.ppgdir], edx ; next time 'sysexec' must not come here 
 29846                              <1> sysexec_18:
 29847                              <1> 	; 18/10/2015
 29848                              <1> 	; 05/08/2015
 29849                              <1> 	; 29/07/2015
 29850 0000A248 8B2D[C0CE0000]      <1> 	mov	ebp, [argv] ; user's stack pointer must point to argument
 29851                              <1> 			    ; list pointers (argument count)
 29852 0000A24E FA                  <1> 	cli
 29853 0000A24F 8B25[84BD0000]      <1>         mov     esp, [tss.esp0]  ; ring 0 (kernel) stack pointer
 29854                              <1> 	;mov   	esp, [u.sp] ; Restore Kernel stack
 29855                              <1> 			    ; for this process	 
 29856                              <1> 	;add	esp, 20 ; --> EIP, CS, EFLAGS, ESP, SS
 29857                              <1> 	;xor	eax, eax ; 0
 29858 0000A255 FEC8                <1> 	dec	al ; eax = 0
 29859 0000A257 66BA2300            <1> 	mov	dx, UDATA
 29860 0000A25B 6652                <1> 	push	dx  ; user's stack segment
 29861 0000A25D 55                  <1> 	push	ebp ; user's stack pointer
 29862                              <1> 		    ; (points to number of arguments)
 29863 0000A25E FB                  <1> 	sti
 29864 0000A25F 9C                  <1> 	pushfd	; EFLAGS
 29865                              <1> 		; Set IF for enabling interrupts in user mode	
 29866                              <1> 	;or	dword [esp], 200h 
 29867                              <1> 	;
 29868                              <1> 	;mov	bx, UCODE
 29869                              <1> 	;push	bx ; user's code segment
 29870 0000A260 6A1B                <1> 	push	UCODE
 29871                              <1> 	;push	0
 29872 0000A262 50                  <1> 	push	eax ; EIP (=0) - start address -	
 29873                              <1> 		; clr -(r5) / popped into ps when rti in 
 29874                              <1> 			  ; / sysrele is executed
 29875                              <1> 		; mov $core,-(r5) / popped into pc when rti 
 29876                              <1> 		                ; / in sysrele is executed
 29877                              <1> 		;mov r5,0f / load second copyz argument
 29878                              <1> 		;tst -(r5) / decrement r5
 29879 0000A263 8925[38CE0000]      <1> 	mov	[u.sp], esp ; 29/07/2015
 29880                              <1> 	; 05/08/2015
 29881                              <1> 	; Remedy of a General Protection Fault during 'iretd' is here !
 29882                              <1> 	; ('push dx' would cause to general protection fault, 
 29883                              <1> 	; after 'pop ds' etc.)
 29884                              <1> 	;
 29885                              <1> 	;; push dx ; ds (UDATA)
 29886                              <1> 	;; push dx ; es (UDATA)
 29887                              <1> 	;; push dx ; fs (UDATA)
 29888                              <1> 	;; push dx ; gs (UDATA)
 29889                              <1> 	;
 29890                              <1> 	; This is a trick to prevent general protection fault
 29891                              <1> 	; during 'iretd' intruction at the end of 'sysrele' (in u1.s):
 29892 0000A269 8EC2                <1> 	mov 	es, dx ; UDATA
 29893 0000A26B 06                  <1> 	push 	es ; ds (UDATA)
 29894 0000A26C 06                  <1> 	push 	es ; es (UDATA)
 29895 0000A26D 06                  <1> 	push 	es ; fs (UDATA)
 29896 0000A26E 06                  <1> 	push	es ; gs (UDATA)
 29897 0000A26F 66BA1000            <1> 	mov	dx, KDATA
 29898 0000A273 8EC2                <1> 	mov	es, dx
 29899                              <1> 	;
 29900                              <1> 	;; pushad simulation
 29901 0000A275 89E5                <1> 	mov	ebp, esp ; esp before pushad
 29902 0000A277 50                  <1> 	push	eax ; eax (0)
 29903 0000A278 50                  <1> 	push	eax ; ecx (0)
 29904 0000A279 50                  <1> 	push	eax ; edx (0)
 29905 0000A27A 50                  <1> 	push	eax ; ebx (0)
 29906 0000A27B 55                  <1> 	push	ebp ; esp before pushad
 29907 0000A27C 50                  <1> 	push	eax ; ebp (0)
 29908 0000A27D 50                  <1> 	push	eax ; esi (0)		
 29909 0000A27E 50                  <1> 	push	eax ; edi (0)	
 29910                              <1> 	;
 29911 0000A27F A3[40CE0000]        <1> 	mov	[u.r0], eax ; eax = 0
 29912 0000A284 8925[3CCE0000]      <1> 	mov	[u.usp], esp
 29913                              <1> 		; mov r5,u.r0 /
 29914                              <1> 		; sub $16.,r5 / skip 8 words
 29915                              <1> 		; mov r5,u.sp / assign user stack pointer value, 
 29916                              <1> 		;             / effectively zeroes all regs
 29917                              <1> 			    ; / when sysrele is executed
 29918                              <1> 		; jsr r0,copyz; core; 0:0 / zero user's core
 29919                              <1> 		; clr u.break
 29920                              <1> 		; mov r5,sp / point sp to user's stack
 29921                              <1> 	;
 29922 0000A28A E958F3FFFF          <1> 	jmp	sysret0
 29923                              <1> 	;jmp	sysret
 29924                              <1> 		; br sysret3 / return to core image at $core
 29925                              <1> 
 29926                              <1> get_argp:
 29927                              <1> 	; 18/10/2015 (nbase, ncount)
 29928                              <1> 	; 21/07/2015
 29929                              <1> 	; 24/06/2015 (Retro UNIX 386 v1)
 29930                              <1> 	; Get (virtual) address of argument from user's core memory
 29931                              <1> 	;
 29932                              <1> 	; INPUT:
 29933                              <1> 	;	esi = virtual address of argument pointer
 29934                              <1> 	; OUTPUT:
 29935                              <1> 	;	eax = virtual address of argument
 29936                              <1> 	;
 29937                              <1> 	; Modified registers: EAX, EBX, ECX, EDX, ESI 
 29938                              <1> 	;
 29939 0000A28F 833D[9DCE0000]00    <1>  	cmp     dword [u.ppgdir], 0 ; /etc/init ?
 29940                              <1> 				    ; (the caller is kernel)
 29941 0000A296 7667                <1>         jna     short get_argpk 
 29942                              <1> 	;
 29943 0000A298 89F3                <1>      	mov	ebx, esi
 29944 0000A29A E8FB94FFFF          <1> 	call	get_physical_addr ; get physical address
 29945 0000A29F 0F8289000000        <1>         jc      get_argp_err
 29946 0000A2A5 A3[B8CE0000]        <1> 	mov 	[nbase], eax ; physical address	
 29947 0000A2AA 66890D[BCCE0000]    <1> 	mov	[ncount], cx ; remain byte count in page (1-4096)
 29948 0000A2B1 B804000000          <1> 	mov	eax, 4 ; 21/07/2015
 29949 0000A2B6 6639C1              <1> 	cmp	cx, ax ; 4
 29950 0000A2B9 735D                <1> 	jnb	short get_argp2
 29951 0000A2BB 89F3                <1> 	mov	ebx, esi
 29952 0000A2BD 01CB                <1> 	add	ebx, ecx
 29953 0000A2BF E8D694FFFF          <1> 	call	get_physical_addr ; get physical address
 29954 0000A2C4 7268                <1> 	jc	short get_argp_err
 29955                              <1> 	;push	esi
 29956 0000A2C6 89C6                <1> 	mov	esi, eax
 29957 0000A2C8 66870D[BCCE0000]    <1> 	xchg	cx, [ncount]
 29958 0000A2CF 8735[B8CE0000]      <1> 	xchg	esi, [nbase]
 29959 0000A2D5 B504                <1> 	mov	ch, 4
 29960 0000A2D7 28CD                <1> 	sub	ch, cl
 29961                              <1> get_argp0:
 29962 0000A2D9 AC                  <1> 	lodsb
 29963 0000A2DA 6650                <1> 	push	ax
 29964 0000A2DC FEC9                <1> 	dec	cl
 29965 0000A2DE 75F9                <1>         jnz     short get_argp0
 29966 0000A2E0 8B35[B8CE0000]      <1> 	mov	esi, [nbase]
 29967                              <1> 	; 21/07/2015
 29968 0000A2E6 0FB6C5              <1> 	movzx	eax, ch
 29969 0000A2E9 0105[B8CE0000]      <1> 	add	[nbase], eax
 29970 0000A2EF 662905[BCCE0000]    <1> 	sub	[ncount], ax
 29971                              <1> get_argp1:
 29972 0000A2F6 AC                  <1> 	lodsb
 29973 0000A2F7 FECD                <1> 	dec	ch
 29974 0000A2F9 743D                <1>         jz      short get_argp3
 29975 0000A2FB 6650                <1>         push	ax
 29976 0000A2FD EBF7                <1> 	jmp     short get_argp1
 29977                              <1> get_argpk:
 29978                              <1> 	; Argument is in kernel's memory space
 29979 0000A2FF 66C705[BCCE0000]00- <1> 	mov	word [ncount], PAGE_SIZE ; 4096
 29980 0000A307 10                  <1>
 29981 0000A308 8935[B8CE0000]      <1> 	mov	[nbase], esi
 29982 0000A30E 8305[B8CE0000]04    <1> 	add	dword [nbase], 4
 29983 0000A315 8B06                <1> 	mov	eax, [esi] ; virtual addr. = physcal addr.
 29984 0000A317 C3                  <1> 	retn
 29985                              <1> get_argp2:
 29986                              <1> 	; 21/07/2015
 29987                              <1> 	;mov	eax, 4
 29988 0000A318 8B15[B8CE0000]      <1> 	mov 	edx, [nbase] ; 18/10/2015
 29989 0000A31E 0105[B8CE0000]      <1> 	add	[nbase], eax
 29990 0000A324 662905[BCCE0000]    <1> 	sub	[ncount], ax
 29991                              <1> 	;
 29992 0000A32B 8B02                <1> 	mov	eax, [edx]
 29993 0000A32D C3                  <1> 	retn
 29994                              <1> get_argp_err:
 29995 0000A32E A3[95CE0000]        <1> 	mov	[u.error], eax
 29996 0000A333 E98CF2FFFF          <1> 	jmp	error
 29997                              <1> get_argp3:
 29998 0000A338 B103                <1> 	mov	cl, 3
 29999                              <1> get_argp4:
 30000 0000A33A C1E008              <1> 	shl	eax, 8
 30001 0000A33D 665A                <1> 	pop	dx
 30002 0000A33F 88D0                <1> 	mov 	al, dl
 30003 0000A341 E2F7                <1>         loop    get_argp4
 30004                              <1> 	;pop	esi
 30005 0000A343 C3                  <1> 	retn	
 30006                              <1> 
 30007                              <1> sysfstat: 
 30008                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30009                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 30010                              <1> 	;
 30011                              <1> 	; 'sysfstat' is identical to 'sysstat' except that it operates
 30012                              <1> 	; on open files instead of files given by name. It puts the
 30013                              <1> 	; buffer address on the stack, gets the i-number and
 30014                              <1> 	; checks to see if the file is open for reading or writing.
 30015                              <1> 	; If the file is open for writing (i-number is negative)
 30016                              <1> 	; the i-number is set positive and a branch into 'sysstat'
 30017                              <1> 	; is made.	
 30018                              <1> 	;
 30019                              <1> 	; Calling sequence:
 30020                              <1> 	;	sysfstat; buf
 30021                              <1> 	; Arguments:
 30022                              <1> 	;	buf - buffer address
 30023                              <1> 	;
 30024                              <1> 	; Inputs: *u.r0 - file descriptor
 30025                              <1> 	; Outputs: buffer is loaded with file information
 30026                              <1> 	; ...............................................................
 30027                              <1> 	;				
 30028                              <1> 	; Retro UNIX 8086 v1 modification:
 30029                              <1> 	;       'sysfstat' system call has two arguments; so,
 30030                              <1> 	;	* 1st argument, file descriptor is in BX register
 30031                              <1> 	;	* 2nd argument, buf is pointed to by CX register
 30032                              <1> 
 30033                              <1> 	; / set status of open file
 30034                              <1> 		; jsr r0,arg; u.off / put buffer address in u.off
 30035 0000A344 51                  <1> 	push	ecx
 30036                              <1> 		; mov u.off,-(sp) / put buffer address on the stack
 30037                              <1> 		; mov *u.r0,r1 / put file descriptor in r1
 30038                              <1> 		; jsr r0,getf / get the files i-number
 30039                              <1> 	; BX = file descriptor (file number)
 30040 0000A345 E8FF000000          <1> 	call	getf1
 30041 0000A34A 6621C0              <1> 	and	ax, ax ; i-number of the file
 30042                              <1> 		; tst	r1 / is it 0?
 30043                              <1> 	;jz	error
 30044                              <1> 		; beq error3 / yes, error
 30045 0000A34D 750F                <1> 	jnz	short sysfstat1
 30046 0000A34F C705[95CE0000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
 30047 0000A357 0000                <1>
 30048 0000A359 E966F2FFFF          <1> 	jmp	error
 30049                              <1> sysfstat1:
 30050 0000A35E 80FC80              <1> 	cmp	ah, 80h
 30051 0000A361 7223                <1>         jb      short sysstat1
 30052                              <1> 		; bgt 1f / if i-number is negative (open for writing)
 30053 0000A363 66F7D8              <1> 	neg	ax
 30054                              <1> 		; neg r1 / make it positive, then branch
 30055 0000A366 EB1E                <1> 	jmp	short sysstat1
 30056                              <1> 		; br 1f / to 1f
 30057                              <1> sysstat:
 30058                              <1> 	; 18/10/2015
 30059                              <1> 	; 07/10/2015
 30060                              <1> 	; 02/09/2015
 30061                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30062                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 30063                              <1> 	;
 30064                              <1> 	; 'sysstat' gets the status of a file. Its arguments are the
 30065                              <1> 	; name of the file and buffer address. The buffer is 34 bytes
 30066                              <1> 	; long and information about the file placed in it.	
 30067                              <1> 	; sysstat calls 'namei' to get the i-number of the file.
 30068                              <1> 	; Then 'iget' is called to get i-node in core. The buffer
 30069                              <1> 	; is then loaded and the results are given in the UNIX
 30070                              <1> 	; Programmers Manual sysstat (II).	
 30071                              <1> 	;
 30072                              <1> 	; Calling sequence:
 30073                              <1> 	;	sysstat; name; buf
 30074                              <1> 	; Arguments:
 30075                              <1> 	;	name - points to the name of the file
 30076                              <1> 	;	buf - address of a 34 bytes buffer
 30077                              <1> 	; Inputs: -
 30078                              <1> 	; Outputs: buffer is loaded with file information
 30079                              <1> 	; ...............................................................
 30080                              <1> 	;				
 30081                              <1> 	; Retro UNIX 8086 v1 modification: 
 30082                              <1> 	;       'sysstat' system call has two arguments; so,
 30083                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
 30084                              <1> 	;	to get sysstat system call arguments from the user;
 30085                              <1> 	;	* 1st argument, name is pointed to by BX register
 30086                              <1> 	;	* 2nd argument, buf is pointed to by CX register
 30087                              <1> 	;
 30088                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
 30089                              <1> 	;	      arguments which were in these registers;
 30090                              <1> 	;	      but, it returns by putting the 1st argument
 30091                              <1> 	;	      in 'u.namep' and the 2nd argument
 30092                              <1> 	;	      on top of stack. (1st argument is offset of the
 30093                              <1> 	;	      file/path name in the user's program segment.)		 	
 30094                              <1> 	
 30095                              <1> 	; / ; name of file; buffer - get files status
 30096                              <1> 		; jsr r0,arg2 / get the 2 arguments
 30097 0000A368 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 30098 0000A36E 51                  <1> 	push	ecx
 30099 0000A36F E80C010000          <1> 	call	namei
 30100                              <1> 		; jsr r0,namei / get the i-number for the file
 30101                              <1> 	;jc	error
 30102                              <1> 		; br error3 / no such file, error
 30103 0000A374 7310                <1> 	jnc	short sysstat1
 30104                              <1> 	; pop 	ecx
 30105                              <1> sysstat_err0:
 30106                              <1> 	; 'file not found !' error
 30107 0000A376 C705[95CE0000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 30108 0000A37E 0000                <1>
 30109 0000A380 E93FF2FFFF          <1> 	jmp	error
 30110                              <1> 
 30111 0000A385 00                  <1> statx: db 0
 30112                              <1> 
 30113                              <1> sysstat1: ; 1:
 30114 0000A386 E891070000          <1> 	call	iget
 30115                              <1> 		; jsr r0,iget / get the i-node into core
 30116                              <1> 	; 07/10/2015 (ax = [ii], inode number)
 30117                              <1> 	; 02/09/2015
 30118 0000A38B 8F05[60CE0000]      <1> 	pop	dword [u.base]
 30119                              <1> 		; mov (sp)+,r3 / move u.off to r3 (points to buffer)
 30120 0000A391 E858000000          <1> 	call	sysstat_gpa ; get physical address
 30121 0000A396 730A                <1> 	jnc 	short sysstat2
 30122                              <1> sysstat_err1:
 30123 0000A398 A3[95CE0000]        <1> 	mov	dword [u.error], eax ; error code
 30124 0000A39D E922F2FFFF          <1> 	jmp	error
 30125                              <1> sysstat2:
 30126 0000A3A2 A0[22CE0000]        <1> 	mov 	al, [ii] ; 07/10/2015 (result of 'iget' call, above)
 30127 0000A3A7 AA                  <1> 	stosb
 30128 0000A3A8 FF05[60CE0000]      <1> 	inc 	dword [u.base]
 30129 0000A3AE 6649                <1> 	dec 	cx
 30130 0000A3B0 7505                <1> 	jnz	short sysstat3
 30131 0000A3B2 E837000000          <1> 	call	sysstat_gpa
 30132                              <1> 	;jc	short sysstat_err1
 30133                              <1> sysstat3:
 30134 0000A3B7 A0[23CE0000]        <1> 	mov 	al, [ii+1] ; 07/10/2015 (result of 'iget' call, above)
 30135 0000A3BC AA                  <1> 	stosb
 30136                              <1> 		; mov r1,(r3)+ / put i-number in 1st word of buffer
 30137 0000A3BD FF05[60CE0000]      <1> 	inc 	dword [u.base]
 30138                              <1> 	;dec 	word [u.pcount]
 30139 0000A3C3 6649                <1> 	dec	cx
 30140 0000A3C5 7505                <1> 	jnz	short sysstat4
 30141 0000A3C7 E822000000          <1> 	call	sysstat_gpa
 30142                              <1> 	;jc	short sysstat_err1	
 30143                              <1> sysstat4:
 30144 0000A3CC BE[16CB0000]        <1> 	mov	esi, inode
 30145                              <1> 		; mov $inode,r2 / r2 points to i-node
 30146                              <1> sysstat5: ; 1:
 30147 0000A3D1 A4                  <1> 	movsb
 30148                              <1> 		; mov (r2)+,(r3)+ / move rest of i-node to buffer
 30149 0000A3D2 FF05[60CE0000]      <1> 	inc 	dword [u.base]
 30150                              <1> 	;dec 	word [u.pcount]
 30151 0000A3D8 6649                <1> 	dec	cx
 30152 0000A3DA 7505                <1> 	jnz	short sysstat6
 30153 0000A3DC E80D000000          <1> 	call	sysstat_gpa
 30154                              <1> 	;jc	short sysstat_err1
 30155                              <1> sysstat6:		
 30156 0000A3E1 81FE[36CB0000]      <1> 	cmp	esi, inode + 32
 30157                              <1> 		; cmp r2,$inode+32 / done?
 30158 0000A3E7 75E8                <1> 	jne	short sysstat5
 30159                              <1> 		; bne 1b / no, go back
 30160 0000A3E9 E9F6F1FFFF          <1> 	jmp	sysret
 30161                              <1> 		; br sysret3 / return through sysret
 30162                              <1> 	;
 30163                              <1> sysstat_gpa: ; get physical address of file status buffer
 30164                              <1> 	; 02/09/2015
 30165 0000A3EE 8B1D[60CE0000]      <1> 	mov 	ebx, [u.base]
 30166                              <1> 	; 07/10/2015
 30167 0000A3F4 E8A193FFFF          <1> 	call	get_physical_addr ; get physical address
 30168                              <1> 	;jc	short sysstat_gpa1
 30169 0000A3F9 729D                <1> 	jc	short sysstat_err1
 30170                              <1> 	; 18/10/2015
 30171 0000A3FB 89C7                <1> 	mov	edi, eax ; physical address
 30172                              <1> 	;mov	[u.pcount], cx ; remain bytes in page
 30173                              <1> ;sysstat_gpa1:
 30174 0000A3FD C3                  <1> 	retn
 30175                              <1> 
 30176                              <1> fclose:
 30177                              <1> 	; 18/06/2015 (Retro UNIX 386 v1 - Beginning)
 30178                              <1> 	;            (32 bit offset pointer modification)
 30179                              <1> 	; 19/04/2013 - 12/01/2014 (Retro UNIX 8086 v1)
 30180                              <1> 	;
 30181                              <1> 	; Given the file descriptor (index to the u.fp list)
 30182                              <1> 	; 'fclose' first gets the i-number of the file via 'getf'.
 30183                              <1> 	; If i-node is active (i-number > 0) the entry in 
 30184                              <1> 	; u.fp list is cleared. If all the processes that opened
 30185                              <1> 	; that file close it, then fsp etry is freed and the file
 30186                              <1> 	; is closed. If not a return is taken. 
 30187                              <1> 	; If the file has been deleted while open, 'anyi' is called
 30188                              <1> 	; to see anyone else has it open, i.e., see if it is appears
 30189                              <1> 	; in another entry in the fsp table. Upon return from 'anyi'
 30190                              <1> 	; a check is made to see if the file is special.	
 30191                              <1> 	;
 30192                              <1> 	; INPUTS ->
 30193                              <1> 	;    r1 - contains the file descriptor (value=0,1,2...)
 30194                              <1> 	;    u.fp - list of entries in the fsp table
 30195                              <1> 	;    fsp - table of entries (4 words/entry) of open files.	 
 30196                              <1> 	; OUTPUTS ->
 30197                              <1> 	;    r1 - contains the same file descriptor
 30198                              <1> 	;    r2 - contains i-number
 30199                              <1> 	;
 30200                              <1> 	; ((AX = R1))
 30201                              <1> 	; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))
 30202                              <1> 	;
 30203                              <1> 	; Retro UNIX 8086 v1 modification : CF = 1
 30204                              <1> 	;              if i-number of the file is 0. (error)  	
 30205                              <1> 	;
 30206 0000A3FE 0FB7D0              <1> 	movzx	edx, ax ; **
 30207 0000A401 6650                <1> 	push	ax ; ***
 30208                              <1> 		; mov r1,-(sp) / put r1 on the stack (it contains 
 30209                              <1> 			     ; / the index to u.fp list)
 30210 0000A403 E83F000000          <1> 	call	getf
 30211                              <1> 		; jsr r0,getf / r1 contains i-number, 
 30212                              <1> 			    ; / cdev has device =, u.fofp 
 30213                              <1> 			    ; / points to 3rd word of fsp entry
 30214 0000A408 6683F801            <1> 	cmp	ax, 1 ; r1
 30215                              <1> 		; tst r1 / is i-number 0?
 30216 0000A40C 7236                <1> 	jb	short fclose_2
 30217                              <1> 		; beq 1f / yes, i-node not active so return
 30218                              <1> 		; tst (r0)+ / no, jump over error return
 30219 0000A40E 89D3                <1> 	mov	ebx, edx ; **
 30220 0000A410 6689C2              <1> 	mov 	dx, ax ; *
 30221                              <1> 		; mov r1,r2 / move i-number to r2 ;*
 30222                              <1> 		; mov (sp),r1 / restore value of r1 from the stack
 30223                              <1> 			    ; / which is index to u.fp ; **
 30224 0000A413 C683[46CE0000]00    <1> 	mov	byte [ebx+u.fp], 0
 30225                              <1> 		; clrb u.fp(r1) / clear that entry in the u.fp list
 30226 0000A41A 8B1D[50CE0000]      <1> 	mov	ebx, [u.fofp]
 30227                              <1> 		; mov u.fofp,r1 / r1 points to 3rd word in fsp entry
 30228                              <1> fclose_0:
 30229 0000A420 FE4B04              <1> 	dec	byte [ebx+4] ; 18/06/2015
 30230                              <1> 		; decb 2(r1) / decrement the number of processes 
 30231                              <1> 			   ; / that have opened the file
 30232 0000A423 791F                <1> 	jns	short fclose_2 ; jump if not negative (jump if bit 7 is 0)	 
 30233                              <1> 		; bge 1f / if all processes haven't closed the file, return
 30234                              <1> 	;
 30235 0000A425 6652                <1> 	push	dx ;*
 30236                              <1> 		; mov r2,-(sp) / put r2 on the stack (i-number)
 30237 0000A427 6631C0              <1> 	xor	ax, ax ; 0
 30238 0000A42A 668943FC            <1> 	mov	[ebx-4], ax ; 0
 30239                              <1> 		; clr -4(r1) / clear 1st word of fsp entry
 30240 0000A42E 8A4305              <1> 	mov	al, [ebx+5] ; 18/06/2015
 30241                              <1> 		; tstb	3(r1) / has this file been deleted
 30242 0000A431 20C0                <1> 	and	al, al
 30243 0000A433 7408                <1> 	jz	short fclose_1
 30244                              <1> 		; beq 2f / no, branch
 30245 0000A435 6689D0              <1> 	mov	ax, dx ; *
 30246                              <1> 		; mov r2,r1 / yes, put i-number back into r1
 30247                              <1> 	; AX = inode number
 30248 0000A438 E868040000          <1> 	call	anyi
 30249                              <1> 		; jsr r0,anyi / free all blocks related to i-number
 30250                              <1> 			    ; / check if file appears in fsp again
 30251                              <1> fclose_1: ; 2:
 30252 0000A43D 6658                <1> 	pop	ax ; *
 30253                              <1> 		; mov (sp)+,r1 / put i-number back into r1
 30254 0000A43F E8E3060000          <1> 	call	iclose ; close if it is special file 
 30255                              <1> 		; jsr r0,iclose / check to see if its a special file
 30256                              <1> fclose_2: ; 1:
 30257 0000A444 6658                <1> 	pop	ax ; ***
 30258                              <1> 		; mov (sp)+,r1 / put index to u.fp back into r1
 30259 0000A446 C3                  <1> 	retn
 30260                              <1> 		; rts r0
 30261                              <1> 
 30262                              <1> getf:	; / get the device number and the i-number of an open file
 30263                              <1> 	; 13/05/2015
 30264                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 30265                              <1> 	; 19/04/2013 - 18/11/2013 (Retro UNIX 8086 v1)
 30266                              <1> 	;
 30267 0000A447 89C3                <1> 	mov	ebx, eax
 30268                              <1> getf1: ;; Calling point from 'rw1' (23/05/2013)
 30269 0000A449 83FB0A              <1> 	cmp	ebx, 10
 30270                              <1> 		; cmp r1,$10. / user limited to 10 open files
 30271 0000A44C 730A                <1>         jnb	short getf2 ; 13/05/2015
 30272                              <1> 	;jnb     error
 30273                              <1> 		; bhis error3 / u.fp is table of users open files, 
 30274                              <1> 			    ; / index in fsp table
 30275 0000A44E 8A9B[46CE0000]      <1> 	mov	bl, [ebx+u.fp]
 30276                              <1> 		; movb	u.fp(r1),r1 / r1 contains number of entry 
 30277                              <1> 		                  ; / in fsp table
 30278 0000A454 08DB                <1> 	or	bl, bl
 30279 0000A456 7503                <1> 	jnz	short getf3
 30280                              <1> 	;jz	short getf4
 30281                              <1> 		; beq 1f / if its zero return
 30282                              <1> getf2:
 30283                              <1> 	; 'File not open !' error (ax=0)
 30284 0000A458 29C0                <1> 	sub	eax, eax
 30285 0000A45A C3                  <1> 	retn
 30286                              <1> getf3:	
 30287                              <1> 	; Retro UNIX 386 v1 modification ! (11/05/2015)
 30288                              <1> 	;
 30289                              <1> 	; 'fsp' table (10 bytes/entry)
 30290                              <1> 	; bit 15				   bit 0
 30291                              <1> 	; ---|-------------------------------------------
 30292                              <1> 	; r/w|		i-number of open file
 30293                              <1> 	; ---|-------------------------------------------
 30294                              <1> 	;		   device number
 30295                              <1> 	; -----------------------------------------------
 30296                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
 30297                              <1> 	; -----------------------------------------------
 30298                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
 30299                              <1> 	; ----------------------|------------------------
 30300                              <1> 	;  flag that says file 	| number of processes
 30301                              <1> 	;   has been deleted	| that have file open 
 30302                              <1> 	; ----------------------|------------------------
 30303                              <1> 	;
 30304 0000A45B B80A000000          <1> 	mov	eax, 10
 30305 0000A460 F6E3                <1> 	mul	bl
 30306 0000A462 BB[10CC0000]        <1> 	mov	ebx, fsp - 6 ; the 3rd word in the fsp entry
 30307 0000A467 01C3                <1> 	add	ebx, eax
 30308                              <1> 		; asl r1
 30309                              <1> 		; asl r1 / multiply by 8 to get index into 
 30310                              <1> 		       ; / fsp table entry
 30311                              <1> 		; asl r1
 30312                              <1> 		; add $fsp-4,r1 / r1 is pointing at the 3rd word 
 30313                              <1> 			      ; / in the fsp entry
 30314 0000A469 891D[50CE0000]      <1> 	mov	[u.fofp], ebx
 30315                              <1> 		; mov r1,u.fofp / save address of 3rd word 
 30316                              <1> 			      ; / in fsp entry in u.fofp
 30317 0000A46F 4B                  <1> 	dec	ebx
 30318 0000A470 4B                  <1> 	dec	ebx
 30319 0000A471 668B03              <1> 	mov	ax, [ebx]
 30320                              <1> 	;mov	[cdev], al ; ;;Retro UNIX 8086 v1 ! 
 30321 0000A474 66A3[26CE0000]      <1> 	mov	[cdev], ax ; ;;in fact (!) 
 30322                              <1> 			     ;;dev number is in 1 byte
 30323                              <1> 		; mov -(r1),cdev / remove the device number  cdev
 30324 0000A47A 4B                  <1> 	dec	ebx
 30325 0000A47B 4B                  <1> 	dec	ebx
 30326 0000A47C 668B03              <1> 	mov	ax, [ebx]
 30327                              <1> 		; mov -(r1),r1 / and the i-number  r1
 30328                              <1> getf4:	; 1:
 30329 0000A47F C3                  <1> 	retn
 30330                              <1> 		; rts r0
 30331                              <1> 
 30332                              <1> namei:
 30333                              <1> 	; 04/12/2015 (14 byte file names)
 30334                              <1> 	; 18/10/2015 (nbase, ncount)
 30335                              <1> 	; 12/10/2015
 30336                              <1> 	; 21/08/2015
 30337                              <1> 	; 18/07/2015
 30338                              <1> 	; 02/07/2015
 30339                              <1> 	; 17/06/2015
 30340                              <1> 	; 16/06/2015 (Retro UNIX 386 v1 - Beginning)
 30341                              <1> 	; 24/04/2013 - 31/07/2013 (Retro UNIX 8086 v1)
 30342                              <1> 	;
 30343                              <1> 	; 'namei' takes a file path name and returns i-number of
 30344                              <1> 	; the file in the current directory or the root directory
 30345                              <1> 	; (if the first character of the pathname is '/').	
 30346                              <1> 	;
 30347                              <1> 	; INPUTS ->
 30348                              <1> 	;    u.namep - points to a file path name
 30349                              <1> 	;    u.cdir - i-number of users directory
 30350                              <1> 	;    u.cdev - device number on which user directory resides	
 30351                              <1> 	; OUTPUTS ->
 30352                              <1> 	;    r1 - i-number of file
 30353                              <1> 	;    cdev
 30354                              <1> 	;    u.dirbuf - points to directory entry where a match 
 30355                              <1> 	;               occurs in the search for file path name.
 30356                              <1> 	;	        If no match u.dirb points to the end of 
 30357                              <1> 	;               the directory and r1 = i-number of the current
 30358                              <1> 	;	        directory.	
 30359                              <1> 	; ((AX = R1))
 30360                              <1> 	;
 30361                              <1> 	; (Retro UNIX Prototype : 07/10/2012 - 05/01/2013, UNIXCOPY.ASM)
 30362                              <1>         ; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))  
 30363                              <1> 	;
 30364                              <1> 
 30365 0000A480 66A1[44CE0000]      <1> 	mov	ax, [u.cdir]
 30366                              <1> 		; mov u.cdir,r1 / put the i-number of current directory
 30367                              <1> 			      ; / in r1
 30368 0000A486 668B15[8ACE0000]    <1> 	mov	dx, [u.cdrv]
 30369 0000A48D 668915[26CE0000]    <1> 	mov	[cdev], dx 	    ; NOTE: Retro UNIX 8086 v1 
 30370                              <1> 				    ; device/drive number is in 1 byte, 
 30371                              <1> 				    ; not in 1 word!
 30372                              <1> 		; mov u.cdev,cdev / device number for users directory 
 30373                              <1> 				; / into cdev
 30374                              <1> 	; 12/10/2015
 30375                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 30376                              <1>       	 ; convert virtual (pathname) addr to physical address
 30377 0000A494 E82C010000          <1> 	call    trans_addr_nmbp ; 12/10/2015
 30378                              <1> 		; esi = physical address of [u.namep]
 30379                              <1> 		; ecx = byte count in the page
 30380 0000A499 803E2F              <1> 	cmp	byte [esi], '/'
 30381                              <1> 		; cmpb *u.namep,$'/ / is first char in file name a /
 30382 0000A49C 751E                <1> 	jne	short namei_1
 30383                              <1> 		; bne 1f
 30384 0000A49E FF05[58CE0000]      <1> 	inc	dword [u.namep]
 30385                              <1> 		; inc u.namep / go to next char
 30386 0000A4A4 6649                <1> 	dec	cx ; remain byte count in the page
 30387 0000A4A6 7506                <1> 	jnz	short namei_0
 30388                              <1> 	; 12/10/2015
 30389 0000A4A8 E818010000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
 30390                              <1> 		; esi = physical address (page start + offset)
 30391                              <1> 		; ecx = byte count in the page
 30392 0000A4AD 4E                  <1> 	dec	esi
 30393                              <1> namei_0:
 30394 0000A4AE 46                  <1> 	inc 	esi  ; go to next char
 30395 0000A4AF 66A1[30CE0000]      <1> 	mov	ax, [rootdir] ; 09/07/2013
 30396                              <1> 		; mov rootdir,r1 / put i-number of rootdirectory in r1
 30397 0000A4B5 C605[26CE0000]00    <1> 	mov	byte [cdev], 0
 30398                              <1> 		; clr cdev / clear device number
 30399                              <1> namei_1: ; 1:
 30400 0000A4BC F606FF              <1> 	test	byte [esi], 0FFh
 30401 0000A4BF 74BE                <1> 	jz	short getf4
 30402                              <1> 	;jz      nig
 30403                              <1> 		; tstb *u.namep / is the character in file name a nul
 30404                              <1> 		; beq nig / yes, end of file name reached; 
 30405                              <1> 			; / branch to "nig"
 30406                              <1> namei_2: ; 1:
 30407                              <1> 	; 18/10/2015
 30408 0000A4C1 8935[B8CE0000]      <1> 	mov 	[nbase], esi
 30409 0000A4C7 66890D[BCCE0000]    <1> 	mov 	[ncount], cx
 30410                              <1> 	;
 30411                              <1> 	;mov	dx, 2
 30412 0000A4CE B202                <1> 	mov	dl, 2 ; user flag (read, non-owner)
 30413 0000A4D0 E859060000          <1> 	call	access
 30414                              <1> 		; jsr r0,access; 2 / get i-node with i-number r1
 30415                              <1> 	; 'access' will not return here if user has not "r" permission !
 30416 0000A4D5 66F705[16CB0000]00- <1> 	test 	word [i.flgs], 4000h
 30417 0000A4DD 40                  <1>
 30418                              <1> 		; bit $40000,i.flgs / directory i-node?
 30419 0000A4DE 746A                <1>         jz      short namei_err
 30420                              <1> 		; beq error3 / no, got an error
 30421                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 30422 0000A4E0 31C0                <1> 	xor	eax, eax
 30423 0000A4E2 A3[5CCE0000]        <1> 	mov	[u.off], eax ; 0
 30424 0000A4E7 66A1[1ACB0000]      <1> 	mov	ax, [i.size]
 30425 0000A4ED A3[54CE0000]        <1> 	mov	[u.dirp], eax
 30426                              <1> 		; mov i.size,u.dirp / put size of directory in u.dirp
 30427                              <1> 		; clr u.off / u.off is file offset used by user
 30428 0000A4F2 C705[50CE0000]-     <1> 	mov	dword [u.fofp], u.off
 30429 0000A4F8 [5CCE0000]          <1>
 30430                              <1> 		; mov $u.off,u.fofp / u.fofp is a pointer to 
 30431                              <1> 				  ; / the offset portion of fsp entry
 30432                              <1> namei_3: ; 2:
 30433 0000A4FC C705[60CE0000]-     <1> 	mov	dword [u.base], u.dirbuf
 30434 0000A502 [72CE0000]          <1>
 30435                              <1> 		; mov $u.dirbuf,u.base / u.dirbuf holds a file name 
 30436                              <1> 				    ; / copied from a directory
 30437 0000A506 C705[64CE0000]1000- <1> 	mov 	dword [u.count], 16 ; 04/12/2015 (10 -> 16) 	
 30438 0000A50E 0000                <1>
 30439                              <1>  		; mov $10.,u.count / u.count is byte count 
 30440                              <1> 				 ; / for reads and writes
 30441 0000A510 66A1[22CE0000]      <1> 	mov 	ax, [ii]
 30442                              <1> 	; 31/07/2013 ('namei_r') - 16/06/2015 ('u.kcall')
 30443 0000A516 FE05[A7CE0000]      <1>  	inc     byte [u.kcall] ; the caller is 'namei' sign	
 30444 0000A51C E800060000          <1>     	call	readi
 30445                              <1> 		; jsr r0,readi / read 10. bytes of file 
 30446                              <1> 		      ; with i-number (r1); i.e. read a directory entry
 30447 0000A521 8B0D[68CE0000]      <1> 	mov 	ecx, [u.nread]
 30448 0000A527 09C9                <1> 	or 	ecx, ecx
 30449                              <1> 		; tst u.nread
 30450 0000A529 741B                <1> 	jz	short nib
 30451                              <1> 		; ble nib / gives error return
 30452                              <1> 	;
 30453 0000A52B 668B1D[72CE0000]    <1> 	mov 	bx, [u.dirbuf]
 30454 0000A532 6621DB              <1> 	and 	bx, bx       
 30455                              <1> 		; tst u.dirbuf /
 30456 0000A535 7522                <1> 	jnz	short namei_4
 30457                              <1> 		; bne 3f / branch when active directory entry 
 30458                              <1> 		       ; / (i-node word in entry non zero)
 30459 0000A537 A1[5CCE0000]        <1> 	mov	eax, [u.off]
 30460 0000A53C 83E810              <1> 	sub	eax, 16 ; 04/12/2015 (10 -> 16) 
 30461 0000A53F A3[54CE0000]        <1> 	mov	[u.dirp], eax
 30462                              <1> 		; mov u.off,u.dirp
 30463                              <1> 		; sub $10.,u.dirp
 30464 0000A544 EBB6                <1> 	jmp	short namei_3
 30465                              <1> 		; br 2b
 30466                              <1> 
 30467                              <1> 	; 18/07/2013
 30468                              <1> nib: 
 30469 0000A546 31C0                <1> 	xor	eax, eax  ; xor ax, ax ; ax = 0 -> file not found 
 30470 0000A548 F9                  <1> 	stc
 30471                              <1> nig:
 30472 0000A549 C3                  <1> 	retn
 30473                              <1> 
 30474                              <1> namei_err:
 30475                              <1> 	; 16/06/2015
 30476 0000A54A C705[95CE0000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a directory !' error
 30477 0000A552 0000                <1>
 30478 0000A554 E96BF0FFFF          <1> 	jmp	error
 30479                              <1> 
 30480                              <1> namei_4: ; 3:
 30481                              <1> 	; 18/10/2015
 30482                              <1> 	; 12/10/2015
 30483                              <1> 	; 21/08/2015
 30484                              <1> 	; 18/07/2015
 30485 0000A559 8B2D[58CE0000]      <1> 	mov	ebp, [u.namep]
 30486                              <1> 		; mov u.namep,r2 / u.namep points into a file name string
 30487 0000A55F BF[74CE0000]        <1> 	mov 	edi, u.dirbuf + 2
 30488                              <1> 		; mov $u.dirbuf+2,r3 / points to file name of directory entry
 30489                              <1> 	; 18/10/2015
 30490 0000A564 8B35[B8CE0000]      <1> 	mov	esi, [nbase]	
 30491 0000A56A 668B0D[BCCE0000]    <1> 	mov	cx, [ncount]
 30492                              <1> 	;
 30493 0000A571 6621C9              <1> 	and	cx, cx
 30494 0000A574 7505                <1> 	jnz	short namei_5	
 30495                              <1> 	;
 30496 0000A576 E850000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 30497                              <1> 		; esi = physical address (page start + offset)
 30498                              <1> 		; ecx = byte count in the page
 30499                              <1> namei_5: ; 3:
 30500 0000A57B 45                  <1> 	inc	ebp ; 18/07/2015
 30501 0000A57C AC                  <1> 	lodsb   ; mov al, [esi] ; inc esi (al = r4)
 30502                              <1> 		; movb (r2)+,r4 / move a character from u.namep string into r4
 30503 0000A57D 08C0                <1> 	or 	al, al
 30504 0000A57F 741D                <1> 	jz 	short namei_7
 30505                              <1> 		; beq 3f / if char is nul, then the last char in string
 30506                              <1> 			; / has been moved
 30507 0000A581 3C2F                <1> 	cmp	al, '/'
 30508                              <1> 		; cmp r4,$'/ / is char a </>
 30509 0000A583 7419                <1> 	je 	short namei_7
 30510                              <1> 		; beq 3f	
 30511                              <1> 	; 12/10/2015
 30512 0000A585 6649                <1> 	dec	cx ; remain byte count in the page
 30513 0000A587 7505                <1> 	jnz	short namei_6
 30514 0000A589 E83D000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 30515                              <1> 		; esi = physical address (page start + offset)
 30516                              <1> 		; ecx = byte count in the page
 30517                              <1> namei_6:
 30518 0000A58E 81FF[82CE0000]      <1>         cmp     edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
 30519                              <1> 		; cmp r3,$u.dirbuf+10. / have I checked
 30520                              <1> 				     ; / all 8 bytes of file name
 30521 0000A594 74E5                <1> 	je	short namei_5
 30522                              <1> 		; beq 3b
 30523 0000A596 AE                  <1> 	scasb	
 30524                              <1> 		; cmpb (r3)+,r4 / compare char in u.namep string to file name 
 30525                              <1> 			      ; / char read from directory
 30526 0000A597 74E2                <1> 	je 	short namei_5
 30527                              <1> 		; beq 3b / branch if chars match
 30528                              <1> 
 30529 0000A599 E95EFFFFFF          <1>         jmp    namei_3 ; 2b
 30530                              <1> 		; br 2b / file names do not match go to next directory entry
 30531                              <1> namei_7: ; 3:
 30532 0000A59E 81FF[82CE0000]      <1> 	cmp	edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
 30533                              <1> 		; cmp r3,$u.dirbuf+10. / if equal all 8 bytes were matched
 30534 0000A5A4 740A                <1> 	je	short namei_8
 30535                              <1> 		; beq 3f
 30536 0000A5A6 8A27                <1> 	mov 	ah, [edi]
 30537                              <1> 	;inc 	edi 
 30538 0000A5A8 20E4                <1> 	and 	ah, ah
 30539                              <1> 		; tstb (r3)+ /
 30540 0000A5AA 0F854CFFFFFF        <1>         jnz     namei_3
 30541                              <1> 		; bne 2b
 30542                              <1> namei_8: ; 3
 30543 0000A5B0 892D[58CE0000]      <1> 	mov	[u.namep], ebp ; 18/07/2015
 30544                              <1> 		; mov r2,u.namep / u.namep points to char 
 30545                              <1> 			       ; / following a / or nul
 30546                              <1> 	;mov	bx, [u.dirbuf]
 30547                              <1> 		; mov u.dirbuf,r1 / move i-node number in directory 
 30548                              <1> 				; / entry to r1
 30549 0000A5B6 20C0                <1> 	and 	al, al
 30550                              <1> 		; tst r4 / if r4 = 0 the end of file name reached,
 30551                              <1> 		      ;  / if r4 = </> then go to next directory
 30552                              <1> 	; mov	ax, bx
 30553 0000A5B8 66A1[72CE0000]      <1> 	mov 	ax, [u.dirbuf] ; 17/06/2015
 30554 0000A5BE 0F85FDFEFFFF        <1>         jnz     namei_2 
 30555                              <1> 		; bne 1b
 30556                              <1> 	; AX = i-number of the file
 30557                              <1> ;;nig:
 30558 0000A5C4 C3                  <1> 	retn
 30559                              <1> 		; tst (r0)+ / gives non-error return
 30560                              <1> ;;nib:
 30561                              <1> ;;	xor	ax, ax ; Retro UNIX 8086 v1 modification !
 30562                              <1> 		       ; ax = 0 -> file not found 
 30563                              <1> ;;	stc	; 27/05/2013
 30564                              <1> ;;	retn
 30565                              <1> 		; rts r0
 30566                              <1> 
 30567                              <1> trans_addr_nmbp:
 30568                              <1> 	; 18/10/2015
 30569                              <1> 	; 12/10/2015
 30570 0000A5C5 8B2D[58CE0000]      <1> 	mov 	ebp, [u.namep]
 30571                              <1> trans_addr_nm: 
 30572                              <1> 	; Convert virtual (pathname) address to physical address
 30573                              <1> 	; (Retro UNIX 386 v1 feature only !)
 30574                              <1> 	; 18/10/2015
 30575                              <1> 	; 12/10/2015 (u.pnbase & u.pncount has been removed from code)
 30576                              <1> 	; 02/07/2015
 30577                              <1> 	; 17/06/2015
 30578                              <1> 	; 16/06/2015
 30579                              <1> 	;
 30580                              <1> 	; INPUTS: 
 30581                              <1> 	;	ebp = pathname address (virtual) ; [u.namep]
 30582                              <1> 	;	[u.pgdir] = user's page directory
 30583                              <1> 	; OUTPUT:
 30584                              <1> 	;       esi = physical address of the pathname
 30585                              <1> 	;	ecx = remain byte count in the page
 30586                              <1> 	;
 30587                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI)
 30588                              <1> 	;
 30589 0000A5CB 833D[9DCE0000]00    <1>         cmp     dword [u.ppgdir], 0  ; /etc/init ? (sysexec)
 30590 0000A5D2 7618                <1> 	jna	short trans_addr_nmk ; the caller is os kernel;
 30591                              <1> 				     ; it is already physical address
 30592 0000A5D4 50                  <1>    	push	eax	
 30593 0000A5D5 89EB                <1> 	mov	ebx, ebp ; [u.namep] ; pathname address (virtual)
 30594 0000A5D7 E8BE91FFFF          <1>        	call	get_physical_addr ; get physical address
 30595 0000A5DC 7204                <1> 	jc	short tr_addr_nm_err
 30596                              <1> 	; 18/10/2015
 30597                              <1> 	; eax = physical address 
 30598                              <1> 	; cx = remain byte count in page (1-4096) 
 30599                              <1> 		; 12/10/2015 (cx = [u.pncount])
 30600 0000A5DE 89C6                <1> 	mov	esi, eax ; 12/10/2015 (esi=[u.pnbase])
 30601 0000A5E0 58                  <1> 	pop	eax 
 30602 0000A5E1 C3                  <1> 	retn
 30603                              <1> 
 30604                              <1> tr_addr_nm_err:
 30605 0000A5E2 A3[95CE0000]        <1> 	mov	[u.error], eax
 30606                              <1> 	;pop 	eax
 30607 0000A5E7 E9D8EFFFFF          <1> 	jmp	error
 30608                              <1> 
 30609                              <1> trans_addr_nmk:
 30610                              <1> 	; 12/10/2015
 30611                              <1> 	; 02/07/2015
 30612 0000A5EC 8B35[58CE0000]      <1> 	mov	esi, [u.namep]  ; [u.pnbase]
 30613 0000A5F2 66B90010            <1> 	mov	cx, PAGE_SIZE ; 4096 ; [u.pncount]
 30614 0000A5F6 C3                  <1> 	retn
 30615                              <1> 
 30616                              <1> syschdir:
 30617                              <1> 	; / makes the directory specified in the argument
 30618                              <1> 	; / the current directory
 30619                              <1> 	;
 30620                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30621                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 30622                              <1> 	;
 30623                              <1> 	; 'syschdir' makes the directory specified in its argument
 30624                              <1> 	; the current working directory.
 30625                              <1> 	;
 30626                              <1> 	; Calling sequence:
 30627                              <1> 	;	syschdir; name
 30628                              <1> 	; Arguments:
 30629                              <1> 	;	name - address of the path name of a directory
 30630                              <1> 	;	       terminated by nul byte.	
 30631                              <1> 	; Inputs: -
 30632                              <1> 	; Outputs: -
 30633                              <1> 	; ...............................................................
 30634                              <1> 	;				
 30635                              <1> 	; Retro UNIX 8086 v1 modification:
 30636                              <1> 	;	 The user/application program puts address of 
 30637                              <1> 	;	 the path name in BX register as 'syschdir' 
 30638                              <1> 	; 	 system call argument.
 30639                              <1> 
 30640 0000A5F7 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 30641                              <1> 		;jsr r0,arg; u.namep / u.namep points to path name
 30642 0000A5FD E87EFEFFFF          <1> 	call	namei
 30643                              <1> 		; jsr r0,namei / find its i-number
 30644                              <1> 	;jc	error
 30645                              <1> 		; br error3
 30646 0000A602 730F                <1> 	jnc	short syschdir0
 30647                              <1> 	; 'directory not found !' error
 30648 0000A604 C705[95CE0000]0C00- <1> 	mov	dword [u.error], ERR_DIR_NOT_FOUND ; 12
 30649 0000A60C 0000                <1>
 30650 0000A60E E9B1EFFFFF          <1> 	jmp	error
 30651                              <1> syschdir0:
 30652 0000A613 E816050000          <1> 	call	access
 30653                              <1> 		; jsr r0,access; 2 / get i-node into core
 30654 0000A618 66F705[16CB0000]00- <1> 	test	word [i.flgs], 4000h
 30655 0000A620 40                  <1>
 30656                              <1> 		; bit $40000,i.flgs / is it a directory?
 30657                              <1> 	;jz	error 
 30658                              <1> 		; beq error3 / no error
 30659 0000A621 750F                <1> 	jnz	short syschdir1
 30660 0000A623 C705[95CE0000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
 30661 0000A62B 0000                <1>
 30662 0000A62D E992EFFFFF          <1> 	jmp	error
 30663                              <1> syschdir1:
 30664 0000A632 66A3[44CE0000]      <1> 	mov	[u.cdir], ax
 30665                              <1> 		; mov r1,u.cdir / move i-number to users 
 30666                              <1> 			      ; / current directory
 30667 0000A638 66A1[26CE0000]      <1> 	mov	ax, [cdev]
 30668 0000A63E 66A3[8ACE0000]      <1> 	mov	[u.cdrv], ax
 30669                              <1> 		; mov cdev,u.cdev / move its device to users 
 30670                              <1> 			        ; / current device
 30671 0000A644 E99BEFFFFF          <1> 	jmp	sysret
 30672                              <1> 		; br sysret3
 30673                              <1> 	
 30674                              <1> syschmod: ; < change mode of file >
 30675                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30676                              <1> 	; 20/06/2013 - 07/07/2013 (Retro UNIX 8086 v1)
 30677                              <1> 	;
 30678                              <1> 	; 'syschmod' changes mode of the file whose name is given as
 30679                              <1> 	; null terminated string pointed to by 'name' has it's mode 
 30680                              <1> 	; changed to 'mode'.
 30681                              <1> 	;
 30682                              <1> 	; Calling sequence:
 30683                              <1> 	;	syschmod; name; mode
 30684                              <1> 	; Arguments:
 30685                              <1> 	;	name - address of the file name
 30686                              <1> 	;	       terminated by null byte.
 30687                              <1> 	;	mode - (new) mode/flags < attributes >
 30688                              <1> 	;	
 30689                              <1> 	; Inputs: -
 30690                              <1> 	; Outputs: -
 30691                              <1> 	; ...............................................................
 30692                              <1> 	;				
 30693                              <1> 	; Retro UNIX 8086 v1 modification: 
 30694                              <1> 	;       'syschmod' system call has two arguments; so,
 30695                              <1> 	;	* 1st argument, name is pointed to by BX register
 30696                              <1> 	;	* 2nd argument, mode is in CX register
 30697                              <1> 	;
 30698                              <1> 	; Mode bits (Flags):
 30699                              <1> 	;	bit 0 - write permission for non-owner (1)
 30700                              <1> 	;	bit 1 - read permission for non-owner (2)
 30701                              <1> 	;	bit 2 - write permission for owner (4)
 30702                              <1> 	;	bit 3 - read permission for owner (8)
 30703                              <1> 	;	bit 4 - executable flag (16) 	
 30704                              <1> 	;	bit 5 - set user ID on execution flag (32) 
 30705                              <1> 	;	bit 6,7,8,9,10,11 are not used (undefined)
 30706                              <1> 	;	bit 12 - large file flag (4096)
 30707                              <1> 	;	bit 13 - file has modified flag (always on) (8192)
 30708                              <1> 	;	bit 14 - directory flag (16384)
 30709                              <1> 	;	bit 15 - 'i-node is allocated' flag (32768)
 30710                              <1> 
 30711                              <1> 	; / name; mode
 30712 0000A649 E814000000          <1> 	call	isown
 30713                              <1> 		;jsr r0,isown / get the i-node and check user status
 30714 0000A64E 66F705[16CB0000]00- <1> 	test	word [i.flgs], 4000h
 30715 0000A656 40                  <1>
 30716                              <1> 		; bit	$40000,i.flgs / directory?
 30717 0000A657 7402                <1> 	jz	short syschmod1
 30718                              <1> 		; beq 2f / no
 30719                              <1> 	; AL = (new) mode
 30720 0000A659 24CF                <1> 	and	al, 0CFh ; 11001111b (clears bit 4 & 5)
 30721                              <1> 		; bic $60,r2 / su & ex / yes, clear set user id and 
 30722                              <1> 			   ; / executable modes
 30723                              <1> syschmod1: ; 2:
 30724 0000A65B A2[16CB0000]        <1> 	mov	[i.flgs], al	
 30725                              <1> 		; movb r2,i.flgs / move remaining mode to i.flgs
 30726 0000A660 EB42                <1> 	jmp	short isown1
 30727                              <1> 		; br 1f
 30728                              <1> 
 30729                              <1> isown:
 30730                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 30731                              <1> 	; 04/05/2013 - 07/07/2013 (Retro UNIX 8086 v1)
 30732                              <1> 	;
 30733                              <1> 	; 'isown' is given a file name (the 1st argument).
 30734                              <1> 	;  It find the i-number of that file via 'namei' 
 30735                              <1> 	;  then gets the i-node into core via 'iget'.
 30736                              <1> 	;  It then tests to see if the user is super user. 
 30737                              <1> 	;  If not, it cheks to see if the user is owner of 
 30738                              <1> 	;  the file. If he is not an error occurs.
 30739                              <1> 	;  If user is the owner 'setimod' is called to indicate
 30740                              <1> 	;  the inode has been modificed and the 2nd argument of
 30741                              <1> 	;  the call is put in r2.
 30742                              <1> 	;
 30743                              <1> 	; INPUTS ->
 30744                              <1> 	;    arguments of syschmod and syschown calls
 30745                              <1> 	; OUTPUTS ->
 30746                              <1> 	;    u.uid - id of user
 30747                              <1> 	;    imod - set to a 1
 30748                              <1> 	;    r2 - contains second argument of the system call				 	
 30749                              <1> 	;
 30750                              <1> 	;   ((AX=R2) output as 2nd argument)
 30751                              <1> 	;
 30752                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 30753                              <1> 	;
 30754                              <1> 		; jsr r0,arg2 / u.namep points to file name
 30755                              <1> 	;; ! 2nd argument on top of stack !
 30756                              <1> 	;; 22/06/2015 - 32 bit modifications
 30757                              <1> 	;; 07/07/2013
 30758 0000A662 891D[58CE0000]      <1> 	mov	[u.namep], ebx ;; 1st argument
 30759 0000A668 51                  <1> 	push 	ecx ;; 2nd argument
 30760                              <1> 	;;
 30761 0000A669 E812FEFFFF          <1> 	call	namei
 30762                              <1> 		; jsr r0,namei / get its i-number
 30763                              <1>        ; Retro UNIX 8086 v1 modification !
 30764                              <1>        ; ax = 0 -> file not found 
 30765                              <1> 	;and	ax, ax
 30766                              <1> 	;jz	error
 30767                              <1> 	;jc	error ; 27/05/2013
 30768                              <1> 		; br error3
 30769 0000A66E 730F                <1> 	jnc	short isown0
 30770                              <1> 	; 'file not found !' error
 30771 0000A670 C705[95CE0000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 30772 0000A678 0000                <1>
 30773 0000A67A E945EFFFFF          <1> 	jmp	error
 30774                              <1> isown0:
 30775 0000A67F E898040000          <1> 	call	iget
 30776                              <1> 		; jsr r0,iget / get i-node into core
 30777 0000A684 A0[8CCE0000]        <1> 	mov	al, [u.uid] ; 02/08/2013
 30778 0000A689 08C0                <1> 	or	al, al
 30779                              <1> 		; tstb u.uid / super user?
 30780 0000A68B 7417                <1> 	jz	short isown1
 30781                              <1> 		; beq 1f / yes, branch
 30782 0000A68D 3A05[19CB0000]      <1> 	cmp	al, [i.uid]
 30783                              <1> 		; cmpb i.uid,u.uid / no, is this the owner of
 30784                              <1> 				 ; / the file
 30785                              <1> 	;jne	error
 30786                              <1> 		; beq 1f / yes
 30787                              <1> 		; jmp error3 / no, error
 30788 0000A693 740F                <1> 	je	short isown1
 30789                              <1> 
 30790 0000A695 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_NOT_OWNER  ; 11
 30791 0000A69D 0000                <1>
 30792                              <1> 			;  'permission denied !' error
 30793 0000A69F E920EFFFFF          <1> 	jmp	error
 30794                              <1> isown1: ; 1:
 30795 0000A6A4 E881040000          <1> 	call	setimod
 30796                              <1> 		; jsr r0,setimod / indicates 
 30797                              <1> 		;	       ; / i-node has been modified
 30798 0000A6A9 58                  <1> 	pop	eax ; 2nd argument
 30799                              <1> 		; mov (sp)+,r2 / mode is put in r2 
 30800                              <1> 		       ; / (u.off put on stack with 2nd arg)
 30801 0000A6AA C3                  <1> 	retn
 30802                              <1> 		; rts r0
 30803                              <1> 
 30804                              <1> ;;arg:  ; < get system call arguments >
 30805                              <1> 	; 'arg' extracts an argument for a routine whose call is 
 30806                              <1> 	; of form:
 30807                              <1> 	;	sys 'routine' ; arg1
 30808                              <1> 	;		or
 30809                              <1> 	;	sys 'routine' ; arg1 ; arg2
 30810                              <1> 	;		or
 30811                              <1> 	;	sys 'routine' ; arg1;...;arg10 (sys exec) 
 30812                              <1> 	;	
 30813                              <1> 	; INPUTS ->
 30814                              <1> 	;    u.sp+18 - contains a pointer to one of arg1..argn
 30815                              <1> 	;	This pointers's value is actually the value of
 30816                              <1> 	;	update pc at the the trap to sysent (unkni) is
 30817                              <1> 	;	made to process the sys instruction
 30818                              <1> 	;    r0 - contains the return address for the routine
 30819                              <1> 	;	that called arg. The data in the word pointer 
 30820                              <1> 	;	to by the return address is used as address
 30821                              <1> 	;	in which the extracted argument is stored   		
 30822                              <1> 	;    	
 30823                              <1> 	; OUTPUTS ->
 30824                              <1> 	;    'address' - contains the extracted argument 
 30825                              <1> 	;    u.sp+18 - is incremented by 2 
 30826                              <1> 	;    r1 - contains the extracted argument
 30827                              <1> 	;    r0 - points to the next instruction to be
 30828                              <1> 	;	 executed in the calling routine.
 30829                              <1> 	;
 30830                              <1>   
 30831                              <1> 	; mov u.sp,r1
 30832                              <1> 	; mov *18.(r1),*(r0)+ / put argument of system call
 30833                              <1> 			; / into argument of arg2
 30834                              <1> 	; add $2,18.(r1) / point pc on stack 
 30835                              <1> 			      ; / to next system argument
 30836                              <1> 	; rts r0
 30837                              <1> 
 30838                              <1> ;;arg2: ; < get system calls arguments - with file name pointer>
 30839                              <1> 	; 'arg2' takes first argument in system call
 30840                              <1> 	;  (pointer to name of the file) and puts it in location
 30841                              <1> 	;  u.namep; takes second argument and puts it in u.off
 30842                              <1> 	;  and on top of the stack
 30843                              <1> 	;	
 30844                              <1> 	; INPUTS ->
 30845                              <1> 	;    u.sp, r0
 30846                              <1> 	;    	
 30847                              <1> 	; OUTPUTS ->
 30848                              <1> 	;    u.namep
 30849                              <1> 	;    u.off 
 30850                              <1> 	;    u.off pushed on stack
 30851                              <1> 	;    r1
 30852                              <1> 	;
 30853                              <1> 
 30854                              <1> 	; jsr	r0,arg; u.namep / u.namep contains value of
 30855                              <1> 				; / first arg in sys call
 30856                              <1> 	; jsr r0,arg; u.off / u.off contains value of 
 30857                              <1> 				; / second arg in sys call
 30858                              <1> 	; mov r0,r1 / r0 points to calling routine
 30859                              <1> 	; mov (sp),r0 / put operation code back in r0
 30860                              <1> 	; mov u.off,(sp) / put pointer to second argument 
 30861                              <1> 			; / on stack
 30862                              <1> 	; jmp (r1) / return to calling routine
 30863                              <1> 
 30864                              <1> syschown: ; < change owner of file >
 30865                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30866                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 30867                              <1> 	;
 30868                              <1> 	; 'syschown' changes the owner of the file whose name is given
 30869                              <1> 	; as null terminated string pointed to by 'name' has it's owner
 30870                              <1> 	; changed to 'owner'
 30871                              <1> 	;
 30872                              <1> 	; Calling sequence:
 30873                              <1> 	;	syschown; name; owner
 30874                              <1> 	; Arguments:
 30875                              <1> 	;	name - address of the file name
 30876                              <1> 	;	       terminated by null byte.
 30877                              <1> 	;	owner - (new) owner (number/ID)
 30878                              <1> 	;	
 30879                              <1> 	; Inputs: -
 30880                              <1> 	; Outputs: -
 30881                              <1> 	; ...............................................................
 30882                              <1> 	;				
 30883                              <1> 	; Retro UNIX 8086 v1 modification: 
 30884                              <1> 	;       'syschown' system call has two arguments; so,
 30885                              <1> 	;	* 1st argument, name is pointed to by BX register
 30886                              <1> 	;	* 2nd argument, owner number is in CX register
 30887                              <1> 	;
 30888                              <1> 	; / name; owner
 30889 0000A6AB E8B2FFFFFF          <1> 	call	isown
 30890                              <1> 		; jsr r0,isown / get the i-node and check user status
 30891 0000A6B0 803D[8CCE0000]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013 
 30892                              <1> 		; tstb u.uid / super user
 30893 0000A6B7 7418                <1> 	jz	short syschown1
 30894                              <1> 		; beq 2f / yes, 2f
 30895 0000A6B9 F605[16CB0000]20    <1>         test    byte [i.flgs], 20h ; 32
 30896                              <1> 		; bit $40,i.flgs / no, set userid on execution?
 30897                              <1> 	;jnz	error
 30898                              <1> 		; bne 3f / yes error, could create Trojan Horses
 30899 0000A6C0 740F                <1> 	jz	short syschown1
 30900                              <1> 	; 'permission denied !'
 30901 0000A6C2 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS  ; 11
 30902 0000A6CA 0000                <1>
 30903 0000A6CC E9F3EEFFFF          <1> 	jmp	error
 30904                              <1> syschown1: ; 2:
 30905                              <1> 	; AL = owner (number/ID)
 30906 0000A6D1 A2[19CB0000]        <1> 	mov	[i.uid], al ; 23/06/2015
 30907                              <1> 		;  movb	r2,i.uid / no, put the new owners id 
 30908                              <1> 			       ; / in the i-node
 30909 0000A6D6 E909EFFFFF          <1> 	jmp	sysret
 30910                              <1> 	; 1: 
 30911                              <1> 		; jmp sysret4
 30912                              <1> 	; 3:
 30913                              <1> 		; jmp	error
 30914                              <1> 
 30915                              <1> systime: ; / get time of year
 30916                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30917                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
 30918                              <1> 	;
 30919                              <1> 	; 20/06/2013
 30920                              <1> 	; 'systime' gets the time of the year.
 30921                              <1> 	; The present time is put on the stack.
 30922                              <1> 	;
 30923                              <1> 	; Calling sequence:
 30924                              <1> 	;	systime
 30925                              <1> 	; Arguments: -
 30926                              <1> 	;	
 30927                              <1> 	; Inputs: -
 30928                              <1> 	; Outputs: sp+2, sp+4 - present time
 30929                              <1> 	; ...............................................................
 30930                              <1> 	;	
 30931                              <1> 	; Retro UNIX 8086 v1 modification: 
 30932                              <1> 	;       'systime' system call will return to the user
 30933                              <1> 	;	with unix time (epoch) in DX:AX register pair
 30934                              <1> 	;
 30935                              <1> 	; 	!! Major modification on original Unix v1 'systime' 
 30936                              <1> 	;	system call for PC compatibility !!		 	
 30937                              <1> 
 30938 0000A6DB E851040000          <1> 	call 	epoch
 30939 0000A6E0 A3[40CE0000]        <1> 	mov 	[u.r0], eax
 30940                              <1> 		; mov s.time,4(sp)
 30941                              <1> 		; mov s.time+2,2(sp) / put the present time 
 30942                              <1> 				   ; / on the stack
 30943                              <1> 		; br sysret4
 30944 0000A6E5 E9FAEEFFFF          <1> 	jmp	sysret 
 30945                              <1> 
 30946                              <1> sysstime: ; / set time
 30947                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30948                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 30949                              <1> 	;
 30950                              <1> 	; 'sysstime' sets the time. Only super user can use this call.
 30951                              <1> 	;
 30952                              <1> 	; Calling sequence:
 30953                              <1> 	;	sysstime
 30954                              <1> 	; Arguments: -
 30955                              <1> 	;	
 30956                              <1> 	; Inputs: sp+2, sp+4 - time system is to be set to.
 30957                              <1> 	; Outputs: -
 30958                              <1> 	; ...............................................................
 30959                              <1> 	;	
 30960                              <1> 	; Retro UNIX 8086 v1 modification: 
 30961                              <1> 	;	the user calls 'sysstime' with unix (epoch) time
 30962                              <1> 	;	(to be set) is in CX:BX register pair as two arguments.
 30963                              <1> 	; 
 30964                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
 30965                              <1> 	;	to get sysstime system call arguments from the user;
 30966                              <1> 	;	* 1st argument, lowword of unix time is in BX register
 30967                              <1> 	;	* 2nd argument, highword of unix time is in CX register		 	
 30968                              <1> 	;
 30969                              <1> 	; 	!! Major modification on original Unix v1 'sysstime' 
 30970                              <1> 	;	system call for PC compatibility !!	
 30971                              <1> 
 30972 0000A6EA 803D[8CCE0000]00    <1> 	cmp	byte [u.uid], 0
 30973                              <1> 		; tstb u.uid / is user the super user
 30974                              <1> 	;ja	error
 30975                              <1> 		; bne error4 / no, error
 30976 0000A6F1 760F                <1> 	jna	short systime1
 30977                              <1> 	; 'permission denied !'
 30978 0000A6F3 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11 
 30979 0000A6FB 0000                <1>
 30980 0000A6FD E9C2EEFFFF          <1> 	jmp	error
 30981                              <1> systime1:
 30982                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - 32 bit version)
 30983                              <1> 	; EBX = unix (epoch) time (from user)
 30984 0000A702 89D8                <1> 	mov	eax, ebx
 30985 0000A704 E829040000          <1> 	call 	set_date_time
 30986                              <1> 		; mov 4(sp),s.time
 30987                              <1> 		; mov 2(sp),s.time+2 / set the system time
 30988 0000A709 E9D6EEFFFF          <1> 	jmp	sysret
 30989                              <1> 		; br sysret4
 30990                              <1> 
 30991                              <1> sysbreak:
 30992                              <1> 	; 18/10/2015
 30993                              <1> 	; 07/10/2015
 30994                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 30995                              <1> 	; 20/06/2013 - 24/03/2014 (Retro UNIX 8086 v1)
 30996                              <1> 	;
 30997                              <1> 	; 'sysbreak' sets the programs break points. 
 30998                              <1> 	; It checks the current break point (u.break) to see if it is
 30999                              <1> 	; between "core" and the stack (sp). If it is, it is made an
 31000                              <1> 	; even address (if it was odd) and the area between u.break
 31001                              <1> 	; and the stack is cleared. The new breakpoint is then put
 31002                              <1> 	; in u.break and control is passed to 'sysret'.
 31003                              <1> 	;
 31004                              <1> 	; Calling sequence:
 31005                              <1> 	;	sysbreak; addr
 31006                              <1> 	; Arguments: -
 31007                              <1> 	;	
 31008                              <1> 	; Inputs: u.break - current breakpoint
 31009                              <1> 	; Outputs: u.break - new breakpoint 
 31010                              <1> 	;	area between old u.break and the stack (sp) is cleared.
 31011                              <1> 	; ...............................................................
 31012                              <1> 	;	
 31013                              <1> 	; Retro UNIX 8086 v1 modification:
 31014                              <1> 	;	The user/application program puts breakpoint address
 31015                              <1> 	;       in BX register as 'sysbreak' system call argument.
 31016                              <1> 	; 	(argument transfer method 1)
 31017                              <1> 	;
 31018                              <1> 	;  NOTE: Beginning of core is 0 in Retro UNIX 8086 v1 !
 31019                              <1> 	; 	((!'sysbreak' is not needed in Retro UNIX 8086 v1!))
 31020                              <1> 	;  NOTE:
 31021                              <1> 	; 	'sysbreak' clears extended part (beyond of previous
 31022                              <1> 	;	'u.break' address) of user's memory for original unix's
 31023                              <1> 	;	'bss' compatibility with Retro UNIX 8086 v1 (19/11/2013)
 31024                              <1> 
 31025                              <1> 		; mov u.break,r1 / move users break point to r1
 31026                              <1> 		; cmp r1,$core / is it the same or lower than core?
 31027                              <1> 		; blos 1f / yes, 1f
 31028                              <1> 	; 23/06/2015
 31029 0000A70E 8B2D[6CCE0000]      <1> 	mov	ebp, [u.break] ; virtual address (offset)
 31030                              <1> 	;and	ebp, ebp
 31031                              <1> 	;jz	short sysbreak_3 
 31032                              <1> 	; Retro UNIX 386 v1 NOTE: u.break points to virtual address !!!
 31033                              <1> 	; (Even break point address is not needed for Retro UNIX 386 v1)
 31034 0000A714 8B15[38CE0000]      <1> 	mov	edx, [u.sp] ; kernel stack at the beginning of sys call
 31035 0000A71A 83C20C              <1> 	add	edx, 12 ; EIP -4-> CS -4-> EFLAGS -4-> ESP (user) 
 31036                              <1> 	; 07/10/2015
 31037 0000A71D 891D[6CCE0000]      <1> 	mov	[u.break], ebx ; virtual address !!!
 31038                              <1> 	;
 31039 0000A723 3B1A                <1> 	cmp	ebx, [edx] ; compare new break point with 
 31040                              <1> 			   ; with top of user's stack (virtual!)
 31041 0000A725 7327                <1> 	jnb	short sysbreak_3
 31042                              <1> 		; cmp r1,sp / is it the same or higher 
 31043                              <1> 			  ; / than the stack?
 31044                              <1> 		; bhis 1f / yes, 1f
 31045 0000A727 89DE                <1> 	mov	esi, ebx
 31046 0000A729 29EE                <1> 	sub	esi, ebp ; new break point - old break point
 31047 0000A72B 7621                <1> 	jna	short sysbreak_3 
 31048                              <1> 	;push	ebx
 31049                              <1> sysbreak_1:
 31050 0000A72D 89EB                <1> 	mov	ebx, ebp  
 31051 0000A72F E86690FFFF          <1> 	call	get_physical_addr ; get physical address
 31052 0000A734 0F82A8FEFFFF        <1> 	jc	tr_addr_nm_err
 31053                              <1> 	; 18/10/2015
 31054 0000A73A 89C7                <1> 	mov	edi, eax 
 31055 0000A73C 29C0                <1> 	sub	eax, eax ; 0
 31056                              <1> 		 ; ECX = remain byte count in page (1-4096)
 31057 0000A73E 39CE                <1> 	cmp	esi, ecx
 31058 0000A740 7302                <1> 	jnb	short sysbreak_2
 31059 0000A742 89F1                <1> 	mov	ecx, esi
 31060                              <1> sysbreak_2:
 31061 0000A744 29CE                <1> 	sub	esi, ecx
 31062 0000A746 01CD                <1> 	add	ebp, ecx
 31063 0000A748 F3AA                <1> 	rep 	stosb
 31064 0000A74A 09F6                <1> 	or	esi, esi
 31065 0000A74C 75DF                <1> 	jnz	short sysbreak_1
 31066                              <1> 	;
 31067                              <1> 		; bit $1,r1 / is it an odd address
 31068                              <1> 		; beq 2f / no, its even
 31069                              <1> 		; clrb (r1)+ / yes, make it even
 31070                              <1> 	; 2: / clear area between the break point and the stack
 31071                              <1> 		; cmp r1,sp / is it higher or same than the stack
 31072                              <1> 		; bhis 1f / yes, quit
 31073                              <1> 		; clr (r1)+ / clear word
 31074                              <1> 		; br 2b / go back
 31075                              <1> 	;pop	ebx
 31076                              <1> sysbreak_3: ; 1:
 31077                              <1> 	;mov	[u.break], ebx ; virtual address !!!
 31078                              <1> 		; jsr r0,arg; u.break / put the "address" 
 31079                              <1> 			; / in u.break (set new break point)
 31080                              <1> 		; br sysret4 / br sysret
 31081 0000A74E E991EEFFFF          <1> 	jmp	sysret
 31082                              <1> 
 31083                              <1> 
 31084                              <1> maknod: 
 31085                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31086                              <1> 	; 02/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 31087                              <1> 	;
 31088                              <1> 	; 'maknod' creates an i-node and makes a directory entry
 31089                              <1> 	; for this i-node in the current directory.
 31090                              <1> 	;
 31091                              <1> 	; INPUTS ->
 31092                              <1> 	;    r1 - contains mode
 31093                              <1> 	;    ii - current directory's i-number	
 31094                              <1> 	;    	
 31095                              <1> 	; OUTPUTS ->
 31096                              <1> 	;    u.dirbuf - contains i-number of free i-node 
 31097                              <1> 	;    i.flgs - flags in new i-node 
 31098                              <1> 	;    i.uid - filled with u.uid
 31099                              <1> 	;    i.nlks - 1 is put in the number of links
 31100                              <1> 	;    i.ctim - creation time				
 31101                              <1> 	;    i.ctim+2 - modification time
 31102                              <1> 	;    imod - set via call to setimod
 31103                              <1> 	;	
 31104                              <1> 	; ((AX = R1)) input
 31105                              <1> 	;
 31106                              <1> 	; (Retro UNIX Prototype : 
 31107                              <1> 	;	30/10/2012 - 01/03/2013, UNIXCOPY.ASM)
 31108                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 31109                              <1> 
 31110                              <1> 	; / r1 contains the mode
 31111 0000A753 80CC80              <1> 	or 	ah, 80h  ; 10000000b
 31112                              <1> 		; bis	$100000,r1 / allocate flag set
 31113 0000A756 6650                <1> 	push	ax
 31114                              <1> 		; mov r1,-(sp) / put mode on stack
 31115                              <1> 	; 31/07/2013
 31116 0000A758 66A1[22CE0000]      <1> 	mov	ax, [ii] ; move current i-number to AX/r1
 31117                              <1> 		; mov ii,r1 / move current i-number to r1
 31118 0000A75E B201                <1> 	mov	dl, 1 ; owner flag mask
 31119 0000A760 E8C9030000          <1> 	call	access	
 31120                              <1> 		; jsr r0,access; 1 / get its i-node into core
 31121 0000A765 6650                <1> 	push	ax
 31122                              <1> 		; mov r1,-(sp) / put i-number on stack
 31123 0000A767 66B82800            <1> 	mov	ax, 40
 31124                              <1> 		; mov $40.,r1 / r1 = 40
 31125                              <1> maknod1: ; 1: / scan for a free i-node (next 4 instructions)
 31126 0000A76B 6640                <1> 	inc	ax
 31127                              <1> 		; inc r1 / r1 = r1 + 1
 31128 0000A76D E8C1030000          <1> 	call	imap
 31129                              <1> 		; jsr r0,imap / get byte address and bit position in 
 31130                              <1> 			    ; /	inode map in r2 & m
 31131                              <1>           ; DX (MQ) has a 1 in the calculated bit position
 31132                              <1>           ; eBX (R2) has byte address of the byte with allocation bit
 31133                              <1> 	; 22/06/2015 - NOTE for next Retro UNIX version: 
 31134                              <1> 	;	       Inode count must be checked here
 31135                              <1> 	; (Original UNIX v1 did not check inode count here !?) 	
 31136 0000A772 8413                <1> 	test	[ebx], dl
 31137                              <1> 		; bitb mq,(r2) / is the i-node active
 31138 0000A774 75F5                <1> 	jnz	short maknod1
 31139                              <1> 		; bne 1b / yes, try the next one
 31140 0000A776 0813                <1> 	or	[ebx], dl
 31141                              <1> 		; bisb mq,(r2) / no, make it active 
 31142                              <1> 			     ; / (put a 1 in the bit map)
 31143 0000A778 E89F030000          <1> 	call	iget
 31144                              <1> 		; jsr r0,iget / get i-node into core
 31145 0000A77D 66F705[16CB0000]00- <1> 	test	word [i.flgs], 8000h 
 31146 0000A785 80                  <1>
 31147                              <1> 		; tst i.flgs / is i-node already allocated
 31148 0000A786 75E3                <1> 	jnz	short maknod1	
 31149                              <1> 		; blt 1b / yes, look for another one
 31150 0000A788 66A3[72CE0000]      <1> 	mov	[u.dirbuf], ax
 31151                              <1> 		; mov r1,u.dirbuf / no, put i-number in u.dirbuf
 31152 0000A78E 6658                <1> 	pop	ax
 31153                              <1> 		; mov (sp)+,r1 / get current i-number back
 31154 0000A790 E887030000          <1> 	call	iget
 31155                              <1> 		; jsr r0,iget / get i-node in core
 31156 0000A795 E87DF7FFFF          <1> 	call	mkdir
 31157                              <1> 		; jsr r0,mkdir / make a directory entry 
 31158                              <1> 			     ; / in current directory
 31159 0000A79A 66A1[72CE0000]      <1> 	mov	ax, [u.dirbuf]
 31160                              <1> 		; mov u.dirbuf,r1 / r1 = new inode number
 31161 0000A7A0 E877030000          <1> 	call	iget
 31162                              <1> 		; jsr r0,iget / get it into core
 31163                              <1> 		; jsr r0,copyz; inode; inode+32. / 0 it out
 31164 0000A7A5 B908000000          <1> 	mov	ecx, 8 
 31165 0000A7AA 31C0                <1> 	xor	eax, eax ; 0
 31166 0000A7AC BF[16CB0000]        <1> 	mov	edi, inode 
 31167 0000A7B1 F3AB                <1> 	rep	stosd
 31168                              <1> 	;
 31169 0000A7B3 668F05[16CB0000]    <1> 	pop	word [i.flgs]
 31170                              <1> 		; mov (sp)+,i.flgs / fill flags
 31171 0000A7BA 8A0D[8CCE0000]      <1> 	mov 	cl, [u.uid] ; 02/08/2013
 31172 0000A7C0 880D[19CB0000]      <1> 	mov 	[i.uid], cl
 31173                              <1> 		; movb u.uid,i.uid / user id	
 31174 0000A7C6 C605[18CB0000]01    <1> 	mov     byte [i.nlks], 1
 31175                              <1> 		; movb $1,i.nlks / 1 link
 31176                              <1> 	;call	epoch ; Retro UNIX 8086 v1 modification !
 31177                              <1> 	;mov	eax, [s.time]
 31178                              <1> 	;mov 	[i.ctim], eax
 31179                              <1> 	 	; mov s.time,i.ctim / time created
 31180                              <1> 	 	; mov s.time+2,i.ctim+2 / time modified
 31181                              <1> 	; Retro UNIX 8086 v1 modification !
 31182                              <1> 	; i.ctime=0, i.ctime+2=0 and
 31183                              <1>         ; 'setimod' will set ctime of file via 'epoch'
 31184 0000A7CD E858030000          <1> 	call setimod
 31185                              <1> 		; jsr r0,setimod / set modified flag
 31186 0000A7D2 C3                  <1> 	retn
 31187                              <1> 		; rts r0 / return
 31188                              <1> 
 31189                              <1> sysseek: ; / moves read write pointer in an fsp entry
 31190                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31191                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 31192                              <1> 	;
 31193                              <1> 	; 'sysseek' changes the r/w pointer of (3rd word of in an
 31194                              <1> 	; fsp entry) of an open file whose file descriptor is in u.r0.
 31195                              <1> 	; The file descriptor refers to a file open for reading or
 31196                              <1> 	; writing. The read (or write) pointer is set as follows:
 31197                              <1> 	;	* if 'ptrname' is 0, the pointer is set to offset.
 31198                              <1> 	;	* if 'ptrname' is 1, the pointer is set to its
 31199                              <1> 	;	  current location plus offset.
 31200                              <1> 	;	* if 'ptrname' is 2, the pointer is set to the
 31201                              <1> 	;	  size of file plus offset.
 31202                              <1> 	; The error bit (e-bit) is set for an undefined descriptor.
 31203                              <1> 	;
 31204                              <1> 	; Calling sequence:
 31205                              <1> 	;	sysseek; offset; ptrname
 31206                              <1> 	; Arguments:
 31207                              <1> 	;	offset - number of bytes desired to move 
 31208                              <1> 	;		 the r/w pointer
 31209                              <1> 	;	ptrname - a switch indicated above
 31210                              <1> 	;
 31211                              <1> 	; Inputs: r0 - file descriptor 
 31212                              <1> 	; Outputs: -
 31213                              <1> 	; ...............................................................
 31214                              <1> 	;	
 31215                              <1> 	; Retro UNIX 8086 v1 modification: 
 31216                              <1> 	;       'sysseek' system call has three arguments; so,
 31217                              <1> 	;	* 1st argument, file descriptor is in BX (BL) register
 31218                              <1> 	;	* 2nd argument, offset is in CX register
 31219                              <1> 	;	* 3rd argument, ptrname/switch is in DX (DL) register	
 31220                              <1> 	;	
 31221                              <1> 
 31222 0000A7D3 E823000000          <1> 	call	seektell
 31223                              <1> 	; AX = u.count
 31224                              <1> 	; BX = *u.fofp
 31225                              <1> 		; jsr r0,seektell / get proper value in u.count
 31226                              <1> 		; add u.base,u.count / add u.base to it
 31227 0000A7D8 0305[60CE0000]      <1> 	add	eax, [u.base] ; add offset (u.base) to base
 31228 0000A7DE 8903                <1> 	mov	[ebx], eax
 31229                              <1> 		; mov u.count,*u.fofp / put result into r/w pointer
 31230 0000A7E0 E9FFEDFFFF          <1> 	jmp	sysret
 31231                              <1> 		; br sysret4
 31232                              <1> 
 31233                              <1> systell: ; / get the r/w pointer
 31234                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31235                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 31236                              <1> 	;
 31237                              <1> 	; Retro UNIX 8086 v1 modification:
 31238                              <1> 	; ! 'systell' does not work in original UNIX v1,
 31239                              <1> 	; 	    it returns with error !
 31240                              <1> 	; Inputs: r0 - file descriptor 
 31241                              <1> 	; Outputs: r0 - file r/w pointer
 31242                              <1> 
 31243                              <1> 	;xor	ecx, ecx ; 0
 31244 0000A7E5 BA01000000          <1> 	mov	edx, 1 ; 05/08/2013
 31245                              <1> 	;call 	seektell
 31246 0000A7EA E812000000          <1> 	call 	seektell0 ; 05/08/2013
 31247                              <1> 	;mov	ebx, [u.fofp]
 31248 0000A7EF 8B03                <1> 	mov	eax, [ebx]
 31249 0000A7F1 A3[40CE0000]        <1> 	mov	[u.r0], eax
 31250 0000A7F6 E9E9EDFFFF          <1> 	jmp	sysret
 31251                              <1> 
 31252                              <1> ; Original unix v1 'systell' system call:
 31253                              <1> 		; jsr r0,seektell
 31254                              <1> 		; br error4
 31255                              <1> 
 31256                              <1> seektell:
 31257                              <1> 	; 03/01/2016
 31258                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31259                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 31260                              <1> 	;
 31261                              <1> 	; 'seektell' puts the arguments from sysseek and systell
 31262                              <1> 	; call in u.base and u.count. It then gets the i-number of
 31263                              <1> 	; the file from the file descriptor in u.r0 and by calling
 31264                              <1> 	; getf. The i-node is brought into core and then u.count
 31265                              <1> 	; is checked to see it is a 0, 1, or 2.
 31266                              <1> 	; If it is 0 - u.count stays the same
 31267                              <1> 	;          1 - u.count = offset (u.fofp)
 31268                              <1> 	;	   2 - u.count = i.size (size of file)
 31269                              <1> 	; 	 		
 31270                              <1> 	; !! Retro UNIX 8086 v1 modification:
 31271                              <1> 	;	Argument 1, file descriptor is in BX;
 31272                              <1> 	;	Argument 2, offset is in CX;
 31273                              <1> 	;	Argument 3, ptrname/switch is in DX register.	
 31274                              <1> 	;
 31275                              <1> 	; mov 	ax, 3 ; Argument transfer method 3 (three arguments)	
 31276                              <1> 	; call 	arg
 31277                              <1> 	;
 31278                              <1> 	; ((Return -> ax = base for offset (position= base+offset))
 31279                              <1> 	;
 31280 0000A7FB 890D[60CE0000]      <1> 	mov 	[u.base], ecx ; offset
 31281                              <1> 		; jsr r0,arg; u.base / puts offset in u.base
 31282                              <1> seektell0:
 31283 0000A801 8915[64CE0000]      <1> 	mov 	[u.count], edx
 31284                              <1> 		; jsr r0,arg; u.count / put ptr name in u.count
 31285                              <1> 	; mov	ax, bx
 31286                              <1> 		; mov *u.r0,r1 / file descriptor in r1 
 31287                              <1> 			     ; / (index in u.fp list)
 31288                              <1> 	; call	getf
 31289                              <1> 		; jsr r0,getf / u.fofp points to 3rd word in fsp entry
 31290                              <1> 	; BX = file descriptor (file number)
 31291 0000A807 E83DFCFFFF          <1> 	call	getf1
 31292 0000A80C 6609C0              <1> 	or	ax, ax ; i-number of the file
 31293                              <1> 		; mov r1,-(sp) / r1 has i-number of file, 
 31294                              <1> 		             ; / put it on the stack
 31295                              <1> 	;jz	error
 31296                              <1> 		; beq error4 / if i-number is 0, not active so error
 31297 0000A80F 750F                <1> 	jnz	short seektell1
 31298 0000A811 C705[95CE0000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
 31299 0000A819 0000                <1>
 31300 0000A81B E9A4EDFFFF          <1> 	jmp	error
 31301                              <1> seektell1:
 31302                              <1> 	;push	eax
 31303 0000A820 80FC80              <1> 	cmp	ah, 80h
 31304 0000A823 7203                <1> 	jb	short seektell2
 31305                              <1> 		; bgt .+4 / if its positive jump
 31306 0000A825 66F7D8              <1> 	neg	ax
 31307                              <1> 		; neg r1 / if not make it positive
 31308                              <1> seektell2:
 31309 0000A828 E8EF020000          <1> 	call	iget
 31310                              <1> 		; jsr r0,iget / get its i-node into core
 31311 0000A82D 8B1D[50CE0000]      <1>         mov     ebx, [u.fofp] ; 05/08/2013
 31312 0000A833 803D[64CE0000]01    <1> 	cmp	byte [u.count], 1
 31313                              <1> 		; cmp u.count,$1 / is ptr name =1
 31314 0000A83A 7705                <1> 	ja	short seektell3
 31315                              <1> 		; blt 2f / no its zero
 31316 0000A83C 740A                <1> 	je	short seektell_4
 31317                              <1> 		; beq 1f / yes its 1
 31318 0000A83E 31C0                <1> 	xor	eax, eax
 31319                              <1> 	;jmp	short seektell_5
 31320 0000A840 C3                  <1> 	retn
 31321                              <1> seektell3:
 31322                              <1> 	; 03/01/2016
 31323                              <1> 	;movzx	eax, word [i.size]
 31324 0000A841 66A1[1ACB0000]      <1>         mov   	ax, [i.size]
 31325                              <1>                 ; mov i.size,u.count /  put number of bytes 
 31326                              <1>                                    ; / in file in u.count
 31327                              <1> 	;jmp	short seektell_5
 31328                              <1> 		; br 2f
 31329 0000A847 C3                  <1> 	retn
 31330                              <1> seektell_4: ; 1: / ptrname =1
 31331                              <1> 	;mov	ebx, [u.fofp]
 31332 0000A848 8B03                <1> 	mov	eax, [ebx]
 31333                              <1> 		; mov *u.fofp,u.count / put offset in u.count
 31334                              <1> ;seektell_5: ; 2: / ptrname =0
 31335                              <1> 	;mov	[u.count], eax
 31336                              <1> 	;pop	eax 
 31337                              <1> 		; mov (sp)+,r1 / i-number on stack  r1
 31338 0000A84A C3                  <1> 	retn
 31339                              <1> 		; rts r0
 31340                              <1> 
 31341                              <1> sysintr: ; / set interrupt handling
 31342                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31343                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 31344                              <1> 	;
 31345                              <1> 	; 'sysintr' sets the interrupt handling value. It puts
 31346                              <1> 	; argument of its call in u.intr then branches into 'sysquit'
 31347                              <1> 	; routine. u.tty is checked if to see if a control tty exists.
 31348                              <1> 	; If one does the interrupt character in the tty buffer is
 31349                              <1> 	; cleared and 'sysret'is called. If one does not exits
 31350                              <1> 	; 'sysret' is just called.	
 31351                              <1> 	;
 31352                              <1> 	; Calling sequence:
 31353                              <1> 	;	sysintr; arg
 31354                              <1> 	; Argument:
 31355                              <1> 	;	arg - if 0, interrupts (ASCII DELETE) are ignored.
 31356                              <1> 	;	    - if 1, intterupts cause their normal result
 31357                              <1> 	;		 i.e force an exit.
 31358                              <1> 	;	    - if arg is a location within the program,
 31359                              <1> 	;		control is passed to that location when
 31360                              <1> 	;		an interrupt occurs.	
 31361                              <1> 	; Inputs: -
 31362                              <1> 	; Outputs: -
 31363                              <1> 	; ...............................................................
 31364                              <1> 	;	
 31365                              <1> 	; Retro UNIX 8086 v1 modification: 
 31366                              <1> 	;       'sysintr' system call sets u.intr to value of BX
 31367                              <1> 	;	then branches into sysquit.
 31368                              <1> 	;
 31369 0000A84B 66891D[84CE0000]    <1> 	mov	[u.intr], bx
 31370                              <1> 		; jsr r0,arg; u.intr / put the argument in u.intr
 31371                              <1> 		; br 1f / go into quit routine
 31372 0000A852 E98DEDFFFF          <1> 	jmp	sysret
 31373                              <1> 
 31374                              <1> sysquit:
 31375                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31376                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 31377                              <1> 	;
 31378                              <1> 	; 'sysquit' turns off the quit signal. it puts the argument of
 31379                              <1> 	; the call in u.quit. u.tty is checked if to see if a control 
 31380                              <1> 	; tty exists. If one does the interrupt character in the tty
 31381                              <1> 	; buffer is cleared and 'sysret'is called. If one does not exits
 31382                              <1> 	; 'sysret' is just called.	
 31383                              <1> 	;
 31384                              <1> 	; Calling sequence:
 31385                              <1> 	;	sysquit; arg
 31386                              <1> 	; Argument:
 31387                              <1> 	;	arg - if 0, this call diables quit signals from the
 31388                              <1> 	;		typewriter (ASCII FS)
 31389                              <1> 	;	    - if 1, quits are re-enabled and cause execution to
 31390                              <1> 	;		cease and a core image to be produced.
 31391                              <1> 	;		 i.e force an exit.
 31392                              <1> 	;	    - if arg is an addres in the program,
 31393                              <1> 	;		a quit causes control to sent to that
 31394                              <1> 	;		location.	
 31395                              <1> 	; Inputs: -
 31396                              <1> 	; Outputs: -
 31397                              <1> 	; ...............................................................
 31398                              <1> 	;	
 31399                              <1> 	; Retro UNIX 8086 v1 modification: 
 31400                              <1> 	;       'sysquit' system call sets u.quit to value of BX
 31401                              <1> 	;	then branches into 'sysret'.
 31402                              <1> 	;
 31403 0000A857 66891D[86CE0000]    <1> 	mov	[u.quit], bx
 31404 0000A85E E981EDFFFF          <1> 	jmp	sysret
 31405                              <1> 		; jsr r0,arg; u.quit / put argument in u.quit
 31406                              <1> 	;1:
 31407                              <1> 		; mov u.ttyp,r1 / move pointer to control tty buffer
 31408                              <1> 			      ; / to r1
 31409                              <1> 		; beq sysret4 / return to user
 31410                              <1> 		; clrb 6(r1) / clear the interrupt character 
 31411                              <1> 			   ; / in the tty buffer
 31412                              <1> 		; br sysret4 / return to user
 31413                              <1> 
 31414                              <1> syssetuid: ; / set process id
 31415                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31416                              <1> 	; 07/07/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 31417                              <1> 	;
 31418                              <1> 	; 'syssetuid' sets the user id (u.uid) of the current process
 31419                              <1> 	; to the process id in (u.r0). Both the effective user and 
 31420                              <1> 	; u.uid and the real user u.ruid are set to this. 
 31421                              <1> 	; Only the super user can make this call.	
 31422                              <1> 	;
 31423                              <1> 	; Calling sequence:
 31424                              <1> 	;	syssetuid
 31425                              <1> 	; Arguments: -
 31426                              <1> 	;
 31427                              <1> 	; Inputs: (u.r0) - contains the process id.
 31428                              <1> 	; Outputs: -
 31429                              <1> 	; ...............................................................
 31430                              <1> 	;	
 31431                              <1> 	; Retro UNIX 8086 v1 modification: 
 31432                              <1> 	;       BL contains the (new) user ID of the current process
 31433                              <1> 
 31434                              <1> 		; movb *u.r0,r1 / move process id (number) to r1
 31435 0000A863 3A1D[8DCE0000]      <1> 	cmp	bl, [u.ruid] 
 31436                              <1> 		; cmpb r1,u.ruid / is it equal to the real user 
 31437                              <1> 			       ; / id number
 31438 0000A869 741E                <1> 	je	short setuid1
 31439                              <1> 		; beq 1f / yes
 31440 0000A86B 803D[8CCE0000]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
 31441                              <1> 		; tstb u.uid / no, is current user the super user?
 31442                              <1> 	;ja	error
 31443                              <1> 		; bne error4 / no, error
 31444 0000A872 760F                <1> 	jna	short setuid0
 31445 0000A874 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11
 31446 0000A87C 0000                <1>
 31447                              <1> 				;  'permission denied !' error
 31448 0000A87E E941EDFFFF          <1> 	jmp	error
 31449                              <1> setuid0:
 31450 0000A883 881D[8DCE0000]      <1> 	mov	[u.ruid], bl
 31451                              <1> setuid1: ; 1:
 31452 0000A889 881D[8CCE0000]      <1> 	mov	[u.uid], bl ; 02/08/2013
 31453                              <1> 		; movb r1,u.uid / put process id in u.uid
 31454                              <1> 		; movb r1,u.ruid / put process id in u.ruid
 31455 0000A88F E950EDFFFF          <1> 	jmp	sysret
 31456                              <1> 		; br sysret4 / system return
 31457                              <1> 
 31458                              <1> sysgetuid: ; < get user id >
 31459                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31460                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 31461                              <1> 	;
 31462                              <1> 	; 'sysgetuid' returns the real user ID of the current process.
 31463                              <1> 	; The real user ID identifies the person who is logged in,
 31464                              <1> 	; in contradistinction to the effective user ID, which
 31465                              <1> 	; determines his access permission at each moment. It is thus
 31466                              <1> 	; useful to programs which operate using the 'set user ID'
 31467                              <1> 	; mode, to find out who invoked them.	
 31468                              <1> 	;
 31469                              <1> 	; Calling sequence:
 31470                              <1> 	;	syssetuid
 31471                              <1> 	; Arguments: -
 31472                              <1> 	;
 31473                              <1> 	; Inputs: -
 31474                              <1> 	; Outputs: (u.r0) - contains the real user's id.
 31475                              <1> 	; ...............................................................
 31476                              <1> 	;	
 31477                              <1> 	; Retro UNIX 8086 v1 modification: 
 31478                              <1> 	;       AL contains the real user ID at return.
 31479                              <1> 	;
 31480 0000A894 0FB605[8DCE0000]    <1> 	movzx 	eax, byte [u.ruid]
 31481 0000A89B A3[40CE0000]        <1> 	mov	[u.r0], eax
 31482                              <1> 		; movb	u.ruid,*u.r0 / move the real user id to (u.r0)
 31483 0000A8A0 E93FEDFFFF          <1> 	jmp	sysret
 31484                              <1> 		; br sysret4 / systerm return, sysret
 31485                              <1> 
 31486                              <1> anyi: 
 31487                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 31488                              <1> 	; 25/04/2013 (Retro UNIX 8086 v1)
 31489                              <1> 	;
 31490                              <1> 	; 'anyi' is called if a file deleted while open.
 31491                              <1> 	; "anyi" checks to see if someone else has opened this file.
 31492                              <1> 	;
 31493                              <1> 	; INPUTS ->
 31494                              <1> 	;    r1 - contains an i-number
 31495                              <1> 	;    fsp - start of table containing open files
 31496                              <1> 	;
 31497                              <1> 	; OUTPUTS ->
 31498                              <1> 	;    "deleted" flag set in fsp entry of another occurrence of
 31499                              <1> 	;	   this file and r2 points 1st word of this fsp entry.
 31500                              <1> 	;    if file not found - bit in i-node map is cleared
 31501                              <1> 	;    			 (i-node is freed)
 31502                              <1> 	;               all blocks related to i-node are freed
 31503                              <1> 	;	        all flags in i-node are cleared
 31504                              <1> 	; ((AX = R1)) input
 31505                              <1> 	;
 31506                              <1> 	;    (Retro UNIX Prototype : 02/12/2012, UNIXCOPY.ASM)
 31507                              <1>         ;    ((Modified registers: eDX, eCX, eBX, eSI, eDI, eBP))  
 31508                              <1> 	;
 31509                              <1> 		; / r1 contains an i-number
 31510 0000A8A5 BB[16CC0000]        <1> 	mov	ebx, fsp
 31511                              <1> 		; mov $fsp,r2 / move start of fsp table to r2
 31512                              <1> anyi_1: ; 1:
 31513 0000A8AA 663B03              <1> 	cmp	ax, [ebx]
 31514                              <1> 		; cmp r1,(r2) / do i-numbers match?
 31515 0000A8AD 7433                <1> 	je	short anyi_3
 31516                              <1> 		; beq 1f / yes, 1f
 31517 0000A8AF 66F7D8              <1> 	neg	ax
 31518                              <1> 		; neg r1 / no complement r1
 31519 0000A8B2 663B03              <1> 	cmp	ax, [ebx]
 31520                              <1> 		; cmp r1,(r2) / do they match now?
 31521 0000A8B5 742B                <1> 	je	short anyi_3
 31522                              <1> 		; beq 1f / yes, transfer
 31523                              <1> 		; / i-numbers do not match
 31524 0000A8B7 83C30A              <1> 	add	ebx, 10 ; fsp table size is 10 bytes
 31525                              <1> 			; in Retro UNIX 386 v1 (22/06/2015)
 31526                              <1> 		; add $8,r2 / no, bump to next entry in fsp table
 31527 0000A8BA 81FB[0ACE0000]      <1> 	cmp	ebx, fsp + (nfiles*10) ; 22/06/2015 
 31528                              <1> 		; cmp r2,$fsp+[nfiles*8] 
 31529                              <1> 				; / are we at last entry in the table
 31530 0000A8C0 72E8                <1> 	jb	short anyi_1
 31531                              <1> 		; blt 1b / no, check next entries i-number
 31532                              <1> 	;cmp	ax, 32768
 31533 0000A8C2 80FC80              <1> 	cmp	ah, 80h ; negative number check
 31534                              <1> 		; tst r1 / yes, no match
 31535                              <1> 		; bge .+4
 31536 0000A8C5 7203                <1> 	jb	short anyi_2
 31537 0000A8C7 66F7D8              <1> 	neg	ax
 31538                              <1> 		; neg r1 / make i-number positive
 31539                              <1> anyi_2:	
 31540 0000A8CA E864020000          <1> 	call	imap
 31541                              <1> 		; jsr r0,imap / get address of allocation bit 
 31542                              <1> 			    ; / in the i-map in r2
 31543                              <1> 	;; DL/DX (MQ) has a 1 in the calculated bit position
 31544                              <1>         ;; eBX (R2) has address of the byte with allocation bit
 31545                              <1>  	; not	dx
 31546 0000A8CF F6D2                <1> 	not 	dl ;; 0 at calculated bit position, other bits are 1
 31547                              <1>         ;and	[ebx], dx
 31548 0000A8D1 2013                <1> 	and 	[ebx], dl 
 31549                              <1> 		; bicb mq,(r2) / clear bit for i-node in the imap
 31550 0000A8D3 E850020000          <1> 	call	itrunc
 31551                              <1> 		; jsr r0,itrunc / free all blocks related to i-node
 31552 0000A8D8 66C705[16CB0000]00- <1>  	mov 	word [i.flgs], 0
 31553 0000A8E0 00                  <1>
 31554                              <1> 		; clr i.flgs / clear all flags in the i-node
 31555 0000A8E1 C3                  <1> 	retn
 31556                              <1> 		;rts	r0 / return
 31557                              <1> anyi_3: ; 1: / i-numbers match
 31558 0000A8E2 FE4309              <1> 	inc 	byte [ebx+9] ; 22/06/2015
 31559                              <1> 		;incb 7(r2) / increment upper byte of the 4th word
 31560                              <1> 		   ; / in that fsp entry (deleted flag of fsp entry)
 31561 0000A8E5 C3                  <1> 	retn
 31562                              <1> 		; rts r0
 31563                              <1> 
 31564                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u7.s
 31565                              <1> ; Last Modification: 14/11/2015
 31566                              <1> 
 31567                              <1> sysmount: ; / mount file system; args special; name
 31568                              <1> 	; 14/11/2015
 31569                              <1> 	; 24/10/2015
 31570                              <1> 	; 13/10/2015
 31571                              <1> 	; 10/07/2015
 31572                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 31573                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
 31574                              <1> 	;
 31575                              <1> 	; 'sysmount' anounces to the system that a removable 
 31576                              <1> 	; file system has been mounted on a special file.
 31577                              <1> 	; The device number of the special file is obtained via
 31578                              <1> 	; a call to 'getspl'. It is put in the I/O queue entry for
 31579                              <1> 	; dismountable file system (sb1) and the I/O queue entry is
 31580                              <1> 	; set up to read (bit 10 is set). 'ppoke' is then called to
 31581                              <1> 	; to read file system into core, i.e. the first block on the
 31582                              <1> 	; mountable file system is read in. This block is super block
 31583                              <1> 	; for the file system. This call is super user restricted.	
 31584                              <1> 	;
 31585                              <1> 	; Calling sequence:
 31586                              <1> 	;	sysmount; special; name
 31587                              <1> 	; Arguments:
 31588                              <1> 	;	special - pointer to name of special file (device)
 31589                              <1> 	;	name -  pointer to name of the root directory of the
 31590                              <1> 	;		newly mounted file system. 'name' should 
 31591                              <1> 	;		always be a directory.
 31592                              <1> 	; Inputs: - 
 31593                              <1> 	; Outputs: -
 31594                              <1> 	; ...............................................................
 31595                              <1> 	;				
 31596                              <1> 	; Retro UNIX 8086 v1 modification: 
 31597                              <1> 	;       'sysmount' system call has two arguments; so,
 31598                              <1> 	;	* 1st argument, special is pointed to by BX register
 31599                              <1> 	;	* 2nd argument, name is in CX register
 31600                              <1> 	;
 31601                              <1> 	;	NOTE: Device numbers, names and related procedures are 
 31602                              <1> 	;	       already modified for IBM PC compatibility and 
 31603                              <1> 	;	       Retro UNIX 8086 v1 device configuration.	
 31604                              <1> 	
 31605                              <1> 	;call	arg2
 31606                              <1> 		; jsr r0,arg2 / get arguments special and name
 31607 0000A8E6 891D[58CE0000]      <1> 	mov	[u.namep], ebx
 31608 0000A8EC 51                  <1> 	push	ecx ; directory name
 31609 0000A8ED 66833D[2CCE0000]00  <1> 	cmp	word [mnti], 0
 31610                              <1> 		; tst mnti / is the i-number of the cross device file
 31611                              <1> 			 ; / zero?
 31612                              <1> 	;ja	error
 31613                              <1>         	; bne errora / no, error
 31614 0000A8F5 0F87E9000000        <1> 	ja	sysmnt_err0
 31615                              <1> 	;
 31616 0000A8FB E8CC000000          <1> 	call	getspl
 31617                              <1> 		; jsr r0,getspl / get special files device number in r1
 31618                              <1> 	; 13/10/2015
 31619 0000A900 0FB7D8              <1> 	movzx	ebx, ax ; ; Retro UNIX 8086 v1 device number (0 to 5)
 31620 0000A903 F683[0AB90000]80    <1>         test    byte [ebx+drv.status], 80h ; 24/10/2015 
 31621 0000A90A 750F                <1> 	jnz	short sysmnt_1
 31622                              <1> sysmnt_err1:
 31623 0000A90C C705[95CE0000]0F00- <1>         mov     dword [u.error], ERR_DRV_NOT_RDY ; drive not ready !
 31624 0000A914 0000                <1>
 31625 0000A916 E9A9ECFFFF          <1> 	jmp	error
 31626                              <1> sysmnt_1:
 31627 0000A91B 8F05[58CE0000]      <1> 	pop	dword [u.namep]
 31628                              <1>         	; mov (sp)+,u.namep / put the name of file to be placed
 31629                              <1> 				  ; / on the device
 31630                              <1> 	; 14/11/2015
 31631 0000A921 53                  <1> 	push	ebx ; 13/10/2015
 31632                              <1> 		; mov r1,-(sp) / save the device number
 31633                              <1>         ;
 31634 0000A922 E859FBFFFF          <1> 	call	namei
 31635                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
 31636                              <1> 		       ; ax = 0 -> file not found 	
 31637                              <1> 	;jz	error
 31638                              <1> 	;jc	error
 31639                              <1> 		; jsr r0,namei / get the i-number of the file
 31640                              <1>                	; br errora
 31641 0000A927 730F                <1> 	jnc	short sysmnt_2
 31642                              <1> sysmnt_err2:
 31643 0000A929 C705[95CE0000]0C00- <1>         mov     dword [u.error], ERR_FILE_NOT_FOUND ; drive not ready !
 31644 0000A931 0000                <1>
 31645 0000A933 E98CECFFFF          <1> 	jmp	error
 31646                              <1> sysmnt_2:	
 31647 0000A938 66A3[2CCE0000]      <1> 	mov	[mnti], ax
 31648                              <1>         	; mov r1,mnti / put it in mnti
 31649                              <1> ;	mov	ebx, sb1 ; super block buffer (of mounted disk)
 31650                              <1> sysmnt_3: ;1:
 31651                              <1>         ;cmp	byte [ebx+1], 0
 31652                              <1> 		; tstb sb1+1 / is 15th bit of I/O queue entry for
 31653                              <1> 			   ; / dismountable device set?
 31654                              <1>         ;jna	short sysmnt_4		
 31655                              <1> 		; bne 1b / (inhibit bit) yes, skip writing
 31656                              <1> 	;call	idle 	; (wait for hardware interrupt)
 31657                              <1> 	;jmp	short sysmnt_3
 31658                              <1> sysmnt_4:   
 31659 0000A93E 58                  <1> 	pop	eax ; Retro UNIX 8086 v1 device number/ID (0 to 5)     
 31660 0000A93F A2[29CE0000]        <1> 	mov	[mdev], al
 31661                              <1> 		; mov  (sp),mntd / no, put the device number in mntd
 31662 0000A944 8803                <1> 	mov	[ebx], al
 31663                              <1>         	; movb (sp),sb1 / put the device number in the lower byte
 31664                              <1> 			      ; / of the I/O queue entry
 31665                              <1> 	;mov	byte [cdev], 1 ; mounted device/drive
 31666                              <1>         	; mov (sp)+,cdev / put device number in cdev
 31667 0000A946 66810B0004          <1>         or	word [ebx], 400h ; Bit 10, 'read' flag/bit
 31668                              <1> 		; bis $2000,sb1 / set the read bit
 31669                              <1> 	; Retro UNIX 386 v1 modification : 
 31670                              <1> 	;	32 bit block number at buffer header offset 4
 31671 0000A94B C7430401000000      <1> 	mov	dword [ebx+4], 1 ; physical block number = 1
 31672 0000A952 E8DD010000          <1> 	call 	diskio
 31673 0000A957 731C                <1> 	jnc	short sysmnt_5
 31674 0000A959 31C0                <1> 	xor 	eax, eax
 31675 0000A95B 66A3[2CCE0000]      <1> 	mov	[mnti], ax ; 0
 31676 0000A961 A2[29CE0000]        <1> 	mov	[mdev], al ; 0
 31677                              <1> 	;mov	[cdev], al ; 0
 31678                              <1> sysmnt_invd:
 31679                              <1> 	; 14/11/2015
 31680 0000A966 FEC8                <1> 	dec 	al
 31681 0000A968 8903                <1> 	mov	[ebx], eax ; 000000FFh
 31682 0000A96A FEC0                <1> 	inc	al
 31683 0000A96C 48                  <1> 	dec	eax
 31684 0000A96D 894304              <1> 	mov	[ebx+4], eax ; 0FFFFFFFFh
 31685 0000A970 E94FECFFFF          <1> 	jmp	error
 31686                              <1> sysmnt_5:
 31687                              <1> 	; 14/11/2015 (Retro UNIX 386 v1 modification)
 31688                              <1> 	; (Following check is needed to prevent mounting an
 31689                              <1> 	; in valid valid file system (in valid super block).
 31690                              <1> 	; 
 31691 0000A975 0FB603              <1> 	movzx	eax, byte [ebx] ; device number
 31692 0000A978 C0E002              <1> 	shl	al, 2 ; 4*index
 31693 0000A97B 8B88[EEB80000]      <1> 	mov	ecx, [eax+drv.size] ; volume (fs) size
 31694 0000A981 C1E103              <1> 	shl 	ecx, 3
 31695 0000A984 0FB715[F1D80000]    <1> 	movzx	edx, word [sb1+4] ; the 1st data word
 31696 0000A98B 39D1                <1> 	cmp	ecx, edx ; compare free map bits and volume size
 31697                              <1> 			 ; (in sectors), if they are not equal
 31698                              <1> 			 ; the disk to be mounted is an...	
 31699 0000A98D 75D7                <1> 	jne	short sysmnt_invd ; invalid disk !
 31700                              <1> 			 ; (which has not got a valid super block)
 31701                              <1> 	;
 31702 0000A98F C6430100            <1> 	mov	byte [ebx+1], 0
 31703                              <1> 	       	; jsr r0,ppoke / read in entire file system
 31704                              <1> ;sysmnt_6: ;1:
 31705                              <1> 	;;cmp	byte [sb1+1], 0
 31706                              <1> 		; tstb   sb1+1 / done reading?
 31707                              <1>    	;;jna	sysret
 31708                              <1> 	;;call	idle ; (wait for hardware interrupt)
 31709                              <1> 	;;jmp	short sysmnt_6
 31710                              <1> 		;bne 1b / no, wait
 31711                              <1>         	;br sysreta / yes
 31712 0000A993 E94CECFFFF          <1> 	jmp	sysret
 31713                              <1> 
 31714                              <1> sysumount: ; / special dismount file system
 31715                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 31716                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
 31717                              <1> 	;
 31718                              <1> 	; 04/11/2013
 31719                              <1> 	; 09/07/2013
 31720                              <1> 	; 'sysumount' anounces to the system that the special file, 
 31721                              <1> 	; indicated as an argument is no longer contain a removable
 31722                              <1> 	; file system. 'getspl' gets the device number of the special
 31723                              <1> 	; file. If no file system was mounted on that device an error
 31724                              <1> 	; occurs. 'mntd' and 'mnti' are cleared and control is passed
 31725                              <1> 	; to 'sysret'.
 31726                              <1> 	;
 31727                              <1> 	; Calling sequence:
 31728                              <1> 	;	sysmount; special
 31729                              <1> 	; Arguments:
 31730                              <1> 	;	special - special file to dismount (device)
 31731                              <1> 	;
 31732                              <1> 	; Inputs: - 
 31733                              <1> 	; Outputs: -
 31734                              <1> 	; ...............................................................
 31735                              <1> 	;				
 31736                              <1> 	; Retro UNIX 8086 v1 modification: 
 31737                              <1> 	;       'sysumount' system call has one argument; so,
 31738                              <1> 	;	* Single argument, special is pointed to by BX register
 31739                              <1> 	;
 31740                              <1> 	
 31741                              <1> 	;mov 	ax, 1 ; one/single argument, put argument in BX	
 31742                              <1> 	;call	arg
 31743                              <1> 		; jsr r0,arg; u.namep / point u.namep to special
 31744 0000A998 891D[58CE0000]      <1>         mov	[u.namep], ebx
 31745 0000A99E E829000000          <1> 	call	getspl
 31746                              <1> 		; jsr r0,getspl / get the device number in r1
 31747 0000A9A3 3A05[29CE0000]      <1> 	cmp	al, [mdev]
 31748                              <1> 		; cmp r1,mntd / is it equal to the last device mounted?
 31749 0000A9A9 7539                <1> 	jne	short sysmnt_err0 ; 'permission denied !' error
 31750                              <1> 	;jne	error
 31751                              <1>         	; bne errora / no error
 31752 0000A9AB 30C0                <1> 	xor	al, al ; ah = 0
 31753                              <1> sysumnt_0: ;1:
 31754 0000A9AD 3805[EED80000]      <1>      	cmp 	[sb1+1], al ; 0
 31755                              <1> 		; tstb sb1+1 / yes, is the device still doing I/O 
 31756                              <1> 			   ; / (inhibit bit set)?
 31757 0000A9B3 7607                <1> 	jna	short sysumnt_1		
 31758                              <1> 		; bne 1b / yes, wait
 31759 0000A9B5 E87B010000          <1> 	call	idle ; (wait for hardware interrupt)
 31760 0000A9BA EBF1                <1> 	jmp	short sysumnt_0
 31761                              <1> sysumnt_1:        
 31762 0000A9BC A2[29CE0000]        <1> 	mov	[mdev], al
 31763                              <1> 	     	; clr mntd / no, clear these
 31764 0000A9C1 66A3[2CCE0000]      <1>    	mov	[mnti], ax
 31765                              <1>         	; clr mnti
 31766 0000A9C7 E918ECFFFF          <1>         jmp	sysret
 31767                              <1> 		; br sysreta / return
 31768                              <1> 
 31769                              <1> getspl: ; / get device number from a special file name
 31770 0000A9CC E8AFFAFFFF          <1> 	call	namei
 31771                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
 31772                              <1> 		       ; ax = 0 -> file not found 	
 31773 0000A9D1 0F8252FFFFFF        <1>         jc      sysmnt_err2 ; 'file not found !' error
 31774                              <1> 	;jz	error
 31775                              <1> 	;jc	error
 31776                              <1> 		; jsr r0,namei / get the i-number of the special file
 31777                              <1>                 ; br errora / no such file
 31778 0000A9D7 6683E803            <1>         sub	ax, 3 ; Retro UNIX 8086 v1 modification !
 31779                              <1> 		      ;	i-number-3, 0 = fd0, 5 = hd3 
 31780                              <1> 		; sub $4,r1 / i-number-4 rk=1,tap=2+n
 31781 0000A9DB 7207                <1>         jc	short sysmnt_err0 ; 'permission denied !' error
 31782                              <1> 	;jc	error
 31783                              <1> 		; ble errora / less than 0?  yes, error
 31784 0000A9DD 6683F805            <1>         cmp	ax, 5 ;
 31785                              <1> 		; cmp  r1,$9. / greater than 9  tap 7
 31786 0000A9E1 7701                <1> 	ja	short sysmnt_err0 ; 'permission denied !' error
 31787                              <1> 	;ja	error
 31788                              <1>         	; bgt errora / yes, error
 31789                              <1>         ; AX = Retro UNIX 8086 v1 Device Number (0 to 5)
 31790                              <1> iopen_retn:
 31791 0000A9E3 C3                  <1> 	retn
 31792                              <1> 		; rts    r0 / return with device number in r1
 31793                              <1> sysmnt_err0:
 31794 0000A9E4 C705[95CE0000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 31795 0000A9EC 0000                <1>
 31796 0000A9EE E9D1EBFFFF          <1> 	jmp	error
 31797                              <1> 
 31798                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS9.INC
 31799                              <1> ; Last Modification: 09/12/2015
 31800                              <1> 
 31801                              <1> syssleep:
 31802                              <1> 	; 29/06/2015 - (Retro UNIX 386 v1)
 31803                              <1> 	; 11/06/2014 - (Retro UNIX 8086 v1)
 31804                              <1> 	;
 31805                              <1> 	; Retro UNIX 8086 v1 feature only
 31806                              <1> 	; (INPUT -> none)
 31807                              <1> 	;
 31808 0000A9F3 0FB61D[8FCE0000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 31809 0000A9FA 8AA3[95CB0000]      <1> 	mov	ah, [ebx+p.ttyc-1] ; current/console tty
 31810 0000AA00 E831010000          <1> 	call	sleep
 31811 0000AA05 E9DAEBFFFF          <1> 	jmp	sysret
 31812                              <1> 
 31813                              <1> vp_clr:
 31814                              <1> 	; Reset/Clear Video Page
 31815                              <1> 	;
 31816                              <1> 	; 30/06/2015 - (Retro UNIX 386 v1)
 31817                              <1> 	; 21/05/2013 - 30/10/2013(Retro UNIX 8086 v1) (U0.ASM)
 31818                              <1> 	;
 31819                              <1> 	; Retro UNIX 8086 v1 feature only !
 31820                              <1> 	;
 31821                              <1> 	; INPUTS -> 
 31822                              <1> 	;   BL = video page number	 
 31823                              <1> 	;
 31824                              <1> 	; OUTPUT ->
 31825                              <1> 	;   none
 31826                              <1> 	; ((Modified registers: eAX, BH, eCX, eDX, eSI, eDI))
 31827                              <1> 	;
 31828                              <1> 	; 04/12/2013
 31829 0000AA0A 28C0                <1> 	sub	al, al
 31830                              <1> 	; al = 0 (clear video page)
 31831                              <1> 	; bl = video page
 31832 0000AA0C B407                <1> 	mov	ah, 07h
 31833                              <1> 	; ah = 7 (attribute/color)
 31834 0000AA0E 6631C9              <1> 	xor 	cx, cx ; 0, left upper column (cl) & row (cl)
 31835 0000AA11 66BA4F18            <1> 	mov	dx, 184Fh ; right lower column & row (dl=24, dh=79)
 31836 0000AA15 E8F36BFFFF          <1> 	call	_scroll_up
 31837                              <1> 	; bl = video page
 31838 0000AA1A 6631D2              <1> 	xor	dx, dx ; 0 (cursor position) 
 31839 0000AA1D E9296EFFFF          <1> 	jmp 	_set_cpos
 31840                              <1> 
 31841                              <1> sysmsg:
 31842                              <1> 	; 11/11/2015
 31843                              <1> 	; 01/07/2015 - (Retro UNIX 386 v1 feature only!)
 31844                              <1> 	; Print user-application message on user's console tty
 31845                              <1> 	;
 31846                              <1> 	; Input -> EBX = Message address
 31847                              <1> 	;	   ECX = Message length (max. 255)
 31848                              <1> 	;	   DL = Color (IBM PC Rombios color attributes)
 31849                              <1> 	;
 31850 0000AA22 81F9FF000000        <1> 	cmp	ecx, MAX_MSG_LEN ; 255
 31851 0000AA28 0F87B6EBFFFF        <1> 	ja	sysret ; nothing to do with big message size
 31852 0000AA2E 08C9                <1> 	or	cl, cl
 31853 0000AA30 0F84AEEBFFFF        <1> 	jz	sysret
 31854 0000AA36 20D2                <1> 	and	dl, dl
 31855 0000AA38 7502                <1> 	jnz	short sysmsg0
 31856 0000AA3A B207                <1> 	mov	dl, 07h ; default color
 31857                              <1> 		; (black background, light gray character) 
 31858                              <1> sysmsg0:
 31859 0000AA3C 891D[60CE0000]      <1> 	mov	[u.base], ebx
 31860 0000AA42 8815[19BE0000]      <1> 	mov	[ccolor], dl ; color attributes
 31861 0000AA48 89E5                <1> 	mov	ebp, esp
 31862 0000AA4A 31DB                <1> 	xor	ebx, ebx ; 0
 31863 0000AA4C 891D[68CE0000]      <1> 	mov	[u.nread], ebx ; 0
 31864                              <1> 	;
 31865 0000AA52 381D[A7CE0000]      <1> 	cmp	[u.kcall], bl ; 0
 31866 0000AA58 7769                <1> 	ja	short sysmsgk ; Temporary (01/07/2015)
 31867                              <1> 	;
 31868 0000AA5A 890D[64CE0000]      <1> 	mov	[u.count], ecx
 31869 0000AA60 41                  <1> 	inc	ecx ; + 00h ; ASCIZZ
 31870 0000AA61 29CC                <1> 	sub	esp, ecx
 31871 0000AA63 89E7                <1> 	mov	edi, esp
 31872 0000AA65 89E6                <1> 	mov	esi, esp
 31873 0000AA67 66891D[A5CE0000]    <1> 	mov	[u.pcount], bx ; reset page (phy. addr.) counter
 31874                              <1> 	; 11/11/2015
 31875 0000AA6E 8A25[70CE0000]      <1> 	mov 	ah, [u.ttyp] ; recent open tty
 31876                              <1> 	; 0 = none
 31877 0000AA74 FECC                <1> 	dec	ah
 31878 0000AA76 790C                <1> 	jns	short sysmsg1 
 31879 0000AA78 8A1D[8FCE0000]      <1> 	mov	bl, [u.uno] ; process number	
 31880 0000AA7E 8AA3[95CB0000]      <1> 	mov	ah, [ebx+p.ttyc-1] ; user's (process's) console tty
 31881                              <1> sysmsg1:
 31882 0000AA84 8825[94CE0000]      <1> 	mov	[u.ttyn], ah
 31883                              <1> sysmsg2:
 31884 0000AA8A E8A0000000          <1> 	call	cpass
 31885 0000AA8F 7416                <1> 	jz	short sysmsg5
 31886 0000AA91 AA                  <1> 	stosb
 31887 0000AA92 20C0                <1> 	and	al, al
 31888 0000AA94 75F4                <1> 	jnz	short sysmsg2
 31889                              <1> sysmsg3:
 31890 0000AA96 80FC07              <1> 	cmp	ah, 7 ; tty number
 31891 0000AA99 7711                <1> 	ja	short sysmsg6 ; serial port
 31892 0000AA9B E83E000000          <1> 	call	print_cmsg
 31893                              <1> sysmsg4:
 31894 0000AAA0 89EC                <1> 	mov	esp, ebp	
 31895 0000AAA2 E93DEBFFFF          <1> 	jmp	sysret
 31896                              <1> sysmsg5:
 31897 0000AAA7 C60700              <1> 	mov	byte [edi], 0
 31898 0000AAAA EBEA                <1> 	jmp	short sysmsg3
 31899                              <1> sysmsg6:
 31900 0000AAAC 8A06                <1> 	mov	al, [esi]
 31901 0000AAAE E87A000000          <1> 	call	sndc
 31902 0000AAB3 72EB                <1> 	jc	short sysmsg4
 31903 0000AAB5 803E00              <1> 	cmp	byte [esi], 0  ; 0 is stop character
 31904 0000AAB8 76E6                <1> 	jna	short sysmsg4
 31905 0000AABA 46                  <1> 	inc 	esi
 31906 0000AABB 8A25[94CE0000]      <1> 	mov	ah, [u.ttyn]
 31907 0000AAC1 EBE9                <1> 	jmp	short sysmsg6
 31908                              <1> 
 31909                              <1> sysmsgk: ; Temporary (01/07/2015)
 31910                              <1> 	; The message has been sent by Kernel (ASCIIZ string)
 31911                              <1> 	; (ECX -character count- will not be considered)
 31912 0000AAC3 8B35[60CE0000]      <1> 	mov	esi, [u.base]
 31913 0000AAC9 8A25[18BE0000]      <1> 	mov	ah, [ptty] ; present/current screen (video page)
 31914 0000AACF 8825[94CE0000]      <1> 	mov	[u.ttyn], ah
 31915 0000AAD5 C605[A7CE0000]00    <1> 	mov	byte [u.kcall], 0
 31916 0000AADC EBB8                <1> 	jmp	short sysmsg3
 31917                              <1> 	
 31918                              <1> 
 31919                              <1> print_cmsg: 
 31920                              <1> 	; 01/07/2015 (retro UNIX 386 v1 feature only !)
 31921                              <1> 	;
 31922                              <1> 	; print message (on user's console tty) 
 31923                              <1> 	;	with requested color
 31924                              <1> 	;
 31925                              <1> 	; INPUTS:
 31926                              <1> 	;	esi = message address
 31927                              <1> 	;	[u.ttyn] = tty number (0 to 7)
 31928                              <1> 	;	[ccolor] = color attributes (IBM PC BIOS colors)
 31929                              <1> 	;
 31930 0000AADE AC                  <1> 	lodsb
 31931                              <1> pcmsg1:
 31932 0000AADF 56                  <1> 	push 	esi
 31933 0000AAE0 0FB61D[94CE0000]    <1>         movzx   ebx, byte [u.ttyn]
 31934 0000AAE7 8A25[19BE0000]      <1> 	mov	ah, [ccolor]
 31935 0000AAED E8C56CFFFF          <1> 	call 	WRITE_TTY
 31936 0000AAF2 5E                  <1> 	pop	esi
 31937 0000AAF3 AC                  <1> 	lodsb
 31938 0000AAF4 20C0                <1> 	and 	al, al  ; 0
 31939 0000AAF6 75E7                <1> 	jnz 	short pcmsg1
 31940 0000AAF8 C3                  <1> 	retn
 31941                              <1> 
 31942                              <1> sysgeterr:
 31943                              <1> 	; 09/12/2015
 31944                              <1> 	; 21/09/2015 - (Retro UNIX 386 v1 feature only!)
 31945                              <1> 	; Get last error number or page fault count
 31946                              <1> 	; (for debugging)
 31947                              <1> 	;
 31948                              <1> 	; Input -> EBX = return type
 31949                              <1> 	;	   0 = last error code (which is in 'u.error')	
 31950                              <1> 	;	   FFFFFFFFh = page fault count for running process
 31951                              <1> 	;	   FFFFFFFEh = total page fault count
 31952                              <1> 	;	   1 .. FFFFFFFDh = undefined 
 31953                              <1> 	;
 31954                              <1> 	; Output -> EAX = last error number or page fault count
 31955                              <1> 	;	   (depending on EBX input)
 31956                              <1> 	; 	
 31957 0000AAF9 21DB                <1> 	and 	ebx, ebx
 31958 0000AAFB 750B                <1> 	jnz	short glerr_2
 31959                              <1> glerr_0:
 31960 0000AAFD A1[95CE0000]        <1> 	mov	eax, [u.error]
 31961                              <1> glerr_1:
 31962 0000AB02 A3[40CE0000]        <1> 	mov	[u.r0], eax
 31963 0000AB07 C3                  <1>  	retn
 31964                              <1> glerr_2:
 31965 0000AB08 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0, FFFFFFFEh -> FFFFFFFFh
 31966 0000AB09 74FD                <1> 	jz	short glerr_2 ; page fault count for process
 31967 0000AB0B 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0	
 31968 0000AB0C 75EF                <1> 	jnz	short glerr_0
 31969 0000AB0E A1[14DB0000]        <1> 	mov	eax, [PF_Count] ; total page fault count
 31970 0000AB13 EBED                <1>         jmp     short glerr_1
 31971                              <1> glerr_3:
 31972 0000AB15 A1[A9CE0000]        <1> 	mov 	eax, [u.pfcount]
 31973 0000AB1A EBE6                <1> 	jmp	short glerr_1
 31974                              <1> 
 31975                              <1> ; temporary - 24/01/2016
 31976                              <1> 
 31977                              <1> iget:
 31978 0000AB1C C3                  <1> 	retn
 31979                              <1> poke:
 31980 0000AB1D C3                  <1> 	retn
 31981                              <1> tswap:
 31982 0000AB1E C3                  <1> 	retn
 31983                              <1> isintr:
 31984 0000AB1F C3                  <1> 	retn
 31985                              <1> writei:
 31986 0000AB20 C3                  <1> 	retn
 31987                              <1> readi:
 31988 0000AB21 C3                  <1> 	retn
 31989                              <1> putlu:
 31990 0000AB22 C3                  <1> 	retn
 31991                              <1> swap:
 31992 0000AB23 C3                  <1> 	retn
 31993                              <1> wswap:
 31994 0000AB24 C3                  <1> 	retn
 31995                              <1> rswap:
 31996 0000AB25 C3                  <1> 	retn
 31997                              <1> iopen:
 31998 0000AB26 C3                  <1> 	retn
 31999                              <1> iclose:
 32000 0000AB27 C3                  <1> 	retn
 32001                              <1> itrunc:
 32002 0000AB28 C3                  <1> 	retn
 32003                              <1> clock:
 32004 0000AB29 C3                  <1> 	retn
 32005                              <1> setimod:
 32006 0000AB2A C3                  <1> 	retn
 32007                              <1> ottyp:
 32008 0000AB2B C3                  <1> 	retn
 32009                              <1> cttyp:
 32010 0000AB2C C3                  <1> 	retn
 32011                              <1> sndc:
 32012 0000AB2D C3                  <1> 	retn
 32013                              <1> access:
 32014 0000AB2E C3                  <1> 	retn
 32015                              <1> cpass:
 32016 0000AB2F C3                  <1> 	retn
 32017                              <1> passc:
 32018 0000AB30 C3                  <1> 	retn
 32019                              <1> epoch:
 32020 0000AB31 C3                  <1> 	retn
 32021                              <1> set_date_time:
 32022 0000AB32 C3                  <1> 	retn
 32023                              <1> imap:
 32024 0000AB33 C3                  <1> 	retn
 32025                              <1> diskio:
 32026 0000AB34 C3                  <1> 	retn
 32027                              <1> idle:
 32028 0000AB35 C3                  <1> 	retn
 32029                              <1> sleep:
 32030 0000AB36 C3                  <1> 	retn
 32031                              <1> 
 32032                              <1> 
 32033                              <1> 
 32034                                  %include 'trdosk7.s' ; 24/01/2016
 32035                              <1> ; ****************************************************************************
 32036                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DISK READ&WRITE : trdosk7.s
 32037                              <1> ; ----------------------------------------------------------------------------
 32038                              <1> ; Last Update: 25/02/2016
 32039                              <1> ; ----------------------------------------------------------------------------
 32040                              <1> ; Beginning: 24/01/2016
 32041                              <1> ; ----------------------------------------------------------------------------
 32042                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 32043                              <1> ; ----------------------------------------------------------------------------
 32044                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 32045                              <1> ; DISK_IO.ASM (20/07/2011)
 32046                              <1> ; ****************************************************************************
 32047                              <1> ; DISK_IO.ASM (c) 2009-2011 Erdogan TAN [ 04/07/2009 ] Last Update: 20/07/2011
 32048                              <1> 
 32049                              <1> disk_write:
 32050                              <1> 	; 25/02/2016
 32051                              <1> 	; 24/02/2016
 32052                              <1> 	; 23/02/2016
 32053 0000AB37 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
 32054 0000AB3B 777B                <1>         ja      short lba_write
 32055                              <1> 
 32056                              <1> chs_write:
 32057                              <1> 	; 25/02/2016
 32058                              <1> 	; 23/02/2016
 32059 0000AB3D C605[A1C70000]03    <1> 	mov	byte [disk_rw_op], 3 ; CHS write
 32060 0000AB44 EB0D                <1> 	jmp	short chs_rw
 32061                              <1> 
 32062                              <1> disk_read:
 32063                              <1> 	; 25/02/2016
 32064                              <1> 	; 24/02/2016
 32065                              <1> 	; 23/02/2016
 32066                              <1> 	; 17/02/2016
 32067                              <1> 	; 14/02/2016
 32068                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 32069                              <1> 	; 17/10/2010
 32070                              <1> 	; 18/04/2010
 32071                              <1> 	;
 32072                              <1> 	; INPUT -> EAX = Logical Block Address
 32073                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
 32074                              <1> 	;	   ECX = Sector Count	
 32075                              <1> 	; 	   EBX = Destination Buffer
 32076                              <1> 	; OUTPUT -> 
 32077                              <1> 	;	   cf = 0 or cf = 1
 32078                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 32079                              <1> 
 32080 0000AB46 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
 32081 0000AB4A 7775                <1>         ja      short lba_read
 32082                              <1> 
 32083                              <1> chs_read:
 32084                              <1> 	; 25/02/2016
 32085                              <1> 	; 24/02/2016
 32086                              <1> 	; 23/02/2016
 32087                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 32088                              <1> 	; 20/07/2011
 32089                              <1> 	; 04/07/2009
 32090                              <1> 	;
 32091                              <1> 	; INPUT -> EAX = Logical Block Address
 32092                              <1> 	;	   ECX = Number of sectors to read
 32093                              <1> 	; 	   ESI = Logical Dos Disk Table Offset (DRV)
 32094                              <1> 	; 	   EBX = Destination Buffer
 32095                              <1> 	; OUTPUT -> 
 32096                              <1> 	;	   cf = 0 or cf = 1
 32097                              <1> 	; (Modified registers: EAX; EBX, ECX, EDX)
 32098                              <1> 
 32099                              <1> 	; 23/02/2016
 32100 0000AB4C C605[A1C70000]02    <1> 	mov	byte [disk_rw_op], 2 ; CHS read
 32101                              <1> 
 32102                              <1> chs_rw:
 32103                              <1> 	;;movzx	edx, word [esi+LD_BPB+SecPerTrack]
 32104                              <1> 	;movzx	edx, byte [esi+LD_BPB+SecPerTrack] ; <= 63
 32105                              <1> 	;mov	[disk_rw_spt], dl
 32106                              <1> 
 32107                              <1> chs_read_next_sector:
 32108 0000AB53 C605[A2C70000]04    <1> 	mov	byte [retry_count], 4
 32109                              <1>      
 32110                              <1> chs_read_retry:
 32111                              <1> 	;mov	[sector_count], ecx ; 23/02/2016
 32112                              <1> 
 32113 0000AB5A 50                  <1> 	push	eax			; Linear sector #
 32114 0000AB5B 51                  <1> 	push	ecx			; # of FAT/FILE/DIR sectors
 32115                              <1>                 
 32116 0000AB5C 0FB74E1E            <1> 	movzx	ecx, word [esi+LD_BPB+SecPerTrack]
 32117                              <1> 	;movzx	ecx, byte [disk_rw_spt] ; 23/02/2016
 32118 0000AB60 29D2                <1> 	sub	edx, edx
 32119 0000AB62 F7F1                <1> 	div	ecx
 32120                              <1> 	; eax = track, dx (dl ) = sector (on track)
 32121                              <1> 	;sub	cl, dl ; 24/02/2016 (spt - sec)
 32122                              <1> 	;push	ecx ; *
 32123 0000AB64 6689D1              <1> 	mov	cx, dx			; Sector (zero based)
 32124 0000AB67 6641                <1> 	inc	cx			; To make it 1 based
 32125 0000AB69 6651                <1> 	push	cx
 32126 0000AB6B 668B4E20            <1> 	mov	cx, [esi+LD_BPB+Heads]
 32127 0000AB6F 6629D2              <1> 	sub	dx, dx
 32128 0000AB72 F7F1                <1> 	div	ecx			; Convert track to head & cyl
 32129                              <1> 	; eax (ax) = cylinder, dx (dl) = head (max. FFh)
 32130 0000AB74 88D6                <1> 	mov	dh, dl
 32131 0000AB76 6659                <1> 	pop	cx			; AX=Cyl, DH=Head, CX=Sector
 32132 0000AB78 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
 32133                              <1> 
 32134 0000AB7B 88C5                <1> 	mov	ch, al			; NOTE: max. 1023 cylinders !                   
 32135 0000AB7D C0CC02              <1> 	ror	ah, 2			; Rotate 2 bits right
 32136 0000AB80 08E1                <1> 	or	cl, ah
 32137                              <1> 
 32138                              <1> 	; 24/02/2016
 32139                              <1> 	;pop	eax ; * (spt - sec) (example: 63 - 0 = 63)
 32140                              <1> 	;cmp	eax, [sector_count]
 32141                              <1> 	;jb	short chs_write_sectors
 32142                              <1> 	;je	short chs_read_sectors
 32143                              <1> 	;; (# of sectors to read is more than remaining sectors on the track)
 32144                              <1> 	;mov	al, [sector_count]
 32145                              <1> ;chs_read_sectors: ; read or write !
 32146 0000AB82 B001                <1> 	mov	al, 1 ; 25/02/2016
 32147 0000AB84 8A25[A1C70000]      <1> 	mov	ah, [disk_rw_op]  ; 02h = chs read, 03h = chs write 
 32148                              <1> 	;
 32149 0000AB8A E83D7DFFFF          <1> 	call	int13h			; BIOS Service func ( ah ) = 2
 32150                              <1>                                         ; Read disk sectors
 32151                              <1>                                         ; AL-sec num CH-track CL-sec
 32152                              <1>                                         ; DH-head DL-drive ES:BX-buffer
 32153                              <1>                                         ; CF-flag AH-stat AL-sec read
 32154                              <1> 	                                ; If CF = 1 then (If AH > 0)
 32155 0000AB8F 8825[A3C70000]      <1> 	mov	[disk_rw_err], ah
 32156                              <1> 	
 32157 0000AB95 59                  <1> 	pop	ecx
 32158 0000AB96 58                  <1> 	pop	eax
 32159 0000AB97 7314                <1> 	jnc	short chs_read_ok
 32160                              <1> 
 32161 0000AB99 803D[A3C70000]09    <1> 	cmp	byte [disk_rw_err], 09h ; DMA crossed 64K segment boundary
 32162 0000ABA0 7408                <1> 	je	short chs_read_error_retn
 32163                              <1>              
 32164 0000ABA2 FE0D[A2C70000]      <1> 	dec	byte [retry_count]
 32165 0000ABA8 75B0                <1> 	jnz	short chs_read_retry
 32166                              <1> 
 32167                              <1> chs_read_error_retn:
 32168 0000ABAA F9                  <1> 	stc
 32169                              <1> 	;retn
 32170 0000ABAB EB69                <1> 	jmp	short update_drv_error_byte
 32171                              <1> 
 32172                              <1> ;chs_write_sectors: ; read or write 
 32173                              <1> 	;; (# of sectors to read is less than remaining sectors on the track)
 32174                              <1> 	;mov	[sector_count], al
 32175                              <1> 	;jmp	short chs_read_sectors
 32176                              <1> 
 32177                              <1> chs_read_ok:
 32178                              <1> 	;; 23/02/2016
 32179                              <1> 	;movzx	edx, byte [sector_count] ; sector count (<= spt)	
 32180                              <1>         ;sub    ecx, edx  ; remaining sector count
 32181                              <1> 	;jna	short update_drv_error_byte	
 32182                              <1> 	;add	eax, edx ; next disk sector
 32183                              <1> 	;shl	edx, 9 ; 512 * sector count
 32184                              <1> 	;add	ebx, edx ; next buffer byte address 
 32185                              <1>         ;jmp     chs_read_next_sector        
 32186                              <1> 	; 25/02/2016
 32187 0000ABAD 40                  <1> 	inc	eax ; next sector
 32188 0000ABAE 81C300020000        <1> 	add	ebx, 512
 32189 0000ABB4 E29D                <1> 	loop	chs_read_next_sector
 32190 0000ABB6 EB5E                <1> 	jmp	short update_drv_error_byte
 32191                              <1> 
 32192                              <1> lba_write:
 32193                              <1> 	; 23/02/2016
 32194 0000ABB8 C605[A1C70000]1C    <1> 	mov	byte [disk_rw_op], 1Ch ; LBA write
 32195 0000ABBF EB07                <1> 	jmp	short lba_rw
 32196                              <1> 
 32197                              <1> lba_read:
 32198                              <1> 	; 23/02/2016
 32199                              <1> 	; 17/02/2016
 32200                              <1> 	; 14/02/2016
 32201                              <1> 	; 13/02/2016
 32202                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 32203                              <1> 	; 10/07/2015 (Retro UNIX 386 v1)
 32204                              <1> 	;
 32205                              <1> 	; INPUT -> EAX = Logical Block Address
 32206                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
 32207                              <1> 	;	   ECX = Sector Count	
 32208                              <1> 	; 	   EBX = Destination Buffer
 32209                              <1> 	; OUTPUT -> 
 32210                              <1> 	;	   cf = 0 or cf = 1
 32211                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 32212                              <1> 
 32213                              <1> 	; LBA read/write (with private LBA function) 
 32214                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 32215                              <1> 
 32216                              <1> 
 32217                              <1> 	; 23/02/2016
 32218 0000ABC1 C605[A1C70000]1B    <1> 	mov	byte [disk_rw_op], 1Bh ; LBA read
 32219                              <1> 
 32220                              <1> lba_rw:
 32221                              <1> 	; 17/02/2016
 32222 0000ABC8 57                  <1> 	push	edi
 32223                              <1> 
 32224 0000ABC9 890D[A4C70000]      <1> 	mov	[sector_count], ecx ; total sector (read) count
 32225                              <1> 
 32226 0000ABCF 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
 32227                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 32228                              <1> 
 32229                              <1> lba_read_next:
 32230 0000ABD2 81F900010000        <1> 	cmp	ecx, 256
 32231 0000ABD8 7605                <1> 	jna	short lba_read_rsc
 32232 0000ABDA B900010000          <1> 	mov	ecx, 256 ; 17/02/2016
 32233                              <1> lba_read_rsc:
 32234 0000ABDF 290D[A4C70000]      <1> 	sub	[sector_count], ecx ; remain sectors
 32235                              <1> 
 32236 0000ABE5 89CF                <1> 	mov	edi, ecx 
 32237 0000ABE7 89C1                <1> 	mov	ecx, eax ; sector number/address
 32238                              <1> 
 32239 0000ABE9 C605[A2C70000]04    <1> 	mov	byte [retry_count], 4
 32240                              <1> lba_read_retry:
 32241 0000ABF0 89F8                <1> 	mov	eax, edi
 32242                              <1> 	;
 32243                              <1> 	; ecx = sector number
 32244                              <1> 	; al = sector count (0 - 255) /// (0 = 256)
 32245                              <1> 	; dl = drive number
 32246                              <1> 	; ebx = buffer offset
 32247                              <1> 	;
 32248                              <1> 	; Function 1Bh = LBA read, 1Ch = LBA write
 32249                              <1> 	; 23/02/2016
 32250 0000ABF2 8A25[A1C70000]      <1> 	mov	ah, [disk_rw_op] ; 1Bh = LBA read, 1Ch = LBA write
 32251 0000ABF8 E8CF7CFFFF          <1> 	call	int13h
 32252                              <1> 	; al = ? (changed)
 32253                              <1> 	; ah = error code
 32254 0000ABFD 8825[A3C70000]      <1> 	mov	[disk_rw_err], ah
 32255 0000AC03 7334                <1> 	jnc	short lba_read_ok
 32256 0000AC05 80FC80              <1> 	cmp	ah, 80h ; time out?
 32257 0000AC08 740A                <1>         je      short lba_read_stc_retn
 32258 0000AC0A FE0D[A2C70000]      <1> 	dec	byte [retry_count]
 32259 0000AC10 7FDE                <1> 	jg	short lba_read_retry
 32260 0000AC12 743A                <1> 	jz	short lba_read_reset
 32261                              <1> 	; sf =  1
 32262                              <1> 
 32263                              <1> lba_read_stc_retn:
 32264 0000AC14 F9                  <1> 	stc
 32265                              <1> lba_read_retn:
 32266 0000AC15 5F                  <1> 	pop	edi
 32267                              <1> 
 32268                              <1> update_drv_error_byte:
 32269 0000AC16 9C                  <1> 	pushf
 32270 0000AC17 53                  <1> 	push	ebx
 32271 0000AC18 6651                <1> 	push	cx
 32272                              <1> 	;or	ecx, ecx
 32273                              <1> 	;jz	short udrv_errb0
 32274 0000AC1A 8A0D[A3C70000]      <1> 	mov	cl, [disk_rw_err]
 32275                              <1> udrv_errb0:
 32276 0000AC20 0FB65E02            <1> 	movzx	ebx, byte [esi+LD_PhyDrvNo]
 32277 0000AC24 80FB02              <1> 	cmp	bl, 2
 32278 0000AC27 7203                <1>         jb      short udrv_errb1
 32279 0000AC29 80EB7E              <1> 	sub	bl, 7Eh
 32280                              <1> 	;cmp	bl, 5
 32281                              <1> 	;ja	short udrv_errb2	
 32282                              <1> udrv_errb1:
 32283 0000AC2C 81C3[11B90000]      <1>         add     ebx, drv.error ; 13/02/2016
 32284 0000AC32 880B                <1> 	mov	[ebx], cl ; error code
 32285                              <1> udrv_errb2:
 32286 0000AC34 6659                <1> 	pop	cx
 32287 0000AC36 5B                  <1> 	pop	ebx
 32288 0000AC37 9D                  <1> 	popf
 32289 0000AC38 C3                  <1> 	retn
 32290                              <1> 
 32291                              <1> lba_read_ok:
 32292 0000AC39 89C8                <1> 	mov	eax, ecx ; sector number
 32293 0000AC3B 01F8                <1> 	add	eax, edi ; sector number (next)
 32294 0000AC3D C1E709              <1> 	shl	edi, 9 ; sector count * 512
 32295 0000AC40 01FB                <1> 	add	ebx, edi ; next buffer offset
 32296                              <1> 
 32297 0000AC42 8B0D[A4C70000]      <1> 	mov	ecx, [sector_count] ; remaining sectors
 32298 0000AC48 09C9                <1> 	or	ecx, ecx
 32299 0000AC4A 7586                <1> 	jnz	short lba_read_next
 32300 0000AC4C EBC7                <1> 	jmp	short lba_read_retn
 32301                              <1> 
 32302                              <1> lba_read_reset:
 32303 0000AC4E B40D                <1> 	mov	ah, 0Dh ; Alternate reset
 32304 0000AC50 E8777CFFFF          <1>         call	int13h
 32305                              <1> 	; al = ? (changed)
 32306                              <1> 	; ah = error code
 32307 0000AC55 7399                <1> 	jnc	short lba_read_retry
 32308 0000AC57 EBBC                <1> 	jmp	short lba_read_retn
 32309                                  %include 'trdosk8.s' ; 24/01/2016
 32310                              <1> ; ****************************************************************************
 32311                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk8.s
 32312                              <1> ; ----------------------------------------------------------------------------
 32313                              <1> ; Last Update: 24/01/2016
 32314                              <1> ; ----------------------------------------------------------------------------
 32315                              <1> ; Beginning: 24/01/2016
 32316                              <1> ; ----------------------------------------------------------------------------
 32317                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 32318                              <1> ; ----------------------------------------------------------------------------
 32319                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 32320                              <1> ; XXXXXXXX.ASM (XX/XX/2011)
 32321                              <1> ;
 32322                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 32323                              <1> ; u0.s (20/11/2015)
 32324                              <1> ; ****************************************************************************
 32325                              <1> 
 32326                              <1> INT4Ah:
 32327                              <1> 	; 24/01/2016
 32328                              <1> 	; this procedure will be called by 'RTC_INT' (in 'timer.s')
 32329 0000AC59 C3                  <1> 	retn
 32330                              <1> 
 32331                              <1> ; u0.s
 32332                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS0.INC
 32333                              <1> ; Last Modification: 20/11/2015
 32334                              <1> 
 32335                              <1> com2_int:
 32336                              <1> 	; 07/11/2015 
 32337                              <1> 	; 24/10/2015
 32338                              <1> 	; 23/10/2015
 32339                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
 32340                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
 32341                              <1> 	; < serial port 2 interrupt handler >
 32342                              <1> 	;
 32343 0000AC5A 890424              <1> 	mov 	[esp], eax ; overwrite call return address
 32344                              <1> 	;push	eax
 32345 0000AC5D 66B80900            <1> 	mov	ax, 9
 32346 0000AC61 EB07                <1> 	jmp	short comm_int
 32347                              <1> com1_int:
 32348                              <1> 	; 07/11/2015
 32349                              <1> 	; 24/10/2015
 32350 0000AC63 890424              <1> 	mov 	[esp], eax ; overwrite call return address
 32351                              <1> 	; 23/10/2015
 32352                              <1> 	;push	eax
 32353 0000AC66 66B80800            <1> 	mov	ax, 8
 32354                              <1> comm_int:
 32355                              <1> 	; 20/11/2015
 32356                              <1> 	; 18/11/2015
 32357                              <1> 	; 17/11/2015
 32358                              <1> 	; 16/11/2015
 32359                              <1> 	; 09/11/2015
 32360                              <1> 	; 08/11/2015
 32361                              <1> 	; 07/11/2015
 32362                              <1> 	; 06/11/2015 (serial4.asm, 'serial')	
 32363                              <1> 	; 01/11/2015
 32364                              <1> 	; 26/10/2015
 32365                              <1> 	; 23/10/2015
 32366 0000AC6A 53                  <1> 	push	ebx
 32367 0000AC6B 56                  <1> 	push	esi
 32368 0000AC6C 57                  <1> 	push	edi
 32369 0000AC6D 1E                  <1> 	push 	ds
 32370 0000AC6E 06                  <1> 	push 	es
 32371                              <1> 	; 18/11/2015
 32372 0000AC6F 0F20DB              <1> 	mov	ebx, cr3
 32373 0000AC72 53                  <1> 	push	ebx ; ****
 32374                              <1> 	;
 32375 0000AC73 51                  <1> 	push	ecx ; ***
 32376 0000AC74 52                  <1> 	push	edx ; **
 32377                              <1> 	;
 32378 0000AC75 BB10000000          <1> 	mov	ebx, KDATA
 32379 0000AC7A 8EDB                <1> 	mov	ds, bx
 32380 0000AC7C 8EC3                <1> 	mov	es, bx
 32381                              <1> 	;
 32382 0000AC7E 8B0D[E8BD0000]      <1> 	mov	ecx, [k_page_dir]
 32383 0000AC84 0F22D9              <1> 	mov	cr3, ecx
 32384                              <1> 	; 20/11/2015
 32385                              <1> 	; Interrupt identification register
 32386 0000AC87 66BAFA02            <1> 	mov	dx, 2FAh ; COM2
 32387                              <1> 	;
 32388 0000AC8B 3C08                <1> 	cmp 	al, 8 
 32389 0000AC8D 7702                <1> 	ja 	short com_i0
 32390                              <1> 	;
 32391                              <1> 	; 20/11/2015
 32392                              <1> 	; 17/11/2015
 32393                              <1> 	; 16/11/2015
 32394                              <1> 	; 15/11/2015
 32395                              <1> 	; 24/10/2015
 32396                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
 32397                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
 32398                              <1> 	; < serial port 1 interrupt handler >
 32399                              <1> 	;
 32400 0000AC8F FEC6                <1> 	inc	dh ; 3FAh ; COM1 Interrupt id. register
 32401                              <1> com_i0:
 32402                              <1> 	;push	eax ; *
 32403                              <1> 	; 07/11/2015
 32404 0000AC91 A2[58BE0000]        <1> 	mov 	byte [ccomport], al
 32405                              <1> 	; 09/11/2015
 32406 0000AC96 0FB7D8              <1> 	movzx	ebx, ax ; 8 or 9
 32407                              <1> 	; 17/11/2015
 32408                              <1>  	; reset request for response status
 32409 0000AC99 88A3[4EBE0000]      <1> 	mov	[ebx+req_resp-8], ah ; 0
 32410                              <1> 	;
 32411                              <1> 	; 20/11/2015
 32412 0000AC9F EC                  <1> 	in	al, dx		; read interrupt id. register
 32413 0000ACA0 EB00                <1> 	JMP	$+2	   	; I/O DELAY
 32414 0000ACA2 2404                <1> 	and	al, 4		; received data available?	
 32415 0000ACA4 7470                <1> 	jz	short com_eoi	; (transmit. holding reg. empty)
 32416                              <1> 	;
 32417                              <1> 	; 20/11/2015
 32418 0000ACA6 80EA02              <1> 	sub	dl, 3FAh-3F8h	; data register (3F8h, 2F8h)
 32419 0000ACA9 EC                  <1> 	in	al, dx     	; read character
 32420                              <1> 	;JMP	$+2	   	; I/O DELAY
 32421                              <1> 	; 08/11/2015
 32422                              <1> 	; 07/11/2015
 32423 0000ACAA 89DE                <1> 	mov	esi, ebx 
 32424 0000ACAC 89DF                <1> 	mov	edi, ebx
 32425 0000ACAE 81C6[52BE0000]      <1> 	add 	esi, rchar - 8 ; points to last received char
 32426 0000ACB4 81C7[54BE0000]      <1> 	add	edi, schar - 8 ; points to last sent char
 32427 0000ACBA 8806                <1> 	mov	[esi], al ; received char (current char)
 32428                              <1> 	; query
 32429 0000ACBC 20C0                <1> 	and	al, al
 32430 0000ACBE 7527                <1> 	jnz	short com_i2
 32431                              <1>    	; response
 32432                              <1> 	; 17/11/2015
 32433                              <1> 	; set request for response status
 32434 0000ACC0 FE83[4EBE0000]      <1>         inc     byte [ebx+req_resp-8] ; 1 
 32435                              <1> 	;
 32436 0000ACC6 6683C205            <1> 	add	dx, 3FDh-3F8h	; (3FDh, 2FDh)
 32437 0000ACCA EC                  <1> 	in	al, dx	   	; read line status register 
 32438 0000ACCB EB00                <1> 	JMP	$+2	   	; I/O DELAY
 32439 0000ACCD 2420                <1> 	and	al, 20h	   	; transmitter holding reg. empty?
 32440 0000ACCF 7445                <1> 	jz	short com_eoi 	; no
 32441 0000ACD1 B0FF                <1> 	mov 	al, 0FFh   	; response			
 32442 0000ACD3 6683EA05            <1> 	sub	dx, 3FDh-3F8h 	; data port (3F8h, 2F8h)
 32443 0000ACD7 EE                  <1> 	out	dx, al	   	; send on serial port
 32444                              <1> 	; 17/11/2015
 32445 0000ACD8 803F00              <1> 	cmp 	byte [edi], 0   ; query ? (schar)
 32446 0000ACDB 7502                <1> 	jne 	short com_i1    ; no
 32447 0000ACDD 8807                <1> 	mov	[edi], al 	; 0FFh (responded)
 32448                              <1> com_i1:
 32449                              <1> 	; 17/11/2015
 32450                              <1> 	; reset request for response status (again)
 32451 0000ACDF FE8B[4EBE0000]      <1>         dec     byte [ebx+req_resp-8] ; 0 
 32452 0000ACE5 EB2F                <1> 	jmp	short com_eoi
 32453                              <1> com_i2:	
 32454                              <1> 	; 08/11/2015
 32455 0000ACE7 3CFF                <1> 	cmp 	al, 0FFh	; (response ?)
 32456 0000ACE9 7417                <1> 	je	short com_i3	; (check for response signal)
 32457                              <1> 	; 07/11/2015
 32458 0000ACEB 3C04                <1> 	cmp	al, 04h	; EOT
 32459 0000ACED 751C                <1> 	jne	short com_i4	
 32460                              <1> 	; EOT = 04h (End of Transmit) - 'CTRL + D'
 32461                              <1> 	;(an EOT char is supposed as a ctrl+brk from the terminal)
 32462                              <1> 	; 08/11/2015
 32463                              <1> 		; ptty -> tty 0 to 7 (pseudo screens)
 32464 0000ACEF 861D[18BE0000]      <1> 	xchg	bl, [ptty]  ; tty number (8 or 9)
 32465 0000ACF5 E80992FFFF          <1> 	call 	ctrlbrk
 32466 0000ACFA 861D[18BE0000]      <1> 	xchg	[ptty], bl ; (restore ptty value and BL value)
 32467                              <1> 	;mov	al, 04h ; EOT
 32468                              <1> 	; 08/11/2015
 32469 0000AD00 EB09                <1> 	jmp	short com_i4	
 32470                              <1> com_i3:
 32471                              <1> 	; 08/11/2015
 32472                              <1> 	; If 0FFh has been received just after a query
 32473                              <1> 	; (schar, ZERO), it is a response signal.
 32474                              <1> 	; 17/11/2015
 32475 0000AD02 803F00              <1>         cmp     byte [edi], 0 ; query ? (schar)
 32476 0000AD05 7704                <1> 	ja	short com_i4 ; no
 32477                              <1> 	; reset query status (schar)
 32478 0000AD07 8807                <1> 	mov	[edi], al ; 0FFh
 32479 0000AD09 FEC0                <1> 	inc	al ; 0
 32480                              <1> com_i4:
 32481                              <1> 	; 27/07/2014
 32482                              <1> 	; 09/07/2014
 32483 0000AD0B D0E3                <1> 	shl	bl, 1	
 32484 0000AD0D 81C3[1ABE0000]      <1> 	add	ebx, ttychr
 32485                              <1> 	; 23/07/2014 (always overwrite)
 32486                              <1> 	;;cmp	word [ebx], 0
 32487                              <1> 	;;ja	short com_eoi
 32488                              <1> 	;
 32489 0000AD13 668903              <1> 	mov	[ebx], ax   ; Save ascii code
 32490                              <1> 			    ; scan code = 0
 32491                              <1> com_eoi:
 32492                              <1> 	;mov	al, 20h
 32493                              <1> 	;out	20h, al	   ; end of interrupt
 32494                              <1> 	;
 32495                              <1> 	; 07/11/2015
 32496                              <1>       	;pop	eax ; *
 32497 0000AD16 A0[58BE0000]        <1> 	mov	al, byte [ccomport] ; current COM port
 32498                              <1> 	 ; al = tty number (8 or 9)
 32499 0000AD1B E85E010000          <1>         call	wakeup
 32500                              <1> com_iret:
 32501                              <1> 	; 23/10/2015
 32502 0000AD20 5A                  <1> 	pop	edx ; **
 32503 0000AD21 59                  <1> 	pop	ecx ; ***
 32504                              <1> 	; 18/11/2015
 32505                              <1> 	;pop	eax ; ****
 32506                              <1> 	;mov	cr3, eax
 32507                              <1> 	;jmp	iiret
 32508 0000AD22 E9345DFFFF          <1> 	jmp	iiretp
 32509                              <1> 
 32510                              <1> ;iiretp: ; 01/09/2015
 32511                              <1> ;	; 28/08/2015
 32512                              <1> ;	pop	eax ; (*) page directory
 32513                              <1> ;	mov	cr3, eax
 32514                              <1> ;iiret:
 32515                              <1> ;	; 22/08/2014
 32516                              <1> ;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
 32517                              <1> ;	out	20h, al	; 8259 PORT
 32518                              <1> ;	;
 32519                              <1> ;	pop	es
 32520                              <1> ;	pop	ds
 32521                              <1> ;	pop	edi
 32522                              <1> ;	pop	esi
 32523                              <1> ;	pop	ebx ; 29/08/2014
 32524                              <1> ;	pop 	eax
 32525                              <1> ;	iretd
 32526                              <1> 
 32527                              <1> sp_init:
 32528                              <1> 	; 07/11/2015
 32529                              <1> 	; 29/10/2015
 32530                              <1> 	; 26/10/2015
 32531                              <1> 	; 23/10/2015
 32532                              <1> 	; 29/06/2015
 32533                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - 115200 baud)
 32534                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1 - 9600 baud)
 32535                              <1> 	; Initialization of Serial Port Communication Parameters
 32536                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
 32537                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
 32538                              <1> 	;
 32539                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
 32540                              <1> 	;
 32541                              <1> 	; INPUT:  (29/06/2015)
 32542                              <1> 	;	AL = 0 for COM1
 32543                              <1> 	;	     1 for COM2
 32544                              <1> 	;	AH = Communication parameters	
 32545                              <1> 	;
 32546                              <1> 	;  (*) Communication parameters (except BAUD RATE):
 32547                              <1> 	;	Bit	4	3	2	1	0
 32548                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
 32549                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
 32550                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
 32551                              <1> 	;		11 = even
 32552                              <1> 	;  Baud rate setting bits: (29/06/2015)
 32553                              <1> 	;		Retro UNIX 386 v1 feature only !
 32554                              <1> 	;	Bit	7    6    5  | Baud rate
 32555                              <1> 	;		------------------------
 32556                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
 32557                              <1> 	;		0    0    1  | 9600 (12)
 32558                              <1> 	;		0    1    0  | 19200 (6) 
 32559                              <1> 	;		0    1	  1  | 38400 (3) 
 32560                              <1> 	;		1    0	  0  | 14400 (8)
 32561                              <1> 	;		1    0	  1  | 28800 (4)
 32562                              <1> 	;		1    1    0  | 57600 (2)
 32563                              <1> 	;		1    1    1  | 115200 (1) 	
 32564                              <1> 	
 32565                              <1> 	; References:	
 32566                              <1> 	; (1) IBM PC-XT Model 286 BIOS Source Code
 32567                              <1> 	;     RS232.ASM --- 10/06/1985 COMMUNICATIONS BIOS (RS232)
 32568                              <1> 	; (2) Award BIOS 1999 - ATORGS.ASM
 32569                              <1> 	; (3) http://wiki.osdev.org/Serial_Ports
 32570                              <1> 	;
 32571                              <1> 	; Set communication parameters for COM1 (= 03h)	
 32572                              <1> 	;
 32573 0000AD27 BB[54BE0000]        <1> 	mov	ebx, com1p		; COM1 parameters  
 32574 0000AD2C 66BAF803            <1> 	mov	dx, 3F8h		; COM1
 32575                              <1> 	 ; 29/10/2015
 32576 0000AD30 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
 32577 0000AD34 E86F000000          <1> 	call	sp_i3	; call A4	
 32578 0000AD39 A880                <1> 	test	al, 80h
 32579 0000AD3B 7410                <1> 	jz	short sp_i0 ; OK..
 32580                              <1> 		; Error !
 32581                              <1> 	;mov	dx, 3F8h
 32582 0000AD3D 80EA05              <1> 	sub	dl, 5 ; 3FDh -> 3F8h
 32583 0000AD40 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
 32584 0000AD44 E85F000000          <1> 	call	sp_i3	; call A4	
 32585 0000AD49 A880                <1> 	test	al, 80h
 32586 0000AD4B 7508                <1> 	jnz	short sp_i1
 32587                              <1> sp_i0:
 32588                              <1>         ; (Note: Serial port interrupts will be disabled here...)	
 32589                              <1>         ; (INT 14h initialization code disables interrupts.)
 32590                              <1> 	;
 32591 0000AD4D C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
 32592 0000AD50 E8DC000000          <1> 	call	sp_i5 ; 29/06/2015
 32593                              <1> sp_i1:
 32594 0000AD55 43                  <1> 	inc	ebx
 32595 0000AD56 66BAF802            <1> 	mov	dx, 2F8h		; COM2
 32596                              <1> 	 ; 29/10/2015
 32597 0000AD5A 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
 32598 0000AD5E E845000000          <1> 	call	sp_i3	; call A4	
 32599 0000AD63 A880                <1> 	test	al, 80h
 32600 0000AD65 7410                <1> 	jz	short sp_i2 ; OK..
 32601                              <1> 		; Error !
 32602                              <1> 	;mov	dx, 2F8h
 32603 0000AD67 80EA05              <1> 	sub	dl, 5 ; 2FDh -> 2F8h
 32604 0000AD6A 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
 32605 0000AD6E E835000000          <1> 	call	sp_i3	; call A4	
 32606 0000AD73 A880                <1> 	test	al, 80h
 32607 0000AD75 7530                <1> 	jnz	short sp_i7
 32608                              <1> sp_i2:
 32609 0000AD77 C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
 32610                              <1> sp_i6:
 32611                              <1> 	;; COM2 - enabling IRQ 3
 32612                              <1> 	; 07/11/2015
 32613                              <1> 	; 26/10/2015
 32614 0000AD7A 9C                  <1> 	pushf
 32615 0000AD7B FA                  <1> 	cli
 32616                              <1> 	;
 32617 0000AD7C 66BAFC02            <1> 	mov	dx, 2FCh   		; modem control register
 32618 0000AD80 EC                  <1> 	in	al, dx 	   		; read register
 32619 0000AD81 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 32620 0000AD83 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
 32621 0000AD85 EE                  <1> 	out	dx, al     		; write back to register
 32622 0000AD86 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 32623 0000AD88 66BAF902            <1> 	mov	dx, 2F9h   		; interrupt enable register
 32624 0000AD8C EC                  <1> 	in	al, dx     		; read register
 32625 0000AD8D EB00                <1> 	JMP	$+2	   		; I/O DELAY
 32626                              <1> 	;or	al, 1      		; receiver data interrupt enable and
 32627 0000AD8F 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
 32628 0000AD91 EE                  <1> 	out	dx, al 	   		; write back to register
 32629 0000AD92 EB00                <1> 	JMP	$+2        		; I/O DELAY
 32630 0000AD94 E421                <1> 	in	al, 21h    		; read interrupt mask register
 32631 0000AD96 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 32632 0000AD98 24F7                <1> 	and	al, 0F7h   		; enable IRQ 3 (COM2)
 32633 0000AD9A E621                <1> 	out	21h, al    		; write back to register
 32634                              <1> 	;
 32635                              <1> 	; 23/10/2015
 32636 0000AD9C B8[5AAC0000]        <1> 	mov 	eax, com2_int
 32637 0000ADA1 A3[79AE0000]        <1> 	mov	[com2_irq3], eax
 32638                              <1> 	; 26/10/2015
 32639 0000ADA6 9D                  <1> 	popf	
 32640                              <1> sp_i7:
 32641 0000ADA7 C3                  <1> 	retn
 32642                              <1> 
 32643                              <1> sp_i3:
 32644                              <1> ;A4:  	;-----	INITIALIZE THE COMMUNICATIONS PORT
 32645                              <1> 	; 28/10/2015
 32646 0000ADA8 FEC2                <1> 	inc	dl	; 3F9h (2F9h)	; 3F9h, COM1 Interrupt enable register 
 32647 0000ADAA B000                <1> 	mov	al, 0
 32648 0000ADAC EE                  <1> 	out	dx, al			; disable serial port interrupt
 32649 0000ADAD EB00                <1> 	JMP	$+2			; I/O DELAY
 32650 0000ADAF 80C202              <1> 	add	dl, 2 	; 3FBh (2FBh)	; COM1 Line control register (3FBh)
 32651 0000ADB2 B080                <1> 	mov	al, 80h			
 32652 0000ADB4 EE                  <1> 	out	dx, al			; SET DLAB=1 ; divisor latch access bit
 32653                              <1> 	;-----	SET BAUD RATE DIVISOR
 32654                              <1> 	; 26/10/2015
 32655 0000ADB5 80EA03              <1> 	sub 	dl, 3   ; 3F8h (2F8h)	; register for least significant byte
 32656                              <1> 					; of the divisor value
 32657 0000ADB8 88C8                <1> 	mov	al, cl	; 1
 32658 0000ADBA EE                  <1> 	out	dx, al			; 1 = 115200 baud (Retro UNIX 386 v1)
 32659                              <1> 					; 2 = 57600 baud
 32660                              <1> 					; 3 = 38400 baud
 32661                              <1> 					; 6 = 19200 baud
 32662                              <1> 					; 12 = 9600 baud (Retro UNIX 8086 v1)
 32663 0000ADBB EB00                <1> 	JMP	$+2			; I/O DELAY
 32664 0000ADBD 28C0                <1> 	sub	al, al
 32665 0000ADBF FEC2                <1> 	inc	dl      ; 3F9h (2F9h)	; register for most significant byte
 32666                              <1> 					; of the divisor value
 32667 0000ADC1 EE                  <1> 	out	dx, al ; 0
 32668 0000ADC2 EB00                <1> 	JMP	$+2			; I/O DELAY
 32669                              <1> 	;	
 32670 0000ADC4 88E8                <1> 	mov	al, ch ; 3		; 8 data bits, 1 stop bit, no parity
 32671                              <1> 	;and	al, 1Fh ; Bits 0,1,2,3,4	
 32672 0000ADC6 80C202              <1> 	add	dl, 2	; 3FBh (2FBh)	; Line control register
 32673 0000ADC9 EE                  <1> 	out	dx, al			
 32674 0000ADCA EB00                <1> 	JMP	$+2			; I/O DELAY
 32675                              <1> 	; 29/10/2015
 32676 0000ADCC FECA                <1> 	dec 	dl 	; 3FAh (2FAh)	; FIFO Control register (16550/16750)
 32677 0000ADCE 30C0                <1> 	xor	al, al			; 0
 32678 0000ADD0 EE                  <1> 	out	dx, al			; Disable FIFOs (reset to 8250 mode)
 32679 0000ADD1 EB00                <1> 	JMP	$+2	
 32680                              <1> sp_i4:
 32681                              <1> ;A18:	;-----	COMM PORT STATUS ROUTINE
 32682                              <1> 	; 29/06/2015 (line status after modem status)
 32683 0000ADD3 80C204              <1> 	add	dl, 4	; 3FEh (2FEh)	; Modem status register
 32684                              <1> sp_i4s:
 32685 0000ADD6 EC                  <1> 	in	al, dx			; GET MODEM CONTROL STATUS
 32686 0000ADD7 EB00                <1> 	JMP	$+2			; I/O DELAY
 32687 0000ADD9 88C4                <1> 	mov	ah, al			; PUT IN (AH) FOR RETURN
 32688 0000ADDB FECA                <1> 	dec	dl	; 3FDh (2FDh)	; POINT TO LINE STATUS REGISTER
 32689                              <1> 					; dx = 3FDh for COM1, 2FDh for COM2
 32690 0000ADDD EC                  <1> 	in	al, dx			; GET LINE CONTROL STATUS
 32691                              <1> 	; AL = Line status, AH = Modem status
 32692 0000ADDE C3                  <1> 	retn
 32693                              <1> 
 32694                              <1> sp_status:
 32695                              <1> 	; 29/06/2015
 32696                              <1> 	; 27/06/2015 (Retro UNIX 386 v1)
 32697                              <1> 	; Get serial port status
 32698 0000ADDF 66BAFE03            <1> 	mov	dx, 3FEh		; Modem status register (COM1)
 32699 0000ADE3 28C6                <1> 	sub	dh, al			; dh = 2 for COM2 (al = 1)
 32700                              <1> 					; dx = 2FEh for COM2
 32701 0000ADE5 EBEF                <1> 	jmp	short sp_i4s
 32702                              <1> 
 32703                              <1> sp_setp: ; Set serial port communication parameters
 32704                              <1> 	; 07/11/2015
 32705                              <1> 	; 29/10/2015
 32706                              <1> 	; 29/06/2015
 32707                              <1> 	; Retro UNIX 386 v1 feature only !	
 32708                              <1> 	;
 32709                              <1> 	; INPUT:
 32710                              <1> 	;	AL = 0 for COM1
 32711                              <1> 	;	     1 for COM2
 32712                              <1> 	;	AH = Communication parameters (*)
 32713                              <1> 	; OUTPUT:
 32714                              <1> 	;	CL = Line status
 32715                              <1> 	;	CH = Modem status
 32716                              <1> 	;   If cf = 1 -> Error code in [u.error]
 32717                              <1> 	;		 'invalid parameter !' 
 32718                              <1> 	;		 	 or
 32719                              <1> 	;		 'device not ready !' error
 32720                              <1> 	;	
 32721                              <1> 	;  (*) Communication parameters (except BAUD RATE):
 32722                              <1> 	;	Bit	4	3	2	1	0
 32723                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
 32724                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
 32725                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
 32726                              <1> 	;		11 = even
 32727                              <1> 	;  Baud rate setting bits: (29/06/2015)
 32728                              <1> 	;		Retro UNIX 386 v1 feature only !
 32729                              <1> 	;	Bit	7    6    5  | Baud rate
 32730                              <1> 	;		------------------------
 32731                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
 32732                              <1> 	;		0    0    1  | 9600 (12)
 32733                              <1> 	;		0    1    0  | 19200 (6) 
 32734                              <1> 	;		0    1	  1  | 38400 (3) 
 32735                              <1> 	;		1    0	  0  | 14400 (8)
 32736                              <1> 	;		1    0	  1  | 28800 (4)
 32737                              <1> 	;		1    1    0  | 57600 (2)
 32738                              <1> 	;		1    1    1  | 115200 (1) 
 32739                              <1> 	;
 32740                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
 32741                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
 32742                              <1> 	;
 32743                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
 32744                              <1> 	;
 32745 0000ADE7 66BAF803            <1> 	mov	dx, 3F8h
 32746 0000ADEB BB[54BE0000]        <1> 	mov	ebx, com1p ; COM1 control byte offset
 32747 0000ADF0 3C01                <1> 	cmp	al, 1
 32748 0000ADF2 776B                <1> 	ja 	short sp_invp_err
 32749 0000ADF4 7203                <1> 	jb	short sp_setp1 ;  COM1 (AL = 0)
 32750 0000ADF6 FECE                <1> 	dec	dh ; 2F8h
 32751 0000ADF8 43                  <1> 	inc	ebx ; COM2 control byte offset
 32752                              <1> sp_setp1:
 32753                              <1> 	; 29/10/2015
 32754 0000ADF9 8823                <1> 	mov	[ebx], ah
 32755 0000ADFB 0FB6CC              <1> 	movzx 	ecx, ah
 32756 0000ADFE C0E905              <1> 	shr	cl, 5 ; -> baud rate index
 32757 0000AE01 80E41F              <1> 	and	ah, 1Fh ; communication parameters except baud rate
 32758 0000AE04 8A81[6EAE0000]      <1> 	mov	al, [ecx+b_div_tbl]
 32759 0000AE0A 6689C1              <1> 	mov	cx, ax
 32760 0000AE0D E896FFFFFF          <1> 	call	sp_i3
 32761 0000AE12 6689C1              <1> 	mov	cx, ax ; CL = Line status, CH = Modem status
 32762 0000AE15 A880                <1> 	test	al, 80h
 32763 0000AE17 740F                <1> 	jz	short sp_setp2
 32764 0000AE19 C603E3              <1>         mov     byte [ebx], 0E3h ; Reset to initial value (11100011b)
 32765                              <1> stp_dnr_err:
 32766 0000AE1C C705[95CE0000]0F00- <1> 	mov	dword [u.error], ERR_DEV_NOT_RDY ; 'device not ready !'
 32767 0000AE24 0000                <1>
 32768                              <1> 	; CL = Line status, CH = Modem status
 32769 0000AE26 F9                  <1> 	stc
 32770 0000AE27 C3                  <1> 	retn
 32771                              <1> sp_setp2:
 32772 0000AE28 80FE02              <1> 	cmp	dh, 2 ; COM2 (2F?h)
 32773 0000AE2B 0F8649FFFFFF        <1>         jna     sp_i6 
 32774                              <1> 		      ; COM1 (3F?h)
 32775                              <1> sp_i5: 
 32776                              <1> 	; 07/11/2015
 32777                              <1> 	; 26/10/2015
 32778                              <1> 	; 29/06/2015
 32779                              <1> 	;
 32780                              <1> 	;; COM1 - enabling IRQ 4
 32781 0000AE31 9C                  <1> 	pushf
 32782 0000AE32 FA                  <1> 	cli
 32783 0000AE33 66BAFC03            <1> 	mov	dx, 3FCh   		; modem control register
 32784 0000AE37 EC                  <1> 	in	al, dx 	   		; read register
 32785 0000AE38 EB00                <1> 	JMP	$+2			; I/O DELAY
 32786 0000AE3A 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
 32787 0000AE3C EE                  <1> 	out	dx, al     		; write back to register
 32788 0000AE3D EB00                <1> 	JMP	$+2			; I/O DELAY
 32789 0000AE3F 66BAF903            <1> 	mov	dx, 3F9h   		; interrupt enable register
 32790 0000AE43 EC                  <1> 	in	al, dx     		; read register
 32791 0000AE44 EB00                <1> 	JMP	$+2			; I/O DELAY
 32792                              <1> 	;or	al, 1      		; receiver data interrupt enable and
 32793 0000AE46 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
 32794 0000AE48 EE                  <1> 	out	dx, al 	   		; write back to register
 32795 0000AE49 EB00                <1> 	JMP	$+2        		; I/O DELAY
 32796 0000AE4B E421                <1> 	in	al, 21h    		; read interrupt mask register
 32797 0000AE4D EB00                <1> 	JMP	$+2			; I/O DELAY
 32798 0000AE4F 24EF                <1> 	and	al, 0EFh   		; enable IRQ 4 (COM1)
 32799 0000AE51 E621                <1> 	out	21h, al    		; write back to register
 32800                              <1> 	;
 32801                              <1> 	; 23/10/2015
 32802 0000AE53 B8[63AC0000]        <1> 	mov 	eax, com1_int
 32803 0000AE58 A3[75AE0000]        <1> 	mov	[com1_irq4], eax
 32804                              <1> 	; 26/10/2015
 32805 0000AE5D 9D                  <1> 	popf
 32806 0000AE5E C3                  <1> 	retn
 32807                              <1> 
 32808                              <1> sp_invp_err:
 32809 0000AE5F C705[95CE0000]1700- <1> 	mov	dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
 32810 0000AE67 0000                <1>
 32811 0000AE69 31C9                <1> 	xor	ecx, ecx
 32812 0000AE6B 49                  <1> 	dec	ecx ; 0FFFFh
 32813 0000AE6C F9                  <1> 	stc
 32814 0000AE6D C3                  <1> 	retn
 32815                              <1> 
 32816                              <1> ; 29/10/2015
 32817                              <1> b_div_tbl: ; Baud rate divisor table (115200/divisor)
 32818 0000AE6E 010C0603080401      <1> 	db 1, 12, 6, 3, 8, 4, 1
 32819                              <1> 
 32820                              <1> 
 32821                              <1> ; 23/10/2015
 32822                              <1> com1_irq4:
 32823 0000AE75 [7DAE0000]          <1> 	dd dummy_retn
 32824                              <1> com2_irq3:
 32825 0000AE79 [7DAE0000]          <1> 	dd dummy_retn
 32826                              <1> 
 32827                              <1> dummy_retn:
 32828 0000AE7D C3                  <1> 	retn
 32829                              <1> 
 32830                              <1> wakeup:
 32831                              <1> 	; 24/01/2016
 32832 0000AE7E C3                  <1> 	retn
 32833                                  %include 'trdosk9.s' ; 04/01/2016
 32834                              <1> ; ****************************************************************************
 32835                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - INITIALIZED DATA : trdosk9.s
 32836                              <1> ; ----------------------------------------------------------------------------
 32837                              <1> ; Last Update: 05/04/2016
 32838                              <1> ; ----------------------------------------------------------------------------
 32839                              <1> ; Beginning: 04/01/2016
 32840                              <1> ; ----------------------------------------------------------------------------
 32841                              <1> ; ----------------------------------------------------------------------------
 32842                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 32843                              <1> ; ----------------------------------------------------------------------------
 32844                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 32845                              <1> ; TRDOS2.ASM (09/11/2011)
 32846                              <1> ; ****************************************************************************
 32847                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
 32848                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
 32849                              <1> ; CMD_INTR.ASM [29/01/2005] Last Update: 09/11/2011
 32850                              <1> ; FILE.ASM [29/10/2009] Last Update: 09/10/2011
 32851                              <1> 
 32852                              <1> ; 12/02/2016
 32853                              <1> Last_DOS_DiskNo: 
 32854 0000AE7F 01                  <1> 		db 1 ; A: = 0 & B: = 1
 32855                              <1> 
 32856                              <1> Restore_CDIR:	
 32857 0000AE80 FF                  <1> 		db 0FFh ; Initial value -> any number except 0
 32858                              <1> 
 32859                              <1> msg_CRLF_temp:  
 32860 0000AE81 070D0A00            <1> 		db  07h, 0Dh, 0Ah, 0
 32861                              <1> 
 32862                              <1> Magic_Bytes:
 32863 0000AE85 04                  <1> 		db 4
 32864 0000AE86 01                  <1> 		db 1
 32865                              <1> mainprog_Version:
 32866 0000AE87 07                  <1> 		db 7
 32867 0000AE88 5B5452444F535D204D- <1> 		db "[TRDOS] Main Program v2.0.050416"
 32868 0000AE91 61696E2050726F6772- <1>
 32869 0000AE9A 616D2076322E302E30- <1>
 32870 0000AEA3 3530343136          <1>
 32871 0000AEA8 0D0A                <1> 		db 0Dh, 0Ah
 32872 0000AEAA 286329204572646F67- <1> 		db "(c) Erdogan Tan 2005-2016"
 32873 0000AEB3 616E2054616E203230- <1>
 32874 0000AEBC 30352D32303136      <1>
 32875 0000AEC3 0D0A00              <1> 		db 0Dh, 0Ah, 0
 32876                              <1> 
 32877                              <1> MainProgCfgFile:
 32878 0000AEC6 4D41494E50524F472E- <1> 		db "MAINPROG.CFG", 0
 32879 0000AECF 43464700            <1>
 32880                              <1> 
 32881                              <1> TRDOSPromptLabel:
 32882 0000AED3 5452444F53          <1> 		db "TRDOS"
 32883 0000AED8 00                  <1> 		db 0
 32884 0000AED9 00<rept>            <1>                 times 5 db 0
 32885 0000AEDE 00                  <1> 		db 0
 32886                              <1> 
 32887                              <1> ; INTERNAL COMMANDS
 32888                              <1> Command_List:
 32889 0000AEDF 44495200            <1> Cmd_Dir:	db "DIR", 0
 32890 0000AEE3 434400              <1> Cmd_Cd:		db "CD", 0
 32891 0000AEE6 433A00              <1> Cmd_Drive:	db "C:", 0
 32892 0000AEE9 56455200            <1> Cmd_Ver:	db "VER", 0
 32893 0000AEED 4558495400          <1> Cmd_Exit:	db "EXIT", 0
 32894 0000AEF2 50524F4D505400      <1> Cmd_Prompt:	db "PROMPT", 0
 32895 0000AEF9 564F4C554D4500      <1> Cmd_Volume:	db "VOLUME", 0
 32896 0000AF00 4C4F4E474E414D4500  <1> Cmd_LongName:	db "LONGNAME", 0
 32897 0000AF09 4441544500          <1> Cmd_Date:	db "DATE", 0
 32898 0000AF0E 54494D4500          <1> Cmd_Time:	db "TIME", 0
 32899 0000AF13 52554E00            <1> Cmd_Run:	db "RUN", 0
 32900 0000AF17 53455400            <1> Cmd_Set:	db "SET", 0 
 32901 0000AF1B 434C5300            <1> Cmd_Cls:	db "CLS", 0
 32902 0000AF1F 53484F5700          <1> Cmd_Show:	db "SHOW", 0
 32903 0000AF24 44454C00            <1> Cmd_Del:	db "DEL", 0
 32904 0000AF28 41545452494200      <1> Cmd_Attrib:	db "ATTRIB", 0
 32905 0000AF2F 52454E414D4500      <1> Cmd_Rename:	db "RENAME", 0
 32906 0000AF36 524D44495200        <1> Cmd_Rmdir:	db "RMDIR", 0
 32907 0000AF3C 4D4B44495200        <1> Cmd_Mkdir:	db "MKDIR", 0
 32908 0000AF42 434F505900          <1> Cmd_Copy:	db "COPY", 0
 32909 0000AF47 4D4F564500          <1> Cmd_Move:	db "MOVE", 0
 32910 0000AF4C 5041544800          <1> Cmd_Path:	db "PATH", 0
 32911 0000AF51 4D454D00            <1> Cmd_Mem:	db "MEM", 0
 32912 0000AF55 00                  <1> 		db 0
 32913 0000AF56 46494E4400          <1> Cmd_Find:	db "FIND", 0
 32914 0000AF5B 5245414446494C4500  <1> Cmd_ReadFile:	db "READFILE", 0
 32915 0000AF64 4543484F00          <1> Cmd_Echo:	db "ECHO", 0
 32916 0000AF69 2A00                <1> Cmd_Remark:	db "*", 0
 32917 0000AF6B 3F00                <1> Cmd_Help:	db "?", 0
 32918 0000AF6D 44455649434500      <1> Cmd_Device:	db "DEVICE", 0
 32919 0000AF74 4445564C49535400    <1> Cmd_DevList:	db "DEVLIST", 0
 32920 0000AF7C 434844495200        <1> Cmd_Chdir:	db "CHDIR", 0
 32921 0000AF82 4245455000          <1> Cmd_Beep:	db "BEEP", 0
 32922                              <1> 		
 32923 0000AF87 00                  <1> 		db 0
 32924                              <1> 
 32925                              <1> ; 15/02/2016 (FILE.ASM, 09/10/2011)
 32926                              <1> invalid_fname_chars:
 32927 0000AF88 222728292A2B2C2F    <1> 		db 22h, 27h, 28h, 29h, 2Ah, 2Bh, 2Ch, 2Fh
 32928 0000AF90 3A3B3C3D3E3F40      <1> 		db 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh, 40h
 32929 0000AF97 5B5C5D5E60          <1> 		db 5Bh, 5Ch, 5Dh, 5Eh, 60h
 32930                              <1> sizeInvFnChars  equ ($ - invalid_fname_chars)                
 32931                              <1> ;
 32932                              <1> 
 32933                              <1> Msg_Enter_Date:
 32934 0000AF9C 456E746572206E6577- <1>                 db 'Enter new date (dd-mm-yy): '
 32935 0000AFA5 206461746520286464- <1>
 32936 0000AFAE 2D6D6D2D7979293A20  <1>
 32937 0000AFB7 00                  <1>                 db 0
 32938                              <1> Msg_Show_Date:
 32939 0000AFB8 43757272656E742064- <1>                 db   'Current date is '
 32940 0000AFC1 61746520697320      <1>
 32941 0000AFC8 30                  <1> Day:            db   '0'
 32942 0000AFC9 30                  <1> 		db   '0'
 32943 0000AFCA 2F                  <1>                 db   '/'
 32944 0000AFCB 30                  <1> Month:          db   '0'
 32945 0000AFCC 30                  <1> 		db   '0'
 32946 0000AFCD 2F                  <1>                 db   '/'
 32947 0000AFCE 30                  <1> Century:        db   '0'
 32948 0000AFCF 30                  <1>                 db   '0'
 32949 0000AFD0 30                  <1> Year:           db   '0'
 32950 0000AFD1 30                  <1> 		db   '0'
 32951 0000AFD2 0D0A00              <1>                 db   0Dh, 0Ah, 0
 32952                              <1> 
 32953                              <1> Msg_Enter_Time:
 32954 0000AFD5 456E746572206E6577- <1> 		db 'Enter new time: '
 32955 0000AFDE 2074696D653A20      <1>
 32956 0000AFE5 00                  <1> 		db 0
 32957                              <1> Msg_Show_Time:
 32958 0000AFE6 43757272656E742074- <1> 		db   'Current time is '
 32959 0000AFEF 696D6520697320      <1>
 32960 0000AFF6 30                  <1> Hour:           db   '0'
 32961 0000AFF7 30                  <1> 		db   '0'
 32962 0000AFF8 3A                  <1> 		db   ':'
 32963 0000AFF9 30                  <1> Minute:         db   '0'
 32964 0000AFFA 30                  <1> 		db   '0'
 32965 0000AFFB 3A                  <1> 		db   ':'
 32966 0000AFFC 30                  <1> Second:         db   '0'
 32967 0000AFFD 30                  <1> 		db   '0'
 32968 0000AFFE 0D0A00              <1> 		db   0Dh, 0Ah, 0
 32969                              <1> 
 32970                              <1> ;VolSize_Unit1:   dd 0
 32971                              <1> ;VolSize_Unit2:   dd 0
 32972                              <1> 
 32973                              <1> VolSize_KiloBytes:
 32974 0000B001 206B696C6F62797465- <1> 		db " kilobytes", 0Dh, 0Ah, 0
 32975 0000B00A 730D0A00            <1>
 32976                              <1> VolSize_Bytes:
 32977 0000B00E 2062797465730D0A00  <1> 		db " bytes", 0Dh, 0Ah, 0
 32978                              <1> Volume_in_drive:
 32979 0000B017 0D0A                <1> 		db 0Dh, 0Ah
 32980                              <1> Vol_FS_Name:
 32981 0000B019 54522046533120      <1> 		db "TR FS1 "
 32982 0000B020 566F6C756D6520696E- <1> 		db "Volume in drive "
 32983 0000B029 20647269766520      <1>
 32984 0000B030 30                  <1> Vol_Drv_Name:   db 30h
 32985 0000B031 3A                  <1> 		db ":"
 32986 0000B032 20697320            <1> 		db " is "
 32987 0000B036 0D0A00              <1> 		db 0Dh, 0Ah, 0
 32988                              <1> Dir_Drive_Str:
 32989 0000B039 54522D444F53204472- <1>                 db "TR-DOS Drive "
 32990 0000B042 69766520            <1>
 32991                              <1> Dir_Drive_Name:
 32992 0000B046 303A                <1>                 db "0:"
 32993 0000B048 0D0A                <1>                 db  0Dh, 0Ah
 32994                              <1> Vol_Str_Header:
 32995 0000B04A 566F6C756D65204E61- <1>                 db "Volume Name: "
 32996 0000B053 6D653A20            <1>
 32997                              <1> Vol_Name:
 32998 0000B057 00<rept>            <1> 		times 64 db 0
 32999 0000B097 00                  <1> 		db 0
 33000                              <1> Vol_Serial_Header:
 33001 0000B098 0D0A                <1> 		db 0Dh, 0Ah
 33002 0000B09A 566F6C756D65205365- <1> 		db "Volume Serial No: "
 33003 0000B0A3 7269616C204E6F3A20  <1>
 33004                              <1> Vol_Serial1:
 33005 0000B0AC 30303030            <1> 		db "0000"
 33006 0000B0B0 2D                  <1> 		db "-"
 33007                              <1> Vol_Serial2:
 33008 0000B0B1 30303030            <1> 		db "0000"
 33009 0000B0B5 0D0A00              <1> 		db 0Dh, 0Ah, 0
 33010                              <1> 
 33011                              <1> ;Vol_Tot_Sec_Str_Start:
 33012                              <1> ;		dd 0
 33013                              <1> Vol_Total_Sector_Header:
 33014 0000B0B8 0D0A                <1> 		db 0Dh, 0Ah
 33015 0000B0BA 566F6C756D65205369- <1> 		db "Volume Size : ", 0
 33016 0000B0C3 7A65203A2000        <1>
 33017                              <1> ;Vol_Tot_Sec_Str: 
 33018                              <1> ;		db "0000000000"
 33019                              <1> ;Vol_Tot_Sec_Str_End:
 33020                              <1> ;		db 0
 33021                              <1> ;Vol_Free_Sectors_Str_Start:
 33022                              <1> ;		dd 0
 33023                              <1> Vol_Free_Sectors_Header:
 33024 0000B0C9 467265652053706163- <1> 		db "Free Space  : ", 0
 33025 0000B0D2 6520203A2000        <1>
 33026                              <1> ;Vol_Free_Sectors_Str:
 33027                              <1> ;		db "0000000000"
 33028                              <1> ;Vol_Free_Sectors_Str_End:
 33029                              <1> ;		db 0
 33030                              <1> 
 33031                              <1> Dir_Str_Header:
 33032 0000B0D8 4469726563746F7279- <1>                 db "Directory: "
 33033 0000B0E1 3A20                <1>
 33034 0000B0E3 2F                  <1> Dir_Str_Root:   db "/"
 33035 0000B0E4 00<rept>            <1> Dir_Str:        times 64 db 0
 33036 0000B124 00000000            <1>                 dd 0
 33037 0000B128 00                  <1>                 db 0
 33038                              <1> 
 33039                              <1> Msg_Bad_Command:
 33040 0000B129 42616420636F6D6D61- <1>                 db "Bad command or file name!"
 33041 0000B132 6E64206F722066696C- <1>
 33042 0000B13B 65206E616D6521      <1>
 33043 0000B142 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33044                              <1> 
 33045                              <1> msgl_drv_not_ready: 
 33046 0000B145 070D0A              <1> 		db 07h, 0Dh, 0Ah
 33047                              <1> 
 33048                              <1> ; CMD_INTR.ASM - 09/11/2011 - Messages
 33049                              <1> 
 33050                              <1> Msg_Not_Ready_Read_Err:
 33051 0000B148 4472697665206E6F74- <1>                 db "Drive not ready or read error!"
 33052 0000B151 207265616479206F72- <1>
 33053 0000B15A 207265616420657272- <1>
 33054 0000B163 6F7221              <1>
 33055 0000B166 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33056                              <1> 
 33057                              <1> Msg_Not_Ready_Write_Err:
 33058 0000B169 4472697665206E6F74- <1>                 db "Drive not ready or write error!"
 33059 0000B172 207265616479206F72- <1>
 33060 0000B17B 207772697465206572- <1>
 33061 0000B184 726F7221            <1>
 33062 0000B188 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33063                              <1> 
 33064                              <1> Msg_Dir_Not_Found:
 33065 0000B18B 4469726563746F7279- <1>                 db "Directory not found!"
 33066 0000B194 206E6F7420666F756E- <1>
 33067 0000B19D 6421                <1>
 33068 0000B19F 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33069                              <1> 
 33070                              <1> Msg_File_Not_Found:
 33071 0000B1A2 46696C65206E6F7420- <1>                 db "File not found!"
 33072 0000B1AB 666F756E6421        <1>
 33073 0000B1B1 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33074                              <1> 
 33075                              <1> Msg_File_Directory_Not_Found:
 33076 0000B1B4 46696C65206F722064- <1>                 db "File or directory not found!"
 33077 0000B1BD 69726563746F727920- <1>
 33078 0000B1C6 6E6F7420666F756E64- <1>
 33079 0000B1CF 21                  <1>
 33080 0000B1D0 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33081                              <1> 
 33082                              <1> Msg_LongName_Not_Found:
 33083 0000B1D3 4C6F6E67206E616D65- <1>                 db "Long name not found!"
 33084 0000B1DC 206E6F7420666F756E- <1>
 33085 0000B1E5 6421                <1>
 33086 0000B1E7 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33087                              <1> 
 33088                              <1> Msg_Insufficient_Memory:
 33089 0000B1EA 496E73756666696369- <1>                 db "Insufficient memory!"
 33090 0000B1F3 656E74206D656D6F72- <1>
 33091 0000B1FC 7921                <1>
 33092 0000B1FE 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33093                              <1> 
 33094                              <1> Msg_Error_Code:
 33095 0000B201 436F6D6D616E642066- <1>                 db 'Command failed! Error code : '
 33096 0000B20A 61696C656421204572- <1>
 33097 0000B213 726F7220636F646520- <1>
 33098 0000B21C 3A20                <1>
 33099 0000B21E 303068              <1> error_code_hex: db '00h'
 33100 0000B221 0A0A00              <1>                 db 0Ah, 0Ah, 0
 33101                              <1> 
 33102                              <1> align 2
 33103                              <1> 
 33104                              <1> ; 10/02/2016
 33105                              <1> ; DIR.ASM - 09/10/2011
 33106                              <1> 
 33107 0000B224 3C4449523E20202020- <1> Type_Dir:       db '<DIR>     ' ; 10 bytes
 33108 0000B22D 20                  <1>
 33109                              <1> 
 33110                              <1> File_Name:
 33111 0000B22E 20<rept>            <1>                 times 12 db 20h
 33112 0000B23A 20                  <1> 		db 20h
 33113                              <1> Dir_Or_FileSize:
 33114 0000B23B 20<rept>            <1>                 times 10 db 20h
 33115 0000B245 20                  <1> 		db 20h
 33116                              <1> File_Attribute:
 33117 0000B246 20202020            <1> 		dd 20202020h
 33118 0000B24A 20                  <1> 		db 20h
 33119                              <1> File_Day:
 33120 0000B24B 3030                <1>                 db '0','0'
 33121 0000B24D 2F                  <1> 		db '/'
 33122                              <1> File_Month:
 33123 0000B24E 3030                <1>                 db '0','0'
 33124 0000B250 2F                  <1> 		db '/'
 33125                              <1> File_Year:
 33126 0000B251 30303030            <1>                 db '0','0','0','0'
 33127 0000B255 20                  <1> 		db 20h
 33128                              <1> File_Hour:
 33129 0000B256 3030                <1>                 db '0','0'
 33130 0000B258 3A                  <1> 		db ':'
 33131                              <1> File_Minute:
 33132 0000B259 3030                <1>                 db '0','0'
 33133 0000B25B 00                  <1> 		db 0
 33134                              <1> 
 33135                              <1> Decimal_File_Count_Header:
 33136 0000B25C 0D0A                <1> 		db 0Dh, 0Ah
 33137                              <1> Decimal_File_Count:
 33138 0000B25E 00<rept>            <1> 		times 6 db 0
 33139                              <1> 
 33140 0000B264 2066696C6528732920- <1> str_files:	db " file(s) & "
 33141 0000B26D 2620                <1>
 33142                              <1> Decimal_Dir_Count: 
 33143 0000B26F 00<rept>            <1> 		times 6 db 0
 33144                              <1> str_dirs:       
 33145 0000B275 206469726563746F72- <1> 		db " directory(s) "
 33146 0000B27E 7928732920          <1>
 33147 0000B283 0D0A00              <1> 		db 0Dh, 0Ah, 0
 33148                              <1> 
 33149 0000B286 206279746528732920- <1> str_bytes:	db " byte(s) in file(s)"
 33150 0000B28F 696E2066696C652873- <1>
 33151 0000B298 29                  <1>
 33152 0000B299 0D0A00              <1> 		db 0Dh, 0Ah, 0
 33153                              <1> 
 33154                              <1> ; CMD_INTR.ASM - 09/11/2011
 33155                              <1> ; 07/10/2010
 33156                              <1> Msg_invalid_name_chars:
 33157 0000B29C 496E76616C69642066- <1>                 db "Invalid file or directory name characters!"
 33158 0000B2A5 696C65206F72206469- <1>
 33159 0000B2AE 726563746F7279206E- <1>
 33160 0000B2B7 616D65206368617261- <1>
 33161 0000B2C0 637465727321        <1>
 33162 0000B2C6 0D0A00              <1>         	db 0Dh, 0Ah, 0
 33163                              <1> ; 21/02/2016
 33164 0000B2C9 46696C65206F722064- <1> Msg_Name_Exists: db "File or directory name exists!"
 33165 0000B2D2 69726563746F727920- <1>
 33166 0000B2DB 6E616D652065786973- <1>
 33167 0000B2E4 747321              <1>
 33168 0000B2E7 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33169                              <1> Msg_DoYouWantMkdir:
 33170 0000B2EA 446F20796F75207761- <1>                 db "Do you want to make directory ", 0
 33171 0000B2F3 6E7420746F206D616B- <1>
 33172 0000B2FC 65206469726563746F- <1>
 33173 0000B305 72792000            <1>
 33174 0000B309 2028592F4E29203F20- <1> Msg_YesNo:      db " (Y/N) ? ", 0  
 33175 0000B312 00                  <1>
 33176 0000B313 000D0A00            <1> Y_N_nextline:	db 0, 0Dh, 0Ah, 0 
 33177 0000B317 4F4B2E0D0A00        <1> Msg_OK:		db "OK.", 0Dh, 0Ah, 0
 33178                              <1> 
 33179                              <1> ; 27/02/2016
 33180                              <1> Msg_DoYouWantRmDir:
 33181 0000B31D 446F20796F75207761- <1>                 db "Do you want to delete directory ", 0
 33182 0000B326 6E7420746F2064656C- <1>
 33183 0000B32F 657465206469726563- <1>
 33184 0000B338 746F72792000        <1>
 33185                              <1> Msg_Dir_Not_Empty:
 33186 0000B33E 4469726563746F7279- <1>                 db "Directory not empty!"
 33187 0000B347 206E6F7420656D7074- <1>
 33188 0000B350 7921                <1>
 33189 0000B352 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33190                              <1> 
 33191                              <1> Msg_DoYouWantDelete:
 33192 0000B355 446F20796F75207761- <1>                 db "Do you want to delete file ",0
 33193 0000B35E 6E7420746F2064656C- <1>
 33194 0000B367 6574652066696C6520- <1>
 33195 0000B370 00                  <1>
 33196                              <1> 
 33197 0000B371 44656C657465642E2E- <1> Msg_Deleted:    db "Deleted...", 0Dh, 0Ah, 0
 33198 0000B37A 2E0D0A00            <1>
 33199                              <1> 
 33200                              <1> Msg_Permission_Denied:
 33201 0000B37E 07                  <1>                 db 7
 33202 0000B37F 5065726D697373696F- <1>                 db "Permission denied!", 0Dh, 0Ah, 0
 33203 0000B388 6E2064656E69656421- <1>
 33204 0000B391 0D0A00              <1>
 33205                              <1> 
 33206                              <1> ; 04/03/2016
 33207 0000B394 4E657720            <1> Msg_New:        db "New "
 33208 0000B398 00                  <1>                 db 0
 33209                              <1> Str_Attributes:
 33210 0000B399 417474726962757465- <1>                 db "Attributes : "
 33211 0000B3A2 73203A20            <1>
 33212 0000B3A6 4E4F524D414C        <1> Attr_Chars:     db "NORMAL"
 33213 0000B3AC 00                  <1>                 db 0
 33214                              <1> 
 33215                              <1> ; 06/03/2016
 33216                              <1> ; CMD_INTR.ASM - 16/11/2010 
 33217                              <1> Msg_DoYouWantRename:
 33218 0000B3AD 446F20796F75207761- <1>                 db "Do you want to rename ", 0
 33219 0000B3B6 6E7420746F2072656E- <1>
 33220 0000B3BF 616D652000          <1>
 33221 0000B3C4 66696C652000        <1> Rename_File:    db "file ", 0
 33222 0000B3CA 6469726563746F7279- <1> Rename_Directory: db "directory ", 0
 33223 0000B3D3 2000                <1>
 33224 0000B3D5 00<rept>            <1> Rename_OldName: times 13 db 0
 33225 0000B3E2 20617320            <1> Msg_File_rename_as: db " as "
 33226 0000B3E6 00<rept>            <1> Rename_NewName: times 13 db 0
 33227                              <1> 
 33228                              <1> ; 08/03/2016
 33229                              <1> ; CMD_INTR.ASM - 01/08/2010 - 23/04/2011
 33230                              <1> msg_not_same_drv:
 33231 0000B3F3 4E6F742073616D6520- <1>                 db "Not same drive!" 
 33232 0000B3FC 647269766521        <1>
 33233 0000B402 0D0A00              <1>                 db 0Dh, 0Ah, 0 
 33234                              <1> 
 33235                              <1> Msg_DoYouWantMoveFile:
 33236 0000B405 446F20796F75207761- <1>                 db "Do you want to move file", 0
 33237 0000B40E 6E7420746F206D6F76- <1>
 33238 0000B417 652066696C6500      <1>
 33239                              <1> 
 33240                              <1> msg_insufficient_disk_space:
 33241 0000B41E 496E73756666696369- <1>                 db "Insufficient disk space!" 
 33242 0000B427 656E74206469736B20- <1>
 33243 0000B430 737061636521        <1>
 33244 0000B436 0D0A00              <1>                 db 0Dh, 0Ah, 0
 33245                              <1> 
 33246                              <1> ; 01/08/2010
 33247                              <1> msg_source_file: 
 33248 0000B439 0D0A536F7572636520- <1> 		db 0Dh, 0Ah, "Source file name      :   "
 33249 0000B442 66696C65206E616D65- <1>
 33250 0000B44B 2020202020203A2020- <1>
 33251 0000B454 20                  <1>
 33252                              <1> msg_source_file_drv: 
 33253 0000B455 203A00              <1> 		db " :", 0
 33254                              <1> msg_destination_file: 
 33255 0000B458 0D0A44657374696E61- <1> 		db 0Dh, 0Ah, "Destination file name :   "
 33256 0000B461 74696F6E2066696C65- <1>
 33257 0000B46A 206E616D65203A2020- <1>
 33258 0000B473 20                  <1>
 33259                              <1> msg_destination_file_drv: 
 33260 0000B474 203A00              <1> 		db " :", 0
 33261                              <1> msg_copy_nextline: 
 33262 0000B477 0D0A00              <1> 		db 0Dh, 0Ah, 0
 33263                              <1> 
 33264                              <1> ; 15/03/2016
 33265                              <1> ; CMD_INTR.ASM
 33266                              <1> 
 33267                              <1> Msg_DoYouWantOverWriteFile:
 33268 0000B47A 446F20796F75207761- <1>                 db "Do you want to overwrite file ",0
 33269 0000B483 6E7420746F206F7665- <1>
 33270 0000B48C 727772697465206669- <1>
 33271 0000B495 6C652000            <1>
 33272                              <1>   
 33273                              <1> Msg_DoYouWantCopyFile:
 33274 0000B499 446F20796F75207761- <1>                 db "Do you want to copy file",0
 33275 0000B4A2 6E7420746F20636F70- <1>
 33276 0000B4AB 792066696C6500      <1>
 33277                              <1> 
 33278                              <1> Msg_read_file_error_before_EOF:
 33279 0000B4B2 46696C652072656164- <1> 		db "File reading error! (before EOF)"
 33280 0000B4BB 696E67206572726F72- <1>
 33281 0000B4C4 2120286265666F7265- <1>
 33282 0000B4CD 20454F4629          <1>
 33283 0000B4D2 0A0A00              <1> 		db 0Ah, 0Ah, 0
 33284                              <1> 
 33285                              <1> ; 18/03/2016
 33286                              <1> ; TRDOS 386 (v2.0) mainprog copy procedure
 33287                              <1> msg_reading:
 33288 0000B4D5 52656164696E672E2E- <1> 		db "Reading... ", 0
 33289 0000B4DE 2E2000              <1>
 33290                              <1> msg_writing:
 33291 0000B4E1 57726974696E672E2E- <1> 		db "Writing... ", 0
 33292 0000B4EA 2E2000              <1>
 33293                              <1> percentagestr:
 33294 0000B4ED 2020202500          <1> 		db "   %", 0 ; "  0%" .. "100%"
 33295                                  
 33296                                  ; 07/03/2015
 33297                                  ; Temporary Code
 33298                                  display_disks:
 33299 0000B4F2 803D[BEB80000]00        	cmp 	byte [fd0_type], 0
 33300 0000B4F9 7605                    	jna 	short ddsks1
 33301 0000B4FB E87D000000              	call	pdskm
 33302                                  ddsks1:
 33303 0000B500 803D[BFB80000]00        	cmp	byte [fd1_type], 0
 33304 0000B507 760C                    	jna	short ddsks2
 33305 0000B509 C605[B5BA0000]31        	mov	byte [dskx], '1'
 33306 0000B510 E868000000              	call	pdskm
 33307                                  ddsks2:
 33308 0000B515 803D[C0B80000]00        	cmp	byte [hd0_type], 0
 33309 0000B51C 7654                    	jna	short ddsk6
 33310 0000B51E 66C705[B3BA0000]68-     	mov	word [dsktype], 'hd'
 33311 0000B526 64                 
 33312 0000B527 C605[B5BA0000]30        	mov	byte [dskx], '0'
 33313 0000B52E E84A000000              	call	pdskm
 33314                                  ddsks3:
 33315 0000B533 803D[C1B80000]00        	cmp	byte [hd1_type], 0
 33316 0000B53A 7636                    	jna	short ddsk6
 33317 0000B53C C605[B5BA0000]31        	mov	byte [dskx], '1'
 33318 0000B543 E835000000              	call	pdskm
 33319                                  ddsks4:
 33320 0000B548 803D[C2B80000]00        	cmp	byte [hd2_type], 0
 33321 0000B54F 7621                    	jna	short ddsk6
 33322 0000B551 C605[B5BA0000]32        	mov	byte [dskx], '2'
 33323 0000B558 E820000000              	call	pdskm
 33324                                  ddsks5:
 33325 0000B55D 803D[C3B80000]00        	cmp	byte [hd3_type], 0
 33326 0000B564 760C                    	jna	short ddsk6
 33327 0000B566 C605[B5BA0000]33        	mov	byte [dskx], '3'
 33328 0000B56D E80B000000              	call	pdskm
 33329                                  ddsk6:
 33330 0000B572 BE[C6BA0000]            	mov	esi, nextline
 33331 0000B577 E806000000              	call	pdskml
 33332                                  pdskm_ok:
 33333 0000B57C C3                      	retn
 33334                                  pdskm:
 33335 0000B57D BE[B1BA0000]            	mov	esi, dsk_ready_msg
 33336                                  pdskml:	
 33337 0000B582 AC                      	lodsb
 33338 0000B583 08C0                    	or	al, al
 33339 0000B585 74F5                    	jz	short pdskm_ok
 33340 0000B587 56                      	push	esi
 33341 0000B588 31DB                    	xor	ebx, ebx ; 0
 33342                                  			; Video page 0 (bl=0)
 33343 0000B58A B407                    	mov	ah, 07h ; Black background, 
 33344                                  			; light gray forecolor
 33345 0000B58C E82662FFFF              	call	WRITE_TTY
 33346 0000B591 5E                      	pop	esi
 33347 0000B592 EBEE                    	jmp	short pdskml
 33348                                  
 33349 0000B594 90<rept>                align 16
 33350                                  
 33351                                  gdt:	; Global Descriptor Table
 33352                                  	; (30/07/2015, conforming cs)
 33353                                  	; (26/03/2015)
 33354                                  	; (24/03/2015, tss)
 33355                                  	; (19/03/2015)
 33356                                  	; (29/12/2013)
 33357                                  	;
 33358 0000B5A0 0000000000000000        	dw 0, 0, 0, 0		; NULL descriptor
 33359                                  	; 18/08/2014
 33360                                  			; 8h kernel code segment, base = 00000000h		
 33361 0000B5A8 FFFF0000009ACF00        	dw 0FFFFh, 0, 9A00h, 00CFh	; KCODE
 33362                                  			; 10h kernel data segment, base = 00000000h	
 33363 0000B5B0 FFFF00000092CF00        	dw 0FFFFh, 0, 9200h, 00CFh	; KDATA
 33364                                  			; 1Bh user code segment, base address = 400000h ; CORE
 33365 0000B5B8 FFFB000040FACF00        	dw 0FBFFh, 0, 0FA40h, 00CFh	; UCODE 
 33366                                  			; 23h user data segment, base address = 400000h ; CORE
 33367 0000B5C0 FFFB000040F2CF00        	dw 0FBFFh, 0, 0F240h, 00CFh	; UDATA
 33368                                  			; Task State Segment
 33369 0000B5C8 6700                    	dw 0067h ; Limit = 103 ; (104-1, tss size = 104 byte, 
 33370                                  			       ;  no IO permission in ring 3)
 33371                                  gdt_tss0:
 33372 0000B5CA 0000                    	dw 0  ; TSS base address, bits 0-15 
 33373                                  gdt_tss1:
 33374 0000B5CC 00                      	db 0  ; TSS base address, bits 16-23 
 33375                                  	      		; 49h	
 33376 0000B5CD E9                      	db 11101001b ; E9h => P=1/DPL=11/0/1/0/B/1 --> B = Task is busy (1)
 33377 0000B5CE 00                      	db 0 ; G/0/0/AVL/LIMIT=0000 ; (Limit bits 16-19 = 0000) (G=0, 1 byte)
 33378                                  gdt_tss2:
 33379 0000B5CF 00                      	db 0  ; TSS base address, bits 24-31 
 33380                                  
 33381                                  gdt_end:
 33382                                  	;; 9Ah = 1001 1010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
 33383                                  					;; Type= 1 (code)/C=0/R=1/A=0
 33384                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
 33385                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
 33386                                  
 33387                                  	;; 92h = 1001 0010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
 33388                                  					;; Type= 0 (data)/E=0/W=1/A=0
 33389                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
 33390                                  		; 0= Data E= Expansion direction (1= down, 0= up)
 33391                                  		; W= Writeable, A= Accessed
 33392                                  	
 33393                                  	;; FAh = 1111 1010b (GDT byte 5) P=1/DPL=11/1/TYPE=1010, 
 33394                                  					;; Type= 1 (code)/C=0/R=1/A=0
 33395                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
 33396                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
 33397                                  
 33398                                  	;; F2h = 1111 0010b (GDT byte 5) P=1/DPL=11/1/TYPE=0010, 
 33399                                  					;; Type= 0 (data)/E=0/W=1/A=0
 33400                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
 33401                                  		; 0= Data E= Expansion direction (1= down, 0= up)
 33402                                  	
 33403                                  	;; CFh = 1100 1111b (GDT byte 6) G=1/B=1/0/AVL=0, Limit=1111b (3)
 33404                                  
 33405                                  		;; Limit = FFFFFh (=> FFFFFh+1= 100000h) // bits 0-15, 48-51 //
 33406                                  		;	 = 100000h * 1000h (G=1) = 4GB
 33407                                  		;; Limit = FFBFFh (=> FFBFFh+1= FFC00h) // bits 0-15, 48-51 //
 33408                                  		;	 = FFC00h * 1000h (G=1) = 4GB - 4MB
 33409                                  		; G= Granularity (1= 4KB), B= Big (32 bit), 
 33410                                  		; AVL= Available to programmers	
 33411                                  
 33412                                  gdtd:
 33413 0000B5D0 2F00                            dw gdt_end - gdt - 1    ; Limit (size)
 33414 0000B5D2 [A0B50000]                      dd gdt			; Address of the GDT
 33415                                  
 33416                                  	; 20/08/2014
 33417                                  idtd:
 33418 0000B5D6 FF01                            dw idt_end - idt - 1    ; Limit (size)
 33419 0000B5D8 [80BB0000]                      dd idt			; Address of the IDT
 33420                                  
 33421                                  Align 4
 33422                                  
 33423                                  	; 21/08/2014
 33424                                  ilist:
 33425                                  	;times 	32 dd cpu_except ; INT 0 to INT 1Fh
 33426                                  	;
 33427                                  	; Exception list
 33428                                  	; 25/08/2014	
 33429 0000B5DC [DB080000]              	dd	exc0	; 0h,  Divide-by-zero Error
 33430 0000B5E0 [E2080000]              	dd	exc1	
 33431 0000B5E4 [E9080000]              	dd 	exc2	
 33432 0000B5E8 [F0080000]              	dd	exc3	
 33433 0000B5EC [F4080000]              	dd	exc4	
 33434 0000B5F0 [F8080000]              	dd	exc5	
 33435 0000B5F4 [FC080000]              	dd 	exc6	; 06h,  Invalid Opcode
 33436 0000B5F8 [00090000]              	dd	exc7	
 33437 0000B5FC [04090000]              	dd	exc8	
 33438 0000B600 [08090000]              	dd	exc9	
 33439 0000B604 [0C090000]              	dd 	exc10	
 33440 0000B608 [10090000]              	dd	exc11
 33441 0000B60C [14090000]              	dd	exc12
 33442 0000B610 [18090000]              	dd	exc13	; 0Dh, General Protection Fault
 33443 0000B614 [1C090000]              	dd 	exc14	; 0Eh, Page Fault
 33444 0000B618 [20090000]              	dd	exc15
 33445 0000B61C [24090000]              	dd	exc16
 33446 0000B620 [28090000]              	dd	exc17
 33447 0000B624 [2C090000]              	dd 	exc18
 33448 0000B628 [30090000]              	dd	exc19
 33449 0000B62C [34090000]              	dd 	exc20
 33450 0000B630 [38090000]              	dd	exc21
 33451 0000B634 [3C090000]              	dd	exc22
 33452 0000B638 [40090000]              	dd	exc23
 33453 0000B63C [44090000]              	dd 	exc24
 33454 0000B640 [48090000]              	dd	exc25
 33455 0000B644 [4C090000]              	dd	exc26
 33456 0000B648 [50090000]              	dd	exc27
 33457 0000B64C [54090000]              	dd 	exc28
 33458 0000B650 [58090000]              	dd	exc29
 33459 0000B654 [5C090000]              	dd 	exc30
 33460 0000B658 [60090000]              	dd	exc31
 33461                                  	; Interrupt list
 33462 0000B65C [11070000]              	dd	timer_int	; INT 20h
 33463                                  		;dd	irq0	
 33464 0000B660 [AD0D0000]              	dd	kb_int		; 24/01/2016
 33465                                  		;dd	irq1
 33466 0000B664 [31080000]              	dd	irq2
 33467                                  		; COM2 int
 33468 0000B668 [35080000]              	dd	irq3
 33469                                  		; COM1 int
 33470 0000B66C [40080000]              	dd	irq4
 33471 0000B670 [4B080000]              	dd	irq5
 33472                                  ;DISKETTE_INT: ;06/02/2015
 33473 0000B674 [77280000]              	dd	fdc_int		; 16/02/2015, IRQ 6 handler	
 33474                                  		;dd	irq6
 33475                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
 33476                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
 33477 0000B678 [C70B0000]              	dd	default_irq7	; 25/02/2015
 33478                                  		;dd	irq7
 33479                                  ; Real Time Clock Interrupt
 33480 0000B67C [6A0A0000]              	dd	rtc_int		; 23/02/2015, IRQ 8 handler
 33481                                  		;dd	irq8	; INT 28h
 33482 0000B680 [5B080000]              	dd	irq9
 33483 0000B684 [5F080000]              	dd	irq10
 33484 0000B688 [63080000]              	dd	irq11
 33485 0000B68C [67080000]              	dd	irq12
 33486 0000B690 [6B080000]              	dd	irq13
 33487                                  ;HDISK_INT1:  ;06/02/2015 	
 33488 0000B694 [BA300000]              	dd	hdc1_int 	; 21/02/2015, IRQ 14 handler		
 33489                                  		;dd	irq14
 33490                                  ;HDISK_INT2:  ;06/02/2015
 33491 0000B698 [E1300000]              	dd	hdc2_int 	; 21/02/2015, IRQ 15 handler		
 33492                                  		;dd	irq15	; INT 2Fh
 33493                                  		; 14/08/2015
 33494 0000B69C [C8940000]              	dd	sysent		; INT 30h (system calls)
 33495                                  	
 33496                                  	;dd	ignore_int
 33497 0000B6A0 00000000                	dd	0
 33498                                  
 33499                                  ;;;
 33500                                  ;;; 11/03/2015
 33501                                  %include 'kybdata.s'	; KEYBOARD (BIOS) DATA
 33502                              <1> ; ****************************************************************************
 33503                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - kybdata.s
 33504                              <1> ; ----------------------------------------------------------------------------
 33505                              <1> ; Last Update: 17/01/2016
 33506                              <1> ; ----------------------------------------------------------------------------
 33507                              <1> ; Beginning: 17/01/2016
 33508                              <1> ; ----------------------------------------------------------------------------
 33509                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 33510                              <1> ; ----------------------------------------------------------------------------
 33511                              <1> ; Turkish Rational DOS
 33512                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 33513                              <1> ;
 33514                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 33515                              <1> ; kybdata.inc (11/03/2015)
 33516                              <1> ;
 33517                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 33518                              <1> ; ****************************************************************************
 33519                              <1> 
 33520                              <1> ; Retro UNIX 386 v1 Kernel - KYBDATA.INC
 33521                              <1> ; Last Modification: 11/03/2015
 33522                              <1> ;		 (Data Section for 'KEYBOARD.INC')	
 33523                              <1> ;
 33524                              <1> ; ///////// KEYBOARD DATA ///////////////
 33525                              <1> 
 33526                              <1> ; 05/12/2014
 33527                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-) 
 33528                              <1> ; 03/06/86  KEYBOARD BIOS
 33529                              <1> 
 33530                              <1> ;---------------------------------------------------------------------------------
 33531                              <1> ;	KEY IDENTIFICATION SCAN TABLES
 33532                              <1> ;---------------------------------------------------------------------------------
 33533                              <1> 
 33534                              <1> ;-----	TABLES FOR ALT CASE ------------
 33535                              <1> ;-----	ALT-INPUT-TABLE 
 33536 0000B6A4 524F50514B          <1> K30:	db	82,79,80,81,75
 33537 0000B6A9 4C4D474849          <1> 	db	76,77,71,72,73		; 10 NUMBER ON KEYPAD
 33538                              <1> ;-----	SUPER-SHIFT-TABLE 
 33539 0000B6AE 101112131415        <1> 	db	16,17,18,19,20,21	; A-Z TYPEWRITER CHARS
 33540 0000B6B4 161718191E1F        <1> 	db	22,23,24,25,30,31
 33541 0000B6BA 202122232425        <1> 	db	32,33,34,35,36,37
 33542 0000B6C0 262C2D2E2F30        <1> 	db	38,44,45,46,47,48
 33543 0000B6C6 3132                <1> 	db	49,50
 33544                              <1> 
 33545                              <1> ;-----	TABLE OF SHIFT KEYS AND MASK VALUES
 33546                              <1> ;-----	KEY_TABLE 
 33547 0000B6C8 52                  <1> _K6:    db      INS_KEY                 ; INSERT KEY
 33548 0000B6C9 3A4546381D          <1> 	db	CAPS_KEY,NUM_KEY,SCROLL_KEY,ALT_KEY,CTL_KEY
 33549 0000B6CE 2A36                <1>         db      LEFT_KEY,RIGHT_KEY
 33550                              <1> _K6L    equ     $-_K6
 33551                              <1> 
 33552                              <1> ;-----	MASK_TABLE
 33553 0000B6D0 80                  <1> _K7:    db      INS_SHIFT               ; INSERT MODE SHIFT
 33554 0000B6D1 4020100804          <1> 	db	CAPS_SHIFT,NUM_SHIFT,SCROLL_SHIFT,ALT_SHIFT,CTL_SHIFT
 33555 0000B6D6 0201                <1> 	db	LEFT_SHIFT,RIGHT_SHIFT
 33556                              <1> 
 33557                              <1> ;-----	TABLES FOR CTRL CASE		;---- CHARACTERS ------
 33558 0000B6D8 1BFF00FFFFFF        <1> _K8:	db	27,-1,0,-1,-1,-1	; Esc, 1, 2, 3, 4, 5
 33559 0000B6DE 1EFFFFFFFF1F        <1> 	db 	30,-1,-1,-1,-1,31	; 6, 7, 8, 9, 0, -
 33560 0000B6E4 FF7FFF111705        <1> 	db	-1,127,-1,17,23,5	; =, Bksp, Tab, Q, W, E
 33561 0000B6EA 12141915090F        <1> 	db	18,20,25,21,9,15	; R, T, Y, U, I, O
 33562 0000B6F0 101B1D0AFF01        <1> 	db	16,27,29,10,-1,1	; P, [, ], Enter, Ctrl, A
 33563 0000B6F6 13040607080A        <1> 	db	19,4,6,7,8,10		; S, D, F, G, H, J
 33564 0000B6FC 0B0CFFFFFFFF        <1> 	db	11,12,-1,-1,-1,-1	; K, L, :, ', `, LShift
 33565 0000B702 1C1A18031602        <1> 	db	28,26,24,3,22,2		; Bkslash, Z, X, C, V, B
 33566 0000B708 0E0DFFFFFFFF        <1> 	db	14,13,-1,-1,-1,-1	; N, M, ,, ., /, RShift
 33567 0000B70E 96FF20FF            <1> 	db	150,-1,' ',-1		; *, ALT, Spc, CL
 33568                              <1> 	;				;----- FUNCTIONS ------		
 33569 0000B712 5E5F60616263        <1> 	db 	94,95,96,97,98,99	; F1 - F6
 33570 0000B718 64656667FFFF        <1> 	db	100,101,102,103,-1,-1	; F7 - F10, NL, SL
 33571 0000B71E 778D848E738F        <1> 	db	119,141,132,142,115,143	; Home, Up, PgUp, -, Left, Pad5
 33572 0000B724 749075917692        <1> 	db 	116,144,117,145,118,146 ; Right, +, End, Down, PgDn, Ins
 33573 0000B72A 93FFFFFF898A        <1> 	db	147,-1,-1,-1,137,138	; Del, SysReq, Undef, WT, F11, F12
 33574                              <1> 
 33575                              <1> ;-----	TABLES FOR LOWER CASE ----------
 33576 0000B730 1B3132333435363738- <1> K10:	db 	27,'1234567890-=',8,9
 33577 0000B739 39302D3D0809        <1>
 33578 0000B73F 71776572747975696F- <1> 	db 	'qwertyuiop[]',13,-1,'asdfghjkl;',39
 33579 0000B748 705B5D0DFF61736466- <1>
 33580 0000B751 67686A6B6C3B27      <1>
 33581 0000B758 60FF5C7A786376626E- <1> 	db	96,-1,92,'zxcvbnm,./',-1,'*',-1,' ',-1
 33582 0000B761 6D2C2E2FFF2AFF20FF  <1>
 33583                              <1> ;-----	LC TABLE SCAN
 33584 0000B76A 3B3C3D3E3F          <1> 	db	59,60,61,62,63		; BASE STATE OF F1 - F10
 33585 0000B76F 4041424344          <1> 	db	64,65,66,67,68
 33586 0000B774 FFFF                <1> 	db	-1,-1			; NL, SL
 33587                              <1> 
 33588                              <1> ;-----	KEYPAD TABLE
 33589 0000B776 474849FF4BFF        <1> K15:	db	71,72,73,-1,75,-1	; BASE STATE OF KEYPAD KEYS
 33590 0000B77C 4DFF4F50515253      <1> 	db	77,-1,79,80,81,82,83
 33591 0000B783 FFFF5C8586          <1> 	db	-1,-1,92,133,134	; SysRq, Undef, WT, F11, F12
 33592                              <1> 
 33593                              <1> ;-----	TABLES FOR UPPER CASE ----------
 33594 0000B788 1B21402324255E262A- <1> K11:	db 	27,'!@#$%',94,'&*()_+',8,0
 33595 0000B791 28295F2B0800        <1>
 33596 0000B797 51574552545955494F- <1> 	db 	'QWERTYUIOP{}',13,-1,'ASDFGHJKL:"'
 33597 0000B7A0 507B7D0DFF41534446- <1>
 33598 0000B7A9 47484A4B4C3A22      <1>
 33599 0000B7B0 7EFF7C5A584356424E- <1> 	db	126,-1,'|ZXCVBNM<>?',-1,'*',-1,' ',-1
 33600 0000B7B9 4D3C3E3FFF2AFF20FF  <1>
 33601                              <1> ;-----	UC TABLE SCAN
 33602 0000B7C2 5455565758          <1> K12:	db	84,85,86,87,88		; SHIFTED STATE OF F1 - F10
 33603 0000B7C7 595A5B5C5D          <1> 	db	89,90,91,92,93
 33604 0000B7CC FFFF                <1> 	db	-1,-1			; NL, SL
 33605                              <1> 
 33606                              <1> ;-----	NUM STATE TABLE
 33607 0000B7CE 3738392D3435362B31- <1> K14:	db 	'789-456+1230.'		; NUMLOCK STATE OF KEYPAD KEYS
 33608 0000B7D7 3233302E            <1>
 33609                              <1> 	;
 33610 0000B7DB FFFF7C8788          <1> 	db	-1,-1,124,135,136	; SysRq, Undef, WT, F11, F12
 33611                              <1> 
 33612                              <1> ; 26/08/2014
 33613                              <1> ; Retro UNIX 8086 v1 - UNIX.ASM (03/03/2014)
 33614                              <1> ; Derived from IBM "pc-at" 
 33615                              <1> ; rombios source code (06/10/1985)
 33616                              <1> ; 'dseg.inc'
 33617                              <1> 
 33618                              <1> ;---------------------------------------;
 33619                              <1> ;	SYSTEM DATA AREA		;
 33620                              <1> ;----------------------------------------
 33621 0000B7E0 00                  <1> BIOS_BREAK	db	0		; BIT 7=1 IF BREAK KEY HAS BEEN PRESSED
 33622                              <1> 
 33623                              <1> ;----------------------------------------
 33624                              <1> ;	KEYBOARD DATA AREAS		;
 33625                              <1> ;----------------------------------------
 33626                              <1> 
 33627 0000B7E1 00                  <1> KB_FLAG		db	0		; KEYBOARD SHIFT STATE AND STATUS FLAGS
 33628 0000B7E2 00                  <1> KB_FLAG_1	db	0		; SECOND BYTE OF KEYBOARD STATUS
 33629 0000B7E3 00                  <1> KB_FLAG_2	db	0		; KEYBOARD LED FLAGS
 33630 0000B7E4 00                  <1> KB_FLAG_3	db	0		; KEYBOARD MODE STATE AND TYPE FLAGS
 33631 0000B7E5 00                  <1> ALT_INPUT	db	0		; STORAGE FOR ALTERNATE KEY PAD ENTRY
 33632 0000B7E6 [F6B70000]          <1> BUFFER_START	dd	KB_BUFFER 	; OFFSET OF KEYBOARD BUFFER START
 33633 0000B7EA [16B80000]          <1> BUFFER_END	dd	KB_BUFFER + 32	; OFFSET OF END OF BUFFER
 33634 0000B7EE [F6B70000]          <1> BUFFER_HEAD	dd	KB_BUFFER 	; POINTER TO HEAD OF KEYBOARD BUFFER
 33635 0000B7F2 [F6B70000]          <1> BUFFER_TAIL	dd	KB_BUFFER 	; POINTER TO TAIL OF KEYBOARD BUFFER
 33636                              <1> ; ------	HEAD = TAIL	INDICATES THAT THE BUFFER IS EMPTY
 33637 0000B7F6 0000<rept>          <1> KB_BUFFER	times	16 dw 0		; ROOM FOR 16 SCAN CODE ENTRIES
 33638                              <1> 
 33639                              <1> ; /// End Of KEYBOARD DATA ///
 33640                                  %include 'vidata.s'	; VIDEO (BIOS) DATA
 33641                              <1> ; ****************************************************************************
 33642                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - vidata.s
 33643                              <1> ; ----------------------------------------------------------------------------
 33644                              <1> ; Last Update: 30/01/2016
 33645                              <1> ; ----------------------------------------------------------------------------
 33646                              <1> ; Beginning: 16/01/2016
 33647                              <1> ; ----------------------------------------------------------------------------
 33648                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 33649                              <1> ; ----------------------------------------------------------------------------
 33650                              <1> ; Turkish Rational DOS
 33651                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 33652                              <1> ;
 33653                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 33654                              <1> ; vidata.inc (11/03/2015)
 33655                              <1> ;
 33656                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
 33657                              <1> ; ****************************************************************************
 33658                              <1> 
 33659                              <1> ; Retro UNIX 386 v1 Kernel - VIDATA.S
 33660                              <1> ; Last Modification: 11/03/2015
 33661                              <1> ;		    (Data section for 'VIDEO.INC')	
 33662                              <1> ;
 33663                              <1> ; ///////// VIDEO DATA ///////////////
 33664                              <1> 
 33665                              <1> ;-----	COLUMNS
 33666                              <1> ;M6:
 33667                              <1> ;	db	40, 40, 80, 80, 40, 40, 80, 80
 33668                              <1> 
 33669                              <1> ;-----	C_REG_TAB
 33670                              <1> ;M7:
 33671                              <1> ;	db	2Ch, 28h, 2Dh, 29h, 2Ah, 2Eh, 1Eh, 29h	; TABLE OF MODE SETS
 33672                              <1> 
 33673                              <1> ;----------------------------------------
 33674                              <1> ;	VIDEO DISPLAY DATA AREA		;
 33675                              <1> ;----------------------------------------
 33676 0000B816 03                  <1> CRT_MODE	db	3	; CURRENT DISPLAY MODE (TYPE)
 33677 0000B817 29                  <1> CRT_MODE_SET	db	29h	; CURRENT SETTING OF THE 3X8 REGISTER
 33678                              <1> 				; (29h default setting for video mode 3)
 33679                              <1> 				; Mode Select register Bits
 33680                              <1> 				;   BIT 0 - 80x25 (1), 40x25 (0)
 33681                              <1> 				;   BIT 1 - ALPHA (0), 320x200 GRAPHICS (1)
 33682                              <1> 				;   BIT 2 - COLOR (0), BW (1)
 33683                              <1> 				;   BIT 3 - Video Sig. ENABLE (1), DISABLE (0)
 33684                              <1> 				;   BIT 4 - 640x200 B&W Graphics Mode (1)
 33685                              <1> 				;   BIT 5 - ALPHA mode BLINKING (1)
 33686                              <1> 				;   BIT 6, 7 - Not Used
 33687                              <1> 
 33688                              <1> ; Mode 0 - 2Ch = 101100b	; 40x25 text, 16 gray colors
 33689                              <1> ; Mode 1 - 28h = 101000b	; 40x25 text, 16 fore colors, 8 back colors
 33690                              <1> ; Mode 2 - 2Dh = 101101b	; 80x25 text, 16 gray colors	
 33691                              <1> ; MODE 3 - 29h = 101001b	; 80x25 text, 16 fore color, 8 back color
 33692                              <1> ; Mode 4 - 2Ah = 101010b	; 320x200 graphics, 4 colors
 33693                              <1> ; Mode 5 - 2Eh = 101110b	; 320x200 graphics, 4 gray colors
 33694                              <1> ; Mode 6 - 1Eh = 011110b	; 640x200 graphics, 2 colors
 33695                              <1> ; Mode 7 - 29h = 101001b	; 80x25 text, black & white colors
 33696                              <1> ; Mode & 37h = Video signal OFF
 33697                              <1> 			
 33698                              <1> video_params:
 33699                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
 33700                              <1> 	;ORGS.ASM ----- 06/10/85   COMPATIBILITY MODULE
 33701                              <1> 	; VIDEO MODE 3
 33702 0000B818 71505A0A1F0619      <1> 	db	71h,50h,5Ah,0Ah,1Fh,6,19h	; SET UP FOR 80X25
 33703 0000B81F 1C02070607          <1> 	db	1Ch,2,7,6,7	; cursor start = 6, cursor stop = 7
 33704 0000B824 00000000            <1> 	db	0,0,0,0
 33705                              <1> 
 33706                              <1> ; 16/01/2016
 33707                              <1> chr_attrib:  ; Character color/attributes for viode pages (0 to 7)
 33708 0000B828 0707070707070707    <1> 	db	07h, 07h, 07h, 07h, 07h, 07h, 07h, 07h
 33709                              <1> ; 30/01/2016
 33710                              <1> vmode:
 33711 0000B830 0303030303030303    <1> 	db	3,3,3,3,3,3,3,3 ; video modes for pseudo screens 
 33712                              <1> 
 33713                              <1> ; /// End Of VIDEO DATA ///
 33714                                  %include 'diskdata.s'	; DISK (BIOS) DATA (initialized)
 33715                              <1> ; ****************************************************************************
 33716                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskdata.s
 33717                              <1> ; ----------------------------------------------------------------------------
 33718                              <1> ; Last Update: 24/01/2016
 33719                              <1> ; ----------------------------------------------------------------------------
 33720                              <1> ; Beginning: 24/01/2016
 33721                              <1> ; ----------------------------------------------------------------------------
 33722                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 33723                              <1> ; ----------------------------------------------------------------------------
 33724                              <1> ; Turkish Rational DOS
 33725                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 33726                              <1> ;
 33727                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 33728                              <1> ; diskdata.inc (11/03/2015)
 33729                              <1> ;
 33730                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 33731                              <1> ; ****************************************************************************
 33732                              <1> 
 33733                              <1> ; Retro UNIX 386 v1 Kernel - DISKDATA.INC
 33734                              <1> ; Last Modification: 11/03/2015
 33735                              <1> ;	(Initialized Disk Parameters Data section for 'DISKIO.INC') 
 33736                              <1> ;
 33737                              <1> 
 33738                              <1> ;----------------------------------------
 33739                              <1> ;	80286 INTERRUPT LOCATIONS	:
 33740                              <1> ;	REFERENCED BY POST & BIOS	:
 33741                              <1> ;----------------------------------------
 33742                              <1> 
 33743 0000B838 [9BB80000]          <1> DISK_POINTER:	dd	MD_TBL6		; Pointer to Diskette Parameter Table
 33744                              <1> 
 33745                              <1> ; IBM PC-XT Model 286 source code ORGS.ASM (06/10/85) - 14/12/2014
 33746                              <1> ;----------------------------------------------------------------
 33747                              <1> ; DISK_BASE							:
 33748                              <1> ;	THIS IS THE SET OF PARAMETERS REQUIRED FOR		:
 33749                              <1> ;	DISKETTE OPERATION. THEY ARE POINTED AT BY THE		:
 33750                              <1> ;	DATA VARIABLE @DISK_POINTER. TO MODIFY THE PARAMETERS,	:
 33751                              <1> ;	BUILD ANOTHER PARAMETER BLOCK AND POINT AT IT		:
 33752                              <1> ;----------------------------------------------------------------
 33753                              <1> 
 33754                              <1> ;DISK_BASE:	
 33755                              <1> ;	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 33756                              <1> ;	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 33757                              <1> ;	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 33758                              <1> ;	DB	2		; 512 BYTES/SECTOR
 33759                              <1> ;	;DB	15		; EOT (LAST SECTOR ON TRACK)
 33760                              <1> ;	db	18		; (EOT for 1.44MB diskette)
 33761                              <1> ;	DB	01BH		; GAP LENGTH
 33762                              <1> ;	DB	0FFH		; DTL
 33763                              <1> ;	;DB	054H		; GAP LENGTH FOR FORMAT
 33764                              <1> ;	db	06ch		; (for 1.44MB dsikette)
 33765                              <1> ;	DB	0F6H		; FILL BYTE FOR FORMAT
 33766                              <1> ;	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 33767                              <1> ;	DB	8		; MOTOR START TIME (1/8 SECONDS)
 33768                              <1> 
 33769                              <1> ;----------------------------------------
 33770                              <1> ;	ROM BIOS DATA AREAS		:
 33771                              <1> ;----------------------------------------
 33772                              <1> 
 33773                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
 33774                              <1> 
 33775                              <1> ;@EQUIP_FLAG	DW	?		; INSTALLED HARDWARE FLAGS
 33776                              <1> 
 33777                              <1> ;----------------------------------------
 33778                              <1> ;	DISKETTE DATA AREAS		:
 33779                              <1> ;----------------------------------------
 33780                              <1> 
 33781                              <1> ;@SEEK_STATUS	DB	?		; DRIVE RECALIBRATION STATUS
 33782                              <1> ;					; BIT 3-0 = DRIVE 3-0 RECALIBRATION
 33783                              <1> ;					; BEFORE NEXT SEEK IF BIT IS = 0
 33784                              <1> ;@MOTOR_STATUS	DB	?		; MOTOR STATUS
 33785                              <1> ;					; BIT 3-0 = DRIVE 3-0 CURRENTLY RUNNING
 33786                              <1> ;					; BIT 7 = CURRENT OPERATION IS A WRITE
 33787                              <1> ;@MOTOR_COUNT	DB	?		; TIME OUT COUNTER FOR MOTOR(S) TURN OFF
 33788                              <1> ;@DSKETTE_STATUS DB	?		; RETURN CODE STATUS BYTE
 33789                              <1> ;					; CMD_BLOCK  IN STACK FOR DISK OPERATION
 33790                              <1> ;@NEC_STATUS	DB	7 DUP(?)	; STATUS BYTES FROM DISKETTE OPERATION
 33791                              <1> 
 33792                              <1> ;----------------------------------------
 33793                              <1> ;	POST AND BIOS WORK DATA AREA	:
 33794                              <1> ;----------------------------------------
 33795                              <1> 
 33796                              <1> ;@INTR_FLAG	DB	?		; FLAG INDICATING AN INTERRUPT HAPPENED
 33797                              <1> 
 33798                              <1> ;----------------------------------------
 33799                              <1> ;	TIMER DATA AREA 		:
 33800                              <1> ;----------------------------------------
 33801                              <1> 
 33802                              <1> ; 17/12/2014  (IRQ 0 - INT 08H)
 33803                              <1> ;TIMER_LOW	equ	46Ch		; Timer ticks (counter)  @ 40h:006Ch
 33804                              <1> ;TIMER_HIGH	equ	46Eh		; (18.2 timer ticks per second)
 33805                              <1> ;TIMER_OFL	equ	470h		; Timer - 24 hours flag  @ 40h:0070h
 33806                              <1> 
 33807                              <1> ;----------------------------------------
 33808                              <1> ;	ADDITIONAL MEDIA DATA		:
 33809                              <1> ;----------------------------------------
 33810                              <1> 
 33811                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
 33812                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
 33813                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
 33814                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
 33815                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
 33816                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
 33817                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
 33818                              <1> 
 33819                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
 33820                              <1> 
 33821                              <1> ;--------------------------------------------------------
 33822                              <1> ;	DRIVE TYPE TABLE				:
 33823                              <1> ;--------------------------------------------------------
 33824                              <1> 		; 16/02/2015 (unix386.s, 32 bit modifications)
 33825                              <1> DR_TYPE:
 33826 0000B83C 01                  <1> 		DB	01		;DRIVE TYPE, MEDIA TABLE
 33827                              <1>                 ;DW      MD_TBL1
 33828 0000B83D [5AB80000]          <1> 		dd	MD_TBL1
 33829 0000B841 82                  <1> 		DB	02+BIT7ON
 33830                              <1> 		;DW      MD_TBL2
 33831 0000B842 [67B80000]          <1>                 dd      MD_TBL2
 33832 0000B846 02                  <1> DR_DEFAULT:	DB	02
 33833                              <1>                 ;DW      MD_TBL3
 33834 0000B847 [74B80000]          <1> 		dd      MD_TBL3
 33835 0000B84B 03                  <1> 		DB	03
 33836                              <1>                 ;DW      MD_TBL4
 33837 0000B84C [81B80000]          <1> 		dd      MD_TBL4
 33838 0000B850 84                  <1> 		DB	04+BIT7ON
 33839                              <1>                 ;DW      MD_TBL5
 33840 0000B851 [8EB80000]          <1> 		dd      MD_TBL5
 33841 0000B855 04                  <1> 		DB	04
 33842                              <1>                 ;DW      MD_TBL6
 33843 0000B856 [9BB80000]          <1> 		dd      MD_TBL6
 33844                              <1> DR_TYPE_E       equ $                   ; END OF TABLE
 33845                              <1> ;DR_CNT		EQU	(DR_TYPE_E-DR_TYPE)/3
 33846                              <1> DR_CNT		equ	(DR_TYPE_E-DR_TYPE)/5
 33847                              <1> ;--------------------------------------------------------
 33848                              <1> ;	MEDIA/DRIVE PARAMETER TABLES			:
 33849                              <1> ;--------------------------------------------------------
 33850                              <1> ;--------------------------------------------------------
 33851                              <1> ;	360 KB MEDIA IN 360 KB DRIVE			:
 33852                              <1> ;--------------------------------------------------------
 33853                              <1> MD_TBL1:        
 33854 0000B85A DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 33855 0000B85B 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 33856 0000B85C 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 33857 0000B85D 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 33858 0000B85E 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 33859 0000B85F 2A                  <1> 	DB	02AH		; GAP LENGTH
 33860 0000B860 FF                  <1> 	DB	0FFH		; DTL
 33861 0000B861 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 33862 0000B862 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 33863 0000B863 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 33864 0000B864 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 33865 0000B865 27                  <1> 	DB	39		; MAX. TRACK NUMBER
 33866 0000B866 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 33867                              <1> ;--------------------------------------------------------
 33868                              <1> ;	360 KB MEDIA IN 1.2 MB DRIVE			:
 33869                              <1> ;--------------------------------------------------------
 33870                              <1> MD_TBL2:        
 33871 0000B867 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 33872 0000B868 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 33873 0000B869 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 33874 0000B86A 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 33875 0000B86B 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 33876 0000B86C 2A                  <1> 	DB	02AH		; GAP LENGTH
 33877 0000B86D FF                  <1> 	DB	0FFH		; DTL
 33878 0000B86E 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 33879 0000B86F F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 33880 0000B870 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 33881 0000B871 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 33882 0000B872 27                  <1> 	DB	39		; MAX. TRACK NUMBER
 33883 0000B873 40                  <1> 	DB	RATE_300	; DATA TRANSFER RATE
 33884                              <1> ;--------------------------------------------------------
 33885                              <1> ;	1.2 MB MEDIA IN 1.2 MB DRIVE			:
 33886                              <1> ;--------------------------------------------------------
 33887                              <1> MD_TBL3:
 33888 0000B874 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 33889 0000B875 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 33890 0000B876 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 33891 0000B877 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 33892 0000B878 0F                  <1> 	DB	15		; EOT (LAST SECTOR ON TRACK)
 33893 0000B879 1B                  <1> 	DB	01BH		; GAP LENGTH
 33894 0000B87A FF                  <1> 	DB	0FFH		; DTL
 33895 0000B87B 54                  <1> 	DB	054H		; GAP LENGTH FOR FORMAT
 33896 0000B87C F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 33897 0000B87D 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 33898 0000B87E 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 33899 0000B87F 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 33900 0000B880 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
 33901                              <1> ;--------------------------------------------------------
 33902                              <1> ;	720 KB MEDIA IN 720 KB DRIVE			:
 33903                              <1> ;--------------------------------------------------------
 33904                              <1> MD_TBL4:
 33905 0000B881 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 33906 0000B882 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 33907 0000B883 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 33908 0000B884 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 33909 0000B885 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 33910 0000B886 2A                  <1> 	DB	02AH		; GAP LENGTH
 33911 0000B887 FF                  <1> 	DB	0FFH		; DTL
 33912 0000B888 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 33913 0000B889 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 33914 0000B88A 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 33915 0000B88B 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 33916 0000B88C 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 33917 0000B88D 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 33918                              <1> ;--------------------------------------------------------
 33919                              <1> ;	720 KB MEDIA IN 1.44 MB DRIVE			:
 33920                              <1> ;--------------------------------------------------------
 33921                              <1> MD_TBL5:
 33922 0000B88E DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 33923 0000B88F 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 33924 0000B890 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 33925 0000B891 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 33926 0000B892 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 33927 0000B893 2A                  <1> 	DB	02AH		; GAP LENGTH
 33928 0000B894 FF                  <1> 	DB	0FFH		; DTL
 33929 0000B895 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 33930 0000B896 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 33931 0000B897 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 33932 0000B898 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 33933 0000B899 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 33934 0000B89A 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 33935                              <1> ;--------------------------------------------------------
 33936                              <1> ;	1.44 MB MEDIA IN 1.44 MB DRIVE			:
 33937                              <1> ;--------------------------------------------------------
 33938                              <1> MD_TBL6:
 33939 0000B89B AF                  <1> 	DB	10101111B	; SRT=A, HD UNLOAD=0F - 1ST SPECIFY BYTE
 33940 0000B89C 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 33941 0000B89D 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 33942 0000B89E 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 33943 0000B89F 12                  <1> 	DB	18		; EOT (LAST SECTOR ON TRACK)
 33944 0000B8A0 1B                  <1> 	DB	01BH		; GAP LENGTH
 33945 0000B8A1 FF                  <1> 	DB	0FFH		; DTL
 33946 0000B8A2 6C                  <1> 	DB	06CH		; GAP LENGTH FOR FORMAT
 33947 0000B8A3 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 33948 0000B8A4 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 33949 0000B8A5 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 33950 0000B8A6 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 33951 0000B8A7 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
 33952                              <1> 
 33953                              <1> 
 33954                              <1> ; << diskette.inc >>
 33955                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 33956                              <1> ;
 33957                              <1> ;----------------------------------------
 33958                              <1> ;	ROM BIOS DATA AREAS		:
 33959                              <1> ;----------------------------------------
 33960                              <1> 
 33961                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
 33962                              <1> 
 33963                              <1> ;----------------------------------------
 33964                              <1> ;	FIXED DISK DATA AREAS		:
 33965                              <1> ;----------------------------------------
 33966                              <1> 
 33967                              <1> ;DISK_STATUS1:	DB	0		; FIXED DISK STATUS
 33968                              <1> ;HF_NUM:		DB	0		; COUNT OF FIXED DISK DRIVES
 33969                              <1> ;CONTROL_BYTE:	DB	0		; HEAD CONTROL BYTE
 33970                              <1> ;@PORT_OFF	DB	?		;  RESERVED (PORT OFFSET)
 33971                              <1> 
 33972                              <1> ;----------------------------------------
 33973                              <1> ;	ADDITIONAL MEDIA DATA		:
 33974                              <1> ;----------------------------------------
 33975                              <1> 
 33976                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
 33977                              <1> ;HF_STATUS	DB	0		; STATUS REGISTER
 33978                              <1> ;HF_ERROR	DB	0		; ERROR REGISTER
 33979                              <1> ;HF_INT_FLAG	DB	0		; FIXED DISK INTERRUPT FLAG
 33980                              <1> ;HF_CNTRL	DB	0		; COMBO FIXED DISK/DISKETTE CARD BIT 0=1
 33981                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
 33982                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
 33983                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
 33984                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
 33985                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
 33986                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
 33987                              <1> 
 33988                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
 33989                              <1> ;
 33990                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 33991                              <1> 
 33992                              <1> ERR_TBL:
 33993 0000B8A8 E0                  <1> 	db	NO_ERR
 33994 0000B8A9 024001BB            <1> 	db	BAD_ADDR_MARK,BAD_SEEK,BAD_CMD,UNDEF_ERR
 33995 0000B8AD 04BB100A            <1> 	db	RECORD_NOT_FND,UNDEF_ERR,BAD_ECC,BAD_SECTOR
 33996                              <1> 
 33997                              <1> ; 17/12/2014 (mov ax, [cfd])
 33998                              <1> ; 11/12/2014
 33999 0000B8B1 00                  <1> cfd:		db 0			; current floppy drive (for GET_PARM)
 34000                              <1> ; 17/12/2014				; instead of 'DISK_POINTER'
 34001 0000B8B2 01                  <1> pfd:		db 1			; previous floppy drive (for GET_PARM)
 34002                              <1> 					; (initial value of 'pfd 
 34003                              <1> 					; must be different then 'cfd' value
 34004                              <1> 					; to force updating/initializing
 34005                              <1> 					; current drive parameters) 
 34006 0000B8B3 90                  <1> align 2
 34007                              <1> 
 34008 0000B8B4 F001                <1> HF_PORT:	dw 	1F0h  ; Default = 1F0h
 34009                              <1> 			      ; (170h)
 34010 0000B8B6 F603                <1> HF_REG_PORT:	dw	3F6h  ; HF_PORT + 206h
 34011                              <1> 
 34012                              <1> ; 05/01/2015 
 34013 0000B8B8 00                  <1> hf_m_s:         db      0     ; (0 = Master, 1 = Slave)
 34014                              <1> 
 34015                              <1> ; *****************************************************************************
 34016                                  ;;;
 34017                                  
 34018 0000B8B9 90                      Align 2
 34019                                  
 34020                                  ; 12/11/2014 (Retro UNIX 386 v1)
 34021 0000B8BA 00                      boot_drv:    db 0 ; boot drive number (physical)
 34022                                  ; 24/11/2014
 34023 0000B8BB 00                      drv:	     db 0 
 34024 0000B8BC 00                      last_drv:    db 0 ; last hdd
 34025 0000B8BD 00                      hdc:         db 0  ; number of hard disk drives
 34026                                  		     ; (present/detected)
 34027                                  ;
 34028                                  ; 24/11/2014 (Retro UNIX 386 v1)
 34029                                  ; Physical drive type & flags
 34030 0000B8BE 00                      fd0_type:    db 0  ; floppy drive type
 34031 0000B8BF 00                      fd1_type:    db 0  ; 4 = 1.44 Mb, 80 track, 3.5" (18 spt)
 34032                                  		     ; 6 = 2.88 Mb, 80 track, 3.5" (36 spt)
 34033                                  		     ; 3 = 720 Kb, 80 track, 3.5" (9 spt)
 34034                                  		     ; 2 = 1.2 Mb, 80 track, 5.25" (15 spt)
 34035                                  		     ; 1 = 360 Kb, 40 track, 5.25" (9 spt)		
 34036 0000B8C0 00                      hd0_type:    db 0  ; EDD status for hd0 (bit 7 = present flag)
 34037 0000B8C1 00                      hd1_type:    db 0  ; EDD status for hd1 (bit 7 = present flag)
 34038 0000B8C2 00                      hd2_type:    db 0  ; EDD status for hd2 (bit 7 = present flag)
 34039 0000B8C3 00                      hd3_type:    db 0  ; EDD status for hd3 (bit 7 = present flag)
 34040                                  		     ; bit 0 - Fixed disk access subset supported
 34041                                  		     ; bit 1 - Drive locking and ejecting
 34042                                  		     ; bit 2 - Enhanced disk drive support
 34043                                  		     ; bit 3 = Reserved (64 bit EDD support)
 34044                                  		     ; (If bit 0 is '1' Retro UNIX 386 v1
 34045                                  		     ; will interpret it as 'LBA ready'!)		
 34046                                  
 34047                                  ; 11/03/2015 - 10/07/2015
 34048 0000B8C4 000000000000000000-     drv.cylinders: dw 0,0,0,0,0,0,0
 34049 0000B8CD 0000000000         
 34050 0000B8D2 000000000000000000-     drv.heads:     dw 0,0,0,0,0,0,0
 34051 0000B8DB 0000000000         
 34052 0000B8E0 000000000000000000-     drv.spt:       dw 0,0,0,0,0,0,0
 34053 0000B8E9 0000000000         
 34054 0000B8EE 000000000000000000-     drv.size:      dd 0,0,0,0,0,0,0
 34055 0000B8F7 000000000000000000-
 34056 0000B900 000000000000000000-
 34057 0000B909 00                 
 34058 0000B90A 00000000000000          drv.status:    db 0,0,0,0,0,0,0
 34059 0000B911 00000000000000          drv.error:     db 0,0,0,0,0,0,0		
 34060                                  ;
 34061                                  
 34062                                  ; 27/08/2014
 34063                                  scr_row:
 34064 0000B918 E0810B00                	dd 0B8000h + 0A0h + 0A0h + 0A0h ; Row 3
 34065                                  scr_col:
 34066 0000B91C 00000000                	dd 0
 34067                                  
 34068                                  ; 20/08/2014
 34069                                    ; /* This is the default interrupt "handler" :-) */ 
 34070                                    ; Linux v0.12 (head.s)
 34071                                  int_msg:
 34072 0000B920 556E6B6E6F776E2069-     	db "Unknown interrupt ! ", 0
 34073 0000B929 6E7465727275707420-
 34074 0000B932 212000             
 34075                                  
 34076                                  
 34077                                  ; 21/08/2014
 34078                                  timer_msg:
 34079 0000B935 49525120302028494E-     	db "IRQ 0 (INT 20h) ! Timer Interrupt : "
 34080 0000B93E 542032306829202120-
 34081 0000B947 54696D657220496E74-
 34082 0000B950 657272757074203A20 
 34083                                  tcountstr:
 34084 0000B959 303030303020            	db "00000 "
 34085 0000B95F 00                      	db 0
 34086                                  
 34087                                  Align 2
 34088                                  	; 21/08/2014
 34089                                  exc_msg:
 34090 0000B960 435055206578636570-     	db "CPU exception ! "
 34091 0000B969 74696F6E202120     
 34092                                  excnstr: 		; 25/08/2014
 34093 0000B970 3F3F68202045495020-     	db "??h", "  EIP : "
 34094 0000B979 3A20               
 34095                                  EIPstr: ; 29/08/2014
 34096 0000B97B 00<rept>                	times 12 db 0
 34097                                  rtc_msg:
 34098 0000B987 5265616C2054696D65-     	db "Real Time Clock - "
 34099 0000B990 20436C6F636B202D20 
 34100                                  datestr:
 34101 0000B999 30302F30302F303030-     	db "00/00/0000"
 34102 0000B9A2 30                 
 34103 0000B9A3 20                      	db " "
 34104                                  daystr:
 34105 0000B9A4 44415920                	db "DAY "
 34106                                  timestr:	
 34107 0000B9A8 30303A30303A3030                db "00:00:00"
 34108 0000B9B0 20                      	db " "
 34109 0000B9B1 00                      	db 0 
 34110                                  
 34111                                  daytmp:
 34112                                  	; 28/02/2015
 34113 0000B9B2 3F3F3F2053554E204D-     	db "??? SUN MON TUE WED THU FRI SAT "
 34114 0000B9BB 4F4E20545545205745-
 34115 0000B9C4 442054485520465249-
 34116 0000B9CD 2053415420         
 34117                                  
 34118 0000B9D2 FF                      ptime_seconds: db 0FFh
 34119                                  
 34120                                  	; 23/02/2015
 34121                                  	; 25/08/2014
 34122                                  ;scounter:
 34123                                  ;	db 5
 34124                                  ;	db 19
 34125                                  
 34126                                  ; 05/11/2014
 34127                                  msg_out_of_memory:
 34128 0000B9D3 070D0A                  	db 	07h, 0Dh, 0Ah
 34129 0000B9D6 496E73756666696369-             db      'Insufficient memory ! (Minimum 2 MB memory is needed.)'
 34130 0000B9DF 656E74206D656D6F72-
 34131 0000B9E8 79202120284D696E69-
 34132 0000B9F1 6D756D2032204D4220-
 34133 0000B9FA 6D656D6F7279206973-
 34134 0000BA03 206E65656465642E29 
 34135 0000BA0C 0D0A00                   	db	0Dh, 0Ah, 0
 34136                                  	;
 34137                                  setup_error_msg:
 34138 0000BA0F 0D0A                    	db 0Dh, 0Ah
 34139 0000BA11 4469736B2053657475-     	db 'Disk Setup Error!' 
 34140 0000BA1A 70204572726F7221   
 34141 0000BA22 0D0A00                  	db 0Dh, 0Ah,0
 34142                                  
 34143                                  ; 06/11/2014
 34144                                  ; Memory Information message
 34145                                  ; 14/08/2015
 34146                                  msg_memory_info:
 34147 0000BA25 07                      	db	07h
 34148 0000BA26 0D0A                    	db	0Dh, 0Ah
 34149                                  	;db 	"MEMORY ALLOCATION INFO", 0Dh, 0Ah, 0Dh, 0Ah
 34150 0000BA28 546F74616C206D656D-     	db	"Total memory : "
 34151 0000BA31 6F7279203A20       
 34152                                  mem_total_b_str: ; 10 digits
 34153 0000BA37 303030303030303030-     	db	"0000000000 bytes", 0Dh, 0Ah
 34154 0000BA40 302062797465730D0A 
 34155 0000BA49 202020202020202020-     	db	"               ", 20h, 20h, 20h
 34156 0000BA52 202020202020202020 
 34157                                  mem_total_p_str: ; 7 digits
 34158 0000BA5B 303030303030302070-     	db	"0000000 pages", 0Dh, 0Ah
 34159 0000BA64 616765730D0A       
 34160 0000BA6A 0D0A                    	db 	0Dh, 0Ah
 34161 0000BA6C 46726565206D656D6F-     	db	"Free memory  : "
 34162 0000BA75 727920203A20       
 34163                                  free_mem_b_str:  ; 10 digits
 34164 0000BA7B 3F3F3F3F3F3F3F3F3F-     	db	"?????????? bytes", 0Dh, 0Ah
 34165 0000BA84 3F2062797465730D0A 
 34166 0000BA8D 202020202020202020-     	db	"               ", 20h, 20h, 20h
 34167 0000BA96 202020202020202020 
 34168                                  free_mem_p_str:  ; 7 digits
 34169 0000BA9F 3F3F3F3F3F3F3F2070-     	db	"??????? pages", 0Dh, 0Ah
 34170 0000BAA8 616765730D0A       
 34171 0000BAAE 0D0A00                  	db	0Dh, 0Ah, 0
 34172                                  
 34173                                  dsk_ready_msg:
 34174 0000BAB1 0D0A                    	db 	0Dh, 0Ah
 34175                                  dsktype:
 34176 0000BAB3 6664                    	db	'fd'
 34177                                  dskx:
 34178 0000BAB5 30                      	db	'0'
 34179 0000BAB6 20                      	db	20h
 34180 0000BAB7 697320524541445920-     	db 	'is READY ...'
 34181 0000BAC0 2E2E2E             
 34182 0000BAC3 00                      	db 	0
 34183                                  
 34184                                  next2line: ; 08/02/2016
 34185 0000BAC4 0D0A                    	db	0Dh, 0Ah
 34186                                  nextline:
 34187 0000BAC6 0D0A00                  	db 	0Dh, 0Ah, 0
 34188                                  
 34189                                  ; KERNEL - SYSINIT Messages
 34190                                  ; 24/08/2015
 34191                                  ; 13/04/2015 - (Retro UNIX 386 v1 Beginning)
 34192                                  ; 14/07/2013
 34193                                  ;kernel_init_err_msg:
 34194                                  ;	db 0Dh, 0Ah
 34195                                  ;	db 07h
 34196                                  ;	db 'Kernel initialization ERROR !'
 34197                                  ;	db 0Dh, 0Ah, 0 
 34198                                  
 34199                                  ;welcome_msg: 
 34200                                  ;	db 0Dh, 0Ah
 34201                                  ;	db 07h
 34202                                  ;	db 'Welcome to TRDOS 386 Operating System !'
 34203                                  ;	db 0Dh, 0Ah
 34204                                  ;	db 'by Erdogan Tan - 05/04/2016 (v2.0.0)'
 34205                                  ;	db 0Dh, 0Ah, 0
 34206                                  
 34207                                  panic_msg:
 34208 0000BAC9 0D0A07                  	db 0Dh, 0Ah, 07h
 34209 0000BACC 4552524F523A204B65-     	db 'ERROR: Kernel Panic !'
 34210 0000BAD5 726E656C2050616E69-
 34211 0000BADE 632021             
 34212 0000BAE1 0D0A00                  	db 0Dh, 0Ah, 0
 34213                                  
 34214                                  ; 10/05/2015
 34215                                  badsys_msg:
 34216 0000BAE4 0D0A                    	db 0Dh, 0Ah
 34217 0000BAE6 07                      	db 07h
 34218 0000BAE7 496E76616C69642053-     	db 'Invalid System Call !'
 34219 0000BAF0 797374656D2043616C-
 34220 0000BAF9 6C2021             
 34221 0000BAFC 0D0A                    	db 0Dh, 0Ah
 34222 0000BAFE 4541583A20              	db 'EAX: '
 34223                                  bsys_msg_eax:
 34224 0000BB03 303030303030303068      	db '00000000h'
 34225 0000BB0C 0D0A                    	db 0Dh, 0Ah
 34226 0000BB0E 4549503A20              	db 'EIP: '
 34227                                  bsys_msg_eip:
 34228 0000BB13 303030303030303068      	db '00000000h' 
 34229 0000BB1C 0D0A00                  	db 0Dh, 0Ah, 0
 34230                                  
 34231                                  BSYS_M_SIZE equ $ - badsys_msg
 34232                                  
 34233                                  
 34234 0000BB1F 90                      align 2
 34235                                  
 34236                                  ; EPOCH Variables
 34237                                  ; 13/04/2015 - Retro UNIX 386 v1 Beginning
 34238                                  ; 09/04/2013 epoch variables
 34239                                  ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013
 34240                                  ;
 34241 0000BB20 B207                    year: 	dw 1970
 34242 0000BB22 0100                    month: 	dw 1
 34243 0000BB24 0100                    day: 	dw 1
 34244 0000BB26 0000                    hour: 	dw 0
 34245 0000BB28 0000                    minute: dw 0
 34246 0000BB2A 0000                    second: dw 0
 34247                                  
 34248                                  DMonth:
 34249 0000BB2C 0000                    	dw 0
 34250 0000BB2E 1F00                    	dw 31
 34251 0000BB30 3B00                    	dw 59
 34252 0000BB32 5A00                    	dw 90
 34253 0000BB34 7800                    	dw 120
 34254 0000BB36 9700                    	dw 151
 34255 0000BB38 B500                    	dw 181
 34256 0000BB3A D400                    	dw 212
 34257 0000BB3C F300                    	dw 243
 34258 0000BB3E 1101                    	dw 273
 34259 0000BB40 3001                    	dw 304
 34260 0000BB42 4E01                    	dw 334
 34261                                  
 34262                                  ; 04/11/2014 (Retro UNIX 386 v1)
 34263 0000BB44 0000                    mem_1m_1k:   dw 0  ; Number of contiguous KB between
 34264                                                       ; 1 and 16 MB, max. 3C00h = 15 MB.
 34265 0000BB46 0000                    mem_16m_64k: dw 0  ; Number of contiguous 64 KB blocks
 34266                                  		   ;   between 16 MB and 4 GB.
 34267                                  
 34268                                  starting_msg:
 34269 0000BB48 5475726B6973682052-     	db "Turkish Rational DOS v2.0 [05/04/2016] ...", 0
 34270 0000BB51 6174696F6E616C2044-
 34271 0000BB5A 4F532076322E30205B-
 34272 0000BB63 30352F30342F323031-
 34273 0000BB6C 365D202E2E2E00     
 34274                                  NextLine:
 34275 0000BB73 0D0A00                  	db 0Dh, 0Ah, 0
 34276                                  
 34277                                  ;msgl_drv_not_ready: 
 34278                                  ;	db 07h, 0Dh, 0Ah
 34279                                  ;       db 'Drive not ready or read error !'
 34280                                  ;       db 0Dh, 0Ah, 0
 34281                                  
 34282 0000BB76 90<rept>                align 16
 34283                                  
 34284                                  bss_start:
 34285                                  
 34286                                  ABSOLUTE bss_start
 34287                                  
 34288                                  	; 11/03/2015
 34289                                  	; Interrupt Descriptor Table (20/08/2014)
 34290                                  idt:
 34291 0000BB80 <res 00000200>          	resb	64*8 ; INT 0 to INT 3Fh
 34292                                  idt_end:
 34293                                  
 34294                                  ;alignb 4
 34295                                  
 34296                                  task_state_segment:
 34297                                  	; 24/03/2015
 34298 0000BD80 <res 00000002>          tss.link:   resw 1
 34299 0000BD82 <res 00000002>          	    resw 1
 34300                                  ; tss offset 4	
 34301 0000BD84 <res 00000004>          tss.esp0:   resd 1
 34302 0000BD88 <res 00000002>          tss.ss0:    resw 1
 34303 0000BD8A <res 00000002>          	    resw 1	
 34304 0000BD8C <res 00000004>          tss.esp1:   resd 1
 34305 0000BD90 <res 00000002>          tss.ss1:    resw 1
 34306 0000BD92 <res 00000002>          	    resw 1 	
 34307 0000BD94 <res 00000004>          tss.esp2:   resd 1
 34308 0000BD98 <res 00000002>          tss.ss2:    resw 1
 34309 0000BD9A <res 00000002>          	    resw 1
 34310                                  ; tss offset 28
 34311 0000BD9C <res 00000004>          tss.CR3:    resd 1
 34312 0000BDA0 <res 00000004>          tss.eip:    resd 1
 34313 0000BDA4 <res 00000004>          tss.eflags: resd 1
 34314                                  ; tss offset 40
 34315 0000BDA8 <res 00000004>          tss.eax:    resd 1		 		
 34316 0000BDAC <res 00000004>          tss.ecx:    resd 1
 34317 0000BDB0 <res 00000004>          tss.edx:    resd 1
 34318 0000BDB4 <res 00000004>          tss.ebx:    resd 1
 34319 0000BDB8 <res 00000004>          tss.esp:    resd 1
 34320 0000BDBC <res 00000004>          tss.ebp:    resd 1
 34321 0000BDC0 <res 00000004>          tss.esi:    resd 1
 34322 0000BDC4 <res 00000004>          tss.edi:    resd 1
 34323                                  ; tss offset 72
 34324 0000BDC8 <res 00000002>          tss.ES:     resw 1
 34325 0000BDCA <res 00000002>          	    resw 1	
 34326 0000BDCC <res 00000002>          tss.CS:	    resw 1
 34327 0000BDCE <res 00000002>          	    resw 1
 34328 0000BDD0 <res 00000002>          tss.SS:	    resw 1
 34329 0000BDD2 <res 00000002>          	    resw 1
 34330 0000BDD4 <res 00000002>          tss.DS:	    resw 1
 34331 0000BDD6 <res 00000002>          	    resw 1
 34332 0000BDD8 <res 00000002>          tss.FS:	    resw 1
 34333 0000BDDA <res 00000002>          	    resw 1
 34334 0000BDDC <res 00000002>          tss.GS:	    resw 1
 34335 0000BDDE <res 00000002>          	    resw 1		
 34336 0000BDE0 <res 00000002>          tss.LDTR:   resw 1
 34337 0000BDE2 <res 00000002>          	    resw 1
 34338                                  ; tss offset 100		
 34339 0000BDE4 <res 00000002>          	    resw 1		
 34340 0000BDE6 <res 00000002>          tss.IOPB:   resw 1
 34341                                  ; tss offset 104 
 34342                                  tss_end:
 34343                                  
 34344 0000BDE8 <res 00000004>          k_page_dir:  resd 1 ; Kernel's (System) Page Directory address
 34345                                  		    ; (Physical address = Virtual address)	 	
 34346 0000BDEC <res 00000004>          memory_size: resd 1 ; memory size in pages
 34347 0000BDF0 <res 00000004>          free_pages:  resd 1 ; number of free pages		
 34348 0000BDF4 <res 00000004>          next_page:   resd 1 ; offset value in M.A.T. for
 34349                                  		    ; first free page search
 34350 0000BDF8 <res 00000004>          last_page:   resd 1 ; offset value in M.A.T. which
 34351                                  		    ; next free page search will be
 34352                                  		    ; stopped after it. (end of M.A.T.)
 34353 0000BDFC <res 00000004>          first_page:  resd 1 ; offset value in M.A.T. which
 34354                                  		    ; first free page search
 34355                                  		    ; will be started on it. (for user)
 34356 0000BE00 <res 00000004>          mat_size:    resd 1 ; Memory Allocation Table size in pages		
 34357                                  
 34358                                  ; 02/09/2014 (Retro UNIX 386 v1)
 34359                                  ; 04/12/2013 (Retro UNIX 8086 v1)
 34360 0000BE04 <res 00000002>          CRT_START:   resw 1 	  ; starting address in regen buffer
 34361                                  			  ; NOTE: active page only	
 34362 0000BE06 <res 00000002>          CURSOR_MODE: resw 1 ; 24/01/2016
 34363 0000BE08 <res 00000010>          CURSOR_POSN: resw 8 ; cursor positions for video pages
 34364                                  ACTIVE_PAGE: 
 34365 0000BE18 <res 00000001>          ptty: 	     resb 1 ; current tty
 34366                                  ; 01/07/2015 - 29/01/2016
 34367 0000BE19 <res 00000001>          ccolor:	     resb 1 ; current color attribute
 34368                                  ; 26/10/2015
 34369                                  ; 07/09/2014
 34370 0000BE1A <res 00000014>          ttychr:      resw ntty+2 ; Character buffer (multiscreen)
 34371                                  
 34372                                  ; 21/08/2014
 34373 0000BE2E <res 00000004>          tcount:	     resd 1
 34374                                  
 34375                                  ; 18/05/2015 (03/06/2013 - Retro UNIX 8086 v1 feature only!)
 34376 0000BE32 <res 00000004>          p_time:      resd 1     ; present time (for systime & sysmdate)
 34377                                  
 34378                                  ; 18/05/2015 (16/08/2013 - Retro UNIX 8086 v1 feature only !)
 34379                                  ; (open mode locks for pseudo TTYs)
 34380                                  ; [ major tty locks (return error in any conflicts) ]
 34381 0000BE36 <res 00000014>          ttyl:        resw ntty+2 ; opening locks for TTYs.
 34382                                  
 34383                                  ; 15/04/2015 (Retro UNIX 386 v1)
 34384                                  ; 22/09/2013 (Retro UNIX 8086 v1)
 34385 0000BE4A <res 0000000A>          wlist:       resb ntty+2 ; wait channel list (0 to 9 for TTYs)
 34386                                  ; 15/04/2015 (Retro UNIX 386 v1)
 34387                                  ;; 12/07/2014 -> sp_init set comm. parameters as 0E3h
 34388                                  ;; 0 means serial port is not available 
 34389                                  ;;comprm: ; 25/06/2014
 34390 0000BE54 <res 00000001>          com1p:       resb 1  ;;0E3h
 34391 0000BE55 <res 00000001>          com2p:       resb 1  ;;0E3h
 34392                                  
 34393                                  ; 17/11/2015
 34394                                  ; request for response (from the terminal)	
 34395 0000BE56 <res 00000002>          req_resp:    resw 1 			
 34396                                  ; 07/11/2015
 34397 0000BE58 <res 00000001>          ccomport:    resb 1 ; current COM (serial) port
 34398                                  		    ; (0= COM1, 1= COM2)
 34399                                  ; 09/11/2015
 34400 0000BE59 <res 00000001>          comqr:	     resb 1 ; 'query or response' sign (u9.s, 'sndc')
 34401                                  ; 07/11/2015
 34402 0000BE5A <res 00000002>          rchar:	     resw 1 ; last received char for COM 1 and COM 2		
 34403 0000BE5C <res 00000002>          schar:	     resw 1 ; last sent char for COM 1 and COM 2
 34404                                  
 34405                                  ; 22/08/2014 (RTC)
 34406                                  ; (Packed BCD)
 34407 0000BE5E <res 00000001>          time_seconds: resb 1
 34408 0000BE5F <res 00000001>          time_minutes: resb 1
 34409 0000BE60 <res 00000001>          time_hours:   resb 1
 34410 0000BE61 <res 00000001>          date_wday:    resb 1
 34411 0000BE62 <res 00000001>          date_day:     resb 1
 34412 0000BE63 <res 00000001>          date_month:   resb 1			
 34413 0000BE64 <res 00000001>          date_year:    resb 1
 34414 0000BE65 <res 00000001>          date_century: resb 1
 34415                                  
 34416                                  ; 24/01/2016
 34417 0000BE66 <res 00000004>          RTC_LH:	       resd 1
 34418 0000BE6A <res 00000001>          RTC_WAIT_FLAG: resb 1
 34419 0000BE6B <res 00000001>          USER_FLAG:     resb 1
 34420                                  
 34421                                  
 34422                                  %include 'diskbss.s'	; UNINITIALIZED DISK (BIOS) DATA
 34423                              <1> ; ****************************************************************************
 34424                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskbss.s
 34425                              <1> ; ----------------------------------------------------------------------------
 34426                              <1> ; Last Update: 24/01/2016
 34427                              <1> ; ----------------------------------------------------------------------------
 34428                              <1> ; Beginning: 24/01/2016
 34429                              <1> ; ----------------------------------------------------------------------------
 34430                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 34431                              <1> ; ----------------------------------------------------------------------------
 34432                              <1> ; Turkish Rational DOS
 34433                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 34434                              <1> ;
 34435                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 34436                              <1> ; diskbss.inc (10/07/2015)
 34437                              <1> ;
 34438                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 34439                              <1> ; ****************************************************************************
 34440                              <1> 
 34441                              <1> ; Retro UNIX 386 v1 Kernel - DISKBSS.INC
 34442                              <1> ; Last Modification: 10/07/2015
 34443                              <1> ;	(Unnitialized Disk Parameters Data section for 'DISKIO.INC') 
 34444                              <1> 
 34445                              <1> alignb 2
 34446                              <1> 
 34447                              <1> ;----------------------------------------
 34448                              <1> ;	TIMER DATA AREA 		:
 34449                              <1> ;----------------------------------------
 34450                              <1> 
 34451                              <1> TIMER_LH:	; 16/02/205
 34452 0000BE6C <res 00000002>      <1> TIMER_LOW:      resw	1               ; LOW WORD OF TIMER COUNT
 34453 0000BE6E <res 00000002>      <1> TIMER_HIGH:     resw	1               ; HIGH WORD OF TIMER COUNT
 34454 0000BE70 <res 00000001>      <1> TIMER_OFL:      resb 	1               ; TIMER HAS ROLLED OVER SINCE LAST READ
 34455                              <1> 
 34456                              <1> ;----------------------------------------
 34457                              <1> ;	DISKETTE DATA AREAS		:
 34458                              <1> ;----------------------------------------
 34459                              <1> 
 34460 0000BE71 <res 00000001>      <1> SEEK_STATUS:	resb	1
 34461 0000BE72 <res 00000001>      <1> MOTOR_STATUS:	resb	1
 34462 0000BE73 <res 00000001>      <1> MOTOR_COUNT:	resb	1
 34463 0000BE74 <res 00000001>      <1> DSKETTE_STATUS:	resb	1
 34464 0000BE75 <res 00000007>      <1> NEC_STATUS:	resb	7
 34465                              <1> 
 34466                              <1> ;----------------------------------------
 34467                              <1> ;	ADDITIONAL MEDIA DATA		:
 34468                              <1> ;----------------------------------------
 34469                              <1> 
 34470 0000BE7C <res 00000001>      <1> LASTRATE:	resb 	1
 34471 0000BE7D <res 00000001>      <1> HF_STATUS:	resb 	1
 34472 0000BE7E <res 00000001>      <1> HF_ERROR:	resb 	1
 34473 0000BE7F <res 00000001>      <1> HF_INT_FLAG:	resb 	1
 34474 0000BE80 <res 00000001>      <1> HF_CNTRL:	resb 	1
 34475 0000BE81 <res 00000004>      <1> DSK_STATE:	resb 	4
 34476 0000BE85 <res 00000002>      <1> DSK_TRK:	resb 	2
 34477                              <1> 
 34478                              <1> ;----------------------------------------
 34479                              <1> ;	FIXED DISK DATA AREAS		:
 34480                              <1> ;----------------------------------------
 34481                              <1> 
 34482 0000BE87 <res 00000001>      <1> DISK_STATUS1:	resb 	1		; FIXED DISK STATUS
 34483 0000BE88 <res 00000001>      <1> HF_NUM:		resb 	1		; COUNT OF FIXED DISK DRIVES
 34484 0000BE89 <res 00000001>      <1> CONTROL_BYTE:	resb 	1		; HEAD CONTROL BYTE
 34485                              <1> ;@PORT_OFF	resb	1		; RESERVED (PORT OFFSET)
 34486                              <1> ;port1_off	resb	1		; Hard disk controller 1 - port offset
 34487                              <1> ;port2_off	resb	1		; Hard idsk controller 2 - port offset
 34488                              <1> 
 34489 0000BE8A <res 00000002>      <1> alignb 4
 34490                              <1> 
 34491                              <1> ;HF_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
 34492                              <1> ;HF1_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
 34493                              <1> HF_TBL_VEC: ; 22/12/2014	
 34494 0000BE8C <res 00000004>      <1> HDPM_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
 34495 0000BE90 <res 00000004>      <1> HDPS_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
 34496 0000BE94 <res 00000004>      <1> HDSM_TBL_VEC:	resd	1 		; Secondary master disk param. tbl. pointer
 34497 0000BE98 <res 00000004>      <1> HDSS_TBL_VEC:	resd	1		; Secondary slave disk param. tbl. pointer
 34498                              <1> 
 34499                              <1> ; 03/01/2015
 34500 0000BE9C <res 00000001>      <1> LBAMode:     	resb	1
 34501                              <1> 
 34502                              <1> ; *****************************************************************************
 34503                                  
 34504                                  ;;; Real Mode Data (10/07/2015 - BSS)
 34505                                  
 34506                                  ;alignb 2
 34507                                  
 34508                                  ; 10/01/2016
 34509                                  %include 'trdoskx.s'	; UNINITIALIZED KERNEL (Logical Drive & FS) DATA
 34510                              <1> ; ****************************************************************************
 34511                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED DATA : trdoskx.s
 34512                              <1> ; ----------------------------------------------------------------------------
 34513                              <1> ; Last Update: 31/03/2016
 34514                              <1> ; ----------------------------------------------------------------------------
 34515                              <1> ; Beginning: 04/01/2016
 34516                              <1> ; ----------------------------------------------------------------------------
 34517                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 34518                              <1> ; ----------------------------------------------------------------------------
 34519                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 34520                              <1> ; TRDOS2.ASM (09/11/2011)
 34521                              <1> ; ****************************************************************************
 34522                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
 34523                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
 34524                              <1> ; DIR.ASM      [17/01/2004] Last Update: 09/10/2011
 34525                              <1> ; CMD_INTR.ASM [29/01/2005] Last update: 09/11/2011
 34526                              <1> ; DRV_FAT.ASM  [07/07/2009] Last update: 21/08/2011
 34527                              <1> 
 34528 0000BE9D <res 00000003>      <1> alignb 4
 34529                              <1> 
 34530 0000BEA0 <res 00000002>      <1> MainProgCfg_FileSize:   resw 1
 34531 0000BEA2 <res 00000002>      <1> MainProgCfg_LineOffset: resw 1
 34532                              <1> 
 34533 0000BEA4 <res 00000004>      <1> Current_VolSerial: resd 1
 34534                              <1> 
 34535 0000BEA8 <res 00000004>      <1> Current_Dir_FCluster: resd 1
 34536                              <1> 
 34537 0000BEAC <res 00000001>      <1> Current_Dir_Level: resb 1
 34538 0000BEAD <res 00000001>      <1> Current_FATType: resb 1
 34539 0000BEAE <res 00000001>      <1> Current_Drv: resb 1
 34540 0000BEAF <res 00000001>      <1> Current_Dir_Drv:   resb 1 ; '?'
 34541 0000BEB0 <res 00000001>      <1>                    resb 1 ; ':'
 34542 0000BEB1 <res 00000001>      <1> Current_Dir_Root:  resb 1 ; '/' 
 34543 0000BEB2 <res 0000005A>      <1> Current_Directory: resb 90
 34544 0000BF0C <res 00000001>      <1> End_Of_Current_Dir_Str: resb 1
 34545 0000BF0D <res 00000001>      <1> Current_Dir_StrLen: resb 1   
 34546                              <1> 
 34547 0000BF0E <res 00000001>      <1> CursorColumn: 	resb 1
 34548 0000BF0F <res 00000001>      <1> CmdArgStart:    resb 1
 34549                              <1> 
 34550                              <1> Remark: ; 03/02/2016
 34551 0000BF10 <res 0000004E>      <1> 		resb 78
 34552                              <1> 
 34553 0000BF5E <res 00000050>      <1> CommandBuffer: 	resb 80
 34554                              <1> 
 34555 0000BFAE <res 00000100>      <1> TextBuffer: resb 256
 34556                              <1> 
 34557                              <1> MasterBootBuff:
 34558 0000C0AE <res 000001BE>      <1> MasterBootCode: resb 1BEh
 34559 0000C26C <res 00000040>      <1> PartitionTable: resb 64
 34560 0000C2AC <res 00000002>      <1> MBIDCode: resw 1
 34561                              <1> 
 34562                              <1> PTable_Buffer:
 34563 0000C2AE <res 00000040>      <1> PTable_hd0: resb 64
 34564 0000C2EE <res 00000040>      <1> PTable_hd1: resb 64
 34565 0000C32E <res 00000040>      <1> PTable_hd2: resb 64
 34566 0000C36E <res 00000040>      <1> PTable_hd3: resb 64
 34567 0000C3AE <res 00000040>      <1> PTable_ep0: resb 64
 34568 0000C3EE <res 00000040>      <1> PTable_ep1: resb 64
 34569 0000C42E <res 00000040>      <1> PTable_ep2: resb 64
 34570 0000C46E <res 00000040>      <1> PTable_ep3: resb 64
 34571                              <1> 
 34572 0000C4AE <res 00000001>      <1> HD_LBA_yes: resb 1
 34573 0000C4AF <res 00000001>      <1> PP_Counter: resb 1
 34574 0000C4B0 <res 00000001>      <1> EP_Counter: resb 1
 34575                              <1> 
 34576 0000C4B1 <res 00000004>      <1> EP_StartSector: resd 1
 34577 0000C4B5 <res 00000004>      <1>                 resd 1
 34578 0000C4B9 <res 00000004>      <1>                 resd 1
 34579 0000C4BD <res 00000004>      <1>                 resd 1
 34580                              <1> 
 34581 0000C4C1 <res 00000200>      <1> DOSBootSectorBuff: resb 512
 34582                              <1> 
 34583                              <1> FAT_BuffDescriptor:
 34584 0000C6C1 <res 00000004>      <1> FAT_CurrentCluster: resd 1
 34585 0000C6C5 <res 00000001>      <1> FAT_BuffValidData: resb 1
 34586 0000C6C6 <res 00000001>      <1> FAT_BuffDrvName: resb 1
 34587 0000C6C7 <res 00000002>      <1> FAT_BuffOffset: resw 1
 34588 0000C6C9 <res 00000004>      <1> FAT_BuffSector: resd 1
 34589                              <1> 
 34590 0000C6CD <res 00000004>      <1> FAT_ClusterCounter: resd 1
 34591 0000C6D1 <res 00000004>      <1> LastCluster: resd 1
 34592                              <1> 
 34593                              <1> ; 18/03/2016 (TRDOS v2.0)
 34594 0000C6D5 <res 00000001>      <1> ClusterBuffer_Valid: resb 1
 34595                              <1> 
 34596                              <1> Dir_BuffDescriptor:
 34597 0000C6D6 <res 00000001>      <1> DirBuff_DRV: resb 1
 34598 0000C6D7 <res 00000001>      <1> DirBuff_FATType: resb 1
 34599 0000C6D8 <res 00000001>      <1> DirBuff_ValidData: resb 1
 34600 0000C6D9 <res 00000002>      <1> DirBuff_CurrentEntry: resw 1
 34601 0000C6DB <res 00000002>      <1> DirBuff_LastEntry: resw 1
 34602 0000C6DD <res 00000004>      <1> DirBuff_Cluster: resd 1 
 34603 0000C6E1 <res 00000002>      <1> DirBuffer_Size: resw 1
 34604                              <1> ;DirBuff_EntryCounter: resw 1
 34605                              <1> 
 34606                              <1> ; 01/02/2016
 34607                              <1> ; these are on (real mode) segment 8000h and later
 34608                              <1> ; FAT_Buffer:	resb 1536 ; 3 sectors
 34609                              <1> ; Dir_Buffer:	resb 512*32
 34610                              <1> ; Logical_DOSDisks:  resb 6656 ; 26 * 256 bytes
 34611                              <1> 
 34612                              <1> ; 18/01/2016
 34613                              <1> 
 34614 0000C6E3 <res 00000004>      <1> FreeClusterCount: resd 1
 34615                              <1> 
 34616 0000C6E7 <res 00000004>      <1> VolSize_Unit1:   resd 1
 34617 0000C6EB <res 00000004>      <1> VolSize_Unit2:   resd 1
 34618                              <1> 
 34619 0000C6EF <res 00000004>      <1> Vol_Tot_Sec_Str_Start:	    resd 1
 34620 0000C6F3 <res 0000000A>      <1> Vol_Tot_Sec_Str: 	    resb 10
 34621 0000C6FD <res 00000001>      <1> Vol_Tot_Sec_Str_End:	    resb 1
 34622 0000C6FE <res 00000001>      <1> resb 1
 34623 0000C6FF <res 00000004>      <1> Vol_Free_Sectors_Str_Start: resd 1
 34624 0000C703 <res 0000000A>      <1> Vol_Free_Sectors_Str:	    resb 10				
 34625 0000C70D <res 00000001>      <1> Vol_Free_Sectors_Str_End:   resb 1
 34626                              <1> 
 34627                              <1> ; 10/02/2016
 34628 0000C70E <res 00000001>      <1> RUN_CDRV: resb 1 ; CMD_INTR.ASM  ; 09/11/2011
 34629                              <1> 
 34630                              <1> ; 24/01/2016
 34631 0000C70F <res 00000080>      <1> PATH_Array:     resb 128 ; DIR.ASM ; 09/10/2011
 34632                              <1> ; 06/02/2016
 34633 0000C78F <res 00000004>      <1> CCD_DriveDT:	resd 1 ; DIR.ASM ; (word)
 34634 0000C793 <res 00000001>      <1> CCD_Level:	resb 1 ; DIR.ASM
 34635 0000C794 <res 00000001>      <1> Last_Dir_Level:	resb 1 ; DIR.ASM
 34636                              <1> ;
 34637 0000C795 <res 00000002>      <1> CDLF_AttributesMask: resw 1 ; DIR.ASM
 34638 0000C797 <res 00000004>      <1> CDLF_FNAddress:	resd 1 ; DIR.ASM (word)
 34639 0000C79B <res 00000002>      <1> CDLF_DEType:	resw 1 ; DIR.ASM
 34640                              <1> ;
 34641 0000C79D <res 00000001>      <1> CD_COMMAND:	resb 1 ; DIR.ASM
 34642                              <1> 
 34643 0000C79E <res 00000002>      <1> alignb 4
 34644                              <1> 
 34645                              <1> ; 29/01/2016
 34646 0000C7A0 <res 00000001>      <1> Program_Exit:	resb 1 ; CMD_INTR.ASM  ; 09/11/2011
 34647                              <1> 
 34648                              <1> ;alignb 4
 34649                              <1> ; 23/02/2016
 34650 0000C7A1 <res 00000001>      <1> disk_rw_op:	resb 1 ;  0 = disk read, 1 = disk write
 34651                              <1> ;disk_rw_spt:	resb 1 ; sectors per track (<= 63) /// (<256)
 34652                              <1> ; 31/01/2016
 34653 0000C7A2 <res 00000001>      <1> retry_count: 	resb 1 ; DISK_IO.ASM ; 20/07/2011 (CHS_RetryCount)
 34654 0000C7A3 <res 00000001>      <1> disk_rw_err: 	resb 1 ; DISK_IO.ASM ; (Disk_IO_err_code)
 34655 0000C7A4 <res 00000004>      <1> sector_count:	resd 1 ; DISK_IO.ASM ; (Disk_RW_SectorCount)
 34656                              <1> 
 34657                              <1> ; 06/02/2016 (long name)
 34658 0000C7A8 <res 00000002>      <1> FDE_AttrMask:	   resw 1 ; DIR.ASM
 34659 0000C7AA <res 00000002>      <1> AmbiguousFileName: resw 1 ; DIR.ASM
 34660 0000C7AC <res 00000001>      <1> PreviousAttr:	   resb 1 ; DIR.ASM
 34661                              <1> ;	
 34662 0000C7AD <res 00000001>      <1> LongNameFound:   resb 1	  ; DIR.ASM
 34663 0000C7AE <res 00000001>      <1> LFN_EntryLength: resb 1   ; DIR.ASM
 34664 0000C7AF <res 00000001>      <1> LFN_CheckSum:    resb 1   ; DIR.ASM
 34665 0000C7B0 <res 00000084>      <1> LongFileName:    resb 132 ; DIR.ASM
 34666                              <1> 
 34667                              <1> ;PATH_Array_Ptr: resw 1 ; DIR.ASM
 34668 0000C834 <res 00000001>      <1> PATH_CDLevel:	 resb 1 ; DIR.ASM
 34669 0000C835 <res 00000001>      <1> PATH_Level:	 resb 1 ; DIR.ASM
 34670                              <1> 
 34671                              <1> ; 07/02/2016
 34672 0000C836 <res 0000000D>      <1> Dir_File_Name:	resb 13 ; DIR.ASM ; 09/10/2011
 34673                              <1> 
 34674                              <1> ; 10/02/2016
 34675                              <1> Dir_Entry_Name:
 34676 0000C843 <res 0000000D>      <1> 		resb 13 ; DIR.ASM
 34677                              <1> 
 34678                              <1> alignb 2
 34679                              <1> 
 34680 0000C850 <res 00000002>      <1> AttributesMask: resw 1 ; CMD_INTR.ASM ; 09/11/2011
 34681                              <1> 
 34682                              <1> ; 10/02/2016 (128 bytes -> 126 bytes)
 34683                              <1> ; 08/02/2016
 34684                              <1> ;FFF Structure (128 bytes) ; DIR.ASM ; 09/10/2011
 34685 0000C852 <res 00000001>      <1> FindFile_Drv:		  resb 1
 34686 0000C853 <res 00000041>      <1> FindFile_Directory:	  resb 65
 34687 0000C894 <res 0000000D>      <1> FindFile_Name:		  resb 13
 34688                              <1> FindFile_LongNameEntryLength:
 34689 0000C8A1 <res 00000001>      <1> FindFile_LongNameYes: 	  resb 1 ; Sign for longname procedures
 34690                              <1> ;Above 80 bytes form
 34691                              <1> ;TR-DOS Source/Destination File FullName Format/Structure
 34692 0000C8A2 <res 00000002>      <1> FindFile_AttributesMask:  resw 1
 34693 0000C8A4 <res 00000020>      <1> FindFile_DirEntry:	  resb 32
 34694 0000C8C4 <res 00000004>      <1> FindFile_DirFirstCluster: resd 1
 34695 0000C8C8 <res 00000004>      <1> FindFile_DirCluster:	  resd 1
 34696 0000C8CC <res 00000002>      <1> FindFile_DirEntryNumber:  resw 1
 34697 0000C8CE <res 00000002>      <1> FindFile_MatchCounter:	  resw 1
 34698 0000C8D0 <res 00000002>      <1> FindFile_Reserved:	  resw 1 ; 06/03/2016
 34699                              <1> 
 34700 0000C8D2 <res 00000004>      <1> First_Path_Pos: resd 1	; DIR.ASM ; 09/10/2011
 34701 0000C8D6 <res 00000004>      <1> Last_Slash_Pos: resd 1	; DIR.ASM 
 34702                              <1> 
 34703                              <1> ; 10/02/2016
 34704 0000C8DA <res 00000002>      <1> File_Count:     resw 1 	; DIR.ASM ; 09/10/2011
 34705 0000C8DC <res 00000002>      <1> Dir_Count:      resw 1
 34706 0000C8DE <res 00000004>      <1> Total_FSize:    resd 1
 34707 0000C8E2 <res 00000004>      <1> TFS_Dec_Begin:  resd 1
 34708 0000C8E6 <res 0000000A>      <1>                 resb 10
 34709 0000C8F0 <res 00000001>      <1> TFS_Dec_End:    resb 1
 34710                              <1> 
 34711 0000C8F1 <res 00000001>      <1> PrintDir_RowCounter: resb 1
 34712                              <1> 
 34713 0000C8F2 <res 00000002>      <1> alignb 4
 34714                              <1> ; 15/02/2015 ('show' command variables)
 34715 0000C8F4 <res 00000004>      <1> Show_FDT:	resd 1
 34716 0000C8F8 <res 00000004>      <1> Show_LDDDT:	resd 1
 34717 0000C8FC <res 00000004>      <1> Show_Cluster:	resd 1
 34718 0000C900 <res 00000004>      <1> Show_FileSize:	resd 1
 34719 0000C904 <res 00000004>      <1> Show_FilePointer: resd 1
 34720 0000C908 <res 00000002>      <1> Show_ClusterPointer: resw 1
 34721 0000C90A <res 00000002>      <1> Show_ClusterSize: resw 1
 34722 0000C90C <res 00000001>      <1> Show_RowCount:	resb 1
 34723                              <1> 
 34724 0000C90D <res 00000003>      <1> alignb 4
 34725                              <1> ; 21/02/2016
 34726 0000C910 <res 00000004>      <1> DelFile_FNPointer:	resd 1 ; ; CMD_INTR.ASM (word) ; 09/11/2011
 34727                              <1> ; 27/02/2016
 34728                              <1> ; DIR.ASM (09/10/2011)
 34729 0000C914 <res 00000004>      <1> DelFile_FCluster:	resd 1
 34730 0000C918 <res 00000002>      <1> DelFile_EntryCounter:	resw 1
 34731 0000C91A <res 00000001>      <1> DelFile_LNEL:		resb 1
 34732 0000C91B <res 00000001>      <1> resb 1
 34733                              <1> 
 34734                              <1> ; DIR.ASM
 34735 0000C91C <res 00000004>      <1> mkdir_DirName_Offset: 	resd 1
 34736 0000C920 <res 00000004>      <1> mkdir_FFCluster:	resd 1
 34737 0000C924 <res 00000004>      <1> mkdir_LastDirCluster:	resd 1
 34738 0000C928 <res 00000004>      <1> mkdir_FreeSectors:	resd 1
 34739 0000C92C <res 00000002>      <1> mkdir_attrib:		resw 1 
 34740 0000C92E <res 00000001>      <1> mkdir_SecPerClust:	resb 1
 34741 0000C92F <res 00000001>      <1> mkdir_add_new_cluster:	resb 1
 34742 0000C930 <res 0000000D>      <1> mkdir_Name:		resb 13
 34743 0000C93D <res 00000002>      <1> resw 1 ; 01/03/2016
 34744                              <1> ; 27/02/2016
 34745 0000C93F <res 00000001>      <1> RmDir_MultiClusters:	resb 1  
 34746 0000C940 <res 00000004>      <1> RmDir_DirEntryOffset:	resd 1 ; 01/03/2016 (word -> dword)
 34747 0000C944 <res 00000004>      <1> RmDir_ParentDirCluster: resd 1
 34748 0000C948 <res 00000004>      <1> RmDir_DirLastCluster:   resd 1
 34749 0000C94C <res 00000004>      <1> RmDir_PreviousCluster:  resd 1
 34750                              <1> ; 22/02/2016
 34751 0000C950 <res 00000001>      <1> UPDLMDT_CDirLevel:	resb 1
 34752 0000C951 <res 00000004>      <1> UPDLMDT_CDirFCluster:	resd 1
 34753                              <1> 	
 34754 0000C955 <res 00000003>      <1> alignb 4
 34755                              <1> ; DRV_FAT.ASM ; 21/08/2011
 34756 0000C958 <res 00000004>      <1> gffc_next_free_cluster:  resd 1
 34757 0000C95C <res 00000004>      <1> gffc_first_free_cluster: resd 1
 34758 0000C960 <res 00000004>      <1> gffc_last_free_cluster:  resd 1
 34759                              <1> 
 34760                              <1> ; 22/02/2016
 34761 0000C964 <res 00000004>      <1> ClusterValue:	resd 1
 34762                              <1> ; 04/03/2016
 34763 0000C968 <res 00000001>      <1> Attributes:	resb 1 
 34764                              <1> ;;CFS_error:  resb 1 ;; 01/03/2016
 34765 0000C969 <res 00000001>      <1> resb 1
 34766 0000C96A <res 00000001>      <1> CFS_OPType: resb 1
 34767 0000C96B <res 00000001>      <1> CFS_Drv:    resb 1
 34768 0000C96C <res 00000004>      <1> CFS_CC:	    resd 1
 34769 0000C970 <res 00000004>      <1> CFS_FAT32FSINFOSEC: resd 1
 34770 0000C974 <res 00000004>      <1> CFS_FAT32FC: resd 1
 34771                              <1> 
 34772                              <1> ; 27/02/2016
 34773                              <1> ;alignb 4
 34774 0000C978 <res 00000004>      <1> glc_prevcluster: resd 1 ; DRV_FAT.ASM (21/08/2011)
 34775                              <1> 
 34776                              <1> ; DIR.ASM
 34777 0000C97C <res 00000002>      <1> DLN_EntryNumber: resw 1
 34778 0000C97E <res 00000001>      <1> DLN_40h:	 resb 1
 34779                              <1> ; 28/02/2016
 34780 0000C97F <res 00000001>      <1> TCC_FATErr:	 resb 1 ; DRV_FAT.ASM
 34781                              <1> 
 34782                              <1> alignb 4
 34783                              <1> ; DIR.ASM (09/10/2011)
 34784 0000C980 <res 00000002>      <1> LCDE_EntryIndex: resw 1 ; LCDE_EntryOffset
 34785 0000C982 <res 00000002>      <1> LCDE_ClusterSN:  resw 1
 34786 0000C984 <res 00000004>      <1> LCDE_Cluster: 	 resd 1
 34787 0000C988 <res 00000004>      <1> LCDE_ByteOffset: resd 1
 34788                              <1> 
 34789                              <1> ;alignb4
 34790                              <1> ; 06/03/2016 (word -> dword)
 34791                              <1> ; CMD_INTR.ASM (01/08/2010)
 34792 0000C98C <res 00000004>      <1> SourceFilePath:	     resd 1
 34793 0000C990 <res 00000004>      <1> DestinationFilePath: resd 1
 34794                              <1> 
 34795                              <1> ;alignb 4
 34796                              <1> ; 06/03/2016
 34797                              <1> ; FILE.ASM (09/10/2011)
 34798                              <1> ;Source File Structure (same with 'Find File' Structure)
 34799 0000C994 <res 00000001>      <1> SourceFile_Drv:			resb 1
 34800 0000C995 <res 00000041>      <1> SourceFile_Directory:		resb 65
 34801 0000C9D6 <res 0000000D>      <1> SourceFile_Name:		resb 13
 34802                              <1> SourceFile_LongNameEntryLength: 
 34803 0000C9E3 <res 00000001>      <1> SourceFile_LongNameYes:		resb 1 ; Sign for longname procedures
 34804                              <1> ;Above 80 bytes
 34805                              <1> ;is TR-DOS Source File FullName Format/Structure
 34806 0000C9E4 <res 00000002>      <1> SourceFile_AttributesMask:	resw 1
 34807 0000C9E6 <res 00000020>      <1> SourceFile_DirEntry:		resb 32
 34808 0000CA06 <res 00000004>      <1> SourceFile_DirFirstCluster:	resd 1
 34809 0000CA0A <res 00000004>      <1> SourceFile_DirCluster:		resd 1
 34810 0000CA0E <res 00000002>      <1> SourceFile_DirEntryNumber:	resw 1
 34811 0000CA10 <res 00000002>      <1> SourceFile_MatchCounter:	resw 1
 34812                              <1> ; 16/03/2016
 34813 0000CA12 <res 00000001>      <1> SourceFile_SecPerClust:		resb 1
 34814 0000CA13 <res 00000001>      <1> SourceFile_Reserved:		resb 1
 34815                              <1> ; Above is 128 bytes
 34816                              <1> 
 34817                              <1> ;Destination File Structure (same with 'Find File' Structure)
 34818 0000CA14 <res 00000001>      <1> DestinationFile_Drv:		resb 1
 34819 0000CA15 <res 00000041>      <1> DestinationFile_Directory: 	resb 65
 34820 0000CA56 <res 0000000D>      <1> DestinationFile_Name:		resb 13
 34821                              <1> DestinationFile_LongNameEntryLength:
 34822 0000CA63 <res 00000001>      <1> DestinationFile_LongNameYes:	resb 1 ; Sign for longname procedures
 34823                              <1> ;Above 80 bytes
 34824                              <1> ;is TR-DOS Destination File FullName Format/Structure
 34825 0000CA64 <res 00000002>      <1> DestinationFile_AttributesMask: resw 1
 34826 0000CA66 <res 00000020>      <1> DestinationFile_DirEntry:	resb 32
 34827 0000CA86 <res 00000004>      <1> DestinationFile_DirFirstCluster: resd 1
 34828 0000CA8A <res 00000004>      <1> DestinationFile_DirCluster:	resd 1
 34829 0000CA8E <res 00000002>      <1> DestinationFile_DirEntryNumber: resw 1
 34830 0000CA90 <res 00000002>      <1> DestinationFile_MatchCounter:	resw 1
 34831                              <1> ; 16/03/2016
 34832 0000CA92 <res 00000001>      <1> DestinationFile_SecPerClust:	resb 1
 34833 0000CA93 <res 00000001>      <1> DestinationFile_Reserved:	resb 1
 34834                              <1> ; Above is 128 bytes
 34835                              <1> 
 34836                              <1> ; 10/03/2016
 34837                              <1> ; FILE.ASM
 34838 0000CA94 <res 00000001>      <1> move_cmd_phase:	   resb 1
 34839 0000CA95 <res 00000001>      <1> msftdf_sf_df_drv:  resb 1
 34840 0000CA96 <res 00000004>      <1> msftdf_drv_offset: resd 1
 34841                              <1> 
 34842                              <1> ; 11/03/2016
 34843                              <1> ; DRV_FAT.ASM (21/08/2011)
 34844 0000CA9A <res 00000004>      <1> FAT_anc_LCluster:  resd 1
 34845 0000CA9E <res 00000004>      <1> FAT_anc_FFCluster: resd 1
 34846                              <1> 
 34847                              <1> ;alignb 4
 34848                              <1> 
 34849                              <1> ; 14/03/2016
 34850                              <1> ; TRDOS 386 = TRDOS v2.0 feature only !
 34851                              <1> ; 'allocate_memory_block' in 'memory.s'
 34852 0000CAA2 <res 00000004>      <1> mem_ipg_count:	resd 1 ; page count (for contiguous allocation)
 34853 0000CAA6 <res 00000004>      <1> mem_pg_count:	resd 1 ; page count (for count down)
 34854 0000CAAA <res 00000004>      <1> mem_aperture:	resd 1 ; contiguous free pages (current)
 34855 0000CAAE <res 00000004>      <1> mem_max_aperture: resd 1 ; maximum value of contiguous free pages
 34856 0000CAB2 <res 00000004>      <1> mem_pg_pos:	resd 1 ; mem. position (page #) of current aperture
 34857 0000CAB6 <res 00000004>      <1> mem_max_pg_pos: resd 1 ; mem. position (page #) of max. aperture
 34858                              <1> 
 34859                              <1> ; 15/03/2016
 34860                              <1> ; FILE.ASM ('copy_source_file_to_destination_file')
 34861 0000CABA <res 00000001>      <1> copy_cmd_phase:       resb 1
 34862 0000CABB <res 00000001>      <1> csftdf_rw_err:	      resb 1
 34863 0000CABC <res 00000001>      <1> DestinationFileFound: resb 1
 34864 0000CABD <res 00000001>      <1> csftdf_cdrv: 	      resb 1
 34865 0000CABE <res 00000004>      <1> csftdf_filesize:      resd 1
 34866                              <1> ; TRDOS386 (TRDOS v2.0)
 34867 0000CAC2 <res 00000004>      <1> csftdf_sf_mem_addr:   resd 1
 34868 0000CAC6 <res 00000004>      <1> csftdf_sf_mem_bsize:  resd 1
 34869                              <1> ;
 34870                              <1> 
 34871 0000CACA <res 00000004>      <1> csftdf_sf_cluster:    resd 1 ; 16/03/2016
 34872 0000CACE <res 00000004>      <1> csftdf_df_cluster:    resd 1
 34873                              <1> ; 16/03/2016
 34874 0000CAD2 <res 00000004>      <1> csftdf_r_size:        resd 1
 34875 0000CAD6 <res 00000004>      <1> csftdf_w_size:        resd 1
 34876 0000CADA <res 00000004>      <1> csftdf_sf_rbytes:     resd 1
 34877 0000CADE <res 00000004>      <1> csftdf_df_wbytes:     resd 1
 34878 0000CAE2 <res 00000001>      <1> csftdf_percentage:    resb 1
 34879                              <1> ; 17/03/2016
 34880 0000CAE3 <res 00000001>      <1> csftdf_videopage:     resb 1
 34881 0000CAE4 <res 00000002>      <1> csftdf_cursorpos:     resw 1
 34882 0000CAE6 <res 00000004>      <1> csftdf_sf_drv_dt:     resd 1
 34883 0000CAEA <res 00000004>      <1> csftdf_df_drv_dt:     resd 1
 34884                              <1> 
 34885                              <1> ; 21/03/2016
 34886                              <1> ; 20/03/20016
 34887                              <1> ; FILE.ASM
 34888 0000CAEE <res 00000004>      <1> createfile_Name_Offset:  resd 1
 34889 0000CAF2 <res 00000004>      <1> createfile_FreeSectors:  resd 1 
 34890 0000CAF6 <res 00000004>      <1> createfile_size:         resd 1
 34891 0000CAFA <res 00000004>      <1> createfile_FFCluster:    resd 1 ; 11/03/2016
 34892 0000CAFE <res 00000004>      <1> createfile_LastDirCluster: resd 1
 34893 0000CB02 <res 00000004>      <1> createfile_Cluster:      resd 1
 34894 0000CB06 <res 00000004>      <1> createfile_PCluster:     resd 1
 34895 0000CB0A <res 00000001>      <1> createfile_attrib:	 resb 1
 34896 0000CB0B <res 00000001>      <1> createfile_SecPerClust:  resb 1
 34897 0000CB0C <res 00000002>      <1> createfile_DirIndex:     resw 1
 34898 0000CB0E <res 00000004>      <1> createfile_CCount:	 resd 1
 34899 0000CB12 <res 00000002>      <1> createfile_BytesPerSec:	 resw 1 ; 23/03/2016
 34900 0000CB14 <res 00000001>      <1> createfile_wfc:	         resb 1
 34901 0000CB15 <res 00000001>      <1> createfile_UpdatePDir:	 resb 1 ; 31/03/2016
 34902                              <1> 
 34903                              <1> ;alignb 4
 34904                                  ; 24/01/2016
 34905                                  %include 'ubss.s'	; UNINITIALIZED KERNEL (USER) DATA
 34906                              <1> ; ****************************************************************************
 34907                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED USER DATA : ubss.s
 34908                              <1> ; ----------------------------------------------------------------------------
 34909                              <1> ; Last Update: 24/01/2016
 34910                              <1> ; ----------------------------------------------------------------------------
 34911                              <1> ; Beginning: 24/01/2016
 34912                              <1> ; ----------------------------------------------------------------------------
 34913                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 34914                              <1> ; ----------------------------------------------------------------------------
 34915                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 34916                              <1> ; ux.s (04/12/2015)
 34917                              <1> ; ****************************************************************************
 34918                              <1> 
 34919                              <1> ; Retro UNIX 386 v1 Kernel - ux.s
 34920                              <1> ; Last Modification: 04/12/2015
 34921                              <1> ;
 34922                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
 34923                              <1> ; (Modified from 
 34924                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
 34925                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
 34926                              <1> ; ----------------------------------------------------------------------------
 34927                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
 34928                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
 34929                              <1> ; <Bell Laboratories (17/3/1972)>
 34930                              <1> ; <Preliminary Release of UNIX Implementation Document>
 34931                              <1> ; (Section E10 (17/3/1972) - ux.s)
 34932                              <1> ; ****************************************************************************
 34933                              <1> 
 34934                              <1> alignb 2
 34935                              <1> 
 34936                              <1> inode:
 34937                              <1> 	; 11/03/2013. 
 34938                              <1> 	;Derived from UNIX v1 source code 'inode' structure (ux).
 34939                              <1> 	;i.
 34940                              <1> 
 34941 0000CB16 <res 00000002>      <1> 	i.flgs:	 resw 1
 34942 0000CB18 <res 00000001>      <1> 	i.nlks:	 resb 1
 34943 0000CB19 <res 00000001>      <1> 	i.uid:	 resb 1
 34944 0000CB1A <res 00000002>      <1>         i.size:  resw 1 ; size
 34945 0000CB1C <res 00000010>      <1> 	i.dskp:	 resw 8 ; 16 bytes
 34946 0000CB2C <res 00000004>      <1> 	i.ctim:	 resd 1
 34947 0000CB30 <res 00000004>      <1> 	i.mtim:	 resd 1
 34948 0000CB34 <res 00000002>      <1> 	i.rsvd:  resw 1 ; Reserved (ZERO/Undefined word for UNIX v1.)
 34949                              <1> 
 34950                              <1> I_SIZE	equ $ - inode 
 34951                              <1> 
 34952                              <1> process:
 34953                              <1> 	; 06/05/2015
 34954                              <1> 	; 11/03/2013 - 05/02/2014
 34955                              <1> 	;Derived from UNIX v1 source code 'proc' structure (ux).
 34956                              <1> 	;p.
 34957                              <1> 	
 34958 0000CB36 <res 00000020>      <1>         p.pid:   resw nproc
 34959 0000CB56 <res 00000020>      <1>         p.ppid:  resw nproc
 34960 0000CB76 <res 00000020>      <1>         p.break: resw nproc
 34961 0000CB96 <res 00000010>      <1>         p.ttyc:  resb nproc ; console tty in Retro UNIX 8086 v1.
 34962 0000CBA6 <res 00000010>      <1> 	p.waitc: resb nproc ; waiting channel in Retro UNIX 8086 v1.
 34963 0000CBB6 <res 00000010>      <1> 	p.link:	 resb nproc
 34964 0000CBC6 <res 00000010>      <1> 	p.stat:	 resb nproc
 34965                              <1> 
 34966                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 fetaure only !) 
 34967 0000CBD6 <res 00000040>      <1> 	p.upage: resd nproc ; Physical address of the process's
 34968                              <1> 			    ; 'user' structure	
 34969                              <1> 
 34970                              <1> 
 34971                              <1> P_SIZE	equ $ - process
 34972                              <1> 
 34973                              <1> 
 34974                              <1> ; fsp table (original UNIX v1)
 34975                              <1> ;
 34976                              <1> ;Entry
 34977                              <1> ;          15                                      0
 34978                              <1> ;  1     |---|---------------------------------------|
 34979                              <1> ;        |r/w|       i-number of open file           |
 34980                              <1> ;        |---|---------------------------------------| 
 34981                              <1> ;        |               device number               |
 34982                              <1> ;        |-------------------------------------------|
 34983                              <1> ;    (*) | offset pointer, i.e., r/w pointer to file |
 34984                              <1> ;        |-------------------------------------------| 
 34985                              <1> ;        |  flag that says    | number of processes  |
 34986                              <1> ;        |   file deleted     | that have file open  |
 34987                              <1> ;        |-------------------------------------------| 
 34988                              <1> ;  2     |                                           |
 34989                              <1> ;        |-------------------------------------------| 
 34990                              <1> ;        |                                           |
 34991                              <1> ;        |-------------------------------------------|
 34992                              <1> ;        |                                           |
 34993                              <1> ;        |-------------------------------------------|
 34994                              <1> ;        |                                           |
 34995                              <1> ;        |-------------------------------------------| 
 34996                              <1> ;  3     |                                           | 
 34997                              <1> ;        |                                           |  
 34998                              <1> ;
 34999                              <1> ; (*) Retro UNIX 386 v1 modification: 32 bit offset pointer 
 35000                              <1> 
 35001                              <1> 
 35002                              <1> ; 15/04/2015
 35003 0000CC16 <res 000001F4>      <1> fsp:	 resb nfiles * 10 ; 11/05/2015 (8 -> 10)
 35004 0000CE0A <res 00000018>      <1> bufp:	 resd (nbuf+2) ; will be initialized 
 35005 0000CE22 <res 00000002>      <1> ii:	 resw 1
 35006 0000CE24 <res 00000002>      <1> idev:	 resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
 35007 0000CE26 <res 00000002>      <1> cdev:    resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
 35008                              <1> ; 18/05/2015
 35009                              <1> ; 26/04/2013 device/drive parameters (Retro UNIX 8086 v1 feature only!)
 35010                              <1> ; 'UNIX' device numbers (as in 'cdev' and 'u.cdrv')
 35011                              <1> ;	0 -> root device (which has Retro UNIX 8086 v1 file system)
 35012                              <1> ; 	1 -> mounted device (which has Retro UNIX 8086 v1 file system)
 35013                              <1> ; 'Retro UNIX 8086 v1' device numbers: (for disk I/O procedures)
 35014                              <1> ;	0 -> fd0 (physical drive, floppy disk 1), physical drive number = 0
 35015                              <1> ;	1 -> fd1 (physical drive, floppy disk 2), physical drive number = 1
 35016                              <1> ;	2 -> hd0 (physical drive, hard disk 1), physical drive number = 80h
 35017                              <1> ;	3 -> hd1 (physical drive, hard disk 2), physical drive number = 81h
 35018                              <1> ;	4 -> hd2 (physical drive, hard disk 3), physical drive number = 82h
 35019                              <1> ;	5 -> hd3 (physical drive, hard disk 4), physical drive number = 83h
 35020 0000CE28 <res 00000001>      <1> rdev:	 resb 1 ; root device number ; Retro UNIX 8086 v1 feature only!
 35021                              <1> 	        ; as above, for physical drives numbers in following table
 35022 0000CE29 <res 00000001>      <1> mdev:	 resb 1 ; mounted device number ; Retro UNIX 8086 v1 feature only!
 35023                              <1> ; 15/04/2015
 35024 0000CE2A <res 00000001>      <1> active:	 resb 1 
 35025 0000CE2B <res 00000001>      <1> 	 resb 1 ; 09/06/2015
 35026 0000CE2C <res 00000002>      <1> mnti:	 resw 1
 35027 0000CE2E <res 00000002>      <1> mpid:	 resw 1
 35028 0000CE30 <res 00000002>      <1> rootdir: resw 1
 35029                              <1> ; 14/02/2014
 35030                              <1> ; Major Modification: Retro UNIX 8086 v1 feature only!
 35031                              <1> ;		      Single level run queue
 35032                              <1> ;		      (in order to solve sleep/wakeup lock)
 35033 0000CE32 <res 00000002>      <1> runq:	 resw 1
 35034 0000CE34 <res 00000001>      <1> imod:	 resb 1
 35035 0000CE35 <res 00000001>      <1> smod:	 resb 1
 35036 0000CE36 <res 00000001>      <1> mmod:	 resb 1
 35037 0000CE37 <res 00000001>      <1> sysflg:	 resb 1
 35038                              <1> 
 35039                              <1> alignb 4
 35040                              <1> 
 35041                              <1> user:
 35042                              <1> 	; 04/12/2015 
 35043                              <1> 	; 18/10/2015
 35044                              <1> 	; 12/10/2015
 35045                              <1> 	; 21/09/2015
 35046                              <1> 	; 24/07/2015
 35047                              <1> 	; 16/06/2015
 35048                              <1> 	; 09/06/2015
 35049                              <1> 	; 11/05/2015
 35050                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit modifications)
 35051                              <1> 	; 10/10/2013
 35052                              <1> 	; 11/03/2013. 
 35053                              <1> 	;Derived from UNIX v1 source code 'user' structure (ux).
 35054                              <1> 	;u.
 35055                              <1> 
 35056 0000CE38 <res 00000004>      <1> 	u.sp:	  resd 1 ; esp (kernel stack at the beginning of 'sysent')
 35057 0000CE3C <res 00000004>      <1> 	u.usp:	  resd 1 ; esp (kernel stack points to user's registers)
 35058 0000CE40 <res 00000004>      <1> 	u.r0:	  resd 1 ; eax
 35059 0000CE44 <res 00000002>      <1> 	u.cdir:	  resw 1
 35060 0000CE46 <res 0000000A>      <1> 	u.fp:	  resb 10
 35061 0000CE50 <res 00000004>      <1> 	u.fofp:	  resd 1
 35062 0000CE54 <res 00000004>      <1> 	u.dirp:	  resd 1
 35063 0000CE58 <res 00000004>      <1> 	u.namep:  resd 1
 35064 0000CE5C <res 00000004>      <1> 	u.off:	  resd 1
 35065 0000CE60 <res 00000004>      <1> 	u.base:	  resd 1
 35066 0000CE64 <res 00000004>      <1> 	u.count:  resd 1
 35067 0000CE68 <res 00000004>      <1> 	u.nread:  resd 1
 35068 0000CE6C <res 00000004>      <1> 	u.break:  resd 1 ; break
 35069 0000CE70 <res 00000002>      <1> 	u.ttyp:	  resw 1 
 35070 0000CE72 <res 00000010>      <1> 	u.dirbuf: resb 16 ; 04/12/2015 (10 -> 16) 
 35071                              <1> 	;u.pri:	  resw 1 ; 14/02/2014
 35072 0000CE82 <res 00000001>      <1> 	u.quant:  resb 1 ; Retro UNIX 8086 v1 Feature only ! (uquant)
 35073 0000CE83 <res 00000001>      <1> 	u.pri:	  resb 1 ; 
 35074 0000CE84 <res 00000002>      <1> 	u.intr:	  resw 1
 35075 0000CE86 <res 00000002>      <1> 	u.quit:	  resw 1
 35076                              <1> 	;u.emt:	  resw 1 ; 10/10/2013
 35077 0000CE88 <res 00000002>      <1> 	u.ilgins: resw 1
 35078 0000CE8A <res 00000002>      <1> 	u.cdrv:	  resw 1 ; cdev
 35079 0000CE8C <res 00000001>      <1> 	u.uid:	  resb 1 ; uid
 35080 0000CE8D <res 00000001>      <1> 	u.ruid:	  resb 1
 35081 0000CE8E <res 00000001>      <1> 	u.bsys:	  resb 1
 35082 0000CE8F <res 00000001>      <1> 	u.uno:	  resb 1
 35083 0000CE90 <res 00000004>      <1>         u.upage:  resd 1 ; 16/04/2015 - Retro Unix 386 v1 feature only !
 35084                              <1> 	; tty number (rtty, rcvt, wtty)
 35085 0000CE94 <res 00000001>      <1> 	u.ttyn:	  resb 1 ; 28/07/2013 - Retro Unix 8086 v1 feature only !
 35086                              <1> 	; last error number
 35087 0000CE95 <res 00000004>      <1> 	u.error:  resd 1 ; 28/07/2013 - 09/03/2015 
 35088                              <1> 		        ; Retro UNIX 8086/386 v1 feature only!
 35089 0000CE99 <res 00000004>      <1> 	u.pgdir:  resd 1 ; 09/03/2015 (page dir addr of process)
 35090 0000CE9D <res 00000004>      <1> 	u.ppgdir: resd 1 ; 06/05/2015 (page dir addr of the parent process)
 35091 0000CEA1 <res 00000004>      <1> 	u.pbase:  resd 1 ; 20/05/2015 (physical base/transfer address)
 35092 0000CEA5 <res 00000002>      <1> 	u.pcount: resw 1 ; 20/05/2015 (byte -transfer- count for page)
 35093                              <1> 	;u.pncount: resw 1 
 35094                              <1> 		; 16/06/2015 (byte -transfer- count for page, 'namei', 'mkdir')
 35095                              <1> 	;u.pnbase:  resd 1 
 35096                              <1> 		; 16/06/2015 (physical base/transfer address, 'namei', 'mkdir')
 35097                              <1> 			 ; 09/06/2015
 35098 0000CEA7 <res 00000001>      <1> 	u.kcall:  resb 1 ; The caller is 'namei' (dskr) or 'mkdir' (dskw) sign		
 35099 0000CEA8 <res 00000001>      <1> 	u.brwdev: resb 1 ; Block device number for direct I/O (bread & bwrite)
 35100                              <1> 			 ; 24/07/2015 - 24/06/2015
 35101                              <1> 	;u.args:  resd 1 ; arguments list (line) offset from start of [u.upage]
 35102                              <1> 			 ; (arg list/line is from offset [u.args] to 4096 in [u.upage])
 35103                              <1> 			 ; ([u.args] points to argument count -argc- address offset)
 35104                              <1>  			 ; 24/06/2015	  	
 35105                              <1> 	;u.core:  resd 1 ; physical start address of user's memory space (for sys exec)
 35106                              <1> 	;u.ecore: resd 1 ; physical end address of user's memory space (for sys exec)
 35107                              <1> 			 ; 21/09/2015 (debugging - page fault analyze)
 35108 0000CEA9 <res 00000004>      <1> 	u.pfcount: resd 1 ; page fault count for (this) process (for sys geterr)
 35109                              <1> 
 35110 0000CEAD <res 00000003>      <1> alignb 4
 35111                              <1> 
 35112                              <1> U_SIZE	equ $ - user
 35113                              <1> 
 35114                              <1> ; 18/10/2015 - Retro UNIX 386 v1 (local variables for 'namei' and 'sysexec')
 35115 0000CEB0 <res 00000004>      <1> pcore:  resd 1 ; physical start address of user's memory space (for sys exec)
 35116 0000CEB4 <res 00000004>      <1> ecore:  resd 1 ; physical start address of user's memory space (for sys exec)
 35117 0000CEB8 <res 00000004>      <1> nbase:	resd 1	; physical base address for 'namei' & 'sysexec'
 35118 0000CEBC <res 00000002>      <1> ncount: resw 1	; remain byte count in page for 'namei' & 'sysexec'
 35119 0000CEBE <res 00000002>      <1> argc:	resw 1	; argument count for 'sysexec'
 35120 0000CEC0 <res 00000004>      <1> argv:	resd 1	; argument list (recent) address for 'sysexec'
 35121                              <1> 
 35122                              <1> ; 03/06/2015 - Retro UNIX 386 v1 Beginning
 35123                              <1> ; 07/04/2013 - 31/07/2013 - Retro UNIX 8086 v1
 35124 0000CEC4 <res 00000001>      <1> rw: 	 resb 1 ;; Read/Write sign (iget)
 35125                              <1> 
 35126                              <1> ;alignb 4
 35127                              <1> 
 35128                              <1> ; 22/08/2015
 35129 0000CEC5 <res 00000820>      <1> buffer: resb nbuf * 520
 35130                              <1> 
 35131 0000D6E5 <res 00000008>      <1> sb0:	resd 2
 35132                              <1> ;s:
 35133                              <1> ; (root disk) super block buffer
 35134                              <1> systm:
 35135                              <1> 	; 13/11/2015 (Retro UNIX 386 v1)	
 35136                              <1> 	; 11/03/2013. 
 35137                              <1> 	;Derived from UNIX v1 source code 'systm' structure (ux).
 35138                              <1> 	;s.
 35139                              <1> 
 35140 0000D6ED <res 00000002>      <1> 	resw 1
 35141 0000D6EF <res 00000168>      <1> 	resb 360 ; 2880 sectors ; original UNIX v1 value: 128
 35142 0000D857 <res 00000002>      <1> 	resw 1
 35143 0000D859 <res 00000020>      <1> 	resb 32	 ; 256+40 inodes ; original UNIX v1 value: 64
 35144 0000D879 <res 00000004>      <1> 	s.time:	 resd 1
 35145 0000D87D <res 00000004>      <1> 	s.syst:	 resd 1
 35146 0000D881 <res 00000004>      <1>         s.wait_: resd 1 ; wait
 35147 0000D885 <res 00000004>      <1> 	s.idlet: resd 1
 35148 0000D889 <res 00000004>      <1> 	s.chrgt: resd 1
 35149 0000D88D <res 00000002>      <1> 	s.drerr: resw 1
 35150                              <1> 
 35151                              <1> S_SIZE	equ $ - systm
 35152                              <1> 
 35153 0000D88F <res 0000005E>      <1> 	resb 512-S_SIZE ; 03/06/2015	 
 35154                              <1> 
 35155 0000D8ED <res 00000008>      <1> sb1:	resd 2
 35156                              <1> ; (mounted disk) super block buffer
 35157                              <1> mount:	
 35158 0000D8F5 <res 00000200>      <1> 	resb 512  ; 03/06/2015
 35159                              <1> 
 35160                              <1> ;/ ux -- unix
 35161                              <1> ;
 35162                              <1> ;systm:
 35163                              <1> ;
 35164                              <1> ;	.=.+2
 35165                              <1> ;	.=.+128.
 35166                              <1> ;	.=.+2
 35167                              <1> ;	.=.+64.
 35168                              <1> ;	s.time: .=.+4
 35169                              <1> ;	s.syst: .=.+4
 35170                              <1> ;	s.wait: .=.+4
 35171                              <1> ;	s.idlet:.=.+4
 35172                              <1> ;	s.chrgt:.=.+4
 35173                              <1> ;	s.drerr:.=.+2
 35174                              <1> ;inode:
 35175                              <1> ;	i.flgs: .=.+2
 35176                              <1> ;	i.nlks: .=.+1
 35177                              <1> ;	i.uid:  .=.+1
 35178                              <1> ;	i.size: .=.+2
 35179                              <1> ;	i.dskp: .=.+16.
 35180                              <1> ;	i.ctim: .=.+4
 35181                              <1> ;	i.mtim: .=.+4
 35182                              <1> ;	. = inode+32.
 35183                              <1> ;mount:	.=.+1024.
 35184                              <1> ;proc:
 35185                              <1> ;	p.pid:  .=.+[2*nproc]
 35186                              <1> ;	p.dska: .=.+[2*nproc]
 35187                              <1> ;	p.ppid: .=.+[2*nproc]
 35188                              <1> ;	p.break:.=.+[2*nproc]
 35189                              <1> ;	p.link: .=.+nproc
 35190                              <1> ;	p.stat: .=.+nproc
 35191                              <1> ;tty:
 35192                              <1> ;	. = .+[ntty*8.]
 35193                              <1> ;fsp:	.=.+[nfiles*8.]
 35194                              <1> ;bufp:	.=.+[nbuf*2]+6
 35195                              <1> ;sb0:	.=.+8
 35196                              <1> ;sb1:	.=.+8
 35197                              <1> ;swp:	.=.+8
 35198                              <1> ;ii:	.=.+2
 35199                              <1> ;idev:	.=.+2
 35200                              <1> ;cdev:	.=.+2
 35201                              <1> ;deverr: .=.+12.
 35202                              <1> ;active: .=.+2
 35203                              <1> ;rfap:	.=.+2
 35204                              <1> ;rkap:	.=.+2
 35205                              <1> ;tcap:	.=.+2
 35206                              <1> ;tcstate:.=.+2
 35207                              <1> ;tcerrc: .=.+2
 35208                              <1> ;mnti:	.=.+2
 35209                              <1> ;mntd:	.=.+2
 35210                              <1> ;mpid:	.=.+2
 35211                              <1> ;clockp: .=.+2
 35212                              <1> ;rootdir:.=.+2
 35213                              <1> ;toutt:	.=.+16.
 35214                              <1> ;touts: .=.+32.
 35215                              <1> ;runq:	.=.+6
 35216                              <1> ;
 35217                              <1> ;wlist:	.=.+40.
 35218                              <1> ;cc:	.=.+30.
 35219                              <1> ;cf:	.=.+31.
 35220                              <1> ;cl:	.=.+31.
 35221                              <1> ;clist:	.=.+510.
 35222                              <1> ;imod:	.=.+1
 35223                              <1> ;smod:	.=.+1
 35224                              <1> ;mmod:	.=.+1
 35225                              <1> ;uquant: .=.+1
 35226                              <1> ;sysflg: .=.+1
 35227                              <1> ;pptiflg:.=.+1
 35228                              <1> ;ttyoch: .=.+1
 35229                              <1> ; .even
 35230                              <1> ; .=.+100.; sstack:
 35231                              <1> ;buffer: .=.+[ntty*140.]
 35232                              <1> ;	.=.+[nbuf*520.]
 35233                              <1> ;
 35234                              <1> ; . = core-64.
 35235                              <1> ;user:
 35236                              <1> ;	u.sp:    .=.+2
 35237                              <1> ;	u.usp:   .=.+2
 35238                              <1> ;	u.r0:    .=.+2
 35239                              <1> ;	u.cdir:  .=.+2
 35240                              <1> ;	u.fp:    .=.+10.
 35241                              <1> ;	u.fofp:  .=.+2
 35242                              <1> ;	u.dirp:  .=.+2
 35243                              <1> ;	u.namep: .=.+2
 35244                              <1> ;	u.off:   .=.+2
 35245                              <1> ;	u.base:  .=.+2
 35246                              <1> ;	u.count: .=.+2
 35247                              <1> ;	u.nread: .=.+2
 35248                              <1> ;	u.break: .=.+2
 35249                              <1> ;	u.ttyp:  .=.+2
 35250                              <1> ;	u.dirbuf:.=.+10.
 35251                              <1> ;	u.pri:   .=.+2
 35252                              <1> ;	u.intr:  .=.+2
 35253                              <1> ;	u.quit:  .=.+2
 35254                              <1> ;	u.emt:   .=.+2
 35255                              <1> ;	u.ilgins:.=.+2
 35256                              <1> ;	u.cdev:  .=.+2
 35257                              <1> ;	u.uid:   .=.+1
 35258                              <1> ;	u.ruid:  .=.+1
 35259                              <1> ;	u.bsys:  .=.+1
 35260                              <1> ;	u.uno:   .=.+1
 35261                              <1> ;. = core
 35262                                  
 35263                                  ;; Memory (swap) Data (11/03/2015)
 35264                                  ; 09/03/2015
 35265 0000DAF5 <res 00000002>          swpq_count: resw 1 ; count of pages on the swap queue
 35266 0000DAF7 <res 00000004>          swp_drv:    resd 1 ; logical drive description table address of the swap drive/disk
 35267 0000DAFB <res 00000004>          swpd_size:  resd 1 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
 35268 0000DAFF <res 00000004>          swpd_free:  resd 1 ; free page blocks (4096 bytes) on swap disk/drive (logical)
 35269 0000DB03 <res 00000004>          swpd_next:  resd 1 ; next free page block
 35270 0000DB07 <res 00000004>          swpd_last:  resd 1 ; last swap page block	
 35271                                  
 35272 0000DB0B <res 00000001>          alignb 4
 35273                                  
 35274                                  ; 10/07/2015
 35275                                  ; 28/08/2014
 35276 0000DB0C <res 00000004>          error_code:	resd 1
 35277                                  ; 29/08/2014
 35278 0000DB10 <res 00000004>          FaultOffset: 	resd 1
 35279                                  ; 21/09/2015
 35280 0000DB14 <res 00000004>          PF_Count:	resd 1	; total page fault count
 35281                                  		       	; (for debugging - page fault analyze)
 35282                                  		 	; 'page_fault_handler' (memory.inc)
 35283                                  			; 'sysgeterr' (u9.s)
 35284                                  ;; 21/08/2015
 35285                                  ;;buffer: resb (nbuf*520) ;; sysdefs.inc, ux.s
 35286                                  ;; ((NOTE: nbuf = 6, buffer r/w problem/bug here !? when nbuf > 4))
 35287                                  
 35288                                  bss_end:
 35289                                  
 35290                                  ; 27/12/2013
 35291                                  _end:  ; end of kernel code
