     1                                  ; ****************************************************************************
     2                                  ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 29/02/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[1A9D]              	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[A49F]              	mov	[mem_1m_1k], cx
   157 00000017 8916[A69F]              	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[339E]                	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[1D9D]          <1> 	inc	byte [hdc]	; count of hard disks (EDD present)
   224 0000004E 8816[1C9D]          <1>         mov     [last_drv], dl  ; last hard disk number
   225 00000052 BB[A09C]            <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[1E9D]            <1> 	mov	si, fd0_type
   243                              <1> L3:
   244                              <1> 	; 14/01/2015
   245 00000063 8816[1B9D]          <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[1E9D]          <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[1D9D]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[1B9D]          <1>         mov     [drv], dl
   276 0000008E 8816[1C9D]          <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[1D9D]          <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[1B9D]          <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[1B9D]          <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[1B9D]          <1> 	inc	byte [drv]
   330 000000FD BB[A09C]            <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[1D9D]            <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[1B9D]          <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[1B9D]          <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[E8BD]            <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[209D]          <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[1E9D]          <1> 	sub	bx, hd0_type - 2 ; 15/01/2015
   370 00000155 81C3[6A9D]          <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[6A9D]          <1> 	sub	bx, drv.status
   379 00000167 C1E302              <1> 	shl	bx, 2
   380 0000016A 81C3[4E9D]          <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[209D]00        <1> 	mov	byte [bx+hd0_type], 0 ; not a valid disk drive !		
   483 000001F4 808F[6C9D]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[6C9D]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[1C9D]          <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[1E9D]            <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[1F9D]            <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[209D]            <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[219D]            <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[229D]            <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[239D]            <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[1B9D]          <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[6A9D]          <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[6A9D]          <1> 	sub	bx, drv.status
   673 00000334 D0E3                <1> 	shl	bl, 1
   674 00000336 81C3[249D]          <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[249D]          <1> 	sub	bx, drv.cylinders
   679 00000342 81C3[329D]          <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[329D]          <1>         sub     bx, drv.heads
   685 00000351 81C3[409D]          <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[409D]          <1>         sub     bx, drv.spt
   690 00000360 D1E3                <1> 	shl	bx, 1
   691 00000362 81C3[4E9D]          <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[309A]                  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 B982070000              	mov  ecx, (bss_end - bss_start)/4
   811                                  	;shr  ecx, 2 ; bss section is already aligned for double words
   812 000003D4 BF[E09F0000]            	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[A49F0000]        	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[50A20000]          	mov	[free_pages], ecx
   836 000003F5 668B15[A69F0000]        	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[50A20000]          	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[4CA20000]            	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[60A20000]          	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[48A20000]          	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[58A20000]            	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[60A20000]        	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[50A20000]          	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[4CA20000]          	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[50A20000]          	sub	[free_pages], ecx ; 07/11/2014
   965                                  	;
   966 000004DA 8B35[48A20000]          	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[48A20000]          	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[4CA20000]          	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[5CA20000]            	mov	[first_page], eax
  1037 00000549 A3[54A20000]            	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[48A20000]                    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[A89F0000]            	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[3C9A0000]            	mov	esi, ilist
  1129 000005AB 8D3D[E09F0000]          	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[369A0000]        	lidt 	[idtd]
  1173                                  	;
  1174                                  	; TSS descriptor setup ; 24/03/2015
  1175 00000604 B8[E0A10000]            	mov	eax, task_state_segment
  1176 00000609 66A3[2A9A0000]          	mov	[gdt_tss0], ax
  1177 0000060F C1C010                  	rol	eax, 16
  1178 00000612 A2[2C9A0000]            	mov	[gdt_tss1], al
  1179 00000617 8825[2F9A0000]          	mov	[gdt_tss2], ah
  1180 0000061D 66C705[46A20000]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[4CA20000]          	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[E4A10000]          	mov	[tss.esp0], esp
  1215 0000064B 66C705[E8A10000]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 E8DB110000              	call	_set_cpos	; 24/01/2016
  1243                                  	;
  1244                                  	; 06/11/2014
  1245 0000066F E8BC120000              	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[209D0000]          	mov	edx, [hd0_type] ; hd0, hd1, hd2, hd3
  1252 0000067B 668B1D[1E9D0000]        	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[6F9E0000]            	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 E817110000              	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 E8DE210000              	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 E844120000              	call	setup_rtc_int	; 22/05/2015 (dsectrpm.s)
  1299                                  	;
  1300 000006C0 E891920000              	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 E8D5340000              	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[78A20000]          	mov	bl, [ptty]	; active_page
  1349 000006D3 89DE                    	mov	esi, ebx
  1350 000006D5 66D1E6                  	shl 	si, 1
  1351 000006D8 81C6[7AA20000]          	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 E8BB100000              	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[48A20000]          	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[10B10000]            	mov 	[u.r0], eax
  1454 0000073A 89E1                    	mov	ecx, esp
  1455 0000073C 83C130                  	add	ecx, ESPACE ; 4 * 12 (stack frame)	
  1456 0000073F 890D[08B10000]          	mov	[u.sp], ecx ; kernel stack pointer at the start of interrupt
  1457 00000745 8925[0CB10000]          	mov	[u.usp], esp ; kernel stack points to user's registers   
  1458                                  	;
  1459 0000074B 8B0D[48A20000]          	mov	ecx, [k_page_dir]
  1460 00000751 0F22D9                  	mov	cr3, ecx
  1461                                  T3:
  1462 00000754 FB                      	sti				; INTERRUPTS BACK ON
  1463 00000755 66FF05[CCA20000]        	INC	word [TIMER_LOW]	; INCREMENT TIME
  1464 0000075C 7507                    	JNZ	short T4		; GO TO TEST_DAY
  1465 0000075E 66FF05[CEA20000]        	INC	word [TIMER_HIGH]	; INCREMENT HIGH WORD OF TIME
  1466                                  T4:					; TEST_DAY
  1467 00000765 66833D[CEA20000]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[CCA20000]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[CCA20000]            	mov	[TIMER_LH], eax
  1479                                  	;	
  1480 00000781 C605[D0A20000]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[D3A20000]            	mov	al, [MOTOR_COUNT]
  1491 0000078F FEC8                    	dec	al
  1492                                  	;mov	[CS:MOTOR_COUNT], al	; DECREMENT DISKETTE MOTOR CONTROL
  1493 00000791 A2[D3A20000]            	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[D2A20000]          	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[8EA20000]          	inc	dword [tcount]
  1560 000007D0 BB[BD9D0000]            	mov	ebx, tcountstr + 4
  1561 000007D5 66A1[8EA20000]          	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[B99D0000]          	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[959D0000]            	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 E89D0F0000              	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 E824100000              	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[3A940000]        	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[36940000]        	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[789D0000]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[789D0000]                  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[DCBD0000]          	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[48A20000]          	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[E0BD0000]          	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[D09D0000]          	mov	[excnstr], ax
  1941                                  	;
  1942                                  	; 29/08/2014
  1943 000009ED A1[E0BD0000]            	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[DB9D0000]            	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[F8190000]          	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[C09D0000]            	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[809D0000]            	mov	esi, int_msg ; message offset
  2020                                  piemsg:
  2021                                          ; 27/08/2014
  2022 00000A42 8105[789D0000]A000-             add     dword [scr_row], 0A0h
  2023 00000A4A 0000               
  2024 00000A4C 8B3D[789D0000]                  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 E8C0300000              	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 E8D2300000              	call	CMOS_READ
  2091 00000A99 A2[BEA20000]            	mov	[time_seconds], al 
  2092 00000A9E B002                    	mov	al, CMOS_MINUTES
  2093 00000AA0 E8C6300000              	call	CMOS_READ
  2094 00000AA5 A2[BFA20000]            	mov	[time_minutes], al 
  2095 00000AAA B004                    	mov	al, CMOS_HOURS
  2096 00000AAC E8BA300000              	call	CMOS_READ
  2097 00000AB1 A2[C0A20000]                    mov     [time_hours], al
  2098 00000AB6 B006                    	mov	al, CMOS_DAY_WEEK 
  2099 00000AB8 E8AE300000              	call	CMOS_READ
  2100 00000ABD A2[C1A20000]            	mov	[date_wday], al
  2101 00000AC2 B007                     	mov	al, CMOS_DAY_MONTH
  2102 00000AC4 E8A2300000              	call	CMOS_READ
  2103 00000AC9 A2[C2A20000]            	mov	[date_day], al
  2104 00000ACE B008                    	mov	al, CMOS_MONTH
  2105 00000AD0 E896300000              	call	CMOS_READ
  2106 00000AD5 A2[C3A20000]            	mov	[date_month], al
  2107 00000ADA B009                    	mov	al, CMOS_YEAR
  2108 00000ADC E88A300000              	call	CMOS_READ
  2109 00000AE1 A2[C4A20000]            	mov	[date_year], al
  2110 00000AE6 B032                    	mov	al, CMOS_CENTURY
  2111 00000AE8 E87E300000              	call	CMOS_READ
  2112 00000AED A2[C5A20000]            	mov	[date_century], al
  2113                                  	;
  2114 00000AF2 B000                    	mov	al, CMOS_SECONDS
  2115 00000AF4 E872300000              	call 	CMOS_READ
  2116 00000AF9 3A05[BEA20000]          	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[329E0000]          	cmp	al, [ptime_seconds]
  2134 00000B0F 74F0                            je      short rtc_retn ; 29/08/2014
  2135                                  	;
  2136 00000B11 A2[329E0000]            	mov	[ptime_seconds], al
  2137                                  	;
  2138 00000B16 A0[C5A20000]            	mov	al, [date_century]
  2139 00000B1B E8BE000000              	call	bcd_to_ascii
  2140 00000B20 66A3[FF9D0000]          	mov	[datestr+6], ax
  2141 00000B26 A0[C4A20000]            	mov	al, [date_year]
  2142 00000B2B E8AE000000              	call	bcd_to_ascii
  2143 00000B30 66A3[019E0000]          	mov	[datestr+8], ax
  2144 00000B36 A0[C3A20000]            	mov	al, [date_month]
  2145 00000B3B E89E000000              	call	bcd_to_ascii
  2146 00000B40 66A3[FC9D0000]          	mov	[datestr+3], ax
  2147 00000B46 A0[C2A20000]            	mov	al, [date_day]
  2148 00000B4B E88E000000              	call	bcd_to_ascii
  2149 00000B50 66A3[F99D0000]          	mov	[datestr], ax
  2150                                  	;
  2151 00000B56 0FB61D[C1A20000]        	movzx	ebx, byte [date_wday]
  2152 00000B5D C0E302                  	shl 	bl, 2
  2153 00000B60 81C3[129E0000]          	add	ebx, daytmp
  2154 00000B66 8B03                    	mov	eax, [ebx]
  2155 00000B68 A3[049E0000]            	mov	[daystr], eax
  2156                                  	;
  2157 00000B6D A0[C0A20000]            	mov	al, [time_hours]
  2158 00000B72 E867000000              	call	bcd_to_ascii
  2159 00000B77 66A3[089E0000]          	mov	[timestr], ax
  2160 00000B7D A0[BFA20000]            	mov	al, [time_minutes]
  2161 00000B82 E857000000              	call	bcd_to_ascii
  2162 00000B87 66A3[0B9E0000]          	mov	[timestr+3], ax
  2163 00000B8D A0[BEA20000]            	mov	al, [time_seconds]
  2164 00000B92 E847000000              	call	bcd_to_ascii
  2165 00000B97 66A3[0E9E0000]          	mov	[timestr+6], ax
  2166                                  	;		
  2167 00000B9D BE[E79D0000]            	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 E8FF0B0000              	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 E8860C0000              	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[429C0000]      <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[429C0000]        <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[449C0000]        <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[419C0000]        <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[529C0000]      <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[4E9C0000]      <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[529C0000]      <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[4E9C0000]      <1>         mov     ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
  2493 00000CEE 3B1D[529C0000]      <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[4E9C0000]      <1>         mov    	ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
  2508 00000CFF 3B1D[529C0000]      <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[439C0000]      <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[4E9C0000]      <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[4E9C0000]      <1>         mov     ebx, [BUFFER_HEAD]      ; GET HEAD POINTER
  2533 00000D39 3B1D[529C0000]      <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[439C0000]      <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[4A9C0000]      <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[469C0000]      <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[439C0000]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[439C0000]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[439C0000]      <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[449C0000]      <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[449C0000]40    <1> 	or	byte [KB_FLAG_3], LC_AB ; INDICATE 1ST ID WAS OK
  2805                              <1> RST_RD_ID:
  2806 00000E34 8025[449C0000]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[449C0000]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[419C0000]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[449C0000]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[449C0000]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[449C0000]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[2E9B0000]        <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[2C9B0000]        <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[429C0000]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[429C0000]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[429C0000]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[429C0000]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[419C0000]      <1> 	mov	bl, [KB_FLAG]		; PUT STATE FLAGS IN BL
  2917 00000F28 BF[289B0000]        <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[299B0000]      <1>         sub     edi, _K6+1              ; ADJUST PTR TO SCAN CODE MATCH
  2926 00000F42 8AA7[309B0000]      <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[419C0000]      <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[449C0000]      <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[429C0000]      <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[429C0000]      <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[429C0000]      <1>         or      [KB_FLAG_1], ah 	; INDICATE THAT THE KEY IS DEPRESSED
  2982 00000FC5 3025[419C0000]      <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[419C0000]      <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[449C0000]      <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[429C0000]      <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[449C0000]        <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[429C0000]      <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[419C0000]      <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[459C0000]        <1> 	mov	al, [ALT_INPUT]
  3028 00001033 B400                <1> 	mov	ah, 0			; SCAN CODE OF 0
  3029 00001035 8825[459C0000]      <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[429C0000]      <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[429C0000]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[429C0000]F7    <1> 	and	byte [KB_FLAG_1], ~HOLD_STATE ; TURN OFF THE HOLD STATE BIT
  3050                              <1> 	;
  3051                              <1> K26:
  3052 00001064 8025[449C0000]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[429C0000]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[049B0000]        <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[059B0000]      <1> 	sub	edi, K30+1		; DI NOW HAS ENTRY VALUE
  3136 000010F5 A0[459C0000]        <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[459C0000]        <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[459C0000]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[4E9C0000]      <1> 	mov	ebx, [BUFFER_HEAD] 	; RESET BUFFER TO EMPTY
  3219 0000119C 891D[529C0000]      <1> 	mov	[BUFFER_TAIL], ebx
  3220 000011A2 C605[409C0000]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 E8FD2A0000          <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[429C0000]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[769C0000]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[779C0000]        <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[429C0000]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[389B0000]        <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[449C0000]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[0E9B0000]        <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[909B0000]        <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[E89B0000]        <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[909B0000]        <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[E89B0000]        <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[449C0000]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[449C0000]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[78A20000]      <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 E85D020000          <1> 	call	set_active_page
  3455 00001336 6658                <1> 	pop	ax
  3456                              <1> K61:					; NOT-CAPS-STATE
  3457 00001338 8B1D[529C0000]      <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[4E9C0000]      <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[529C0000]      <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 E839050000          <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[439C0000]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[439C0000]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[439C0000]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[439C0000]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[439C0000]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[439C0000]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[439C0000]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[439C0000]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[439C0000]F8    <1> 	and	byte [KB_FLAG_2], 0F8h	; ~KB_LEDS ; CLEAR MODE INDICATOR BITS
  3582 0000140C 0805[439C0000]      <1> 	or	[KB_FLAG_2], al 	; SAVE PRESENT INDICATORS FOR NEXT TIME
  3583 00001412 F605[439C0000]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[439C0000]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[439C0000]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[419C0000]        <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: 30/01/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> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3655 00001448 9C                  <1> 	pushfd
  3656 00001449 0E                  <1> 	push 	cs
  3657 0000144A E851000000          <1> 	call 	VIDEO_IO_1
  3658 0000144F C3                  <1> 	retn
  3659                              <1> 
  3660                              <1> ;--- INT 10 H -------------------------------------------------------------------
  3661                              <1> ; VIDEO_IO									:	
  3662                              <1> ;	THESE ROUTINES PROVIDE THE CRT DISPLAY INTERFACE			:
  3663                              <1> ;	THE FOLLOWING FUNCTIONS ARE PROVIDED:					:
  3664                              <1> ;										:
  3665                              <1> ;    (AH)= 00H	SET MODE (AL) CONTAINS MODE VALUE				:
  3666                              <1> ;		(AL) = 00H  40X25 BW MODE (POWER ON DEFAULT)			:
  3667                              <1> ;		(AL) = 01H  40X25 COLOR						:
  3668                              <1> ;		(AL) = 02H  80X25 BW						:
  3669                              <1> ;		(AL) = 03H  80X25 COLOR						:
  3670                              <1> ;		              GRAPHICS MODES					:
  3671                              <1> ;		(AL) = 04H  320X200 COLOR					:
  3672                              <1> ;		(AL) = 05H  320X200 BW MODE					:
  3673                              <1> ;		(AL) = 06H  640X200 BW MODE					:
  3674                              <1> ;		(AL) = 07H   80X25 MONOCHROME (USED INTERNAL TO VIDEO ONLY)	:
  3675                              <1> ;		*** NOTES -BW MODES OPERATE SAME AS COLOR MODES, BUT COLOR	:
  3676                              <1> ;		           BURST IS NOT ENABLED					:
  3677                              <1> ;		          -CURSOR IS NOT DISPLAYED IN GRAPHICS MODE		:
  3678                              <1> ;    (AH)= 01H	SET CURSOR TYPE							:
  3679                              <1> ;		(CH) = BITS 4-0 = START LINE FOR CURSOR				:
  3680                              <1> ;		       ** HARDWARE WILL ALWAYS CAUSE BLINK			:
  3681                              <1> ;		       ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING	:
  3682                              <1> ;		          OR NO CURSOR AT ALL					:
  3683                              <1> ;		(CL) = BITS 4-0 = END LINE FOR CURSOR				:
  3684                              <1> ;    (AH)= 02H	SET CURSOR POSITION						:
  3685                              <1> ;		(DH,DL) = ROW,COLUMN  (00H,00H) IS UPPER LEFT			:
  3686                              <1> ;		(BH) = A PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
  3687                              <1> ;    (AH)= 03H	READ CURSOR POSITION						:
  3688                              <1> ;		(BH) = PAGE NUMBER (MUST BE 00H FOR GRAPHICS MODES)		:
  3689                              <1> ;		ON EXIT (DH,DL) = ROW,COLUMN OF CURRENT CURSOR			:
  3690                              <1> ;		        (CH,CL) = CURSOR MODE CURRENTLY SET			:
  3691                              <1> ;    (AH)= 04H	READ LIGHT PEN POSITION						:
  3692                              <1> ;		ON EXIT:							:
  3693                              <1> ;		(AH) = 00H -- LIGHT PEN SWITCH NOT DOWN/NOT TRIGGERED		:
  3694                              <1> ;		(AH) = 01H -- VALID LIGHT PEN VALUE IN REGISTERS		:
  3695                              <1> ;		        (DH,DL) = ROW,COLUMN OF CHARACTER LP POSITION		:
  3696                              <1> ;		        (CH) = RASTER LINE (0-199)				:
  3697                              <1> ;		        (BX) = PIXEL COLUMN (0-319,639)				:
  3698                              <1> ;    (AH)= 05H	SELECT ACTIVE DISPLAY PAGE (VALID ONLY FOR ALPHA MODES)		:
  3699                              <1> ;		(AL) = NEW PAGE VALUE (0-7 FOR MODES 0&1, 0-3 FOR MODES 2&3)	:
  3700                              <1> ;    (AH)= 06H	SCROLL ACTIVE PAGE UP						:
  3701                              <1> ;		(AL) = NUMBER OF LINES. ( LINES BLANKED AT BOTTOM OF WINDOW )	:
  3702                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
  3703                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
  3704                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
  3705                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
  3706                              <1> ;    (AH)= 07H	SCROLL ACTIVE PAGE DOWN						:
  3707                              <1> ;		(AL) = NUMBER OF LINES, INPUT LINES BLANKED AT TOP OF WINDOW	:
  3708                              <1> ;		        (AL) = 00H MEANS BLANK ENTIRE WINDOW			:
  3709                              <1> ;		(CH,CL) = ROW,COLUMN OF UPPER LEFT CORNER OF SCROLL		:
  3710                              <1> ;		(DH,DL) = ROW,COLUMN OF LOWER RIGHT CORNER OF SCROLL		:
  3711                              <1> ;		(BH) = ATTRIBUTE TO BE USED ON BLANK LINE			:
  3712                              <1> ;										:
  3713                              <1> ;   CHARACTER HANDLING ROUTINES							:
  3714                              <1> ;										:
  3715                              <1> ;    (AH)= 08H	READ ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
  3716                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3717                              <1> ;		ON EXIT:							:
  3718                              <1> ;		(AL) = CHAR READ						:
  3719                              <1> ;		(AH) = ATTRIBUTE OF CHARACTER READ (ALPHA MODES ONLY)		:
  3720                              <1> ;    (AH)= 09H	WRITE ATTRIBUTE/CHARACTER AT CURRENT CURSOR POSITION		:
  3721                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3722                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
  3723                              <1> ;		(AL) = CHAR TO WRITE						:
  3724                              <1> ;		(BL) = ATTRIBUTE OF CHARACTER (ALPHA)/COLOR OF CHAR (GRAPHICS)	:
  3725                              <1> ;		         SEE NOTE ON WRITE DOT FOR BIT 7 OF BL = 1.		:
  3726                              <1> ;    (AH) = 0AH	WRITE CHARACTER ONLY AT CURRENT CURSOR POSITION			:
  3727                              <1> ;		(BH) = DISPLAY PAGE (VALID FOR ALPHA MODES ONLY)		:
  3728                              <1> ;		(CX) = COUNT OF CHARACTERS TO WRITE				:
  3729                              <1> ;		(AL) = CHAR TO WRITE						:
  3730                              <1> ;		       NOTE: USE FUNCTION (AH)= 09H IN GRAPHICS MODES		:
  3731                              <1> ;	FOR READ/WRITE CHARACTER INTERFACE WHILE IN GRAPHICS MODE, THE		:
  3732                              <1> ;		CHARACTERS ARE FORMED FROM A CHARACTER GENERATOR IMAGE		:
  3733                              <1> ;		MAINTAINED IN THE SYSTEM ROM. ONLY THE 1ST 128 CHARS		:
  3734                              <1> ;		ARE CONTAINED THERE. TO READ/WRITE THE SECOND 128 CHARS,	:
  3735                              <1> ;		THE USER MUST INITIALIZE THE POINTER AT INTERRUPT 1FH		:
  3736                              <1> ;		(LOCATION 0007CH) TO POINT TO THE 1K BYTE TABLE CONTAINING	:
  3737                              <1> ;		THE CODE POINTS FOR THE SECOND 128 CHARS (128-255).		:
  3738                              <1> ;	FOR WRITE CHARACTER INTERFACE IN GRAPHICS MODE, THE REPLICATION FACTOR	:
  3739                              <1> ;		CONTAINED IN (CX) ON ENTRY WILL PRODUCE VALID RESULTS ONLY	:
  3740                              <1> ;		FOR CHARACTERS CONTAINED ON THE SAME ROW. CONTINUATION TO	:
  3741                              <1> ;		SUCCEEDING LINES WILL NOT PRODUCE CORRECTLY.			:
  3742                              <1> ;										:
  3743                              <1> ;    GRAPHICS INTERFACE								:
  3744                              <1> ;    (AH)= 0BH	SET COLOR PALETTE						:
  3745                              <1> ;		(BH) = PALETTE COLOR ID BEING SET (0-127)			:
  3746                              <1> ;		(BL) = COLOR VALUE TO BE USED WITH THAT COLOR ID		:
  3747                              <1> ;		       NOTE: FOR THE CURRENT COLOR CARD, THIS ENTRY POINT HAS	:
  3748                              <1> ;		               MEANING ONLY FOR 320X200 GRAPHICS.		:
  3749                              <1> ;		       COLOR ID = 0 SELECTS THE BACKGROUND COLOR (0-15)		:
  3750                              <1> ;		       COLOR ID = 1 SELECTS THE PALETTE TO BE USED:		:
  3751                              <1> ;		               0 = GREEN(1)/RED(2)/YELLOW(3)			:
  3752                              <1> ;		               1 = CYAN(1)/MAGENTA(2)/WHITE(3)			:
  3753                              <1> ;		       IN 40X25 OR 80X25 ALPHA MODES, THE VALUE SET FOR 	:
  3754                              <1> ;		               PALETTE COLOR 0 INDICATES THE BORDER COLOR	:
  3755                              <1> ;		               TO BE USED (VALUES 0-31, WHERE 16-31 SELECT	:
  3756                              <1> ;		               THE HIGH INTENSITY BACKGROUND SET.		:
  3757                              <1> ;    (AH)= 0CH	WRITE DOT							:
  3758                              <1> ;		(DX) = ROW NUMBER						:
  3759                              <1> ;		(CX) = COLUMN NUMBER						:
  3760                              <1> ;		(AL) = COLOR VALUE						:
  3761                              <1> ;		        IF BIT 7 OF AL = 1, THEN THE COLOR VALUE IS EXCLUSIVE	:
  3762                              <1> ;		        ORed WITH THE CURRENT CONTENTS OF THE DOT		:
  3763                              <1> ;    (AH)= ODH	READ DOT							:
  3764                              <1> ;		(DX) = ROW NUMBER						:
  3765                              <1> ;		(CX) = COLUMN NUMBER						:
  3766                              <1> ;		(AL) = RETURNS THE DOT READ					:
  3767                              <1> ;										:
  3768                              <1> ;    ASCII TELETYPE ROUTINE FOR OUTPUT						:
  3769                              <1> ;										:
  3770                              <1> ;    (AH)= 0EH	WRITE TELETYPE TO ACTIVE PAGE					:
  3771                              <1> ;		(AL) = CHAR TO WRITE						:
  3772                              <1> ;		(BL) = FOREGROUND COLOR IN GRAPHICS MODE			:
  3773                              <1> ;		NOTE -- SCREEN WIDTH IS CONTROLLED BY PREVIOUS MODE SET		:
  3774                              <1> ;    (AH)= 0FH	CURRENT VIDEO STATE						:
  3775                              <1> ;		RETURNS THE CURRENT VIDEO STATE					:
  3776                              <1> ;		(AL) = MODE CURRENTLY SET ( SEE (AH)=00H FOR EXPLANATION)	:
  3777                              <1> ;		(AH) = NUMBER OR CHARACTER COLUMNS ON SCREEN			:
  3778                              <1> ;		(BH) = CURRENT ACTIVE DISPLAY PAGE				:
  3779                              <1> ;    (AH)= 10H	RESERVED							:
  3780                              <1> ;    (AH)= 11H	RESERVED							:
  3781                              <1> ;    (AH)= 12H	RESERVED							:
  3782                              <1> ;    (AH)= 13H	WRITE STRING							:
  3783                              <1> ;			ES:BP  -  POINTER T0 STRING TO BE WRITTEN		:
  3784                              <1> ;			CX     -  LENGTH OF CHARACTER STRING TO WRITTEN		:
  3785                              <1> ;			DX     -  CURSOR POSITION FOR STRING TO BE WRITTEN	:
  3786                              <1> ;			BH     -  PAGE NUMBER					:
  3787                              <1> ;		(AL)= 00H	WRITE CHARACTER STRING				:
  3788                              <1> ;			BL     -  ATTRIBUTE					:
  3789                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
  3790                              <1> ;			CURSOR NOT MOVED					:
  3791                              <1> ;		(AL)= 01H	WRITE CHARACTER STRING AND MOVE CURSOR		:
  3792                              <1> ;			BL     -  ATTRIBUTE					:
  3793                              <1> ;			STRING IS  <CHAR,CHAR, ... ,CHAR>			:
  3794                              <1> ;			CURSOR MOVED						:
  3795                              <1> ;		(AL)= 02H	WRITE CHARACTER AND ATTRIBUTE STRING		:
  3796                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
  3797                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
  3798                              <1> ;			CURSOR IS NOT MOVED					:
  3799                              <1> ;		(AL)= 03H WRITE CHARACTER AND ATTRIBUTE STRING AND MOVE CURSOR	:
  3800                              <1> ;			       (VALID FOR ALPHA MODES ONLY)			:
  3801                              <1> ;			STRING IS <CHAR,ATTR,CHAR,ATTR ..  ,CHAR,ATTR>		:
  3802                              <1> ;			CURSOR IS MOVED						:
  3803                              <1> ;		 NOTE:  CARRIAGE RETURN, LINE FEED, BACKSPACE, AND BELL ARE	:
  3804                              <1> ;		        TREATED AS COMMANDS RATHER THAN PRINTABLE CHARACTERS.	:
  3805                              <1> ;										:
  3806                              <1> ;	BX,CX,DX,SI,DI,BP,SP,DS,ES,SS PRESERVED DURING CALLS EXCEPT FOR		:
  3807                              <1> ;	BX,CX,DX RETURN VALUES ON FUNCTIONS 03H,04H,0DH AND 0FH. ON ALL CALLS	:
  3808                              <1> ;	AX IS MODIFIED.								:
  3809                              <1> ;--------------------------------------------------------------------------------
  3810                              <1> 
  3811 00001450 [EB140000]          <1> M1:	dd	SET_MODE	; TABLE OF ROUTINES WITHIN VIDEO I/O
  3812 00001454 [4B150000]          <1> 	dd	SET_CTYPE
  3813 00001458 [60150000]          <1> 	dd	SET_CPOS
  3814 0000145C [67150000]          <1> 	dd	READ_CURSOR
  3815 00001460 [F0140000]          <1> 	dd	VIDEO_RETURN	; READ_LPEN
  3816 00001464 [89150000]          <1> 	dd	ACT_DISP_PAGE
  3817 00001468 [02160000]          <1> 	dd	SCROLL_UP
  3818 0000146C [E6160000]          <1> 	dd	SCROLL_DOWN
  3819 00001470 [31170000]          <1> 	dd	READ_AC_CURRENT
  3820 00001474 [5F170000]          <1> 	dd	WRITE_AC_CURRENT
  3821 00001478 [72170000]          <1> 	dd	WRITE_C_CURRENT
  3822 0000147C [F0140000]          <1> 	dd	VIDEO_RETURN	; SET_COLOR
  3823 00001480 [F0140000]          <1> 	dd	VIDEO_RETURN	; WRITE_DOT
  3824 00001484 [F0140000]          <1> 	dd	VIDEO_RETURN	; READ_DOT
  3825 00001488 [B6170000]          <1> 	dd	WRITE_TTY
  3826 0000148C [D8140000]          <1> 	dd	VIDEO_STATE
  3827 00001490 [F0140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3828 00001494 [F0140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3829 00001498 [F0140000]          <1> 	dd	VIDEO_RETURN	; RESERVED
  3830 0000149C [F0140000]          <1> 	dd	VIDEO_RETURN	; WRITE_STRING
  3831                              <1> M1L	EQU	$ - M1
  3832                              <1> 
  3833                              <1> VIDEO_IO_1:
  3834 000014A0 FB                  <1> 	sti				; INTERRUPTS BACK ON
  3835 000014A1 FC                  <1> 	cld				; SET DIRECTION FORWARD
  3836 000014A2 80FC14              <1> 	cmp	ah, M1L/4		; TEST FOR WITHIN TABLE RANGE
  3837 000014A5 7320                <1> 	jnb	short M4		; BRANCH TO EXIT IF NOT A VALID COMMAND
  3838                              <1> 
  3839 000014A7 06                  <1> 	push	es
  3840 000014A8 1E                  <1> 	push	ds			; SAVE WORK AND PARAMETER REGISTERS
  3841 000014A9 52                  <1> 	push	edx
  3842 000014AA 51                  <1> 	push	ecx
  3843 000014AB 53                  <1> 	push	ebx
  3844 000014AC 56                  <1> 	push	esi
  3845 000014AD 57                  <1> 	push	edi
  3846 000014AE 55                  <1> 	push	ebp
  3847 000014AF 66BE1000            <1> 	mov	si, KDATA 		; POINT DS: TO DATA SEGMENT
  3848 000014B3 8EDE                <1> 	mov	ds, si
  3849 000014B5 8EC6                <1> 	mov	es, si
  3850 000014B7 BF00800B00          <1> 	mov	edi, 0B8000h		; GET offset FOR COLOR CARD
  3851 000014BC D0E4                <1> 	shl	ah, 1			; TIMES 2 FOR WORD TABLE LOOKUP
  3852 000014BE 0FB6F4              <1> 	movzx	esi, ah			; MOVE OFFSET INTO LOOK UP REGISTER (SI)
  3853                              <1> 	;mov	ah, [CRT_MODE]		; MOVE CURRENT MODE INTO (AH) REGISTER
  3854                              <1> 
  3855 000014C1 FFA6[50140000]      <1> 	JMP	dword [esi+M1]		; GO TO SELECTED FUNCTION
  3856                              <1> 
  3857                              <1> M4:					;	COMMAND NOT VALID
  3858 000014C7 CF                  <1> 	iret				; DO NOTHING IF NOT IN VALID RANGE
  3859                              <1> 
  3860                              <1> 
  3861                              <1> ; 02/09/2014 (Retro UNIX 386 v1)
  3862                              <1> ;
  3863                              <1> ; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3864                              <1> 
  3865                              <1> set_mode_3:  	; will be called from 'write_tty' 
  3866 000014C8 53                  <1> 	push	ebx
  3867 000014C9 52                  <1> 	push	edx
  3868 000014CA 50                  <1> 	push	eax
  3869 000014CB 57                  <1> 	push	edi
  3870 000014CC 51                  <1> 	push	ecx
  3871 000014CD E827000000          <1> 	call	set_txt_mode
  3872 000014D2 59                  <1> 	pop	ecx
  3873 000014D3 5F                  <1> 	pop	edi
  3874 000014D4 58                  <1> 	pop	eax
  3875 000014D5 5A                  <1> 	pop	edx
  3876 000014D6 5B                  <1> 	pop	ebx
  3877 000014D7 C3                  <1> 	retn
  3878                              <1> 
  3879                              <1> VIDEO_STATE:
  3880                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3881                              <1> 
  3882                              <1> ;---------------------------------------------------
  3883                              <1> ; VIDEO STATE
  3884                              <1> ;  RETURNS THE CURRENT VIDEO STATE IN AX
  3885                              <1> ;  AH = NUMBER OF COLUMNS ON THE SCREEN
  3886                              <1> ;  AL = CURRENT VIDEO MODE
  3887                              <1> ;  BH = CURRENT ACTIVE PAGE
  3888                              <1> ;---------------------------------------------------
  3889                              <1> 
  3890                              <1> 	;mov	ah, [CRT_COLS]	; GET NUMBER OF COLUMNS
  3891 000014D8 B480                <1> 	mov	ah, 80h
  3892 000014DA A0[769C0000]        <1> 	mov	al, [CRT_MODE]	; CURRENT MODE
  3893                              <1> 	;movzx	esi, al
  3894                              <1> 	;mov	ah, [esi+M6] 
  3895                              <1> 	; BL = active page (not BH!)
  3896 000014DF 8A1D[78A20000]      <1> 	mov	bl, [ACTIVE_PAGE] ; GET CURRENT ACTIVE PAGE
  3897 000014E5 5D                  <1> 	pop	ebp		; RECOVER REGISTERS
  3898 000014E6 5F                  <1> 	pop	edi
  3899 000014E7 5E                  <1> 	pop	esi
  3900 000014E8 59                  <1> 	pop	ecx	; DISCARD SAVED BX
  3901 000014E9 EB09                <1> 	jmp	short M15	; RETURN TO CALLER
  3902                              <1> 
  3903                              <1> SET_MODE:
  3904                              <1> 	; For 32 bit TRDOS and Retro UNIX 386:
  3905                              <1> 	;	valid video mode: 03h only!
  3906                              <1> 	;	(VGA modes will be selected with another routine)
  3907                              <1> 	;
  3908                              <1> 	; set_txt_mode ; 80*25 (16 fore colors, 8 back colors)
  3909                              <1> 
  3910                              <1> ;------------------------------------------------------
  3911                              <1> ; SET MODE					      :
  3912                              <1> ;	THIS ROUTINE INITIALIZES THE ATTACHMENT TO    :
  3913                              <1> ;	THE SELECTED MODE, THE SCREEN IS BLANKED.     :
  3914                              <1> ; INPUT						      :
  3915                              <1> ;	(AL) - MODE SELECTED (RANGE 0-7)	      :
  3916                              <1> ; OUTPUT					      :
  3917                              <1> ;	NONE					      :
  3918                              <1> ;------------------------------------------------------
  3919                              <1> 
  3920 000014EB E809000000          <1> 	call	set_txt_mode
  3921                              <1> 
  3922                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3923                              <1> 
  3924                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  3925                              <1> 
  3926                              <1> VIDEO_RETURN:
  3927 000014F0 5D                  <1> 	pop	ebp
  3928 000014F1 5F                  <1> 	pop	edi
  3929 000014F2 5E                  <1> 	pop	esi
  3930 000014F3 5B                  <1> 	pop	ebx
  3931                              <1> M15:			;VIDEO_RETURN_C
  3932 000014F4 59                  <1> 	pop	ecx
  3933 000014F5 5A                  <1> 	pop	edx
  3934 000014F6 1F                  <1> 	pop	ds
  3935 000014F7 07                  <1> 	pop	es	; RECOVER SEGMENTS
  3936 000014F8 CF                  <1> 	iret		; ALL DONE
  3937                              <1> 
  3938                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3939                              <1> set_txt_mode:
  3940                              <1> 	;mov	dx, 03D4h 	; address of color card
  3941 000014F9 B003                <1> 	mov	al, 3
  3942                              <1> ;M8:
  3943 000014FB A2[769C0000]        <1> 	mov	[CRT_MODE], al  ; save mode in global variable
  3944 00001500 B029                <1> 	mov	al, 29h
  3945                              <1> 	;mov	[CRT_MODE_SET], al ; save the mode set value
  3946 00001502 2437                <1> 	and	al, 037h	; video off, save high resolution bit	
  3947                              <1> 	;push	dx  		; save port value
  3948                              <1> 	;add	dx, 4		; point to control register
  3949 00001504 66BAD803            <1> 	mov	dx, 3D8h
  3950 00001508 EE                  <1> 	out	dx, al		; reset video to off to suppress rolling
  3951                              <1> 	;pop	dx
  3952                              <1> ;M9:
  3953 00001509 BB[789C0000]        <1> 	mov	ebx, video_params ; initialization table
  3954 0000150E 668B430A            <1> 	mov	ax, [ebx+10]      ; get the cursor mode from the table	
  3955 00001512 86E0                <1> 	xchg 	ah, al
  3956 00001514 66A3[66A20000]      <1> 	mov	[CURSOR_MODE], ax ; save cursor mode
  3957 0000151A 30E4                <1> 	xor	ah, ah		  ; ah is register number during loop 
  3958                              <1> 	
  3959                              <1> ;-----	LOOP THROUGH TABLE, OUTPUTTING REGISTER ADDRESS, THEN VALUE FROM TABLE
  3960 0000151C B910000000          <1> 	mov	ecx, 16 ; 16/01/2016
  3961                              <1> M10:			;  initialization loop
  3962 00001521 88E0                <1> 	mov	al, ah 	; get 6845 register number
  3963 00001523 EE                  <1> 	out	dx, al
  3964 00001524 6642                <1> 	inc	dx      ; point to data port
  3965 00001526 FEC4                <1> 	inc	ah	; next register value
  3966 00001528 8A03                <1> 	mov	al, [ebx] ; get table value
  3967 0000152A EE                  <1> 	out	dx, al	; out to chip
  3968 0000152B 43                  <1> 	inc	ebx	; next in table
  3969 0000152C 664A                <1> 	dec	dx	; back to pointer register
  3970 0000152E E2F1                <1> 	loop	M10	; do the whole table
  3971                              <1> 
  3972                              <1> ;-----	FILL REGEN AREA WITH BLANK
  3973                              <1> 	;xor	ax, ax  
  3974                              <1> 	;mov	[CRT_START], ax  ; start address saved in global
  3975                              <1> 	;mov	[ACTIVE_PAGE], al ; 0 ; (re)set page value
  3976                              <1> 	;mov	ecx, 8192 ; number of words in color card
  3977                              <1> 	; black background, light gray characeter color, space character
  3978                              <1> 	;mov	ax, 0720h ; fill char for alpha - attribute
  3979                              <1> ;M13:			  ; clear buffer
  3980                              <1> 	;add	edi, 0B8000h ; [crt_base]
  3981                              <1> 	;rep	stosw	; FILL THE REGEN BUFFER WITH BLANKS
  3982                              <1> 
  3983                              <1> ;-----	ENABLE VIDEO AND CORRECT PORT SETTING
  3984                              <1> 	;mov	dx, 3D4h ; mov dx, word [ADDR_6845]
  3985                              <1> 			 ; prepare to output to video enable port
  3986                              <1> 	;add	dx,4	 ; point to the mode control gerister
  3987 00001530 66BAD803            <1> 	mov	dx, 3D8h
  3988                              <1> 	;mov	al, [CRT_MODE_SET] ; get the mode set value
  3989 00001534 B029                <1> 	mov	al, 29h
  3990 00001536 EE                  <1> 	out	dx, al	 ; set video enable port
  3991                              <1> 
  3992                              <1> ;----- 	DETERMINE NUMBER OF COLUMNS, BOTH FOR ENTIRE DISPLAY
  3993                              <1> ;----- 	AND THE NUMBER TO BE USED FOR TTY INTERFACE
  3994                              <1> 	;
  3995                              <1> 	;mov	byte [CRT_COLS], 80h ; initialize number of columns count
  3996                              <1> 	;
  3997                              <1> ;-----	SET CURSOR POSITIONS
  3998                              <1> 	;mov	word [CRT_LEN], 80*25*2
  3999 00001537 BF[68A20000]        <1> 	mov	edi, CURSOR_POSN
  4000 0000153C B904000000          <1> 	mov	ecx, 4	; clear all cursor positions (16 bytes)
  4001 00001541 31C0                <1> 	xor	eax, eax
  4002 00001543 F3AB                <1> 	rep 	stosd	; fill with zeroes
  4003                              <1> 
  4004                              <1> ;-----	SET UP OVERSCAN REGISTER
  4005 00001545 6642                <1> 	inc	dx	; set overscan port to a default
  4006 00001547 B030                <1> 	mov	al, 30h	; 30H value for all modes except 640X200 bw
  4007                              <1> ;M14:
  4008 00001549 EE                  <1> 	out	dx, al	; output the correct value to 3D9 port
  4009                              <1> 	;mov	[CRT_PALETTE], al ; save the value for future use
  4010                              <1> 
  4011                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  4012 0000154A C3                  <1> 	retn
  4013                              <1> 
  4014                              <1> SET_CTYPE:
  4015                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4016 0000154B E802000000          <1> 	call	_set_ctype
  4017 00001550 EB9E                <1> 	jmp	short VIDEO_RETURN
  4018                              <1> 
  4019                              <1> _set_ctype:
  4020                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
  4021                              <1> 	;
  4022                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4023                              <1> 
  4024                              <1> 	; (CH) = BITS 4-0 = START LINE FOR CURSOR
  4025                              <1> 	;  ** HARDWARE WILL ALWAYS CAUSE BLINK
  4026                              <1> 	;  ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING
  4027                              <1> 	;     OR NO CURSOR AT ALL
  4028                              <1> 	; (CL) = BITS 4-0 = END LINE FOR CURSOR
  4029                              <1> 
  4030                              <1> ;------------------------------------------------
  4031                              <1> ; SET_CTYPE
  4032                              <1> ;	THIS ROUTINE SETS THE CURSOR VALUE
  4033                              <1> ; INPUT
  4034                              <1> ;	(CX) HAS CURSOR VALUE CH-START LINE, CL-STOP LINE
  4035                              <1> ; OUTPUT	
  4036                              <1> ;	NONE
  4037                              <1> ;------------------------------------------------
  4038                              <1> 
  4039 00001552 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  4040 00001554 66890D[66A20000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
  4041                              <1> 	;call	m16	; output cx register
  4042                              <1> 	;retn
  4043 0000155B E915030000          <1>         jmp     m16
  4044                              <1> 
  4045                              <1> SET_CPOS:
  4046                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4047 00001560 E8E5020000          <1> 	call	_set_cpos
  4048 00001565 EB89                <1> 	jmp	short VIDEO_RETURN
  4049                              <1> 
  4050                              <1> READ_CURSOR:
  4051                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4052                              <1> 	;
  4053                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4054                              <1> 
  4055                              <1> ;------------------------------------------------------
  4056                              <1> ; READ_CURSOR
  4057                              <1> ;	THIS ROUTINE READS THE CURRENT CURSOR VALUE FROM THE
  4058                              <1> ;	845, FORMATS IT, AND SENDS IT BACK TO THE CALLER
  4059                              <1> ; INPUT
  4060                              <1> ;	BH - PAGE OF CURSOR
  4061                              <1> ; OUTPUT
  4062                              <1> ;	DX - ROW, COLUMN OF THE CURRENT CURSOR POSITION
  4063                              <1> ;	CX - CURRENT CURSOR MODE
  4064                              <1> ;------------------------------------------------------
  4065                              <1> 
  4066                              <1> 	; BL = Video page number (0 to 7)
  4067                              <1> 	
  4068                              <1> 
  4069 00001567 E810000000          <1> 	call	get_cpos
  4070 0000156C 0FB70D[66A20000]    <1> 	movzx	ecx, word [CURSOR_MODE]
  4071                              <1> 
  4072 00001573 5D                  <1> 	pop	ebp
  4073 00001574 5F                  <1> 	pop	edi
  4074 00001575 5E                  <1> 	pop	esi
  4075 00001576 5B                  <1> 	pop	ebx
  4076 00001577 58                  <1> 	pop	eax	; DISCARD SAVED CX AND DX
  4077 00001578 58                  <1> 	pop	eax
  4078 00001579 1F                  <1> 	pop	ds
  4079 0000157A 07                  <1> 	pop	es
  4080 0000157B CF                  <1> 	iret
  4081                              <1> 
  4082                              <1> get_cpos:
  4083                              <1> 	; 16/01/2016
  4084                              <1> 	; BL = Video page number (0 to 7)
  4085                              <1> 	;
  4086 0000157C D0E3                <1> 	shl	bl, 1 ; WORD OFFSET
  4087 0000157E 0FB6F3              <1> 	movzx	esi, bl 
  4088 00001581 0FB796[68A20000]    <1> 	movzx	edx, word [esi+CURSOR_POSN]
  4089 00001588 C3                  <1> 	retn
  4090                              <1> 
  4091                              <1> ACT_DISP_PAGE:
  4092                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4093                              <1> 	;
  4094                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4095                              <1> 	;
  4096                              <1> ;-----------------------------------------------------
  4097                              <1> ; ACT_DISP_PAGE
  4098                              <1> ;	THIS ROUTINE SETS THE ACTIVE DISPLAY PAGE, ALLOWING
  4099                              <1> ;	THE FULL USE OF THE MEMORY SET ASIDE FOR THE VIDEO ATTACHMENT
  4100                              <1> ; INPUT
  4101                              <1> ;	AL HAS THE NEW ACTIVE DISPLAY PAGE
  4102                              <1> ; OUTPUT
  4103                              <1> ;	THE 6845 IS RESET TO DISPLAY THAT PAGE
  4104                              <1> ;-----------------------------------------------------
  4105                              <1> 
  4106 00001589 E805000000          <1> 	call	set_active_page
  4107 0000158E E95DFFFFFF          <1>         jmp     VIDEO_RETURN
  4108                              <1> 
  4109                              <1> set_active_page:   ; tty_sw
  4110                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4111                              <1> 	; 30/06/2015
  4112                              <1> 	; 04/03/2014  (act_disp_page --> tty_sw)
  4113                              <1> 	; 10/12/2013
  4114                              <1> 	; 04/12/2013
  4115                              <1> 	;
  4116 00001593 A2[78A20000]        <1> 	mov	[ACTIVE_PAGE], al ; save active page value ; [ptty]
  4117                              <1> 	;mov	cx, [CRT_LEN] ; get saved length of regen buffer
  4118 00001598 66B9A00F            <1> 	mov	cx, 25*80*2
  4119                              <1> 	; 27/06/2015
  4120 0000159C 0FB6D8              <1> 	movzx	ebx, al
  4121                              <1> 	;
  4122 0000159F 6698                <1> 	cbw	; 07/09/2014 (ah=0)
  4123 000015A1 66F7E1              <1> 	mul 	cx	; display page times regen length
  4124                              <1> 	; 10/12/2013
  4125 000015A4 66A3[64A20000]      <1> 	mov	[CRT_START], ax ; save start address for later
  4126 000015AA 6689C1              <1> 	mov	cx, ax ; start address to cx
  4127                              <1> 	;sar	cx, 1
  4128 000015AD 66D1E9              <1> 	shr	cx, 1	; divide by 2 for 6845 handling
  4129 000015B0 B40C                <1> 	mov	ah, 12	; 6845 register for start address
  4130 000015B2 E8BE020000          <1> 	call	m16
  4131                              <1> 	;sal	bx, 1
  4132                              <1> 	; 01/09/2014
  4133 000015B7 D0E3                <1> 	shl	bl, 1	; *2 for word offset
  4134 000015B9 81C3[68A20000]      <1> 	add	ebx, CURSOR_POSN
  4135 000015BF 668B13              <1> 	mov	dx, [ebx] ; get cursor for this page
  4136                              <1> 	; 16/01/2016
  4137                              <1> 	;call	m18
  4138                              <1> 	;retn
  4139 000015C2 E99A020000          <1> 	jmp	m18
  4140                              <1> 
  4141                              <1> position:
  4142                              <1> 	; 27/06/2015
  4143                              <1> 	; 02/09/2014
  4144                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4145                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1)
  4146                              <1> 	;
  4147                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4148                              <1> 	;
  4149                              <1> ;-----------------------------------------
  4150                              <1> ; POSITION
  4151                              <1> ;	THIS SERVICE ROUTINE CALCULATES THE REGEN BUFFER ADDRESS
  4152                              <1> ;	OF A CHARACTER IN THE ALPHA MODE
  4153                              <1> ; INPUT
  4154                              <1> ;	AX = ROW, COLUMN POSITION
  4155                              <1> ; OUTPUT
  4156                              <1> ;	AX = OFFSET OF CHAR POSITION IN REGEN BUFFER
  4157                              <1> ;-----------------------------------------
  4158                              <1> 
  4159                              <1> 		; DX = ROW, COLUMN POSITION
  4160                              <1> 	;movzx	eax, byte [CRT_COLS] ; 27/06/2015
  4161 000015C7 31C0                <1> 	xor	eax, eax ; 02/09/2014
  4162 000015C9 B050                <1> 	mov	al, 80   ; determine bytes to row	
  4163 000015CB F6E6                <1> 	mul	dh	 ; row value
  4164 000015CD 30F6                <1> 	xor	dh, dh   ; 0	
  4165 000015CF 6601D0              <1> 	add	ax, dx	 ; add column value to the result
  4166 000015D2 66D1E0              <1> 	shl	ax, 1	; * 2 for attribute bytes
  4167                              <1> 		; EAX = AX = OFFSET OF CHAR POSITION IN REGEN BUFFER 
  4168 000015D5 C3                  <1> 	retn
  4169                              <1> 
  4170                              <1> find_position:
  4171                              <1> 	; 27/06/2015
  4172                              <1> 	; 07/09/2014
  4173                              <1> 	; 02/09/2014
  4174                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4175                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4176 000015D6 0FB6CB              <1> 	movzx	ecx, bl ; video page number ; 27/06/2015 (movzx)
  4177 000015D9 89CE                <1> 	mov	esi, ecx
  4178 000015DB 66D1E6              <1> 	shl	si, 1
  4179 000015DE 668B96[68A20000]    <1> 	mov	dx, [esi + CURSOR_POSN]
  4180 000015E5 740A                <1> 	jz	short p21
  4181 000015E7 6631F6              <1> 	xor	si, si
  4182                              <1> p20:
  4183                              <1> 	;add	si, [CRT_LEN]
  4184 000015EA 6681C6A00F          <1> 	add	si, 80*25*2 ; add length of buffer for one page		
  4185 000015EF E2F9                <1> 	loop	p20
  4186                              <1> p21:
  4187 000015F1 6621D2              <1> 	and	dx, dx
  4188 000015F4 7407                <1> 	jz	short p22
  4189 000015F6 E8CCFFFFFF          <1> 	call 	position ; determine location in regen in page
  4190 000015FB 01C6                <1> 	add	esi, eax ; add location to start of regen page
  4191                              <1> p22:	
  4192                              <1> 	;mov	dx, [addr_6845] ; get base address of active display			
  4193                              <1> 	;mov	dx, 03D4h ; I/O address of color card
  4194                              <1> 	;add	dx, 6	; point at status port
  4195 000015FD 66BADA03            <1> 	mov	dx, 03DAh ; status port
  4196                              <1> 	; cx = 0
  4197 00001601 C3                  <1> 	retn
  4198                              <1> 
  4199                              <1> SCROLL_UP:
  4200                              <1> 	; 30/01/2016
  4201                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4202                              <1> 	; 07/09/2014
  4203                              <1> 	; 02/09/2014
  4204                              <1> 	; 01/09/2014 (Retro UNIX 386 v1 - beginning)
  4205                              <1> 	; 04/04/2014
  4206                              <1> 	; 04/12/2013
  4207                              <1> 	;
  4208                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4209                              <1> 	;
  4210                              <1> ;----------------------------------------------
  4211                              <1> ; SCROLL UP
  4212                              <1> ;	THIS ROUTINE MOVES A BLOCK OF CHARACTERS UP
  4213                              <1> ;	ON THE SCREEN
  4214                              <1> ; INPUT
  4215                              <1> ;	(AH) = CURRENT CRT MODE
  4216                              <1> ;	(AL) = NUMBER OF ROWS TO SCROLL
  4217                              <1> ;	(CX) = ROW/COLUMN OF UPPER LEFT CORNER
  4218                              <1> ;	(DX) = ROW/COLUMN OF LOWER RIGHT CORNER
  4219                              <1> ;	(BH) = ATTRIBUTE TO BE USED ON BLANKED LINE
  4220                              <1> ;	(DS) = DATA SEGMENT
  4221                              <1> ;	(ES) = REGEN BUFFER SEGMENT
  4222                              <1> ; OUTPUT
  4223                              <1> ;	NONE -- THE REGEN BUFFER IS MODIFIED
  4224                              <1> ;--------------------------------------------
  4225                              <1> 
  4226 00001602 E805000000          <1> 	call	_scroll_up
  4227 00001607 E9E4FEFFFF          <1>         jmp     VIDEO_RETURN
  4228                              <1> 
  4229                              <1> _scroll_up:  ; from 'write_tty'
  4230                              <1> 	;
  4231                              <1> 	; ((ah = 3))
  4232                              <1> 	; cl = left upper column
  4233                              <1> 	; ch = left upper row
  4234                              <1> 	; dl = right lower column
  4235                              <1> 	; dh = right lower row
  4236                              <1> 	;
  4237                              <1> 	; al = line count 
  4238                              <1> 	; ah = attribute to be used on blanked line	
  4239                              <1> 	; bl = video page number (0 to 7)
  4240                              <1> 	; 
  4241                              <1> 
  4242 0000160C E86C000000          <1> 	call	test_line_count ; 16/01/2016
  4243                              <1> 
  4244                              <1> 	;mov	bh, [CRT_MODE] ; current video mode	
  4245                              <1> 	;cmp	bh, 4
  4246                              <1>  	;jb	short n1
  4247                              <1> 
  4248                              <1> 	;cmp	bh, 7 ; TEST FOR BW CARD
  4249                              <1> 	;jne	GRAPHICS_UP
  4250                              <1> n1:
  4251 00001611 30FF                <1> 	xor	bh, bh	; 0
  4252 00001613 6650                <1> 	push	ax ; *
  4253                              <1> 	;mov 	esi, [CRT_BASE]
  4254 00001615 BE00800B00          <1>         mov     esi, 0B8000h  
  4255 0000161A 3A1D[78A20000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4256 00001620 750B                <1> 	jne	short n2
  4257                              <1> 	;
  4258 00001622 66A1[64A20000]      <1>         mov     ax, [CRT_START]
  4259 00001628 6601C6              <1>         add     si, ax
  4260 0000162B EB0F                <1>         jmp     short n4
  4261                              <1> n2:
  4262 0000162D 20DB                <1>         and     bl, bl
  4263 0000162F 740B                <1> 	jz	short n4
  4264 00001631 88D8                <1> 	mov	al, bl
  4265                              <1> n3:
  4266                              <1>         ;add    si, [CRT_LEN]
  4267                              <1>         ;add    esi, 80*25*2 
  4268 00001633 6681C6A00F          <1>         add     si, 80*25*2
  4269 00001638 FEC8                <1>         dec	al
  4270 0000163A 75F7                <1> 	jnz	short n3
  4271                              <1> n4:	
  4272 0000163C E84D000000          <1> 	call	scroll_position ; 16/01/2016
  4273 00001641 7419                <1>         jz      short n6 
  4274                              <1> 
  4275 00001643 01CE                <1>         add     esi, ecx ; from address for scroll
  4276 00001645 88F7                <1> 	mov	bh, dh  ; #rows in block
  4277 00001647 28C7                <1> 	sub	bh, al	; #rows to be moved
  4278                              <1> n5:
  4279 00001649 E880000000          <1> 	call	n10 ; 16/01/2016
  4280                              <1> 	
  4281                              <1>         ;mov    cl, [CRT_COLS] 
  4282                              <1> 	;add	cl, cl
  4283                              <1>         ;mov    ecx, 80*2
  4284 0000164E 66B9A000            <1>         mov     cx, 80*2
  4285 00001652 01CE                <1>         add     esi, ecx  ; next line
  4286 00001654 01CF                <1>         add     edi, ecx
  4287 00001656 FECF                <1> 	dec	bh	 ; count of lines to move
  4288 00001658 75EF                <1> 	jnz	short n5 ; row loop
  4289                              <1> 	; bh = 0
  4290 0000165A 88C6                <1> 	mov	dh, al	 ; #rows	
  4291                              <1> n6:
  4292                              <1> 	; attribute in ah
  4293 0000165C B020                <1> 	mov	al, ' '	 ; fill with blanks
  4294                              <1> n7:
  4295 0000165E E878000000          <1> 	call	n11 ; 16/01/2016
  4296                              <1> 
  4297                              <1> 	;mov	cl, [CRT_COLS]
  4298                              <1> 	;add	cl, cl
  4299                              <1>         ;mov    ecx, 80*2
  4300 00001663 66B9A000            <1>         mov	cx, 80*2
  4301 00001667 01CF                <1>         add     edi, ecx
  4302 00001669 FECE                <1> 	dec	dh
  4303 0000166B 75F1                <1> 	jnz	short n7
  4304                              <1> 	;
  4305 0000166D 3A1D[78A20000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4306 00001673 7507                <1> 	jne	short n8
  4307                              <1> 	;mov	al, [CRT_MODE_SET] ; get the value of mode set
  4308 00001675 B029                <1> 	mov	al, 29h ; (ORGS.ASM), M7 mode set table value for mode 3	
  4309 00001677 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  4310 0000167B EE                  <1> 	out	dx, al
  4311                              <1> n8:
  4312 0000167C C3                  <1> 	retn
  4313                              <1> 
  4314                              <1> 
  4315                              <1> test_line_count:
  4316                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4317                              <1> 	; 07/09/2014 (scroll_up)
  4318 0000167D 08C0                <1> 	or	al, al
  4319 0000167F 740C                <1> 	jz	short al_set
  4320 00001681 88F7                <1> 	mov	bh, dh	; subtract lower row from upper row
  4321 00001683 28EF                <1> 	sub	bh, ch
  4322 00001685 FEC7                <1> 	inc	bh	; adjust difference by 1
  4323 00001687 38C7                <1> 	cmp	bh, al 	; line count = amount of rows in window?
  4324 00001689 7502                <1> 	jne	short al_set ; if not the we're all set
  4325 0000168B 30C0                <1> 	xor	al, al	; otherwise set al to zero
  4326                              <1> al_set:
  4327 0000168D C3                  <1> 	retn
  4328                              <1> 
  4329                              <1> scroll_position:
  4330                              <1> 	; 30/01/2016
  4331                              <1>         ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4332                              <1> 	; 07/09/2014 (scroll_up)
  4333                              <1> 
  4334 0000168E 6652                <1> 	push	dx
  4335 00001690 6689CA              <1> 	mov	dx, cx	; now, upper left position in DX
  4336 00001693 E82FFFFFFF          <1> 	call	position
  4337 00001698 01C6                <1> 	add	esi, eax
  4338 0000169A 89F7                <1> 	mov	edi, esi
  4339 0000169C 665A                <1> 	pop	dx	; lower right position in DX
  4340 0000169E 6629CA              <1> 	sub	dx, cx
  4341 000016A1 FEC6                <1> 	inc	dh	; dh = #rows 
  4342 000016A3 FEC2                <1> 	inc	dl	; dl = #cols in block
  4343 000016A5 59                  <1> 	pop	ecx 	; return address
  4344 000016A6 6658                <1> 	pop	ax	; * ; al = line count, ah = attribute
  4345 000016A8 51                  <1> 	push	ecx	; return address
  4346 000016A9 0FB7C8              <1> 	movzx	ecx, ax
  4347                              <1> 	;mov	ah, [CRT_COLS]
  4348 000016AC B450                <1> 	mov	ah, 80
  4349 000016AE F6E4                <1> 	mul	ah	; determine offset to from address
  4350 000016B0 6601C0              <1> 	add	ax, ax  ; *2 for attribute byte
  4351                              <1> 	;
  4352 000016B3 6650                <1> 	push	ax	; offset 
  4353 000016B5 6652                <1> 	push	dx
  4354                              <1> 	;
  4355                              <1> 	; 04/04/2014
  4356 000016B7 66BADA03            <1> 	mov	dx, 3DAh ; guaranteed to be color card here	
  4357                              <1> n9:                      ; wait_display_enable
  4358 000016BB EC                  <1>         in      al, dx   ; get port
  4359 000016BC A808                <1> 	test	al, RVRT ; wait for vertical retrace	
  4360 000016BE 74FB                <1> 	jz	short n9 ; wait_display_enable
  4361 000016C0 B025                <1> 	mov	al, 25h
  4362 000016C2 B2D8                <1> 	mov	dl, 0D8h ; address control port
  4363 000016C4 EE                  <1> 	out	dx, al	; turn off video during vertical retrace
  4364 000016C5 665A                <1> 	pop	dx	; #rows, #cols
  4365 000016C7 6658                <1>        	pop	ax	; offset
  4366 000016C9 6691                <1> 	xchg	ax, cx	; 
  4367                              <1> 	; ecx = offset, al = line count, ah = attribute
  4368                              <1> 	;
  4369 000016CB 08C0                <1> 	or	al, al
  4370 000016CD C3                  <1> 	retn
  4371                              <1> 
  4372                              <1> n10:
  4373                              <1> 	; Move rows
  4374 000016CE 88D1                <1> 	mov	cl, dl	; get # of cols to move
  4375 000016D0 56                  <1> 	push	esi
  4376 000016D1 57                  <1> 	push	edi	; save start address
  4377                              <1> n10r:
  4378 000016D2 66A5                <1> 	movsw		; move that line on screen
  4379 000016D4 FEC9                <1> 	dec	cl
  4380 000016D6 75FA                <1>         jnz     short n10r
  4381 000016D8 5F                  <1> 	pop	edi
  4382 000016D9 5E                  <1> 	pop	esi	; recover addresses
  4383 000016DA C3                  <1> 	retn
  4384                              <1> n11:
  4385                              <1> 	; Clear rows
  4386                              <1>                 ; dh =  #rows
  4387 000016DB 88D1                <1>         mov	cl, dl	; get # of cols to clear
  4388 000016DD 57                  <1>         push    edi     ; save address
  4389                              <1> n11r:
  4390 000016DE 66AB                <1>         stosw           ; store fill character
  4391 000016E0 FEC9                <1> 	dec	cl
  4392 000016E2 75FA                <1>         jnz     short n11r
  4393 000016E4 5F                  <1>         pop     edi     ; recover address
  4394 000016E5 C3                  <1> 	retn
  4395                              <1> 
  4396                              <1> SCROLL_DOWN:
  4397                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4398                              <1> 	;
  4399                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4400                              <1> 
  4401                              <1> ;------------------------------------------
  4402                              <1> ; SCROLL DOWN
  4403                              <1> ;	THIS ROUTINE MOVES THE CHARACTERS WITHIN A DEFINED
  4404                              <1> ;	BLOCK DOWN ON THE SCREEN, FILLING THE TOP LINES
  4405                              <1> ;	WITH A DEFINED CHARACTER
  4406                              <1> ; INPUT
  4407                              <1> ;	(AH) = CURRENT CRT MODE
  4408                              <1> ;	(AL) = NUMBER OF LINES TO SCROLL
  4409                              <1> ;	(CX) = UPPER LEFT CORNER OF RECION
  4410                              <1> ;	(DX) = LOWER RIGHT CORNER OF REGION
  4411                              <1> ;	(BH) = FILL CHARACTER
  4412                              <1> ;	(DS) = DATA SEGMENT
  4413                              <1> ;	(ES) = REGEN SEGMENT
  4414                              <1> ; OUTPUT
  4415                              <1> ;	NONE -- SCREEN IS SCROLLED
  4416                              <1> ;------------------------------------------
  4417                              <1> 
  4418                              <1> 	; ((ah = 3))
  4419                              <1> 	; cl = left upper column
  4420                              <1> 	; ch = left upper row
  4421                              <1> 	; dl = right lower column
  4422                              <1> 	; dh = right lower row
  4423                              <1> 	;
  4424                              <1> 	; al = line count 
  4425                              <1> 	; ah = attribute to be used on blanked line	
  4426                              <1> 	; bl = video page number (0 to 7)
  4427                              <1> 	; 
  4428                              <1> 
  4429                              <1> 	; !!!!
  4430 000016E6 FD                  <1> 	std		; DIRECTION FOR SCROLL DOWN
  4431                              <1> 	; !!!!
  4432 000016E7 E891FFFFFF          <1> 	call	test_line_count ; 16/01/2016
  4433                              <1> 	
  4434                              <1> 	;mov	bh, [CRT_MODE] ; current video mode
  4435                              <1> 	;cmp	bh, 4
  4436                              <1>  	;jb	short n12
  4437                              <1> 
  4438                              <1> 	;cmp	bh, 7 ; TEST FOR BW CARD
  4439                              <1> 	;jne	GRAPHICS_DOWN
  4440                              <1> 
  4441                              <1> n12:			; CONTINUE_DOWN
  4442 000016EC 6650                <1> 	push	ax	; * ; save attribute in ah
  4443 000016EE 6689D0              <1> 	mov	ax, dx	; LOWER RIGHT CORNER
  4444 000016F1 E898FFFFFF          <1> 	call	scroll_position	; GET REGEN LOCATION
  4445 000016F6 7419                <1> 	jz	short n14
  4446 000016F8 29CE                <1> 	sub	esi, ecx  ; SI IS FROM ADDRESS
  4447 000016FA 88F7                <1> 	mov	bh, dh  ; #rows in block
  4448 000016FC 28C7                <1> 	sub	bh, al	; #rows to be moved
  4449                              <1> n13:
  4450 000016FE E8CBFFFFFF          <1> 	call	n10	; MOVE ONE ROW
  4451                              <1> 
  4452                              <1> 	;mov    cl, [CRT_COLS] 
  4453                              <1> 	;add	cl, cl
  4454                              <1>         ;mov    ecx, 80*2
  4455 00001703 66B9A000            <1>         mov     cx, 80*2
  4456 00001707 29CE                <1>         sub     esi, ecx  ; next line
  4457 00001709 29CF                <1>         sub     edi, ecx
  4458 0000170B FECF                <1> 	dec	bh	 ; count of lines to move
  4459 0000170D 75EF                <1> 	jnz	short n13 ; row loop
  4460                              <1> 	; bh = 0
  4461 0000170F 88C6                <1> 	mov	dh, al	 ; #rows
  4462                              <1> n14:
  4463                              <1> 	; attribute in ah
  4464 00001711 B020                <1> 	mov	al, ' '	 ; fill with blanks
  4465                              <1> n15:
  4466 00001713 E8C3FFFFFF          <1> 	call	n11 ; 16/01/2016
  4467                              <1> 
  4468                              <1> 	;mov	cl, [CRT_COLS]
  4469                              <1> 	;add	cl, cl
  4470                              <1>         ;mov    ecx, 80*2
  4471 00001718 B1A0                <1>         mov	cl, 80*2
  4472 0000171A 29CF                <1>         sub     edi, ecx
  4473 0000171C FECE                <1> 	dec	dh
  4474 0000171E 75F3                <1> 	jnz	short n15
  4475                              <1> 	;
  4476 00001720 3A1D[78A20000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4477 00001726 7507                <1> 	jne	short n16
  4478                              <1> 	;mov	al, [CRT_MODE_SET] ; get the value of mode set
  4479 00001728 B029                <1> 	mov	al, 29h ; (ORGS.ASM), M7 mode set table value for mode 3	
  4480 0000172A 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  4481 0000172E EE                  <1> 	out	dx, al
  4482                              <1> n16:
  4483                              <1> 	; !!!!
  4484 0000172F FC                  <1> 	cld		; Clear direction flag !
  4485                              <1> 	; !!!!
  4486 00001730 C3                  <1> 	retn
  4487                              <1> 
  4488                              <1> READ_AC_CURRENT:
  4489                              <1> 	; 18/01/2016
  4490                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4491                              <1> 	;
  4492                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4493                              <1> 	;
  4494                              <1> 
  4495 00001731 E805000000          <1> 	call	_read_ac_current
  4496 00001736 E9B5FDFFFF          <1>         jmp     VIDEO_RETURN
  4497                              <1> 
  4498                              <1> ;------------------------------------------------------------------------
  4499                              <1> ; READ_AC_CURRENT							:
  4500                              <1> ;	THIS ROUTINE READS THE ATTRIBUTE AND CHARACTER AT THE CURRENT	:
  4501                              <1> ;	CURSOR POSITION AND RETURNS THEM TO THE CALLER			:
  4502                              <1> ; INPUT									:
  4503                              <1> ;	(AH) = CURRENT CRT MODE						:
  4504                              <1> ;	(BH) = DISPLAY PAGE ( ALPHA MODES ONLY )			:
  4505                              <1> ;	(DS) = DATA SEGMENT						:
  4506                              <1> ;	(ES) = REGEN SEGMENT						:
  4507                              <1> ; OUTPUT								:
  4508                              <1> ;	(AL) = CHARACTER READ						:
  4509                              <1> ;	(AH) = ATTRIBUTE READ						:
  4510                              <1> ;------------------------------------------------------------------------
  4511                              <1> 
  4512                              <1> _read_ac_current: ; 18/01/2016
  4513                              <1> 
  4514                              <1> p10:
  4515 0000173B E896FEFFFF          <1> 	call	find_position	; GET REGEN LOCATION AND PORT ADDRESS
  4516                              <1> 	;
  4517                              <1> 	; esi = regen location
  4518                              <1> 	; dx = status port
  4519                              <1> 	;
  4520                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE
  4521                              <1> 	;
  4522                              <1> p11:			; wait for horizontal retrace is low or vertical
  4523 00001740 FB                  <1> 	sti		; enable interrupts first
  4524 00001741 3A1D[78A20000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4525 00001747 750C                <1> 	jne	short p14 
  4526 00001749 FA                  <1> 	cli 		; block interrupts for single loop
  4527 0000174A EC                  <1> 	in	al, dx	; get status from the adapter
  4528 0000174B A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  4529 0000174D 75F1                <1> 	jnz	short p11 ; wait until it is
  4530                              <1> p12:			;  wait for either retrace high
  4531 0000174F EC                  <1> 	in	al, dx ; get status again
  4532 00001750 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  4533 00001752 74FB                <1> 	jz	short p12 ; wait until either retrace active
  4534 00001754 FB                  <1> 	sti
  4535                              <1> p14:
  4536 00001755 81C600800B00        <1> 	add	esi, 0B8000h 
  4537 0000175B 668B06              <1> 	mov	ax, [esi]
  4538                              <1> 
  4539 0000175E C3                  <1> 	retn	; 18/01/2016
  4540                              <1> 
  4541                              <1> 
  4542                              <1> WRITE_AC_CURRENT:
  4543                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4544                              <1> 	;
  4545                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4546                              <1> 	;
  4547                              <1> ;----------------------------------------------------------------
  4548                              <1> ; WRITE_AC_CURRENT						:
  4549                              <1> ;	THTS ROUTINE WRITES THE ATTRIBUTE AND CHARACTER		:
  4550                              <1> ;	AT THE CURRENT CURSOR POSITION				:
  4551                              <1> ; INPUT								:
  4552                              <1> ;	(AH) = CURRENT CRT MODE					:
  4553                              <1> ;	(BH) = DISPLAY PAGE					:
  4554                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  4555                              <1> ;	(AL) = CHAR TO WRITE					:
  4556                              <1> ;	(BL) = ATTRIBUTE OF CHAR TO WRITE			:
  4557                              <1> ;	(DS) = DATA SEGMENT					:
  4558                              <1> ;	(ES) = REGEN SEGMENT					:
  4559                              <1> ; OUTPUT							:
  4560                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  4561                              <1> ;----------------------------------------------------------------
  4562                              <1> 
  4563 0000175F E821000000          <1> 	call	_write_c_current
  4564                              <1> 
  4565 00001764 0FB6F3              <1> 	movzx	esi, bl ; video page number (0 to 7)	
  4566 00001767 88A6[889C0000]      <1> 	mov	[esi+chr_attrib], ah ; color/attribute
  4567                              <1> 
  4568 0000176D E97EFDFFFF          <1>         jmp     VIDEO_RETURN
  4569                              <1> 
  4570                              <1> WRITE_C_CURRENT:
  4571                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4572                              <1> 	;
  4573                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4574                              <1> 	;
  4575                              <1> 
  4576                              <1> 	;and	bl, 7 ; video page number (<= 7)
  4577 00001772 0FB6F3              <1> 	movzx	esi, bl	
  4578 00001775 8AA6[889C0000]      <1> 	mov	ah, [esi+chr_attrib]
  4579                              <1> 
  4580 0000177B E805000000          <1> 	call	_write_c_current
  4581 00001780 E96BFDFFFF          <1>         jmp     VIDEO_RETURN
  4582                              <1> 
  4583                              <1> ;----------------------------------------------------------------
  4584                              <1> ; WRITE_C_CURRENT						:
  4585                              <1> ;	THIS ROUTINE WRITES THE CHARACTER AT			:
  4586                              <1> ;	THE CURRENT CURSOR POSITION, ATTRIBUTE UNCHANGED	:
  4587                              <1> ; INPUT								:
  4588                              <1> ;	(AH) = CURRENT CRT MODE					:
  4589                              <1> ;	(BH) = DISPLAY PAGE					:
  4590                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  4591                              <1> ;	(AL) = CHAR TO WRITE					:
  4592                              <1> ;	(DS) = DATA SEGMENT					:
  4593                              <1> ;	(ES) = REGEN SEGMENT					:
  4594                              <1> ; OUTPUT							:
  4595                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  4596                              <1> ;----------------------------------------------------------------
  4597                              <1> 
  4598                              <1> _write_c_current:  ; from 'write_tty'
  4599                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4600                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4601                              <1> 	; 18/01/2014
  4602                              <1> 	; 04/12/2013
  4603                              <1> 	;
  4604                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4605                              <1> 	;
  4606                              <1> 
  4607 00001785 FA                  <1> 	cli		
  4608                              <1> 	; bl = video page
  4609                              <1> 	; al = character
  4610                              <1> 	; ah = color/attribute
  4611 00001786 6652                <1> 	push	dx
  4612 00001788 6650                <1> 	push	ax	; save character & attribute/color
  4613 0000178A E847FEFFFF          <1> 	call 	find_position  ; get regen location and port address
  4614                              <1> 	; esi = regen location
  4615                              <1> 	; dx = status port
  4616                              <1> 	;
  4617                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE
  4618                              <1> 	;
  4619                              <1> p41:			; wait for horizontal retrace is low or vertical
  4620 0000178F FB                  <1> 	sti		; enable interrupts first
  4621 00001790 3A1D[78A20000]      <1>         cmp     bl, [ACTIVE_PAGE]
  4622 00001796 7510                <1> 	jne	short p44 
  4623 00001798 FA                  <1> 	cli 		; block interrupts for single loop
  4624 00001799 EC                  <1> 	in	al, dx	; get status from the adapter
  4625 0000179A A808                <1> 	test	al, RVRT ; check for vertical retrace first
  4626 0000179C 7509                <1> 	jnz	short p43 ; Do fast write now if vertical retrace
  4627 0000179E A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  4628 000017A0 75ED                <1> 	jnz	short p41 ; wait until it is
  4629                              <1> p42:			;  wait for either retrace high
  4630 000017A2 EC                  <1> 	in	al, dx ; get status again
  4631 000017A3 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  4632 000017A5 74FB                <1> 	jz	short p42 ; wait until either retrace active
  4633                              <1> p43:	
  4634 000017A7 FB                  <1> 	sti
  4635                              <1> p44:
  4636 000017A8 6658                <1> 	pop	ax	; restore the character (al) & attribute (ah)
  4637 000017AA 81C600800B00        <1> 	add	esi, 0B8000h ; 30/08/2014 (crt_base) 
  4638                              <1> 				; Retro UNIX 386 v1 feature only!
  4639 000017B0 668906              <1> 	mov	[esi], ax
  4640 000017B3 665A                <1> 	pop	dx
  4641 000017B5 C3                  <1> 	retn
  4642                              <1> 
  4643                              <1> ; 18/01/2016
  4644                              <1> ; 16/01/2016
  4645                              <1> ; 30/06/2015
  4646                              <1> ; 27/06/2015
  4647                              <1> ; 11/03/2015
  4648                              <1> ; 02/09/2014
  4649                              <1> ; 30/08/2014
  4650                              <1> ; VIDEO FUNCTIONS
  4651                              <1> ; (write_tty - Retro UNIX 8086 v1 - U9.ASM, 01/02/2014)
  4652                              <1> 
  4653                              <1> WRITE_TTY:
  4654                              <1> 	; 30/01/2016
  4655                              <1> 	; 18/01/2016
  4656                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  4657                              <1> 	; 13/08/2015
  4658                              <1> 	; 02/09/2014
  4659                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  4660                              <1> 	; 01/02/2014 (Retro UNIX 8086 v1 - last update)
  4661                              <1> 	; 03/12/2013 (Retro UNIX 8086 v1 - beginning)	
  4662                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
  4663                              <1> 	;
  4664                              <1> 	; INPUT -> AH = Color (Forecolor, Backcolor)
  4665                              <1> 	;	   AL = Character to be written
  4666                              <1> 	;	   EBX = Video Page (0 to 7)
  4667                              <1> 	;	   (BH = 0 --> Video Mode 3)
  4668                              <1> 
  4669                              <1> RVRT	equ	00001000b	; VIDEO VERTICAL RETRACE BIT
  4670                              <1> RHRZ	equ	00000001b	; VIDEO HORIZONTAL RETRACE BIT
  4671                              <1> 
  4672                              <1> ; Derived from "WRITE_TTY" procedure of IBM "pc-at" rombios source code
  4673                              <1> ; (06/10/1985), 'video.asm', INT 10H, VIDEO_IO
  4674                              <1> ;
  4675                              <1> ; 06/10/85  VIDEO DISPLAY BIOS
  4676                              <1> ;
  4677                              <1> ;--- WRITE_TTY ------------------------------------------------------------------
  4678                              <1> ;										:
  4679                              <1> ;   THIS INTERFACE PROVIDES A TELETYPE LIKE INTERFACE TO THE			:
  4680                              <1> ;   VIDEO CARDS. THE INPUT CHARACTER IS WRITTEN TO THE CURRENT			:
  4681                              <1> ;   CURSOR POSITION, AND THE CURSOR IS MOVED TO THE NEXT POSITION.		:
  4682                              <1> ;   IF THE CURSOR LEAVES THE LAST COLUMN OF THE FIELD, THE COLUMN		:
  4683                              <1> ;   IS SET TO ZERO, AND THE ROW VALUE IS INCREMENTED. IF THE ROW		:
  4684                              <1> ;   ROW VALUE LEAVES THE FIELD, THE CURSOR IS PLACED ON THE LAST ROW,		:
  4685                              <1> ;   FIRST COLUMN, AND THE ENTIRE SCREEN IS SCROLLED UP ONE LINE.		:
  4686                              <1> ;   WHEN THE SCREEN IS SCROLLED UP, THE ATTRIBUTE FOR FILLING THE		:
  4687                              <1> ;   NEWLY BLANKED LINE IS READ FROM THE CURSOR POSITION ON THE PREVIOUS		:
  4688                              <1> ;   LINE BEFORE THE SCROLL, IN CHARACTER MODE. IN GRAPHICS MODE,		:
  4689                              <1> ;   THE 0 COLOR IS USED.							:
  4690                              <1> ;   ENTRY --									:
  4691                              <1> ;     (AH) = CURRENT CRT MODE							:
  4692                              <1> ;     (AL) = CHARACTER TO BE WRITTEN						:
  4693                              <1> ;	    NOTE THAT BACK SPACE, CARRIAGE RETURN, BELL AND LINE FEED ARE	:
  4694                              <1> ;	    HANDLED AS COMMANDS RATHER THAN AS DISPLAY GRAPHICS CHARACTERS	:
  4695                              <1> ;     (BL) = FOREGROUND COLOR FOR CHAR WRITE IF CURRENTLY IN A GRAPHICS MODE	:
  4696                              <1> ;   EXIT -- 									:
  4697                              <1> ;     ALL REGISTERS SAVED							:
  4698                              <1> ;--------------------------------------------------------------------------------
  4699                              <1> 
  4700 000017B6 FA                  <1> 	cli
  4701                              <1> 	;
  4702                              <1> 	; READ CURSOR (04/12/2013)
  4703                              <1> 	; Retro UNIX 386 v1 Modifications: 30/08/2014
  4704 000017B7 08FF                <1> 	or	bh, bh
  4705 000017B9 0F85D5000000        <1> 	jnz	beeper
  4706                              <1> 	; 01/09/2014
  4707 000017BF 803D[769C0000]03    <1> 	cmp	byte [CRT_MODE], 3
  4708 000017C6 7405                <1> 	je	short m3
  4709                              <1> 	;
  4710 000017C8 E8FBFCFFFF          <1> 	call	set_mode_3 ; 16/01/2016
  4711                              <1> m3:
  4712 000017CD 89DE                <1> 	mov 	esi, ebx ; 13/08/2015 (0 to 7)
  4713 000017CF 66D1E6              <1> 	shl	si, 1
  4714 000017D2 81C6[68A20000]      <1> 	add	esi, CURSOR_POSN
  4715 000017D8 668B16              <1> 	mov	dx, [esi]
  4716                              <1> 	;
  4717                              <1> 	; dx now has the current cursor position
  4718                              <1> 	;
  4719 000017DB 3C0D                <1> 	cmp	al, 0Dh		; is it carriage return or control character
  4720 000017DD 762F                <1> 	jbe	short u8
  4721                              <1> 	;
  4722                              <1> 	; write the char to the screen
  4723                              <1> u0:	
  4724                              <1> 	; ah = attribute/color
  4725                              <1> 	; al = character
  4726                              <1> 	; bl = video page number (0 to 7)
  4727                              <1> 	; bh = 0
  4728                              <1> 	;
  4729 000017DF E8A1FFFFFF          <1> 	call	_write_c_current ; 16/01/2015
  4730                              <1> 	;
  4731                              <1> 	; position the cursor for next char
  4732 000017E4 FEC2                <1> 	inc	dl		; next column
  4733                              <1> 	;cmp	dl, [CRT_COLS]
  4734 000017E6 80FA50              <1> 	cmp	dl, 80		; test for column overflow 
  4735 000017E9 755F                <1>         jne     _set_cpos
  4736 000017EB B200                <1> 	mov	dl, 0		; column = 0
  4737                              <1> u10:				; (line feed found)
  4738 000017ED 80FE18              <1> 	cmp	dh, 25-1 	; check for last row
  4739 000017F0 7218                <1> 	jb 	short u6
  4740                              <1> 	;
  4741                              <1> 	; scroll required
  4742                              <1> u1:	
  4743                              <1> 	; SET CURSOR POSITION (04/12/2013)
  4744 000017F2 E853000000          <1> 	call	_set_cpos
  4745                              <1> 	;
  4746                              <1> 	; determine value to fill with during scroll
  4747                              <1> u2:
  4748                              <1> 	; bl = video page number
  4749                              <1> 	;
  4750 000017F7 E83FFFFFFF          <1> 	call _read_ac_current ; 18/01/2016
  4751                              <1> 	;
  4752                              <1> 	; al = character, ah = attribute
  4753                              <1> 	; bl = video page number 	
  4754                              <1> u3:
  4755                              <1> 	;;mov	ax, 0601h 	; scroll one line
  4756                              <1> 	;;sub	cx, cx		; upper left corner
  4757                              <1> 	;;mov	dh, 25-1 	; lower right row
  4758                              <1> 	;;;mov	dl, [CRT_COLS]
  4759                              <1> 	;mov	dl, 80		; lower right column	
  4760                              <1> 	;;dec	dl
  4761                              <1> 	;;mov	dl, 79
  4762                              <1> 
  4763                              <1> 	;;call	scroll_up	; 04/12/2013
  4764                              <1> 	;;; 11/03/2015
  4765                              <1> 	; 02/09/2014
  4766                              <1> 	;;;mov	cx, [crt_ulc] ; Upper left corner  (0000h)
  4767                              <1> 	;;;mov	dx, [crt_lrc] ; Lower right corner (184Fh)
  4768                              <1> 	; 11/03/2015
  4769 000017FC 6629C9              <1> 	sub	cx, cx
  4770 000017FF 66BA4F18            <1> 	mov	dx, 184Fh ; dl = 79 (column), dh = 24 (row)
  4771                              <1> 	;
  4772 00001803 B001                <1> 	mov	al, 1		; scroll 1 line up
  4773                              <1> 		; ah = attribute
  4774 00001805 E902FEFFFF          <1> 	jmp	_scroll_up	; 16/01/2016
  4775                              <1> ;u4:
  4776                              <1> 	;;int	10h		; video-call return
  4777                              <1> 				; scroll up the screen
  4778                              <1> 				; tty return
  4779                              <1> ;u5:
  4780                              <1> 	;retn			; return to the caller
  4781                              <1> 
  4782                              <1> u6:				; set-cursor-inc
  4783 0000180A FEC6                <1> 	inc	dh		; next row
  4784                              <1> 				; set cursor
  4785                              <1> ;u7:					
  4786                              <1> 	;;mov	ah, 02h
  4787                              <1> 	;;jmp	short u4 	; establish the new cursor
  4788                              <1> 	;call	_set_cpos
  4789                              <1> 	;jmp 	short u5
  4790 0000180C EB3C                <1> 	jmp     _set_cpos
  4791                              <1> 
  4792                              <1> 	; check for control characters
  4793                              <1> u8:
  4794 0000180E 7438                <1> 	je	short u9
  4795 00001810 3C0A                <1> 	cmp	al, 0Ah		; is it a line feed (0Ah)
  4796 00001812 74D9                <1> 	je	short u10
  4797 00001814 3C07                <1> 	cmp	al, 07h 	; is it a bell
  4798 00001816 747C                <1> 	je	short u11
  4799 00001818 3C08                <1> 	cmp	al, 08h		; is it a backspace
  4800                              <1> 	;jne	short u0
  4801 0000181A 7424                <1> 	je	short bs	; 12/12/2013
  4802                              <1> 	; 12/12/2013 (tab stop)
  4803 0000181C 3C09                <1> 	cmp	al, 09h		; is it a tab stop
  4804 0000181E 75BF                <1> 	jne	short u0
  4805 00001820 88D0                <1> 	mov	al, dl
  4806 00001822 6698                <1> 	cbw
  4807 00001824 B108                <1> 	mov	cl, 8
  4808 00001826 F6F1                <1> 	div	cl
  4809 00001828 28E1                <1> 	sub	cl, ah
  4810                              <1> ts:
  4811                              <1> 	; 02/09/2014
  4812                              <1> 	; 01/09/2014
  4813 0000182A B020                <1> 	mov	al, 20h
  4814                              <1> tsloop:
  4815 0000182C 6651                <1> 	push	cx
  4816 0000182E 6650                <1> 	push	ax
  4817 00001830 30FF                <1> 	xor 	bh, bh
  4818                              <1> 	;mov	bl, [ACTIVE_PAGE]
  4819 00001832 E896FFFFFF          <1> 	call	m3
  4820 00001837 6658                <1> 	pop	ax  ; ah = attribute/color
  4821 00001839 6659                <1> 	pop	cx
  4822 0000183B FEC9                <1> 	dec	cl
  4823 0000183D 75ED                <1> 	jnz	short tsloop
  4824 0000183F C3                  <1> 	retn
  4825                              <1> bs:	
  4826                              <1> 	; back space found
  4827                              <1> 
  4828 00001840 08D2                <1> 	or	dl, dl 		; is it already at start of line
  4829                              <1> 	;je	short u7 	; set_cursor
  4830 00001842 7406                <1> 	jz	short _set_cpos
  4831 00001844 664A                <1> 	dec	dx     		; no -- just move it back
  4832                              <1> 	;jmp	short u7
  4833 00001846 EB02                <1> 	jmp	short _set_cpos
  4834                              <1> 
  4835                              <1> 	; carriage return found
  4836                              <1> u9:
  4837 00001848 B200                <1> 	mov	dl, 0 		; move to first column
  4838                              <1> 	;jmp	short u7
  4839                              <1> 	;jmp	short _set_cpos ; 30/01/2016
  4840                              <1> 
  4841                              <1> 	; line feed found
  4842                              <1> ;u10:
  4843                              <1> ;	cmp	dh, 25-1 	; bottom of screen
  4844                              <1> ;	jne	short u6 	; no, just set the cursor
  4845                              <1> ;       jmp     u1              ; yes, scroll the screen
  4846                              <1> 
  4847                              <1> _set_cpos:
  4848                              <1> 	; 27/06/2015
  4849                              <1> 	; 01/09/2014
  4850                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  4851                              <1> 	;
  4852                              <1> 	; 12/12/2013 (Retro UNIX 8086 v1 - last update) 
  4853                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1 - beginning)
  4854                              <1> 	;
  4855                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  4856                              <1> 	;
  4857                              <1> ;----------------------------------------------
  4858                              <1> ; SET_CPOS
  4859                              <1> ;	THIS ROUTINE SETS THE CURRENT CURSOR POSITION TO THE
  4860                              <1> ;	NEW X-Y VALUES PASSED
  4861                              <1> ; INPUT
  4862                              <1> ;	DX - ROW,COLUMN OF NEW CURSOR
  4863                              <1> ;	BH - DISPLAY PAGE OF CURSOR
  4864                              <1> ; OUTPUT
  4865                              <1> ;	CURSOR ID SET AT 6845 IF DISPLAY PAGE IS CURRENT DISPLAY
  4866                              <1> ;----------------------------------------------
  4867                              <1> 	;
  4868 0000184A BE[68A20000]        <1> 	mov	esi, CURSOR_POSN
  4869 0000184F 0FB6C3              <1>         movzx   eax, bl	; BL = video page number ; 27/06/2015 (movzx)
  4870                              <1> ;	or	al, al
  4871                              <1> ;	jz	short _set_cpos_0
  4872 00001852 D0E0                <1>         shl     al, 1   ; word offset
  4873 00001854 01C6                <1>         add     esi, eax
  4874                              <1> ;_set_cpos_0:
  4875 00001856 668916              <1> 	mov	[esi], dx ; save the pointer
  4876 00001859 381D[78A20000]      <1> 	cmp	[ACTIVE_PAGE], bl
  4877 0000185F 7532                <1> 	jne	short m17
  4878                              <1> 	;call	m18	; CURSOR SET
  4879                              <1> ;m17:			; SET_CPOS_RETURN
  4880                              <1> 	; 01/09/2014
  4881                              <1> ;	retn
  4882                              <1> 		; DX  = row/column
  4883                              <1> m18:
  4884 00001861 E861FDFFFF          <1> 	call	position ; determine location in regen buffer	
  4885 00001866 668B0D[64A20000]    <1> 	mov	cx, [CRT_START]
  4886 0000186D 6601C1              <1> 	add	cx, ax  ; add char position in regen buffer
  4887                              <1> 			; to the start address (offset) for this page
  4888 00001870 66D1E9              <1> 	shr	cx, 1	; divide by 2 for char only count
  4889 00001873 B40E                <1> 	mov	ah, 14	; register number for cursor
  4890                              <1> 	;call	m16	; output value to the 6845	
  4891                              <1> 	;retn
  4892                              <1> 
  4893                              <1> 	;-----	THIS ROUTINE OUTPUTS THE CX REGISTER
  4894                              <1> 	;	TO THE 6845 REGISTERS NAMED IN (AH)
  4895                              <1> m16:
  4896 00001875 FA                  <1> 	cli
  4897                              <1> 	;mov	dx, [addr_6845] ; address register
  4898 00001876 66BAD403            <1> 	mov 	dx, 03D4h ; I/O address of color card
  4899 0000187A 88E0                <1> 	mov	al, ah	; get value
  4900 0000187C EE                  <1> 	out	dx, al	; register set
  4901 0000187D 6642                <1> 	inc	dx	; data register
  4902 0000187F EB00                <1> 	jmp	$+2	; i/o delay
  4903 00001881 88E8                <1> 	mov	al, ch	; data
  4904 00001883 EE                  <1> 	out	dx, al	
  4905 00001884 664A                <1> 	dec	dx	
  4906 00001886 88E0                <1> 	mov	al, ah
  4907 00001888 FEC0                <1> 	inc	al	; point to other data register
  4908 0000188A EE                  <1> 	out	dx, al	; set for second register
  4909 0000188B 6642                <1> 	inc	dx
  4910 0000188D EB00                <1> 	jmp	$+2	; i/o delay
  4911 0000188F 88C8                <1> 	mov	al, cl	; second data value
  4912 00001891 EE                  <1> 	out	dx, al
  4913 00001892 FB                  <1> 	sti
  4914                              <1> m17:
  4915 00001893 C3                  <1> 	retn
  4916                              <1> 
  4917                              <1> beeper: 
  4918                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4919                              <1> 	; 18/01/2014
  4920                              <1> 	; 03/12/2013
  4921                              <1> 	; bell found
  4922                              <1> u11:
  4923 00001894 FB                  <1> 	sti
  4924 00001895 3A1D[78A20000]      <1> 	cmp	bl, [ACTIVE_PAGE]
  4925 0000189B 7551                <1> 	jne	short u12	; Do not sound the beep 
  4926                              <1> 				; if it is not written on the active page
  4927 0000189D 66B93305            <1> 	mov	cx, 1331 	; divisor for 896 hz tone
  4928 000018A1 B31F                <1> 	mov	bl, 31		; set count for 31/64 second for beep
  4929                              <1> 	;call	beep		; sound the pod bell
  4930                              <1> 	;jmp	short u5 	; tty_return
  4931                              <1> 	;retn
  4932                              <1> 	
  4933                              <1> TIMER	equ 	040h   		; 8254 TIMER - BASE ADDRESS
  4934                              <1> PORT_B	equ	061h		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  4935                              <1> GATE2	equ	00000001b	; TIMER 2 INPUT CATE CLOCK BIT
  4936                              <1> SPK2	equ	00000010b	; SPEAKER OUTPUT DATA ENABLE BIT
  4937                              <1> 
  4938                              <1> beep:
  4939                              <1> 	; 07/02/2015
  4940                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  4941                              <1> 	; 18/01/2014
  4942                              <1> 	; 03/12/2013
  4943                              <1> 	;
  4944                              <1> 	; TEST4.ASM - 06/10/85  POST AND BIOS UTILITY ROUTINES
  4945                              <1> 	;
  4946                              <1> 	; ROUTINE TO SOUND THE BEEPER USING TIMER 2 FOR TONE
  4947                              <1> 	;
  4948                              <1> 	; ENTRY:
  4949                              <1> 	;    (BL) = DURATION COUNTER ( 1 FOR 1/64 SECOND )
  4950                              <1> 	;    (CX) = FREQUENCY DIVISOR (1193180/FREQUENCY) (1331 FOR 886 HZ)
  4951                              <1> 	; EXIT:				:
  4952                              <1> 	;    (AX),(BL),(CX) MODIFIED.
  4953                              <1> 
  4954 000018A3 9C                  <1> 	pushf  ; 18/01/2014	; save interrupt status
  4955 000018A4 FA                  <1> 	cli			; block interrupts during update
  4956 000018A5 B0B6                <1> 	mov	al, 10110110b	; select timer 2, lsb, msb binary
  4957 000018A7 E643                <1> 	out	TIMER+3, al 	; write timer mode register
  4958 000018A9 EB00                <1> 	jmp	$+2		; I/O delay
  4959 000018AB 88C8                <1> 	mov	al, cl		; divisor for hz (low)
  4960 000018AD E642                <1> 	out	TIMER+2,AL	; write timer 2 count - lsb
  4961 000018AF EB00                <1> 	jmp	$+2		; I/O delay
  4962 000018B1 88E8                <1> 	mov	al, ch		; divisor for hz (high)
  4963 000018B3 E642                <1> 	out	TIMER+2, al	; write timer 2 count - msb
  4964 000018B5 E461                <1> 	in	al, PORT_B	; get current setting of port
  4965 000018B7 88C4                <1> 	mov	ah, al		; save that setting
  4966 000018B9 0C03                <1> 	or	al, GATE2+SPK2	; gate timer 2 and turn speaker on
  4967 000018BB E661                <1> 	out	PORT_B, al	; and restore interrupt status
  4968                              <1> 	;popf	; 18/01/2014
  4969 000018BD FB                  <1> 	sti
  4970                              <1> g7:				; 1/64 second per count (bl)
  4971 000018BE B90B040000          <1> 	mov	ecx, 1035	; delay count for 1/64 of a second	
  4972 000018C3 E827000000          <1> 	call	waitf		; go to beep delay 1/64 count
  4973 000018C8 FECB                <1> 	dec	bl		; (bl) length count expired?
  4974 000018CA 75F2                <1> 	jnz	short g7	; no - continue beeping speaker
  4975                              <1> 	;
  4976                              <1> 	;pushf			; save interrupt status
  4977 000018CC FA                  <1> 	cli  	; 18/01/2014	; block interrupts during update
  4978 000018CD E461                <1> 	in	al, PORT_B	; get current port value
  4979                              <1>         ;or      al, not (GATE2+SPK2) ; isolate current speaker bits in case
  4980 000018CF 0CFC                <1>         or      al, ~(GATE2+SPK2)
  4981 000018D1 20C4                <1>         and	ah, al		; someone turned them off during beep
  4982 000018D3 88E0                <1> 	mov	al, ah		; recover value of port
  4983                              <1>         ;or      al, not (GATE2+SPK2) ; force speaker data off
  4984 000018D5 0CFC                <1> 	or 	al, ~(GATE2+SPK2) ; isolate current speaker bits in case
  4985 000018D7 E661                <1> 	out	PORT_B, al	; and stop speaker timer
  4986                              <1> 	;popf			; restore interrupt flag state
  4987 000018D9 FB                  <1> 	sti
  4988 000018DA B90B040000          <1> 	mov	ecx, 1035	; force 1/64 second delay (short)
  4989 000018DF E80B000000          <1> 	call	waitf		; minimum delay between all beeps
  4990                              <1> 	;pushf			; save interrupt status
  4991 000018E4 FA                  <1> 	cli			; block interrupts during update
  4992 000018E5 E461                <1> 	in	al, PORT_B	; get current port value in case	
  4993 000018E7 2403                <1> 	and	al, GATE2+SPK2	; someone turned them on
  4994 000018E9 08E0                <1> 	or	al, ah		; recover value of port_b
  4995 000018EB E661                <1> 	out	PORT_B, al	; restore speaker status
  4996 000018ED 9D                  <1> 	popf			; restore interrupt flag state
  4997                              <1> u12:	
  4998 000018EE C3                  <1> 	retn
  4999                              <1> 
  5000                              <1> REFRESH_BIT equ	00010000b 	; REFRESH TEST BIT
  5001                              <1> 
  5002                              <1> WAITF:
  5003                              <1> waitf:
  5004                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  5005                              <1> 	; 03/12/2013
  5006                              <1> 	;
  5007                              <1> ;	push ax			; save work register (ah)	
  5008                              <1> ;waitf1:
  5009                              <1> 				; use timer 1 output bits
  5010                              <1> ;	in	al, PORT_B	; read current counter output status
  5011                              <1> ;	and	al, REFRESH_BIT	; mask for refresh determine bit
  5012                              <1> ;	cmp	al, ah		; did it just change
  5013                              <1> ;	je	short waitf1	; wait for a change in output line
  5014                              <1> ;	;
  5015                              <1> ;	mov	ah, al		; save new lflag state
  5016                              <1> ;	loop	waitf1		; decrement half cycles till count end		
  5017                              <1> ;	;
  5018                              <1> ;	pop	ax		; restore (ah)
  5019                              <1> ;	retn			; return (cx)=0
  5020                              <1> 
  5021                              <1> ; 06/02/2015 (unix386.s <-- dsectrm2.s)
  5022                              <1> ; 17/12/2014 (dsectrm2.s)
  5023                              <1> ; WAITF
  5024                              <1> ; /// IBM PC-XT Model 286 System BIOS Source Code - Test 4 - 06/10/85 ///
  5025                              <1> ;
  5026                              <1> ;---WAITF-----------------------------------------------------------------------
  5027                              <1> ;	FIXED TIME WAIT ROUTINE (HARDWARE CONTROLLED - NOT PROCESSOR)
  5028                              <1> ; ENTRY:
  5029                              <1> ;	(CX) =	COUNT OF 15.085737 MICROSECOND INTERVALS TO WAIT
  5030                              <1> ;	      	MEMORY REFRESH TIMER 1 OUTPUT USED AS REFERENCE
  5031                              <1> ; EXIT:
  5032                              <1> ;	       	AFTER (CX) TIME COUNT (PLUS OR MINUS 16 MICROSECONDS)
  5033                              <1> ;	(CX) = 0	
  5034                              <1> ;-------------------------------------------------------------------------------
  5035                              <1> 
  5036                              <1> ; Refresh period: 30 micro seconds (15-80 us)
  5037                              <1> ; (16/12/2014 - AWARDBIOS 1999 - ATORGS.ASM, WAIT_REFRESH)
  5038                              <1> 
  5039                              <1> ;WAITF:					; DELAY FOR (CX)*15.085737 US
  5040 000018EF 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER (AH)
  5041                              <1> 	; 16/12/2014
  5042                              <1> 	;shr	cx, 1			; convert to count of 30 micro seconds
  5043 000018F1 D1E9                <1> 	shr	ecx, 1	; 21/02/2015
  5044                              <1> ;17/12/2014	
  5045                              <1> ;WAITF1:
  5046                              <1> ;	IN	AL, PORT_B   ;061h	; READ CURRENT COUNTER OUTPUT STATUS
  5047                              <1> ;	AND	AL, REFRESH_BIT	;00010000b ; MASK FOR REFRESH DETERMINE BIT
  5048                              <1> ;	CMP	AL, AH			; DID IT JUST CHANGE
  5049                              <1> ;	JE	short WAITF1		; WAIT FOR A CHANGE IN OUTPUT LINE
  5050                              <1> ;	MOV	AH, AL			; SAVE NEW FLAG STATE
  5051                              <1> ;	LOOP	WAITF1			; DECREMENT HALF CYCLES TILL COUNT END		
  5052                              <1> 	;
  5053                              <1> 	; 17/12/2014
  5054                              <1> 	;
  5055                              <1> 	; Modification from 'WAIT_REFRESH' procedure of AWARD BIOS - 1999
  5056                              <1> 	;
  5057                              <1> ;WAIT_REFRESH:  Uses port 61, bit 4 to have CPU speed independent waiting.
  5058                              <1> ;   	INPUT:  CX = number of refresh periods to wait
  5059                              <1> ;     	       (refresh periods = 1 per 30 microseconds on most machines)
  5060                              <1> WR_STATE_0:
  5061 000018F3 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  5062 000018F5 A810                <1> 	TEST	AL,010H
  5063 000018F7 74FA                <1> 	JZ	SHORT WR_STATE_0
  5064                              <1> WR_STATE_1:
  5065 000018F9 E461                <1> 	IN	AL,PORT_B		; IN AL,SYS1
  5066 000018FB A810                <1> 	TEST	AL,010H
  5067 000018FD 75FA                <1> 	JNZ	SHORT WR_STATE_1
  5068 000018FF E2F2                <1>         LOOP    WR_STATE_0
  5069                              <1> 	;
  5070 00001901 6658                <1> 	POP	AX			; RESTORE (AH)
  5071 00001903 C3                  <1> 	RETn				; (CX) = 0
  5072                              <1> 
  5073                              <1> ; % include 'vidata.s' ; VIDEO DATA
  5074                              <1> 
  5075                              <1> ; /// End Of VIDEO FUNCTIONS ///
  5076                                  
  5077                                  setup_rtc_int:
  5078                                  ; source: http://wiki.osdev.org/RTC
  5079 00001904 FA                      	cli		; disable interrupts
  5080                                  	; default int frequency is 1024 Hz (Lower 4 bits of register A is 0110b or 6)
  5081                                  	; in order to change this ...
  5082                                  	; frequency  = 32768 >> (rate-1) --> 32768 >> 5 = 1024
  5083                                  	; (rate must be above 2 and not over 15)
  5084                                  	; new rate = 15 --> 32768 >> (15-1) = 2 Hz
  5085 00001905 B08A                    	mov	al, 8Ah 
  5086 00001907 E670                    	out	70h, al ; set index to register A, disable NMI
  5087 00001909 90                      	nop
  5088 0000190A E471                    	in	al, 71h ; get initial value of register A
  5089 0000190C 88C4                    	mov 	ah, al
  5090 0000190E 80E4F0                  	and	ah, 0F0h
  5091 00001911 B08A                    	mov	al, 8Ah 
  5092 00001913 E670                    	out	70h, al ; reset index to register A
  5093 00001915 88E0                    	mov	al, ah
  5094 00001917 0C0F                    	or	al, 0Fh	; new rate (0Fh -> 15)
  5095 00001919 E671                    	out	71h, al ; write only our rate to A. Note, rate is the bottom 4 bits. 
  5096                                  	; enable RTC interrupt
  5097 0000191B B08B                    	mov	al, 8Bh ;
  5098 0000191D E670                    	out	70h, al ; select register B and disable NMI
  5099 0000191F 90                      	nop
  5100 00001920 E471                    	in	al, 71h ; read the current value of register B
  5101 00001922 88C4                    	mov	ah, al  ;
  5102 00001924 B08B                    	mov 	al, 8Bh ;
  5103 00001926 E670                    	out	70h, al ; set the index again (a read will reset the index to register B)	
  5104 00001928 88E0                    	mov	al, ah  ;
  5105 0000192A 0C40                    	or	al, 40h ;
  5106 0000192C E671                    	out	71h, al ; write the previous value ORed with 0x40. This turns on bit 6 of register B
  5107 0000192E FB                      	sti
  5108 0000192F C3                      	retn
  5109                                  
  5110                                  ; Write memory information
  5111                                  ; 29/01/2016
  5112                                  ; 06/11/2014
  5113                                  ; 14/08/2015 
  5114                                  memory_info:	
  5115 00001930 A1[4CA20000]            	mov	eax, [memory_size] ; in pages
  5116 00001935 50                      	push	eax
  5117 00001936 C1E00C                  	shl	eax, 12		   ; in bytes
  5118 00001939 BB0A000000              	mov	ebx, 10
  5119 0000193E 89D9                    	mov	ecx, ebx	   ; 10
  5120 00001940 BE[979E0000]            	mov	esi, mem_total_b_str	
  5121 00001945 E8BE000000              	call	bintdstr
  5122 0000194A 58                      	pop	eax
  5123 0000194B B107                    	mov	cl, 7
  5124 0000194D BE[BB9E0000]            	mov	esi, mem_total_p_str
  5125 00001952 E8B1000000              	call	bintdstr	
  5126                                  	; 14/08/2015
  5127 00001957 E8C9000000              	call	calc_free_mem
  5128                                  	; edx = calculated free pages
  5129                                  	; ecx = 0
  5130 0000195C A1[50A20000]            	mov 	eax, [free_pages]
  5131 00001961 39D0                    	cmp	eax, edx ; calculated free mem value 
  5132                                  		; and initial free mem value are same or not?
  5133 00001963 751D                    	jne 	short pmim ; print mem info with '?' if not
  5134 00001965 52                      	push 	edx ; free memory in pages	
  5135                                  	;mov 	eax, edx
  5136 00001966 C1E00C                  	shl	eax, 12 ; convert page count
  5137                                  			; to byte count
  5138 00001969 B10A                    	mov	cl, 10
  5139 0000196B BE[DB9E0000]            	mov	esi, free_mem_b_str
  5140 00001970 E893000000              	call	bintdstr
  5141 00001975 58                      	pop	eax
  5142 00001976 B107                    	mov	cl, 7
  5143 00001978 BE[FF9E0000]            	mov	esi, free_mem_p_str
  5144 0000197D E886000000              	call	bintdstr
  5145                                  pmim:
  5146 00001982 BE[859E0000]            	mov	esi, msg_memory_info
  5147                                  	;
  5148 00001987 B407                    	mov	ah, 07h ; Black background, 
  5149                                  			; light gray forecolor
  5150                                  print_kmsg: ; 29/01/2016
  5151 00001989 8825[79A20000]          	mov	[ccolor], ah
  5152                                  pkmsg_loop:
  5153 0000198F AC                      	lodsb
  5154 00001990 08C0                    	or	al, al
  5155 00001992 7411                    	jz	short pkmsg_ok
  5156 00001994 56                      	push	esi
  5157 00001995 31DB                    	xor	ebx, ebx ; 0
  5158                                  			; Video page 0 (bl=0)
  5159 00001997 8A25[79A20000]          	mov	ah, [ccolor]
  5160 0000199D E814FEFFFF              	call	WRITE_TTY
  5161 000019A2 5E                      	pop	esi
  5162 000019A3 EBEA                    	jmp	short pkmsg_loop
  5163                                  pkmsg_ok:
  5164 000019A5 C3                      	retn
  5165                                  
  5166                                  ; Convert binary number to hexadecimal string
  5167                                  ; 10/05/2015  
  5168                                  ; dsectpm.s (28/02/2015)
  5169                                  ; Retro UNIX 386 v1 - Kernel v0.2.0.6  
  5170                                  ; 01/12/2014
  5171                                  ; 25/11/2014
  5172                                  ;
  5173                                  bytetohex:
  5174                                  	; INPUT ->
  5175                                  	; 	AL = byte (binary number)
  5176                                  	; OUTPUT ->
  5177                                  	;	AX = hexadecimal string
  5178                                  	;
  5179 000019A6 53                      	push	ebx
  5180 000019A7 31DB                    	xor	ebx, ebx
  5181 000019A9 88C3                    	mov	bl, al
  5182 000019AB C0EB04                  	shr	bl, 4
  5183 000019AE 8A9B[F8190000]          	mov	bl, [ebx+hexchrs] 	 	
  5184 000019B4 86D8                    	xchg	bl, al
  5185 000019B6 80E30F                  	and	bl, 0Fh
  5186 000019B9 8AA3[F8190000]          	mov	ah, [ebx+hexchrs] 
  5187 000019BF 5B                      	pop	ebx	
  5188 000019C0 C3                      	retn
  5189                                  
  5190                                  wordtohex:
  5191                                  	; INPUT ->
  5192                                  	; 	AX = word (binary number)
  5193                                  	; OUTPUT ->
  5194                                  	;	EAX = hexadecimal string
  5195                                  	;
  5196 000019C1 53                      	push	ebx
  5197 000019C2 31DB                    	xor	ebx, ebx
  5198 000019C4 86E0                    	xchg	ah, al
  5199 000019C6 6650                    	push	ax
  5200 000019C8 88E3                    	mov	bl, ah
  5201 000019CA C0EB04                  	shr	bl, 4
  5202 000019CD 8A83[F8190000]          	mov	al, [ebx+hexchrs] 	 	
  5203 000019D3 88E3                    	mov	bl, ah
  5204 000019D5 80E30F                  	and	bl, 0Fh
  5205 000019D8 8AA3[F8190000]          	mov	ah, [ebx+hexchrs]
  5206 000019DE C1E010                  	shl	eax, 16
  5207 000019E1 6658                    	pop	ax
  5208 000019E3 5B                      	pop	ebx
  5209 000019E4 EBC0                    	jmp	short bytetohex
  5210                                  	;mov	bl, al
  5211                                  	;shr	bl, 4
  5212                                  	;mov	bl, [ebx+hexchrs] 	 	
  5213                                  	;xchg	bl, al	 	
  5214                                  	;and	bl, 0Fh
  5215                                  	;mov	ah, [ebx+hexchrs] 
  5216                                  	;pop	ebx	
  5217                                  	;retn
  5218                                  
  5219                                  dwordtohex:
  5220                                  	; INPUT ->
  5221                                  	; 	EAX = dword (binary number)
  5222                                  	; OUTPUT ->
  5223                                  	;	EDX:EAX = hexadecimal string
  5224                                  	;
  5225 000019E6 50                      	push	eax
  5226 000019E7 C1E810                  	shr	eax, 16
  5227 000019EA E8D2FFFFFF              	call	wordtohex
  5228 000019EF 89C2                    	mov	edx, eax
  5229 000019F1 58                      	pop	eax
  5230 000019F2 E8CAFFFFFF              	call	wordtohex
  5231 000019F7 C3                      	retn
  5232                                  
  5233                                  ; 10/05/2015
  5234                                  hex_digits:
  5235                                  hexchrs:
  5236 000019F8 303132333435363738-     	db '0123456789ABCDEF'
  5237 00001A01 39414243444546     
  5238                                  
  5239                                  ; Convert binary number to decimal/numeric string
  5240                                  ; 06/11/2014
  5241                                  ; Temporary Code
  5242                                  ;
  5243                                  
  5244                                  bintdstr:
  5245                                  	; EAX = binary number
  5246                                  	; ESI = decimal/numeric string address
  5247                                  	; EBX = divisor (10)
  5248                                  	; ECX = string length (<=10)
  5249 00001A08 01CE                    	add	esi, ecx
  5250                                  btdstr0:
  5251 00001A0A 4E                      	dec	esi
  5252 00001A0B 31D2                    	xor	edx, edx
  5253 00001A0D F7F3                    	div	ebx
  5254 00001A0F 80C230                  	add	dl, 30h
  5255 00001A12 8816                    	mov	[esi], dl
  5256 00001A14 FEC9                    	dec	cl
  5257 00001A16 740C                    	jz	btdstr2
  5258 00001A18 09C0                    	or	eax, eax
  5259 00001A1A 75EE                    	jnz	short btdstr0
  5260                                  btdstr1:
  5261 00001A1C 4E                      	dec	esi
  5262 00001A1D C60620                          mov     byte [esi], 20h ; blank space
  5263 00001A20 FEC9                    	dec	cl
  5264 00001A22 75F8                    	jnz	short btdstr1
  5265                                  btdstr2:
  5266 00001A24 C3                      	retn
  5267                                  
  5268                                  ; Calculate free memory pages on M.A.T.
  5269                                  ; 06/11/2014
  5270                                  ; Temporary Code
  5271                                  ;
  5272                                  
  5273                                  calc_free_mem:
  5274 00001A25 31D2                    	xor	edx, edx
  5275                                  	;xor	ecx, ecx
  5276 00001A27 668B0D[60A20000]        	mov	cx, [mat_size] ; in pages
  5277 00001A2E C1E10A                  	shl	ecx, 10	; 1024 dwords per page
  5278 00001A31 BE00001000              	mov	esi, MEM_ALLOC_TBL
  5279                                  cfm0:
  5280 00001A36 AD                      	lodsd
  5281 00001A37 51                      	push	ecx
  5282 00001A38 B920000000              	mov	ecx, 32
  5283                                  cfm1:
  5284 00001A3D D1E8                    	shr	eax, 1
  5285 00001A3F 7301                    	jnc	short cfm2
  5286 00001A41 42                      	inc	edx
  5287                                  cfm2:
  5288 00001A42 E2F9                    	loop	cfm1
  5289 00001A44 59                      	pop	ecx
  5290 00001A45 E2EF                    	loop	cfm0
  5291 00001A47 C3                      	retn
  5292                                  
  5293                                  %include 'diskio.s'  ; 07/03/2015
  5294                              <1> ; ****************************************************************************
  5295                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskio.s
  5296                              <1> ; ----------------------------------------------------------------------------
  5297                              <1> ; Last Update: 18/02/2016
  5298                              <1> ; ----------------------------------------------------------------------------
  5299                              <1> ; Beginning: 24/01/2016
  5300                              <1> ; ----------------------------------------------------------------------------
  5301                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
  5302                              <1> ; ----------------------------------------------------------------------------
  5303                              <1> ; Turkish Rational DOS
  5304                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
  5305                              <1> ;
  5306                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
  5307                              <1> ; diskio.inc (22/08/2015)
  5308                              <1> ;
  5309                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
  5310                              <1> ; ****************************************************************************
  5311                              <1> 
  5312                              <1> ; Retro UNIX 386 v1 Kernel - DISKIO.INC
  5313                              <1> ; Last Modification: 22/08/2015
  5314                              <1> ; 	(Initialized Disk Parameters Data is in 'DISKDATA.INC') 
  5315                              <1> ; 	(Uninitialized Disk Parameters Data is in 'DISKBSS.INC') 
  5316                              <1> 
  5317                              <1> ; DISK I/O SYSTEM - Erdogan Tan (Retro UNIX 386 v1 project)
  5318                              <1> 
  5319                              <1> ; ///////// DISK I/O SYSTEM ///////////////
  5320                              <1> 
  5321                              <1> ; 06/02/2015
  5322                              <1> diskette_io:
  5323 00001A48 9C                  <1> 	pushfd
  5324 00001A49 0E                  <1> 	push 	cs
  5325 00001A4A E809000000          <1> 	call 	DISKETTE_IO_1
  5326 00001A4F C3                  <1> 	retn
  5327                              <1> 	
  5328                              <1> ;;;;;; DISKETTE I/O ;;;;;;;;;;;;;;;;;;;; 06/02/2015 ;;;
  5329                              <1> ;//////////////////////////////////////////////////////
  5330                              <1> 
  5331                              <1> ; DISKETTE I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  5332                              <1> ; 20/02/2015
  5333                              <1> ; 06/02/2015 (unix386.s)
  5334                              <1> ; 16/12/2014 - 02/01/2015 (dsectrm2.s)
  5335                              <1> ;
  5336                              <1> ; Code (DELAY) modifications - AWARD BIOS 1999 (ADISK.EQU, COMMON.MAC)
  5337                              <1> ;
  5338                              <1> ; ADISK.EQU
  5339                              <1> 
  5340                              <1> ;----- Wait control constants 
  5341                              <1> 
  5342                              <1> ;amount of time to wait while RESET is active.
  5343                              <1> 
  5344                              <1> WAITCPU_RESET_ON	EQU	21		;Reset on must last at least 14us
  5345                              <1> 						;at 250 KBS xfer rate.
  5346                              <1> 						;see INTEL MCS, 1985, pg. 5-456
  5347                              <1> 
  5348                              <1> WAITCPU_FOR_STATUS	EQU	100		;allow 30 microseconds for
  5349                              <1> 						;status register to become valid
  5350                              <1> 						;before re-reading.
  5351                              <1> 
  5352                              <1> ;After sending a byte to NEC, status register may remain
  5353                              <1> ;incorrectly set for 24 us.
  5354                              <1> 
  5355                              <1> WAITCPU_RQM_LOW		EQU	24		;number of loops to check for
  5356                              <1> 						;RQM low.
  5357                              <1> 
  5358                              <1> ; COMMON.MAC
  5359                              <1> ;
  5360                              <1> ;	Timing macros
  5361                              <1> ;
  5362                              <1> 
  5363                              <1> %macro 		SIODELAY 0 			; SHORT IODELAY
  5364                              <1> 		jmp short $+2
  5365                              <1> %endmacro		
  5366                              <1> 
  5367                              <1> %macro		IODELAY  0			; NORMAL IODELAY
  5368                              <1> 		jmp short $+2
  5369                              <1> 		jmp short $+2
  5370                              <1> %endmacro
  5371                              <1> 
  5372                              <1> %macro		NEWIODELAY 0
  5373                              <1> 		out	0ebh,al
  5374                              <1> %endmacro 
  5375                              <1> 
  5376                              <1> ; (According to) AWARD BIOS 1999 - ATORGS.ASM (dw -> equ, db -> equ)
  5377                              <1> ;;; WAIT_FOR_MEM
  5378                              <1> ;WAIT_FDU_INT_LO	equ	017798		; 2.5 secs in 30 micro units.
  5379                              <1> ;WAIT_FDU_INT_HI	equ	1
  5380                              <1> WAIT_FDU_INT_LH		equ	83334		; 27/02/2015 (2.5 seconds waiting)
  5381                              <1> ;;; WAIT_FOR_PORT
  5382                              <1> ;WAIT_FDU_SEND_LO	equ	16667		; .5 secons in 30 us units.
  5383                              <1> ;WAIT_FDU_SEND_HI	equ	0
  5384                              <1> WAIT_FDU_SEND_LH	equ 	16667		; 27/02/2015	
  5385                              <1> ;Time to wait while waiting for each byte of NEC results = .5
  5386                              <1> ;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  5387                              <1> ;WAIT_FDU_RESULTS_LO	equ	16667		; .5 seconds in 30 micro units.
  5388                              <1> ;WAIT_FDU_RESULTS_HI	equ	0
  5389                              <1> WAIT_FDU_RESULTS_LH	equ	16667  ; 27/02/2015
  5390                              <1> ;;; WAIT_REFRESH
  5391                              <1> ;amount of time to wait for head settle, per unit in parameter
  5392                              <1> ;table = 1 ms.
  5393                              <1> WAIT_FDU_HEAD_SETTLE	equ	33		; 1 ms in 30 micro units.
  5394                              <1> 
  5395                              <1> 
  5396                              <1> ; //////////////// DISKETTE I/O ////////////////
  5397                              <1> 
  5398                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - POSTEQU.INC)
  5399                              <1> 
  5400                              <1> ;----------------------------------------
  5401                              <1> ;	EQUATES USED BY POST AND BIOS	:
  5402                              <1> ;----------------------------------------
  5403                              <1> 
  5404                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
  5405                              <1> ;PORT_A		EQU	060H		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
  5406                              <1> ;PORT_B		EQU	061H		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  5407                              <1> ;REFRESH_BIT	EQU	00010000B	; REFRESH TEST BIT
  5408                              <1> 
  5409                              <1> ;----------------------------------------
  5410                              <1> ;	CMOS EQUATES FOR THIS SYSTEM	:
  5411                              <1> ;-------------------------------------------------------------------------------
  5412                              <1> ;CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
  5413                              <1> ;CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
  5414                              <1> ;NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
  5415                              <1> 					;  HIGH BIT OF CMOS LOCATION ADDRESS
  5416                              <1> 
  5417                              <1> ;---------- CMOS TABLE LOCATION ADDRESS'S ## -----------------------------------
  5418                              <1> CMOS_DISKETTE	EQU	010H		; DISKETTE DRIVE TYPE BYTE	      ;
  5419                              <1> ;		EQU	011H		; - RESERVED			      ;C
  5420                              <1> CMOS_DISK	EQU	012H		; FIXED DISK TYPE BYTE		      ;H
  5421                              <1> ;		EQU	013H		; - RESERVED			      ;E
  5422                              <1> CMOS_EQUIP	EQU	014H		; EQUIPMENT WORD LOW BYTE	      ;C
  5423                              <1> 
  5424                              <1> ;---------- DISKETTE EQUATES ---------------------------------------------------
  5425                              <1> INT_FLAG	EQU	10000000B	; INTERRUPT OCCURRENCE FLAG
  5426                              <1> DSK_CHG 	EQU	10000000B	; DISKETTE CHANGE FLAG MASK BIT
  5427                              <1> DETERMINED	EQU	00010000B	; SET STATE DETERMINED IN STATE BITS
  5428                              <1> HOME		EQU	00010000B	; TRACK 0 MASK
  5429                              <1> SENSE_DRV_ST	EQU	00000100B	; SENSE DRIVE STATUS COMMAND
  5430                              <1> TRK_SLAP	EQU	030H		; CRASH STOP (48 TPI DRIVES)
  5431                              <1> QUIET_SEEK	EQU	00AH		; SEEK TO TRACK 10
  5432                              <1> ;MAX_DRV 	EQU	2		; MAX NUMBER OF DRIVES
  5433                              <1> HD12_SETTLE	EQU	15		; 1.2 M HEAD SETTLE TIME
  5434                              <1> HD320_SETTLE	EQU	20		; 320 K HEAD SETTLE TIME
  5435                              <1> MOTOR_WAIT	EQU	37		; 2 SECONDS OF COUNTS FOR MOTOR TURN OFF
  5436                              <1> 
  5437                              <1> ;---------- DISKETTE ERRORS ----------------------------------------------------
  5438                              <1> ;TIME_OUT	EQU	080H		; ATTACHMENT FAILED TO RESPOND
  5439                              <1> ;BAD_SEEK	EQU	040H		; SEEK OPERATION FAILED
  5440                              <1> BAD_NEC 	EQU	020H		; DISKETTE CONTROLLER HAS FAILED
  5441                              <1> BAD_CRC 	EQU	010H		; BAD CRC ON DISKETTE READ
  5442                              <1> MED_NOT_FND	EQU	00CH		; MEDIA TYPE NOT FOUND
  5443                              <1> DMA_BOUNDARY	EQU	009H		; ATTEMPT TO DMA ACROSS 64K BOUNDARY
  5444                              <1> BAD_DMA 	EQU	008H		; DMA OVERRUN ON OPERATION
  5445                              <1> MEDIA_CHANGE	EQU	006H		; MEDIA REMOVED ON DUAL ATTACH CARD
  5446                              <1> RECORD_NOT_FND	EQU	004H		; REQUESTED SECTOR NOT FOUND
  5447                              <1> WRITE_PROTECT	EQU	003H		; WRITE ATTEMPTED ON WRITE PROTECT DISK
  5448                              <1> BAD_ADDR_MARK	EQU	002H		; ADDRESS MARK NOT FOUND
  5449                              <1> BAD_CMD 	EQU	001H		; BAD COMMAND PASSED TO DISKETTE I/O
  5450                              <1> 
  5451                              <1> ;---------- DISK CHANGE LINE EQUATES -------------------------------------------
  5452                              <1> NOCHGLN 	EQU	001H		; NO DISK CHANGE LINE AVAILABLE
  5453                              <1> CHGLN		EQU	002H		; DISK CHANGE LINE AVAILABLE
  5454                              <1> 
  5455                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS ---------------------------------------
  5456                              <1> TRK_CAPA	EQU	00000001B	; 80 TRACK CAPABILITY
  5457                              <1> FMT_CAPA	EQU	00000010B	; MULTIPLE FORMAT CAPABILITY (1.2M)
  5458                              <1> DRV_DET 	EQU	00000100B	; DRIVE DETERMINED
  5459                              <1> MED_DET 	EQU	00010000B	; MEDIA DETERMINED BIT
  5460                              <1> DBL_STEP	EQU	00100000B	; DOUBLE STEP BIT
  5461                              <1> RATE_MSK	EQU	11000000B	; MASK FOR CLEARING ALL BUT RATE
  5462                              <1> RATE_500	EQU	00000000B	; 500 KBS DATA RATE
  5463                              <1> RATE_300	EQU	01000000B	; 300 KBS DATA RATE
  5464                              <1> RATE_250	EQU	10000000B	; 250 KBS DATA RATE
  5465                              <1> STRT_MSK	EQU	00001100B	; OPERATION START RATE MASK
  5466                              <1> SEND_MSK	EQU	11000000B	; MASK FOR SEND RATE BITS
  5467                              <1> 
  5468                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS COMPATIBILITY -------------------------
  5469                              <1> M3D3U		EQU	00000000B	; 360 MEDIA/DRIVE NOT ESTABLISHED
  5470                              <1> M3D1U		EQU	00000001B	; 360 MEDIA,1.2DRIVE NOT ESTABLISHED
  5471                              <1> M1D1U		EQU	00000010B	; 1.2 MEDIA/DRIVE NOT ESTABLISHED
  5472                              <1> MED_UNK 	EQU	00000111B	; NONE OF THE ABOVE
  5473                              <1> 
  5474                              <1> ;---------- INTERRUPT EQUATES --------------------------------------------------
  5475                              <1> ;EOI		EQU	020H		; END OF INTERRUPT COMMAND TO 8259
  5476                              <1> ;INTA00		EQU	020H		; 8259 PORT
  5477                              <1> INTA01		EQU	021H		; 8259 PORT
  5478                              <1> INTB00		EQU	0A0H		; 2ND 8259
  5479                              <1> INTB01		EQU	0A1H		;
  5480                              <1> 
  5481                              <1> ;-------------------------------------------------------------------------------
  5482                              <1> DMA08		EQU	008H		; DMA STATUS REGISTER PORT ADDRESS
  5483                              <1> DMA		EQU	000H		; DMA CH.0 ADDRESS REGISTER PORT ADDRESS
  5484                              <1> DMA18		EQU	0D0H		; 2ND DMA STATUS PORT ADDRESS
  5485                              <1> DMA1		EQU	0C0H		; 2ND DMA CH.0 ADDRESS REGISTER ADDRESS
  5486                              <1> ;-------------------------------------------------------------------------------
  5487                              <1> ;TIMER		EQU	040H		; 8254 TIMER - BASE ADDRESS
  5488                              <1> 
  5489                              <1> ;-------------------------------------------------------------------------------
  5490                              <1> DMA_PAGE	EQU	081H		; START OF DMA PAGE REGISTERS
  5491                              <1> 
  5492                              <1> ; 06/02/2015 (unix386.s, protected mode modifications)
  5493                              <1> ; (unix386.s <-- dsectrm2.s)
  5494                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - DSEG.INC)
  5495                              <1> 
  5496                              <1> ; 10/12/2014
  5497                              <1> ;
  5498                              <1> ;int40h:
  5499                              <1> ;	pushf
  5500                              <1> ;	push 	cs
  5501                              <1> ;	;cli
  5502                              <1> ;	call 	DISKETTE_IO_1
  5503                              <1> ;	retn
  5504                              <1> 
  5505                              <1> ; DSKETTE ----- 04/21/86 DISKETTE BIOS
  5506                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  5507                              <1> ;
  5508                              <1> 
  5509                              <1> ;-- INT13H ---------------------------------------------------------------------
  5510                              <1> ; DISKETTE I/O
  5511                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO THE 5 1/4 INCH 360 KB,
  5512                              <1> ;	1.2 MB, 720 KB AND 1.44 MB DISKETTE DRIVES.
  5513                              <1> ; INPUT
  5514                              <1> ;	(AH) =  00H RESET DISKETTE SYSTEM
  5515                              <1> ;		HARD RESET TO NEC, PREPARE COMMAND, RECALIBRATE REQUIRED
  5516                              <1> ;		ON ALL DRIVES
  5517                              <1> ;------------------------------------------------------------------------------- 
  5518                              <1> ;	(AH)= 01H  READ THE STATUS OF THE SYSTEM INTO (AH)
  5519                              <1> ;		@DISKETTE_STATUS FROM LAST OPERATION IS USED
  5520                              <1> ;-------------------------------------------------------------------------------
  5521                              <1> ;	REGISTERS FOR READ/WRITE/VERIFY/FORMAT
  5522                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5523                              <1> ;	(DH) - HEAD NUMBER (0-1 ALLOWED, NOT VALUE CHECKED)
  5524                              <1> ;	(CH) - TRACK NUMBER (NOT VALUE CHECKED)
  5525                              <1> ;		MEDIA	DRIVE	TRACK NUMBER
  5526                              <1> ;		320/360	320/360	    0-39
  5527                              <1> ;		320/360	1.2M	    0-39
  5528                              <1> ;		1.2M	1.2M	    0-79
  5529                              <1> ;		720K	720K	    0-79
  5530                              <1> ;		1.44M	1.44M	    0-79	
  5531                              <1> ;	(CL) - 	SECTOR NUMBER (NOT VALUE CHECKED, NOT USED FOR FORMAT)
  5532                              <1> ;		MEDIA	DRIVE	SECTOR NUMBER
  5533                              <1> ;		320/360	320/360	     1-8/9
  5534                              <1> ;		320/360	1.2M	     1-8/9
  5535                              <1> ;		1.2M	1.2M	     1-15
  5536                              <1> ;		720K	720K	     1-9
  5537                              <1> ;		1.44M	1.44M	     1-18		
  5538                              <1> ;	(AL)	NUMBER OF SECTORS (NOT VALUE CHECKED)
  5539                              <1> ;		MEDIA	DRIVE	MAX NUMBER OF SECTORS
  5540                              <1> ;		320/360	320/360	        8/9
  5541                              <1> ;		320/360	1.2M	        8/9
  5542                              <1> ;		1.2M	1.2M		15
  5543                              <1> ;		720K	720K		9
  5544                              <1> ;		1.44M	1.44M		18
  5545                              <1> ;
  5546                              <1> ;	(ES:BX) - ADDRESS OF BUFFER (NOT REQUIRED FOR VERIFY)
  5547                              <1> ;
  5548                              <1> ;-------------------------------------------------------------------------------
  5549                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY
  5550                              <1> ;-------------------------------------------------------------------------------
  5551                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY
  5552                              <1> ;-------------------------------------------------------------------------------
  5553                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS
  5554                              <1> ;-------------------------------------------------------------------------------
  5555                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK
  5556                              <1> ;		(ES,BX) MUST POINT TO THE COLLECTION OF DESIRED ADDRESS FIELDS
  5557                              <1> ;		FOR THE	TRACK. EACH FIELD IS COMPOSED OF 4 BYTES, (C,H,R,N),
  5558                              <1> ;		WHERE C = TRACK NUMBER, H=HEAD NUMBER, R = SECTOR NUMBER, 
  5559                              <1> ;		N= NUMBER OF BYTES PER SECTOR (00=128,01=256,02=512,03=1024),
  5560                              <1> ;		THERE MUST BE ONE ENTRY FOR EVERY SECTOR ON THE TRACK.
  5561                              <1> ;		THIS INFORMATION IS USED TO FIND THE REQUESTED SECTOR DURING 
  5562                              <1> ;		READ/WRITE ACCESS.
  5563                              <1> ;		PRIOR TO FORMATTING A DISKETTE, IF THERE EXISTS MORE THAN
  5564                              <1> ;		ONE SUPPORTED MEDIA FORMAT TYPE WITHIN THE DRIVE IN QUESTION,
  5565                              <1> ;		THEN "SET DASD TYPE" (INT 13H, AH = 17H) OR 'SET MEDIA TYPE'
  5566                              <1> ;		(INT 13H, AH =  18H) MUST BE CALLED TO SET THE DISKETTE TYPE
  5567                              <1> ;		THAT IS TO BE FORMATTED. IF "SET DASD TYPE" OR "SET MEDIA TYPE"
  5568                              <1> ;		IS NOT CALLED, THE FORMAT ROUTINE WILL ASSUME THE 
  5569                              <1> ;		MEDIA FORMAT TO BE THE MAXIMUM CAPACITY OF THE DRIVE.
  5570                              <1> ;
  5571                              <1> ;		THESE PARAMETERS OF DISK BASE MUST BE CHANGED IN ORDER TO
  5572                              <1> ;		FORMAT THE FOLLOWING MEDIAS:
  5573                              <1> ;		---------------------------------------------
  5574                              <1> ;		: MEDIA  :     DRIVE      : PARM 1 : PARM 2 :
  5575                              <1> ;		---------------------------------------------
  5576                              <1> ;		: 320K	 : 320K/360K/1.2M :  50H   :   8    :
  5577                              <1> ;		: 360K	 : 320K/360K/1.2M :  50H   :   9    :
  5578                              <1> ;		: 1.2M	 : 1.2M           :  54H   :  15    :
  5579                              <1> ;		: 720K	 : 720K/1.44M     :  50H   :   9    :
  5580                              <1> ;		: 1.44M	 : 1.44M          :  6CH   :  18    :		  	
  5581                              <1> ;		---------------------------------------------
  5582                              <1> ;		NOTES: - PARM 1 = GAP LENGTH FOR FORMAT
  5583                              <1> ;		       - PARM 2 = EOT (LAST SECTOR ON TRACK)
  5584                              <1> ;		       - DISK BASE IS POINTED BY DISK POINTER LOCATED
  5585                              <1> ;			 AT ABSOLUTE ADDRESS 0:78.
  5586                              <1> ;		       - WHEN FORMAT OPERATIONS ARE COMPLETE, THE PARAMETERS
  5587                              <1> ;			 SHOULD BE RESTORED TO THEIR RESPECTIVE INITIAL VALUES.			
  5588                              <1> ;-------------------------------------------------------------------------------
  5589                              <1> ;	(AH) = 08H READ DRIVE PARAMETERS
  5590                              <1> ;	REGISTERS
  5591                              <1> ;	  INPUT
  5592                              <1> ;	    (DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5593                              <1> ;	  OUTPUT
  5594                              <1> ;	    (ES:DI) POINTS TO DRIVE PARAMETER TABLE
  5595                              <1> ;	    (CH) - LOW ORDER 8 OF 10 BITS MAXIMUM NUMBER OF TRACKS
  5596                              <1> ;	    (CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
  5597                              <1> ;	           BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
  5598                              <1> ;	    (DH) - MAXIMUM HEAD NUMBER
  5599                              <1> ;	    (DL) - NUMBER OF DISKETTE DRIVES INSTALLED
  5600                              <1> ;	    (BH) - 0
  5601                              <1> ;	    (BL) - BITS 7 THRU 4 - 0
  5602                              <1> ;	           BITS 3 THRU 0 - VALID DRIVE TYPE VALUE IN CMOS
  5603                              <1> ;	    (AX) - 0
  5604                              <1> ;	 UNDER THE FOLLOWING CIRCUMSTANCES:
  5605                              <1> ;	    (1) THE DRIVE NUMBER IS INVALID,
  5606                              <1> ;	    (2) THE DRIVE TYPE IS UNKNOWN AND CMOS IS NOT PRESENT, 
  5607                              <1> ;	    (3) THE DRIVE TYPE IS UNKNOWN AND CMOS IS BAD,
  5608                              <1> ;	    (4) OR THE DRIVE TYPE IS UNKNOWN AND THE CMOS DRIVE TYPE IS INVALID
  5609                              <1> ;	    THEN ES,AX,BX,CX,DH,DI=0 ; DL=NUMBER OF DRIVES. 
  5610                              <1> ;	    IF NO DRIVES ARE PRESENT THEN: ES,AX,BX,CX,DX,DI=0.
  5611                              <1> ;	    @DISKETTE_STATUS = 0 AND CY IS RESET.
  5612                              <1> ;-------------------------------------------------------------------------------
  5613                              <1> ;	(AH)= 15H  READ DASD TYPE
  5614                              <1> ;	OUTPUT REGISTERS
  5615                              <1> ;	(AH) - ON RETURN IF CARRY FLAG NOT SET, OTHERWISE ERROR	
  5616                              <1> ;		00 - DRIVE NOT PRESENT	
  5617                              <1> ;		01 - DISKETTE, NO CHANGE LINE AVAILABLE
  5618                              <1> ;		02 - DISKETTE, CHANGE LINE AVAILABLE	
  5619                              <1> ;		03 - RESERVED (FIXED DISK)
  5620                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5621                              <1> ;-------------------------------------------------------------------------------
  5622                              <1> ;	(AH)= 16H  DISK CHANGE LINE STATUS
  5623                              <1> ;	OUTPUT REGISTERS
  5624                              <1> ;	(AH) - 00 - DISK CHANGE LINE NOT ACTIVE	
  5625                              <1> ;	       06 - DISK CHANGE LINE ACTIVE & CARRY BIT ON
  5626                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
  5627                              <1> ;-------------------------------------------------------------------------------
  5628                              <1> ;	(AH)= 17H  SET DASD TYPE FOR FORMAT
  5629                              <1> ;	INPUT REGISTERS
  5630                              <1> ;	(AL) -	00 - NOT USED	
  5631                              <1> ;		01 - DISKETTE 320/360K IN 360K DRIVE	
  5632                              <1> ;		02 - DISKETTE 360K IN 1.2M DRIVE
  5633                              <1> ;		03 - DISKETTE 1.2M IN 1.2M DRIVE
  5634                              <1> ;		04 - DISKETTE 720K IN 720K DRIVE
  5635                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED:
  5636                              <1> ;	       (DO NOT USE WHEN DISKETTE ATTACH CARD USED)
  5637                              <1> ;-------------------------------------------------------------------------------
  5638                              <1> ;	(AH)= 18H  SET MEDIA TYPE FOR FORMAT
  5639                              <1> ;	INPUT REGISTERS
  5640                              <1> ;	(CH) - LOW ORDER 8 OF 10 BITS MAXIMUM TRACKS
  5641                              <1> ;	(CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
  5642                              <1> ;	       BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
  5643                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHACKED)
  5644                              <1> ;	OUTPUT REGISTERS:
  5645                              <1> ;	(ES:DI) - POINTER TO DRIVE PARAMETERS TABLE FOR THIS MEDIA TYPE,
  5646                              <1> ;		  UNCHANGED IF (AH) IS NON-ZERO
  5647                              <1> ;	(AH) - 00H, CY = 0, TRACK AND SECTORS/TRACK COMBINATION IS SUPPORTED
  5648                              <1> ;	     - 01H, CY = 1, FUNCTION IS NOT AVAILABLE
  5649                              <1> ;	     - 0CH, CY = 1, TRACK AND SECTORS/TRACK COMBINATION IS NOT SUPPORTED
  5650                              <1> ;	     - 80H, CY = 1, TIME OUT (DISKETTE NOT PRESENT)		
  5651                              <1> ;-------------------------------------------------------------------------------
  5652                              <1> ;	DISK CHANGE STATUS IS ONLY CHECKED WHEN A MEDIA SPECIFIED IS OTHER
  5653                              <1> ;	THAN 360 KB DRIVE. IF THE DISK CHANGE LINE IS FOUND TO BE
  5654                              <1> ;	ACTIVE THE FOLLOWING ACTIONS TAKE PLACE:
  5655                              <1> ;		ATTEMPT TO RESET DISK CHANGE LINE TO INACTIVE STATE. 
  5656                              <1> ;		IF ATTEMPT SUCCEEDS SET DASD TYPE FOR FORMAT AND RETURN DISK 
  5657                              <1> ;		CHANGE ERROR CODE
  5658                              <1> ;		IF ATTEMPT FAILS RETURN TIMEOUT ERROR CODE AND SET DASD TYPE 
  5659                              <1> ;		TO A PREDETERMINED STATE INDICATING MEDIA TYPE UNKNOWN.
  5660                              <1> ;	IF THE DISK CHANGE LINE IN INACTIVE PERFORM SET DASD TYPE FOR FORMAT.
  5661                              <1> ;
  5662                              <1> ; DATA VARIABLE -- @DISK_POINTER
  5663                              <1> ;	DOUBLE WORD POINTER TO THE CURRENT SET OF DISKETTE PARAMETERS
  5664                              <1> ;-------------------------------------------------------------------------------
  5665                              <1> ; OUTPUT FOR ALL FUNCTIONS
  5666                              <1> ;	AH = STATUS OF OPERATION
  5667                              <1> ;		STATUS BITS ARE DEFINED IN THE EQUATES FOR @DISKETTE_STATUS
  5668                              <1> ;		VARIABLE IN THE DATA SEGMENT OF THIS MODULE
  5669                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN, EXCEPT FOR READ DASD
  5670                              <1> ;		TYPE AH=(15)).
  5671                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)
  5672                              <1> ;	FOR READ/WRITE/VERIFY
  5673                              <1> ;		DS,BX,DX,CX PRESERVED
  5674                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISKETTE CODE, THE APPROPRIATE 
  5675                              <1> ;		ACTION IS TO RESET THE DISKETTE, THEN RETRY THE OPERATION.
  5676                              <1> ;		ON READ ACCESSES, NO MOTOR START DELAY IS TAKEN, SO THAT 
  5677                              <1> ;		THREE RETRIES ARE REQUIRED ON READS TO ENSURE THAT THE 
  5678                              <1> ;		PROBLEM IS NOT DUE TO MOTOR START-UP.
  5679                              <1> ;-------------------------------------------------------------------------------
  5680                              <1> ;
  5681                              <1> ; DISKETTE STATE MACHINE - ABSOLUTE ADDRESS 40:90 (DRIVE A) & 91 (DRIVE B)
  5682                              <1> ;
  5683                              <1> ;   -----------------------------------------------------------------
  5684                              <1> ;   |       |       |       |       |       |       |       |       |
  5685                              <1> ;   |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
  5686                              <1> ;   |       |       |       |       |       |       |       |       |
  5687                              <1> ;   -----------------------------------------------------------------
  5688                              <1> ;	|	|	|	|	|	|	|	|
  5689                              <1> ;	|	|	|	|	|	-----------------
  5690                              <1> ;	|	|	|	|	|		|
  5691                              <1> ;	|	|	|	|    RESERVED		|
  5692                              <1> ;	|	|	|	|		  PRESENT STATE
  5693                              <1> ;	|	|	|	|	000: 360K IN 360K DRIVE UNESTABLISHED
  5694                              <1> ;	|	|	|	|	001: 360K IN 1.2M DRIVE UNESTABLISHED
  5695                              <1> ;	|	|	|	|	010: 1.2M IN 1.2M DRIVE UNESTABLISHED
  5696                              <1> ;	|	|	|	|	011: 360K IN 360K DRIVE ESTABLISHED
  5697                              <1> ;	|	|	|	|	100: 360K IN 1.2M DRIVE ESTABLISHED
  5698                              <1> ;	|	|	|	|	101: 1.2M IN 1.2M DRIVE ESTABLISHED
  5699                              <1> ;	|	|	|	|	110: RESERVED
  5700                              <1> ;	|	|	|	|	111: NONE OF THE ABOVE
  5701                              <1> ;	|	|	|	|
  5702                              <1> ;	|	|	|	------>	MEDIA/DRIVE ESTABLISHED
  5703                              <1> ;	|	|	|
  5704                              <1> ;	|	|	-------------->	DOUBLE STEPPING REQUIRED (360K IN 1.2M
  5705                              <1> ;	|	|			DRIVE)
  5706                              <1> ;	|	|
  5707                              <1> ;	------------------------------>	DATA TRANSFER RATE FOR THIS DRIVE:
  5708                              <1> ;
  5709                              <1> ;						00: 500 KBS
  5710                              <1> ;						01: 300 KBS
  5711                              <1> ;						10: 250 KBS
  5712                              <1> ;						11: RESERVED
  5713                              <1> ;
  5714                              <1> ;
  5715                              <1> ;-------------------------------------------------------------------------------
  5716                              <1> ; STATE OPERATION STARTED - ABSOLUTE ADDRESS 40:92 (DRIVE A) & 93 (DRIVE B)
  5717                              <1> ;-------------------------------------------------------------------------------
  5718                              <1> ; PRESENT CYLINDER NUMBER - ABSOLUTE ADDRESS 40:94 (DRIVE A) & 95 (DRIVE B)
  5719                              <1> ;-------------------------------------------------------------------------------
  5720                              <1> 
  5721                              <1> struc MD
  5722 00000000 <res 00000001>      <1> 	.SPEC1		resb	1	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
  5723 00000001 <res 00000001>      <1> 	.SPEC2		resb	1	; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
  5724 00000002 <res 00000001>      <1> 	.OFF_TIM	resb	1	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
  5725 00000003 <res 00000001>      <1> 	.BYT_SEC	resb	1	; 512 BYTES/SECTOR
  5726 00000004 <res 00000001>      <1> 	.SEC_TRK	resb	1	; EOT (LAST SECTOR ON TRACK)
  5727 00000005 <res 00000001>      <1> 	.GAP		resb	1	; GAP LENGTH
  5728 00000006 <res 00000001>      <1> 	.DTL		resb	1	; DTL
  5729 00000007 <res 00000001>      <1> 	.GAP3		resb	1	; GAP LENGTH FOR FORMAT
  5730 00000008 <res 00000001>      <1> 	.FIL_BYT	resb	1	; FILL BYTE FOR FORMAT
  5731 00000009 <res 00000001>      <1> 	.HD_TIM		resb	1	; HEAD SETTLE TIME (MILLISECONDS)
  5732 0000000A <res 00000001>      <1> 	.STR_TIM	resb	1	; MOTOR START TIME (1/8 SECONDS)
  5733 0000000B <res 00000001>      <1> 	.MAX_TRK	resb	1	; MAX. TRACK NUMBER
  5734 0000000C <res 00000001>      <1> 	.RATE		resb	1	; DATA TRANSFER RATE
  5735                              <1> endstruc
  5736                              <1> 
  5737                              <1> BIT7OFF	EQU	7FH
  5738                              <1> BIT7ON	EQU	80H
  5739                              <1> 
  5740                              <1> ;;int13h: ; 16/02/2015
  5741                              <1> ;; 16/02/2015 - 21/02/2015
  5742                              <1> int40h:
  5743 00001A50 9C                  <1> 	pushfd
  5744 00001A51 0E                  <1> 	push 	cs
  5745 00001A52 E801000000          <1> 	call 	DISKETTE_IO_1
  5746 00001A57 C3                  <1> 	retn	
  5747                              <1> 
  5748                              <1> DISKETTE_IO_1:
  5749                              <1> 
  5750 00001A58 FB                  <1> 	STI				; INTERRUPTS BACK ON
  5751 00001A59 55                  <1> 	PUSH	eBP			; USER REGISTER
  5752 00001A5A 57                  <1> 	PUSH	eDI			; USER REGISTER
  5753 00001A5B 52                  <1> 	PUSH	eDX			; HEAD #, DRIVE # OR USER REGISTER
  5754 00001A5C 53                  <1> 	PUSH	eBX			; BUFFER OFFSET PARAMETER OR REGISTER
  5755 00001A5D 51                  <1> 	PUSH	eCX			; TRACK #-SECTOR # OR USER REGISTER
  5756 00001A5E 89E5                <1> 	MOV	eBP,eSP			; BP     => PARAMETER LIST DEP. ON AH
  5757                              <1> 					; [BP]   = SECTOR #
  5758                              <1> 					; [BP+1] = TRACK #
  5759                              <1> 					; [BP+2] = BUFFER OFFSET
  5760                              <1> 					; FOR RETURN OF DRIVE PARAMETERS:
  5761                              <1> 					; CL/[BP] = BITS 7&6 HI BITS OF MAX CYL
  5762                              <1> 					; 	    BITS 0-5 MAX SECTORS/TRACK
  5763                              <1> 					; CH/[BP+1] = LOW 8 BITS OF MAX CYL.
  5764                              <1> 					; BL/[BP+2] = BITS 7-4 = 0
  5765                              <1> 					;	      BITS 3-0 = VALID CMOS TYPE
  5766                              <1> 					; BH/[BP+3] = 0
  5767                              <1> 					; DL/[BP+4] = # DRIVES INSTALLED
  5768                              <1> 					; DH/[BP+5] = MAX HEAD #
  5769                              <1> 					; DI/[BP+6] = OFFSET TO DISK BASE
  5770 00001A60 06                  <1> 	push	es ; 06/02/2015	
  5771 00001A61 1E                  <1> 	PUSH	DS			; BUFFER SEGMENT PARM OR USER REGISTER
  5772 00001A62 56                  <1> 	PUSH	eSI			; USER REGISTERS
  5773                              <1> 	;CALL	DDS			; SEGMENT OF BIOS DATA AREA TO DS
  5774                              <1> 	;mov	cx, cs
  5775                              <1> 	;mov	ds, cx
  5776 00001A63 66B91000            <1> 	mov	cx, KDATA
  5777 00001A67 8ED9                <1>         mov     ds, cx
  5778 00001A69 8EC1                <1>         mov     es, cx
  5779                              <1> 
  5780                              <1> 	;CMP	AH,(FNC_TAE-FNC_TAB)/2	; CHECK FOR > LARGEST FUNCTION
  5781 00001A6B 80FC19              <1> 	cmp	ah,(FNC_TAE-FNC_TAB)/4 ; 18/02/2015
  5782 00001A6E 7202                <1> 	JB	short OK_FUNC		; FUNCTION OK
  5783 00001A70 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
  5784                              <1> OK_FUNC:
  5785 00001A72 80FC01              <1> 	CMP	AH,1			; RESET OR STATUS ?
  5786 00001A75 760C                <1> 	JBE	short OK_DRV		; IF RESET OR STATUS DRIVE ALWAYS OK
  5787 00001A77 80FC08              <1> 	CMP	AH,8			; READ DRIVE PARMS ?
  5788 00001A7A 7407                <1> 	JZ	short OK_DRV		; IF SO DRIVE CHECKED LATER
  5789 00001A7C 80FA01              <1> 	CMP	DL,1			; DRIVES 0 AND 1 OK
  5790 00001A7F 7602                <1> 	JBE	short OK_DRV		; IF 0 OR 1 THEN JUMP
  5791 00001A81 B414                <1> 	MOV	AH,14H			; REPLACE WITH KNOWN INVALID FUNCTION
  5792                              <1> OK_DRV:
  5793 00001A83 31C9                <1> 	xor	ecx, ecx
  5794                              <1> 	;mov	esi, ecx ; 08/02/2015
  5795 00001A85 89CF                <1> 	mov	edi, ecx ; 08/02/2015
  5796 00001A87 88E1                <1> 	MOV	CL,AH			; CL = FUNCTION
  5797                              <1> 	;XOR	CH,CH			; CX = FUNCTION
  5798                              <1> 	;SHL	CL, 1			; FUNCTION TIMES 2
  5799 00001A89 C0E102              <1> 	SHL	CL, 2 ; 20/02/2015	; FUNCTION TIMES 4 (for 32 bit offset)
  5800 00001A8C BB[C41A0000]        <1> 	MOV	eBX,FNC_TAB		; LOAD START OF FUNCTION TABLE
  5801 00001A91 01CB                <1> 	ADD	eBX,eCX			; ADD OFFSET INTO TABLE => ROUTINE
  5802 00001A93 88F4                <1> 	MOV	AH,DH			; AX = HEAD #,# OF SECTORS OR DASD TYPE
  5803 00001A95 30F6                <1> 	XOR	DH,DH			; DX = DRIVE #
  5804 00001A97 6689C6              <1> 	MOV	SI,AX			; SI = HEAD #,# OF SECTORS OR DASD TYPE
  5805 00001A9A 6689D7              <1> 	MOV     DI,DX                   ; DI = DRIVE #
  5806                              <1> 	;
  5807                              <1> 	; 11/12/2014
  5808 00001A9D 8815[119D0000]      <1>         mov     [cfd], dl               ; current floppy drive (for 'GET_PARM')        
  5809                              <1> 	;
  5810 00001AA3 8A25[D4A20000]      <1> 	MOV	AH, [DSKETTE_STATUS]	; LOAD STATUS TO AH FOR STATUS FUNCTION
  5811 00001AA9 C605[D4A20000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; INITIALIZE FOR ALL OTHERS
  5812                              <1> 
  5813                              <1> ;	THROUGHOUT THE DISKETTE BIOS, THE FOLLOWING INFORMATION IS CONTAINED IN
  5814                              <1> ;	THE FOLLOWING MEMORY LOCATIONS AND REGISTERS. NOT ALL DISKETTE BIOS
  5815                              <1> ;	FUNCTIONS REQUIRE ALL OF THESE PARAMETERS.
  5816                              <1> ;
  5817                              <1> ;		DI	: DRIVE #
  5818                              <1> ;		SI-HI	: HEAD #
  5819                              <1> ;		SI-LOW	: # OF SECTORS OR DASD TYPE FOR FORMAT
  5820                              <1> ;		ES	: BUFFER SEGMENT
  5821                              <1> ;		[BP]	: SECTOR #
  5822                              <1> ;		[BP+1]	: TRACK #
  5823                              <1> ;		[BP+2]	: BUFFER OFFSET
  5824                              <1> ;
  5825                              <1> ;	ACROSS CALLS TO SUBROUTINES THE CARRY FLAG (CY=1), WHERE INDICATED IN 
  5826                              <1> ;	SUBROUTINE PROLOGUES, REPRESENTS AN EXCEPTION RETURN (NORMALLY AN ERROR 
  5827                              <1> ;	CONDITION). IN MOST CASES, WHEN CY = 1, @DSKETTE_STATUS CONTAINS THE 
  5828                              <1> ;	SPECIFIC ERROR CODE.
  5829                              <1> ;
  5830                              <1> 					; (AH) = @DSKETTE_STATUS
  5831 00001AB0 FF13                <1> 	CALL	dWORD [eBX]		; CALL THE REQUESTED FUNCTION
  5832 00001AB2 5E                  <1> 	POP	eSI			; RESTORE ALL REGISTERS
  5833 00001AB3 1F                  <1> 	POP	DS
  5834 00001AB4 07                  <1> 	pop	es	; 06/02/2015
  5835 00001AB5 59                  <1> 	POP	eCX
  5836 00001AB6 5B                  <1> 	POP	eBX
  5837 00001AB7 5A                  <1> 	POP	eDX
  5838 00001AB8 5F                  <1> 	POP	eDI
  5839 00001AB9 89E5                <1> 	MOV	eBP, eSP
  5840 00001ABB 50                  <1> 	PUSH	eAX
  5841 00001ABC 9C                  <1> 	PUSHFd
  5842 00001ABD 58                  <1> 	POP	eAX
  5843                              <1> 	;MOV	[BP+6], AX
  5844 00001ABE 89450C              <1> 	mov	[ebp+12], eax  ; 18/02/2015, flags
  5845 00001AC1 58                  <1> 	POP	eAX
  5846 00001AC2 5D                  <1> 	POP	eBP
  5847 00001AC3 CF                  <1> 	IRETd
  5848                              <1> 
  5849                              <1> ;-------------------------------------------------------------------------------
  5850                              <1> ; DW --> dd (06/02/2015)
  5851 00001AC4 [281B0000]          <1> FNC_TAB	dd	DSK_RESET		; AH = 00H; RESET
  5852 00001AC8 [A11B0000]          <1> 	dd	DSK_STATUS		; AH = 01H; STATUS
  5853 00001ACC [B21B0000]          <1> 	dd	DSK_READ		; AH = 02H; READ
  5854 00001AD0 [C31B0000]          <1> 	dd	DSK_WRITE		; AH = 03H; WRITE
  5855 00001AD4 [D41B0000]          <1> 	dd	DSK_VERF		; AH = 04H; VERIFY
  5856 00001AD8 [E51B0000]          <1> 	dd	DSK_FORMAT		; AH = 05H; FORMAT
  5857 00001ADC [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 06H; INVALID
  5858 00001AE0 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 07H; INVALID
  5859 00001AE4 [771C0000]          <1> 	dd	DSK_PARMS		; AH = 08H; READ DRIVE PARAMETERS
  5860 00001AE8 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 09H; INVALID
  5861 00001AEC [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 0AH; INVALID
  5862 00001AF0 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 0BH; INVALID
  5863 00001AF4 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 0CH; INVALID
  5864 00001AF8 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 0DH; INVALID
  5865 00001AFC [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 0EH; INVALID
  5866 00001B00 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 0FH; INVALID
  5867 00001B04 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 10H; INVALID
  5868 00001B08 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 11H; INVALID
  5869 00001B0C [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 12H; INVALID
  5870 00001B10 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 13H; INVALID
  5871 00001B14 [6A1C0000]          <1> 	dd	FNC_ERR			; AH = 14H; INVALID
  5872 00001B18 [381D0000]          <1> 	dd	DSK_TYPE		; AH = 15H; READ DASD TYPE
  5873 00001B1C [631D0000]          <1> 	dd	DSK_CHANGE		; AH = 16H; CHANGE STATUS
  5874 00001B20 [9D1D0000]          <1> 	dd	FORMAT_SET		; AH = 17H; SET DASD TYPE
  5875 00001B24 [201E0000]          <1> 	dd	SET_MEDIA		; AH = 18H; SET MEDIA TYPE	
  5876                              <1> FNC_TAE EQU     $                       ; END
  5877                              <1> 
  5878                              <1> ;-------------------------------------------------------------------------------
  5879                              <1> ; DISK_RESET	(AH = 00H)	
  5880                              <1> ;		RESET THE DISKETTE SYSTEM.
  5881                              <1> ;
  5882                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  5883                              <1> ;-------------------------------------------------------------------------------
  5884                              <1> DSK_RESET:
  5885 00001B28 66BAF203            <1> 	MOV	DX,03F2H		; ADAPTER CONTROL PORT
  5886 00001B2C FA                  <1> 	CLI				; NO INTERRUPTS
  5887 00001B2D A0[D2A20000]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  5888 00001B32 243F                <1> 	AND	AL,00111111B		; KEEP SELECTED AND MOTOR ON BITS
  5889 00001B34 C0C004              <1> 	ROL	AL,4			; MOTOR VALUE TO HIGH NIBBLE
  5890                              <1> 					; DRIVE SELECT TO LOW NIBBLE
  5891 00001B37 0C08                <1> 	OR	AL,00001000B		; TURN ON INTERRUPT ENABLE
  5892 00001B39 EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
  5893 00001B3A C605[D1A20000]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  5894                              <1> 	;JMP	$+2			; WAIT FOR I/O
  5895                              <1> 	;JMP	$+2			; WAIT FOR I/O (TO INSURE MINIMUM
  5896                              <1> 					;      PULSE WIDTH)
  5897                              <1> 	; 19/12/2014
  5898                              <1> 	NEWIODELAY
  5899 00001B41 E6EB                <2>  out 0ebh,al
  5900                              <1> 
  5901                              <1> 	; 17/12/2014 
  5902                              <1> 	; AWARD BIOS 1999 - RESETDRIVES (ADISK.ASM)
  5903 00001B43 B915000000          <1> 	mov	ecx, WAITCPU_RESET_ON	; cx = 21 -- Min. 14 micro seconds !?
  5904                              <1> wdw1:
  5905                              <1> 	NEWIODELAY   ; 27/02/2015
  5906 00001B48 E6EB                <2>  out 0ebh,al
  5907 00001B4A E2FC                <1> 	loop	wdw1
  5908                              <1> 	;
  5909 00001B4C 0C04                <1> 	OR	AL,00000100B		; TURN OFF RESET BIT
  5910 00001B4E EE                  <1> 	OUT	DX,AL			; RESET THE ADAPTER
  5911                              <1> 	; 16/12/2014
  5912                              <1> 	IODELAY
  5913 00001B4F EB00                <2>  jmp short $+2
  5914 00001B51 EB00                <2>  jmp short $+2
  5915                              <1> 	;
  5916                              <1> 	;STI				; ENABLE THE INTERRUPTS
  5917 00001B53 E8250C0000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  5918 00001B58 723E                <1> 	JC	short DR_ERR		; IF ERROR, RETURN IT
  5919 00001B5A 66B9C000            <1> 	MOV	CX,11000000B		; CL = EXPECTED @NEC_STATUS
  5920                              <1> NXT_DRV:
  5921 00001B5E 6651                <1> 	PUSH	CX			; SAVE FOR CALL
  5922 00001B60 B8[961B0000]        <1> 	MOV	eAX, DR_POP_ERR 	; LOAD NEC_OUTPUT ERROR ADDRESS
  5923 00001B65 50                  <1> 	PUSH	eAX			; "
  5924 00001B66 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  5925 00001B68 E8030B0000          <1> 	CALL	NEC_OUTPUT
  5926 00001B6D 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  5927 00001B6E E83A0C0000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  5928 00001B73 6659                <1> 	POP	CX			; RESTORE AFTER CALL
  5929 00001B75 7221                <1> 	JC	short DR_ERR		; ERROR RETURN
  5930 00001B77 3A0D[D5A20000]      <1> 	CMP	CL, [NEC_STATUS]	; TEST FOR DRIVE READY TRANSITION
  5931 00001B7D 7519                <1> 	JNZ	short DR_ERR		; EVERYTHING OK
  5932 00001B7F FEC1                <1> 	INC	CL			; NEXT EXPECTED @NEC_STATUS
  5933 00001B81 80F9C3              <1> 	CMP	CL,11000011B		; ALL POSSIBLE DRIVES CLEARED
  5934 00001B84 76D8                <1> 	JBE	short NXT_DRV		; FALL THRU IF 11000100B OR >
  5935                              <1> 	;
  5936 00001B86 E852030000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
  5937                              <1> RESBAC:
  5938 00001B8B E806090000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  5939 00001B90 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  5940 00001B93 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  5941 00001B95 C3                  <1> 	RETn		
  5942                              <1> DR_POP_ERR:
  5943 00001B96 6659                <1> 	POP	CX			; CLEAR STACK
  5944                              <1> DR_ERR:
  5945 00001B98 800D[D4A20000]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; SET ERROR CODE
  5946 00001B9F EBEA                <1> 	JMP	SHORT RESBAC		; RETURN FROM RESET
  5947                              <1> 
  5948                              <1> ;-------------------------------------------------------------------------------
  5949                              <1> ; DISK_STATUS	(AH = 01H)
  5950                              <1> ;	DISKETTE STATUS.
  5951                              <1> ;
  5952                              <1> ; ON ENTRY:	AH : STATUS OF PREVIOUS OPERATION
  5953                              <1> ;
  5954                              <1> ; ON EXIT:	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF PREVIOUS OPERATION.
  5955                              <1> ;-------------------------------------------------------------------------------
  5956                              <1> DSK_STATUS:
  5957 00001BA1 8825[D4A20000]      <1> 	MOV	[DSKETTE_STATUS],AH	; PUT BACK FOR SETUP END
  5958 00001BA7 E8EA080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  5959 00001BAC 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  5960 00001BAF 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  5961 00001BB1 C3                  <1> 	RETn		
  5962                              <1> 
  5963                              <1> ;-------------------------------------------------------------------------------
  5964                              <1> ; DISK_READ	(AH = 02H)	
  5965                              <1> ;	DISKETTE READ.
  5966                              <1> ;
  5967                              <1> ; ON ENTRY:	DI	: DRIVE #
  5968                              <1> ;		SI-HI	: HEAD #
  5969                              <1> ;		SI-LOW	: # OF SECTORS
  5970                              <1> ;		ES	: BUFFER SEGMENT
  5971                              <1> ;		[BP]	: SECTOR #
  5972                              <1> ;		[BP+1]	: TRACK #
  5973                              <1> ;		[BP+2]	: BUFFER OFFSET
  5974                              <1> ;
  5975                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  5976                              <1> ;-------------------------------------------------------------------------------
  5977                              <1> 
  5978                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
  5979                              <1> 
  5980                              <1> DSK_READ:
  5981 00001BB2 8025[D2A20000]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
  5982 00001BB9 66B846E6            <1> 	MOV	AX,0E646H		; AX = NEC COMMAND, DMA COMMAND
  5983 00001BBD E825040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  5984 00001BC2 C3                  <1> 	RETn
  5985                              <1> 
  5986                              <1> ;-------------------------------------------------------------------------------
  5987                              <1> ; DISK_WRITE	(AH = 03H)
  5988                              <1> ;	DISKETTE WRITE.
  5989                              <1> ;
  5990                              <1> ; ON ENTRY:	DI	: DRIVE #
  5991                              <1> ;		SI-HI	: HEAD #
  5992                              <1> ;		SI-LOW	: # OF SECTORS
  5993                              <1> ;		ES	: BUFFER SEGMENT
  5994                              <1> ;		[BP]	: SECTOR #
  5995                              <1> ;		[BP+1]	: TRACK #
  5996                              <1> ;		[BP+2]	: BUFFER OFFSET
  5997                              <1> ;
  5998                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  5999                              <1> ;-------------------------------------------------------------------------------
  6000                              <1> 
  6001                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
  6002                              <1> 
  6003                              <1> DSK_WRITE:
  6004 00001BC3 66B84AC5            <1> 	MOV	AX,0C54AH		; AX = NEC COMMAND, DMA COMMAND
  6005 00001BC7 800D[D2A20000]80    <1>         OR      byte [MOTOR_STATUS],10000000B ; INDICATE WRITE OPERATION
  6006 00001BCE E814040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  6007 00001BD3 C3                  <1> 	RETn
  6008                              <1> 
  6009                              <1> ;-------------------------------------------------------------------------------
  6010                              <1> ; DISK_VERF	(AH = 04H)
  6011                              <1> ;	DISKETTE VERIFY.
  6012                              <1> ;
  6013                              <1> ; ON ENTRY:	DI	: DRIVE #
  6014                              <1> ;		SI-HI	: HEAD #
  6015                              <1> ;		SI-LOW	: # OF SECTORS
  6016                              <1> ;		ES	: BUFFER SEGMENT
  6017                              <1> ;		[BP]	: SECTOR #
  6018                              <1> ;		[BP+1]	: TRACK #
  6019                              <1> ;		[BP+2]	: BUFFER OFFSET
  6020                              <1> ;
  6021                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6022                              <1> ;-------------------------------------------------------------------------------
  6023                              <1> DSK_VERF:
  6024 00001BD4 8025[D2A20000]7F    <1> 	AND	byte [MOTOR_STATUS],01111111B ; INDICATE A READ OPERATION
  6025 00001BDB 66B842E6            <1> 	MOV	AX,0E642H		; AX = NEC COMMAND, DMA COMMAND
  6026 00001BDF E803040000          <1> 	CALL	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  6027 00001BE4 C3                  <1> 	RETn
  6028                              <1> 
  6029                              <1> ;-------------------------------------------------------------------------------
  6030                              <1> ; DISK_FORMAT	(AH = 05H)
  6031                              <1> ;	DISKETTE FORMAT.
  6032                              <1> ;
  6033                              <1> ; ON ENTRY:	DI	: DRIVE #
  6034                              <1> ;		SI-HI	: HEAD #
  6035                              <1> ;		SI-LOW	: # OF SECTORS
  6036                              <1> ;		ES	: BUFFER SEGMENT
  6037                              <1> ;		[BP]	: SECTOR #
  6038                              <1> ;		[BP+1]	: TRACK #
  6039                              <1> ;		[BP+2]	: BUFFER OFFSET
  6040                              <1> ;		@DISK_POINTER POINTS TO THE PARAMETER TABLE OF THIS DRIVE
  6041                              <1> ;
  6042                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6043                              <1> ;-------------------------------------------------------------------------------
  6044                              <1> DSK_FORMAT:
  6045 00001BE5 E83C030000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6046 00001BEA E838050000          <1> 	CALL	FMT_INIT		; ESTABLISH STATE IF UNESTABLISHED
  6047 00001BEF 800D[D2A20000]80    <1>         OR      byte [MOTOR_STATUS], 10000000B ; INDICATE WRITE OPERATION
  6048 00001BF6 E880050000          <1> 	CALL	MED_CHANGE		; CHECK MEDIA CHANGE AND RESET IF SO
  6049 00001BFB 725D                <1>         JC      short FM_DON            ; MEDIA CHANGED, SKIP
  6050 00001BFD E8DB020000          <1> 	CALL	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
  6051 00001C02 E8E6050000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMPT RATE IS SAME AS LAST RATE
  6052 00001C07 7405                <1>         JZ      short FM_WR             ; YES, SKIP SPECIFY COMMAND
  6053 00001C09 E8BD050000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO CONTROLLER
  6054                              <1> FM_WR:
  6055 00001C0E E873060000          <1> 	CALL	FMTDMA_SET		; SET UP THE DMA FOR FORMAT
  6056 00001C13 7245                <1>         JC      short FM_DON            ; RETURN WITH ERROR
  6057 00001C15 B44D                <1> 	MOV	AH,04DH			; ESTABLISH THE FORMAT COMMAND
  6058 00001C17 E8D0060000          <1> 	CALL	NEC_INIT		; INITIALIZE THE NEC
  6059 00001C1C 723C                <1>         JC      short FM_DON            ; ERROR - EXIT
  6060 00001C1E B8[5A1C0000]        <1>         MOV     eAX, FM_DON             ; LOAD ERROR ADDRESS
  6061 00001C23 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6062 00001C24 B203                <1> 	MOV	DL,3			; BYTES/SECTOR VALUE TO NEC
  6063 00001C26 E83F090000          <1> 	CALL	GET_PARM
  6064 00001C2B E8400A0000          <1> 	CALL	NEC_OUTPUT
  6065 00001C30 B204                <1> 	MOV	DL,4			; SECTORS/TRACK VALUE TO NEC
  6066 00001C32 E833090000          <1> 	CALL	GET_PARM
  6067 00001C37 E8340A0000          <1> 	CALL	NEC_OUTPUT
  6068 00001C3C B207                <1> 	MOV	DL,7			; GAP LENGTH VALUE TO NEC
  6069 00001C3E E827090000          <1> 	CALL	GET_PARM
  6070 00001C43 E8280A0000          <1> 	CALL	NEC_OUTPUT
  6071 00001C48 B208                <1> 	MOV	DL,8			; FILLER BYTE TO NEC
  6072 00001C4A E81B090000          <1> 	CALL	GET_PARM
  6073 00001C4F E81C0A0000          <1> 	CALL	NEC_OUTPUT
  6074 00001C54 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  6075 00001C55 E810070000          <1> 	CALL	NEC_TERM		; TERMINATE, RECEIVE STATUS, ETC,
  6076                              <1> FM_DON:
  6077 00001C5A E8F8020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6078 00001C5F E832080000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6079 00001C64 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6080 00001C67 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6081 00001C69 C3                  <1> 	RETn
  6082                              <1> 
  6083                              <1> ;-------------------------------------------------------------------------------
  6084                              <1> ; FNC_ERR
  6085                              <1> ;	INVALID FUNCTION REQUESTED OR INVALID DRIVE: 
  6086                              <1> ;	SET BAD COMMAND IN STATUS.
  6087                              <1> ;
  6088                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6089                              <1> ;-------------------------------------------------------------------------------
  6090                              <1> FNC_ERR:				; INVALID FUNCTION REQUEST
  6091 00001C6A 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
  6092 00001C6D B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
  6093 00001C6F 8825[D4A20000]      <1> 	MOV	[DSKETTE_STATUS],AH	; STORE IN DATA AREA
  6094 00001C75 F9                  <1> 	STC				; SET CARRY INDICATING ERROR
  6095 00001C76 C3                  <1> 	RETn
  6096                              <1> 
  6097                              <1> ;-------------------------------------------------------------------------------
  6098                              <1> ; DISK_PARMS	(AH = 08H)	
  6099                              <1> ;	READ DRIVE PARAMETERS.
  6100                              <1> ;
  6101                              <1> ; ON ENTRY:	DI : DRIVE #
  6102                              <1> ;
  6103                              <1> ; ON EXIT:	CL/[BP]   = BITS 7 & 6 HI 2 BITS OF MAX CYLINDER
  6104                              <1> ;		            BITS 0-5 MAX SECTORS/TRACK
  6105                              <1> ;		CH/[BP+1] = LOW 8 BITS OF MAX CYLINDER
  6106                              <1> ;		BL/[BP+2] = BITS 7-4 = 0
  6107                              <1> ;		            BITS 3-0 = VALID CMOS DRIVE TYPE
  6108                              <1> ;		BH/[BP+3] = 0
  6109                              <1> ;		DL/[BP+4] = # DRIVES INSTALLED (VALUE CHECKED)
  6110                              <1> ;		DH/[BP+5] = MAX HEAD #
  6111                              <1> ;		DI/[BP+6] = OFFSET TO DISK_BASE
  6112                              <1> ;		ES        = SEGMENT OF DISK_BASE
  6113                              <1> ;		AX        = 0
  6114                              <1> ;
  6115                              <1> ;		NOTE : THE ABOVE INFORMATION IS STORED IN THE USERS STACK AT
  6116                              <1> ;		       THE LOCATIONS WHERE THE MAIN ROUTINE WILL POP THEM
  6117                              <1> ;		       INTO THE APPROPRIATE REGISTERS BEFORE RETURNING TO THE
  6118                              <1> ;		       CALLER.
  6119                              <1> ;-------------------------------------------------------------------------------
  6120                              <1> DSK_PARMS:
  6121 00001C77 E8AA020000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  6122                              <1>      ;	MOV	WORD [BP+2],0		; DRIVE TYPE = 0
  6123 00001C7C 29D2                <1> 	sub     edx, edx ; 20/02/2015
  6124 00001C7E 895504              <1>         mov	[ebp+4], edx ; 20/02/2015
  6125                              <1>      ;  MOV     AX, [EQUIP_FLAG]        ; LOAD EQUIPMENT FLAG FOR # DISKETTES
  6126                              <1>      ;  AND     AL,11000001B            ; KEEP DISKETTE DRIVE BITS
  6127                              <1>      ;  MOV     DL,2                    ; DISKETTE DRIVES = 2
  6128                              <1>      ;  CMP     AL,01000001B            ; 2 DRIVES INSTALLED ?
  6129                              <1>      ;  JZ      short STO_DL            ; IF YES JUMP
  6130                              <1>      ;  DEC     DL                      ; DISKETTE DRIVES = 1
  6131                              <1>      ;  CMP     AL,00000001B            ; 1 DRIVE INSTALLED ?
  6132                              <1>      ;  JNZ     short NON_DRV           ; IF NO JUMP
  6133                              <1> 	;sub	edx, edx
  6134 00001C81 66A1[1E9D0000]      <1> 	mov     ax, [fd0_type]
  6135 00001C87 6621C0              <1> 	and     ax, ax
  6136 00001C8A 7474                <1> 	jz      short NON_DRV
  6137 00001C8C FEC2                <1> 	inc     dl
  6138 00001C8E 20E4                <1> 	and     ah, ah
  6139 00001C90 7402                <1> 	jz      short STO_DL
  6140 00001C92 FEC2                <1> 	inc     dl
  6141                              <1> STO_DL:
  6142                              <1> 	;MOV	[BP+4],DL		; STORE NUMBER OF DRIVES
  6143 00001C94 895508              <1> 	mov	[ebp+8], edx ; 20/02/2015	 	
  6144 00001C97 6683FF01            <1> 	CMP	DI,1			; CHECK FOR VALID DRIVE
  6145 00001C9B 7766                <1> 	JA	short NON_DRV1		; DRIVE INVALID
  6146                              <1> 	;MOV	BYTE [BP+5],1		; MAXIMUM HEAD NUMBER =	1
  6147 00001C9D C6450901            <1> 	mov	byte [ebp+9], 1  ; 20/02/2015	
  6148 00001CA1 E8BB080000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  6149                              <1> 	;;20/02/2015
  6150                              <1> 	;;JC	short CHK_EST		; IF CMOS BAD CHECKSUM ESTABLISHED
  6151                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE TYPE
  6152 00001CA6 7412                <1> 	JZ	short CHK_EST		; JUMP IF SO
  6153 00001CA8 E805020000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6154 00001CAD 720B                <1> 	JC	short CHK_EST		; TYPE NOT IN TABLE (POSSIBLE BAD CMOS)
  6155                              <1> 	;MOV	[BP+2],AL		; STORE VALID CMOS DRIVE TYPE
  6156 00001CAF 884504              <1>         mov	[ebp+4], al ; 06/02/2015
  6157 00001CB2 8A4B04              <1> 	MOV     CL, [eBX+MD.SEC_TRK]     ; GET SECTOR/TRACK
  6158 00001CB5 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]     ; GET MAX. TRACK NUMBER
  6159 00001CB8 EB36                <1> 	JMP	SHORT STO_CX		; CMOS GOOD, USE CMOS
  6160                              <1> CHK_EST:
  6161 00001CBA 8AA7[E1A20000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; LOAD STATE FOR THIS DRIVE
  6162 00001CC0 F6C410              <1> 	TEST	AH,MED_DET		; CHECK FOR ESTABLISHED STATE
  6163 00001CC3 743E                <1> 	JZ	short NON_DRV1		; CMOS BAD/INVALID OR UNESTABLISHED
  6164                              <1> USE_EST:
  6165 00001CC5 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE STATE
  6166 00001CC8 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  6167 00001CCB 7557                <1> 	JNE	short USE_EST2		; NO, GO CHECK OTHER RATE
  6168                              <1> 
  6169                              <1> ;-----	DATA RATE IS 250 KBS, TRY 360 KB TABLE FIRST
  6170                              <1> 
  6171 00001CCD B001                <1> 	MOV	AL,01			; DRIVE TYPE 1 (360KB)
  6172 00001CCF E8DE010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6173 00001CD4 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6174 00001CD7 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6175 00001CDA F687[E1A20000]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; 80 TRACK ?
  6176 00001CE1 740D                <1> 	JZ	short STO_CX		; MUST BE 360KB DRIVE 
  6177                              <1> 
  6178                              <1> ;-----	IT IS 1.44 MB DRIVE
  6179                              <1> 
  6180                              <1> PARM144:
  6181 00001CE3 B004                <1> 	MOV	AL,04			; DRIVE TYPE 4 (1.44MB)
  6182 00001CE5 E8C8010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6183 00001CEA 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6184 00001CED 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6185                              <1> STO_CX:
  6186 00001CF0 894D00              <1> 	MOV	[eBP],eCX		; SAVE POINTER IN STACK FOR RETURN
  6187                              <1> ES_DI:
  6188                              <1> 	;MOV	[BP+6],BX		; ADDRESS OF MEDIA/DRIVE PARM TABLE 
  6189 00001CF3 895D0C              <1> 	mov	[ebp+12], ebx ; 06/02/2015
  6190                              <1> 	;MOV	AX,CS			; SEGMENT MEDIA/DRIVE PARAMETER TABLE
  6191                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
  6192                              <1> DP_OUT:
  6193 00001CF6 E85C020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6194 00001CFB 6631C0              <1> 	XOR	AX,AX			; CLEAR
  6195 00001CFE F8                  <1> 	CLC
  6196 00001CFF C3                  <1> 	RETn
  6197                              <1> 
  6198                              <1> ;-----	NO DRIYE PRESENT HANDLER
  6199                              <1> 
  6200                              <1> NON_DRV:
  6201                              <1> 	;MOV	BYTE [BP+4],0		; CLEAR NUMBER OF DRIVES
  6202 00001D00 895508              <1> 	mov	[ebp+8], edx ; 0 ; 20/02/2015
  6203                              <1> NON_DRV1:
  6204 00001D03 6681FF8000          <1> 	CMP	DI,80H			; CHECK FOR FIXED MEDIA TYPE REQUEST
  6205 00001D08 720C                <1> 	JB	short NON_DRV2		; CONTINUE IF NOT REQUEST FALL THROUGH
  6206                              <1> 
  6207                              <1> ;-----	FIXED DISK REQUEST FALL THROUGH ERROR
  6208                              <1> 	
  6209 00001D0A E848020000          <1> 	CALL	XLAT_OLD		; ELSE TRANSLATE TO COMPATIBLE MODE
  6210 00001D0F 6689F0              <1> 	MOV	AX,SI			; RESTORE AL
  6211 00001D12 B401                <1> 	MOV	AH,BAD_CMD		; SET BAD COMMAND ERROR
  6212 00001D14 F9                  <1> 	STC
  6213 00001D15 C3                  <1> 	RETn
  6214                              <1> 
  6215                              <1> NON_DRV2:
  6216                              <1> 	;XOR	AX,AX			; CLEAR PARMS IF NO DRIVES OR CMOS BAD
  6217 00001D16 31C0                <1> 	xor	eax, eax	
  6218 00001D18 66894500            <1> 	MOV	[eBP],AX		; TRACKS, SECTORS/TRACK = 0
  6219                              <1> 	;MOV	[BP+5],AH		; HEAD = 0
  6220 00001D1C 886509              <1> 	mov	[ebp+9], ah ; 06/02/2015
  6221                              <1> 	;MOV	[BP+6],AX		; OFFSET TO DISK_BASE = 0
  6222 00001D1F 89450C              <1> 	mov	[ebp+12], eax
  6223                              <1> 	;MOV	ES,AX			; ES IS SEGMENT OF TABLE
  6224 00001D22 EBD2                <1> 	JMP	SHORT DP_OUT
  6225                              <1> 
  6226                              <1> ;-----	DATA RATE IS EITHER 300 KBS OR 500 KBS, TRY 1.2 MB TABLE FIRST
  6227                              <1> 
  6228                              <1> USE_EST2:
  6229 00001D24 B002                <1> 	MOV	AL,02			; DRIVE TYPE 2 (1.2MB)
  6230 00001D26 E887010000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6231 00001D2B 8A4B04              <1>         MOV     CL, [eBX+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6232 00001D2E 8A6B0B              <1>         MOV     CH, [eBX+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  6233 00001D31 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  6234 00001D34 74BA                <1> 	JZ	short STO_CX		; MUST BE 1.2MB DRIVE
  6235 00001D36 EBAB                <1> 	JMP	SHORT PARM144		; ELSE, IT IS 1.44MB DRIVE 
  6236                              <1> 
  6237                              <1> ;-------------------------------------------------------------------------------
  6238                              <1> ; DISK_TYPE (AH = 15H)	
  6239                              <1> ;	THIS ROUTINE RETURNS THE TYPE OF MEDIA INSTALLED.
  6240                              <1> ;
  6241                              <1> ;  ON ENTRY:	DI = DRIVE #
  6242                              <1> ;
  6243                              <1> ;  ON EXIT:	AH = DRIVE TYPE, CY=0
  6244                              <1> ;-------------------------------------------------------------------------------
  6245                              <1> DSK_TYPE:
  6246 00001D38 E8E9010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6247 00001D3D 8A87[E1A20000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET PRESENT STATE INFORMATION
  6248 00001D43 08C0                <1> 	OR	AL,AL			; CHECK FOR NO DRIVE
  6249 00001D45 7418                <1> 	JZ	short NO_DRV
  6250 00001D47 B401                <1> 	MOV	AH,NOCHGLN		; NO CHANGE LINE FOR 40 TRACK DRIVE
  6251 00001D49 A801                <1> 	TEST	AL,TRK_CAPA		; IS THIS DRIVE AN 80 TRACK DRIVE?
  6252 00001D4B 7402                <1> 	JZ	short DT_BACK			; IF NO JUMP
  6253 00001D4D B402                <1> 	MOV	AH,CHGLN		; CHANGE LINE FOR 80 TRACK DRIVE
  6254                              <1> DT_BACK:
  6255 00001D4F 6650                <1> 	PUSH	AX			; SAVE RETURN VALUE
  6256 00001D51 E801020000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6257 00001D56 6658                <1> 	POP	AX			; RESTORE RETURN VALUE
  6258 00001D58 F8                  <1> 	CLC				; NO ERROR
  6259 00001D59 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6260 00001D5C 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6261 00001D5E C3                  <1> 	RETn
  6262                              <1> NO_DRV:	
  6263 00001D5F 30E4                <1> 	XOR	AH,AH			; NO DRIVE PRESENT OR UNKNOWN
  6264 00001D61 EBEC                <1> 	JMP	SHORT DT_BACK
  6265                              <1> 
  6266                              <1> ;-------------------------------------------------------------------------------
  6267                              <1> ; DISK_CHANGE	(AH = 16H)
  6268                              <1> ;	THIS ROUTINE RETURNS THE STATE OF THE DISK CHANGE LINE.
  6269                              <1> ;
  6270                              <1> ; ON ENTRY:	DI = DRIVE #
  6271                              <1> ;
  6272                              <1> ; ON EXIT:	AH = @DSKETTE_STATUS
  6273                              <1> ;		     00 - DISK CHANGE LINE INACTIVE, CY = 0
  6274                              <1> ;		     06 - DISK CHANGE LINE ACTIVE, CY = 1
  6275                              <1> ;-------------------------------------------------------------------------------
  6276                              <1> DSK_CHANGE:
  6277 00001D63 E8BE010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6278 00001D68 8A87[E1A20000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET MEDIA STATE INFORMATION
  6279 00001D6E 08C0                <1> 	OR	AL,AL			; DRIVE PRESENT ?
  6280 00001D70 7422                <1> 	JZ	short DC_NON		; JUMP IF NO DRIVE
  6281 00001D72 A801                <1> 	TEST	AL,TRK_CAPA		; 80 TRACK DRIVE ?
  6282 00001D74 7407                <1> 	JZ	short SETIT		; IF SO , CHECK CHANGE LINE
  6283                              <1> DC0:
  6284 00001D76 E88D0A0000          <1>         CALL    READ_DSKCHNG            ; GO CHECK STATE OF DISK CHANGE LINE
  6285 00001D7B 7407                <1> 	JZ	short FINIS		; CHANGE LINE NOT ACTIVE
  6286                              <1> 
  6287 00001D7D C605[D4A20000]06    <1> SETIT:	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; INDICATE MEDIA REMOVED
  6288                              <1> 
  6289 00001D84 E8CE010000          <1> FINIS:	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6290 00001D89 E808070000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6291 00001D8E 6689F3              <1> 	MOV	BX,SI			; GET SAVED AL TO BL
  6292 00001D91 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6293 00001D93 C3                  <1> 	RETn
  6294                              <1> DC_NON:
  6295 00001D94 800D[D4A20000]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; SET TIMEOUT, NO DRIVE
  6296 00001D9B EBE7                <1> 	JMP	SHORT FINIS
  6297                              <1> 
  6298                              <1> ;-------------------------------------------------------------------------------
  6299                              <1> ; FORMAT_SET	(AH = 17H)
  6300                              <1> ;	THIS ROUTINE IS USED TO ESTABLISH THE TYPE OF MEDIA TO BE USED
  6301                              <1> ;	FOR THE FOLLOWING FORMAT OPERATION.
  6302                              <1> ;
  6303                              <1> ; ON ENTRY:	SI LOW = DASD TYPE FOR FORMAT
  6304                              <1> ;		DI     = DRIVE #
  6305                              <1> ;
  6306                              <1> ; ON EXIT:	@DSKETTE_STATUS REFLECTS STATUS
  6307                              <1> ;		AH = @DSKETTE_STATUS
  6308                              <1> ;		CY = 1 IF ERROR
  6309                              <1> ;-------------------------------------------------------------------------------
  6310                              <1> FORMAT_SET:
  6311 00001D9D E884010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6312 00001DA2 6656                <1> 	PUSH	SI			; SAVE DASD TYPE
  6313 00001DA4 6689F0              <1> 	MOV	AX,SI			; AH = ? , AL , DASD TYPE
  6314 00001DA7 30E4                <1> 	XOR	AH,AH			; AH , 0 , AL , DASD TYPE
  6315 00001DA9 6689C6              <1> 	MOV	SI,AX			; SI = DASD TYPE
  6316 00001DAC 80A7[E1A20000]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  6317 00001DB3 664E                <1> 	DEC	SI			; CHECK FOR 320/360K MEDIA & DRIVE
  6318 00001DB5 7509                <1> 	JNZ	short NOT_320		; BYPASS IF NOT
  6319 00001DB7 808F[E1A20000]90    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_250 ; SET TO 320/360
  6320 00001DBE EB48                <1> 	JMP	SHORT S0
  6321                              <1> 
  6322                              <1> NOT_320:
  6323 00001DC0 E8B6030000          <1> 	CALL	MED_CHANGE		; CHECK FOR TIME_OUT
  6324 00001DC5 803D[D4A20000]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT
  6325 00001DCC 743A                <1> 	JZ	short S0		; IF TIME OUT TELL CALLER
  6326                              <1> S3:
  6327 00001DCE 664E                <1> 	DEC	SI			; CHECK FOR 320/360K IN 1.2M DRIVE
  6328 00001DD0 7509                <1> 	JNZ	short NOT_320_12	; BYPASS IF NOT
  6329 00001DD2 808F[E1A20000]70    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+DBL_STEP+RATE_300 ; SET STATE
  6330 00001DD9 EB2D                <1> 	JMP	SHORT S0
  6331                              <1> 
  6332                              <1> NOT_320_12:
  6333 00001DDB 664E                <1> 	DEC	SI			; CHECK FOR 1.2M MEDIA IN 1.2M DRIVE
  6334 00001DDD 7509                <1> 	JNZ	short NOT_12		; BYPASS IF NOT
  6335 00001DDF 808F[E1A20000]10    <1> 	OR	byte [DSK_STATE+eDI], MED_DET+RATE_500 ; SET STATE VARIABLE
  6336 00001DE6 EB20                <1> 	JMP	SHORT S0		; RETURN TO CALLER
  6337                              <1> 
  6338                              <1> NOT_12:	
  6339 00001DE8 664E                <1> 	DEC	SI			; CHECK FOR SET DASD TYPE 04
  6340 00001DEA 752B                <1> 	JNZ	short FS_ERR		; BAD COMMAND EXIT IF NOT VALID TYPE
  6341                              <1> 
  6342 00001DEC F687[E1A20000]04    <1> 	TEST	byte [DSK_STATE+eDI], DRV_DET ; DRIVE DETERMINED ?
  6343 00001DF3 740B                <1> 	JZ	short ASSUME		; IF STILL NOT DETERMINED ASSUME
  6344 00001DF5 B050                <1> 	MOV	AL,MED_DET+RATE_300
  6345 00001DF7 F687[E1A20000]02    <1>         TEST    byte [DSK_STATE+eDI], FMT_CAPA ; MULTIPLE FORMAT CAPABILITY ?
  6346 00001DFE 7502                <1> 	JNZ	short OR_IT_IN		; IF 1.2 M THEN DATA RATE 300
  6347                              <1> 
  6348                              <1> ASSUME:
  6349 00001E00 B090                <1> 	MOV	AL,MED_DET+RATE_250	; SET UP
  6350                              <1> 
  6351                              <1> OR_IT_IN:
  6352 00001E02 0887[E1A20000]      <1> 	OR	[DSK_STATE+eDI], AL	; OR IN THE CORRECT STATE
  6353                              <1> S0:
  6354 00001E08 E84A010000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6355 00001E0D E884060000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6356 00001E12 665B                <1> 	POP	BX			; GET SAVED AL TO BL
  6357 00001E14 88D8                <1> 	MOV	AL,BL			; PUT BACK FOR RETURN
  6358 00001E16 C3                  <1> 	RETn
  6359                              <1> 
  6360                              <1> FS_ERR:
  6361 00001E17 C605[D4A20000]01    <1> 	MOV	byte [DSKETTE_STATUS], BAD_CMD ; UNKNOWN STATE,BAD COMMAND
  6362 00001E1E EBE8                <1> 	JMP	SHORT S0
  6363                              <1> 
  6364                              <1> ;-------------------------------------------------------------------------------
  6365                              <1> ; SET_MEDIA	(AH = 18H)
  6366                              <1> ;	THIS ROUTINE SETS THE TYPE OF MEDIA AND DATA RATE 
  6367                              <1> ;	TO BE USED FOR THE FOLLOWING FORMAT OPERATION.
  6368                              <1> ;
  6369                              <1> ; ON ENTRY:
  6370                              <1> ;	[BP]	= SECTOR PER TRACK
  6371                              <1> ;	[BP+1]	= TRACK #
  6372                              <1> ;	DI	= DRIVE #
  6373                              <1> ;
  6374                              <1> ; ON EXIT:
  6375                              <1> ;	@DSKETTE_STATUS REFLECTS STATUS
  6376                              <1> ;	IF NO ERROR:
  6377                              <1> ;		AH = 0
  6378                              <1> ;		CY = 0
  6379                              <1> ;		ES = SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  6380                              <1> ;		DI/[BP+6] = OFFSET OF MEDIA/DRIVE PARAMETER TABLE
  6381                              <1> ;	IF ERROR:	
  6382                              <1> ;		AH = @DSKETTE_STATUS
  6383                              <1> ;		CY = 1
  6384                              <1> ;-------------------------------------------------------------------------------
  6385                              <1> SET_MEDIA:
  6386 00001E20 E801010000          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6387 00001E25 F687[E1A20000]01    <1>         TEST    byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR CHANGE LINE AVAILABLE
  6388 00001E2C 7415                <1> 	JZ	short SM_CMOS		; JUMP IF 40 TRACK DRIVE
  6389 00001E2E E848030000          <1> 	CALL	MED_CHANGE		; RESET CHANGE LINE
  6390 00001E33 803D[D4A20000]80    <1> 	CMP	byte [DSKETTE_STATUS], TIME_OUT ; IF TIME OUT TELL CALLER
  6391 00001E3A 746B                <1> 	JE	short SM_RTN
  6392 00001E3C C605[D4A20000]00    <1> 	MOV	byte [DSKETTE_STATUS], 0 ; CLEAR STATUS
  6393                              <1> SM_CMOS:
  6394 00001E43 E819070000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  6395                              <1> 	;;20/02/2015
  6396                              <1> 	;;JC	short MD_NOT_FND	; ERROR IN CMOS
  6397                              <1> 	;;OR	AL,AL			; TEST FOR NO DRIVE
  6398 00001E48 745D                <1> 	JZ	short SM_RTN		; RETURN IF SO
  6399 00001E4A E863000000          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  6400 00001E4F 7231                <1> 	JC	short MD_NOT_FND	; TYPE NOT IN TABLE (BAD CMOS)
  6401 00001E51 57                  <1> 	PUSH	eDI			; SAVE REG.
  6402 00001E52 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR. TYPE TABLE
  6403 00001E54 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6404                              <1> DR_SEARCH:
  6405 00001E59 8AA3[9C9C0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  6406 00001E5F 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  6407 00001E62 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH ?
  6408 00001E64 7516                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT DRIVE TYPE
  6409                              <1> DR_FND:
  6410 00001E66 8BBB[9D9C0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAM TABLE
  6411                              <1> MD_SEARCH:
  6412 00001E6C 8A6704              <1>         MOV     AH, [eDI+MD.SEC_TRK]    ; GET SECTOR/TRACK
  6413 00001E6F 386500              <1> 	CMP	[eBP],AH		; MATCH?
  6414 00001E72 7508                <1> 	JNE	short NXT_MD		; NO, CHECK NEXT MEDIA
  6415 00001E74 8A670B              <1>         MOV     AH, [eDI+MD.MAX_TRK]    ; GET MAX. TRACK #
  6416 00001E77 386501              <1> 	CMP 	[eBP+1],AH		; MATCH?
  6417 00001E7A 740F                <1> 	JE	short MD_FND		; YES, GO GET RATE
  6418                              <1> NXT_MD:
  6419                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6420 00001E7C 83C305              <1>         add	ebx, 5 ; 18/02/2015
  6421 00001E7F E2D8                <1> 	LOOP    DR_SEARCH
  6422 00001E81 5F                  <1> 	POP	eDI			; RESTORE REG.
  6423                              <1> MD_NOT_FND:
  6424 00001E82 C605[D4A20000]0C    <1> 	MOV	byte [DSKETTE_STATUS], MED_NOT_FND ; ERROR, MEDIA TYPE NOT FOUND
  6425 00001E89 EB1C                <1> 	JMP	SHORT SM_RTN		; RETURN
  6426                              <1> MD_FND:
  6427 00001E8B 8A470C              <1>         MOV     AL, [eDI+MD.RATE]       ; GET RATE
  6428 00001E8E 3C40                <1> 	CMP	AL,RATE_300		; DOUBLE STEP REQUIRED FOR RATE 300
  6429 00001E90 7502                <1> 	JNE	short MD_SET
  6430 00001E92 0C20                <1> 	OR	AL,DBL_STEP
  6431                              <1> MD_SET:
  6432                              <1> 	;MOV	[BP+6],DI		; SAVE TABLE POINTER IN STACK
  6433 00001E94 897D0C              <1> 	mov	[ebp+12], edi ; 18/02/2015
  6434 00001E97 0C10                <1> 	OR	AL,MED_DET		; SET MEDIA ESTABLISHED
  6435 00001E99 5F                  <1> 	POP	eDI
  6436 00001E9A 80A7[E1A20000]0F    <1> 	AND	byte [DSK_STATE+eDI], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  6437 00001EA1 0887[E1A20000]      <1> 	OR	[DSK_STATE+eDI], AL
  6438                              <1> 	;MOV	AX, CS			; SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  6439                              <1> 	;MOV	ES, AX			; ES IS SEGMENT OF TABLE
  6440                              <1> SM_RTN:
  6441 00001EA7 E8AB000000          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6442 00001EAC E8E5050000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6443 00001EB1 C3                  <1> 	RETn
  6444                              <1> 
  6445                              <1> ;----------------------------------------------------------------
  6446                              <1> ; DR_TYPE_CHECK							:
  6447                              <1> ;	CHECK IF THE GIVEN DRIVE TYPE IN REGISTER (AL)		:
  6448                              <1> ;	IS SUPPORTED IN BIOS DRIVE TYPE TABLE			:
  6449                              <1> ; ON ENTRY:							:
  6450                              <1> ;	AL = DRIVE TYPE						:
  6451                              <1> ; ON EXIT:							:
  6452                              <1> ;	CS = SEGMENT MEDIA/DRIVE PARAMETER TABLE (CODE)		:
  6453                              <1> ;	CY = 0 	DRIVE TYPE SUPPORTED				:
  6454                              <1> ;	     BX = OFFSET TO MEDIA/DRIVE PARAMETER TABLE		:
  6455                              <1> ;	CY = 1	DRIVE TYPE NOT SUPPORTED 			:
  6456                              <1> ; REGISTERS ALTERED: eBX						:
  6457                              <1> ;----------------------------------------------------------------		
  6458                              <1> DR_TYPE_CHECK:
  6459 00001EB2 6650                <1> 	PUSH	AX			
  6460 00001EB4 51                  <1> 	PUSH	eCX
  6461 00001EB5 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  6462 00001EB7 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6463                              <1> TYPE_CHK:	
  6464 00001EBC 8AA3[9C9C0000]      <1> 	MOV	AH,[DR_TYPE+eBX]	; GET DRIVE TYPE
  6465 00001EC2 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  6466 00001EC4 740D                <1> 	JE	short DR_TYPE_VALID	; YES, RETURN WITH CARRY RESET
  6467                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6468 00001EC6 83C305              <1>         add	ebx, 5	; 16/02/2015 (32 bit address modification)
  6469 00001EC9 E2F1                <1> 	LOOP    TYPE_CHK
  6470                              <1> 	;
  6471 00001ECB BB[FB9C0000]        <1> 	mov	ebx, MD_TBL6		; 1.44MB fd parameter table
  6472                              <1> 					; Default for GET_PARM (11/12/2014)
  6473                              <1> 	;
  6474 00001ED0 F9                  <1> 	STC				; DRIVE TYPE NOT FOUND IN TABLE
  6475 00001ED1 EB06                <1> 	JMP	SHORT TYPE_RTN
  6476                              <1> DR_TYPE_VALID:
  6477 00001ED3 8B9B[9D9C0000]      <1> 	MOV	eBX,[DR_TYPE+eBX+1] 	; BX = MEDIA TABLE
  6478                              <1> TYPE_RTN:
  6479 00001ED9 59                  <1> 	POP	eCX
  6480 00001EDA 6658                <1> 	POP	AX
  6481 00001EDC C3                  <1> 	RETn	
  6482                              <1> 		
  6483                              <1> ;----------------------------------------------------------------
  6484                              <1> ; SEND_SPEC							:
  6485                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  6486                              <1> ;	THE DRIVE PARAMETER TABLE POINTED BY @DISK_POINTER	:
  6487                              <1> ; ON ENTRY:	@DISK_POINTER = DRIVE PARAMETER TABLE		:
  6488                              <1> ; ON EXIT:	NONE						:	
  6489                              <1> ; REGISTERS ALTERED: CX, DX					:
  6490                              <1> ;----------------------------------------------------------------		
  6491                              <1> SEND_SPEC:
  6492 00001EDD 50                  <1> 	PUSH	eAX			; SAVE AX
  6493 00001EDE B8[041F0000]        <1> 	MOV	eAX, SPECBAC		; LOAD ERROR ADDRESS
  6494 00001EE3 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6495 00001EE4 B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  6496 00001EE6 E885070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6497 00001EEB 28D2                <1> 	SUB	DL,DL			; FIRST SPECIFY BYTE
  6498 00001EED E878060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  6499 00001EF2 E879070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6500 00001EF7 B201                <1> 	MOV	DL,1			; SECOND SPECIFY BYTE
  6501 00001EF9 E86C060000          <1> 	CALL	GET_PARM		; GET PARAMETER TO AH
  6502 00001EFE E86D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6503 00001F03 58                  <1> 	POP	eAX			; POP ERROR RETURN
  6504                              <1> SPECBAC:
  6505 00001F04 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  6506 00001F05 C3                  <1> 	RETn
  6507                              <1> 
  6508                              <1> ;----------------------------------------------------------------
  6509                              <1> ; SEND_SPEC_MD							:
  6510                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  6511                              <1> ;	THE MEDIA/DRIVE PARAMETER TABLE POINTED BY (CS:BX)	:
  6512                              <1> ; ON ENTRY:	CS:BX = MEDIA/DRIVE PARAMETER TABLE		:
  6513                              <1> ; ON EXIT:	NONE						:	
  6514                              <1> ; REGISTERS ALTERED: AX						:
  6515                              <1> ;----------------------------------------------------------------		
  6516                              <1> SEND_SPEC_MD:
  6517 00001F06 50                  <1> 	PUSH	eAX			; SAVE RATE DATA
  6518 00001F07 B8[241F0000]        <1> 	MOV	eAX, SPEC_ESBAC		; LOAD ERROR ADDRESS
  6519 00001F0C 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  6520 00001F0D B403                <1> 	MOV	AH,03H			; SPECIFY COMMAND
  6521 00001F0F E85C070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6522 00001F14 8A23                <1>         MOV     AH, [eBX+MD.SPEC1]      ; GET 1ST SPECIFY BYTE
  6523 00001F16 E855070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6524 00001F1B 8A6301              <1>         MOV     AH, [eBX+MD.SPEC2]      ; GET SECOND SPECIFY BYTE
  6525 00001F1E E84D070000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE COMMAND
  6526 00001F23 58                  <1> 	POP	eAX			; POP ERROR RETURN
  6527                              <1> SPEC_ESBAC:
  6528 00001F24 58                  <1> 	POP	eAX			; RESTORE ORIGINAL AX VALUE
  6529 00001F25 C3                  <1> 	RETn
  6530                              <1> 
  6531                              <1> ;-------------------------------------------------------------------------------
  6532                              <1> ; XLAT_NEW  
  6533                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM COMPATIBLE
  6534                              <1> ;	MODE TO NEW ARCHITECTURE.
  6535                              <1> ;
  6536                              <1> ; ON ENTRY:	DI = DRIVE #
  6537                              <1> ;-------------------------------------------------------------------------------
  6538                              <1> XLAT_NEW:
  6539 00001F26 83FF01              <1> 	CMP	eDI,1				; VALID DRIVE
  6540 00001F29 7725                <1> 	JA	short XN_OUT			; IF INVALID BACK
  6541 00001F2B 80BF[E1A20000]00    <1> 	CMP	byte [DSK_STATE+eDI], 0		; NO DRIVE ?
  6542 00001F32 741D                <1> 	JZ	short DO_DET			; IF NO DRIVE ATTEMPT DETERMINE
  6543 00001F34 6689F9              <1> 	MOV	CX,DI				; CX = DRIVE NUMBER
  6544 00001F37 C0E102              <1> 	SHL	CL,2				; CL = SHIFT COUNT, A=0, B=4
  6545 00001F3A A0[E0A20000]        <1> 	MOV	AL, [HF_CNTRL]			; DRIVE INFORMATION
  6546 00001F3F D2C8                <1> 	ROR	AL,CL				; TO LOW NIBBLE
  6547 00001F41 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA	; KEEP DRIVE BITS
  6548 00001F43 80A7[E1A20000]F8    <1>         AND     byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA)
  6549 00001F4A 0887[E1A20000]      <1> 	OR	[DSK_STATE+eDI], AL		; UPDATE DRIVE STATE
  6550                              <1> XN_OUT:
  6551 00001F50 C3                  <1> 	RETn
  6552                              <1> DO_DET:
  6553 00001F51 E8BF080000          <1> 	CALL	DRIVE_DET			; TRY TO DETERMINE
  6554 00001F56 C3                  <1> 	RETn
  6555                              <1> 
  6556                              <1> ;-------------------------------------------------------------------------------
  6557                              <1> ; XLAT_OLD 
  6558                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM NEW
  6559                              <1> ;	ARCHITECTURE TO COMPATIBLE MODE.
  6560                              <1> ;
  6561                              <1> ; ON ENTRY:	DI = DRIVE
  6562                              <1> ;-------------------------------------------------------------------------------
  6563                              <1> XLAT_OLD:
  6564 00001F57 83FF01              <1> 	CMP	eDI,1			; VALID DRIVE ?
  6565                              <1>         ;JA     short XO_OUT            ; IF INVALID BACK
  6566 00001F5A 0F8786000000        <1>         ja      XO_OUT
  6567 00001F60 80BF[E1A20000]00    <1>         CMP	byte [DSK_STATE+eDI],0	; NO DRIVE ?
  6568 00001F67 747D                <1> 	JZ	short XO_OUT		; IF NO DRIVE TRANSLATE DONE
  6569                              <1> 
  6570                              <1> ;-----	TEST FOR SAVED DRIVE INFORMATION ALREADY SET
  6571                              <1> 
  6572 00001F69 6689F9              <1> 	MOV	CX,DI			; CX = DRIVE NUMBER
  6573 00001F6C C0E102              <1> 	SHL	CL,2			; CL = SHIFT COUNT, A=0, B=4
  6574 00001F6F B402                <1> 	MOV	AH,FMT_CAPA		; LOAD MULTIPLE DATA RATE BIT MASK
  6575 00001F71 D2CC                <1> 	ROR	AH,CL			; ROTATE BY MASK
  6576 00001F73 8425[E0A20000]      <1> 	TEST	[HF_CNTRL], AH		; MULTIPLE-DATA RATE DETERMINED ?
  6577 00001F79 751C                <1> 	JNZ	short SAVE_SET		; IF SO, NO NEED TO RE-SAVE
  6578                              <1> 
  6579                              <1> ;-----	ERASE DRIVE BITS IN @HF_CNTRL FOR THIS DRIVE
  6580                              <1> 
  6581 00001F7B B407                <1> 	MOV	AH,DRV_DET+FMT_CAPA+TRK_CAPA ; MASK TO KEEP
  6582 00001F7D D2CC                <1> 	ROR	AH,CL			; FIX MASK TO KEEP
  6583 00001F7F F6D4                <1> 	NOT	AH			; TRANSLATE MASK
  6584 00001F81 2025[E0A20000]      <1> 	AND	[HF_CNTRL], AH		; KEEP BITS FROM OTHER DRIVE INTACT
  6585                              <1> 
  6586                              <1> ;-----	ACCESS CURRENT DRIVE BITS AND STORE IN @HF_CNTRL
  6587                              <1> 
  6588 00001F87 8A87[E1A20000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; ACCESS STATE
  6589 00001F8D 2407                <1> 	AND	AL,DRV_DET+FMT_CAPA+TRK_CAPA ; KEEP DRIVE BITS
  6590 00001F8F D2C8                <1> 	ROR	AL,CL			; FIX FOR THIS DRIVE
  6591 00001F91 0805[E0A20000]      <1> 	OR	[HF_CNTRL], AL		; UPDATE SAVED DRIVE STATE
  6592                              <1> 
  6593                              <1> ;-----	TRANSLATE TO COMPATIBILITY MODE
  6594                              <1> 
  6595                              <1> SAVE_SET:
  6596 00001F97 8AA7[E1A20000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  6597 00001F9D 88E7                <1> 	MOV	BH,AH			; TO BH FOR LATER
  6598 00001F9F 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE
  6599 00001FA2 80FC00              <1> 	CMP	AH,RATE_500		; RATE 500 ?
  6600 00001FA5 7410                <1> 	JZ	short CHK_144		; YES 1.2/1.2 OR 1.44/1.44
  6601 00001FA7 B001                <1> 	MOV	AL,M3D1U		; AL = 360 IN 1.2 UNESTABLISHED
  6602 00001FA9 80FC40              <1> 	CMP	AH,RATE_300		; RATE 300 ?
  6603 00001FAC 7518                <1> 	JNZ	short CHK_250		; NO, 360/360, 720/720 OR 720/1.44
  6604 00001FAE F6C720              <1> 	TEST	BH,DBL_STEP		; CHECK FOR DOUBLE STEP
  6605 00001FB1 751F                <1> 	JNZ	short TST_DET		; MUST BE 360 IN 1.2
  6606                              <1> UNKNO:
  6607 00001FB3 B007                <1> 	MOV	AL,MED_UNK		; NONE OF THE ABOVE
  6608 00001FB5 EB22                <1> 	JMP	SHORT AL_SET		; PROCESS COMPLETE
  6609                              <1> CHK_144:
  6610 00001FB7 E8A5050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  6611                              <1> 	;;20/02/2015
  6612                              <1> 	;;JC	short UNKNO		; ERROR, SET 'NONE OF ABOVE'
  6613 00001FBC 74F5                <1> 	jz	short UNKNO ;; 20/02/2015
  6614 00001FBE 3C02                <1> 	CMP	AL,2			; 1.2MB DRIVE ?
  6615 00001FC0 75F1                <1> 	JNE	short UNKNO		; NO, GO SET 'NONE OF ABOVE'
  6616 00001FC2 B002                <1> 	MOV	AL,M1D1U		; AL = 1.2 IN 1.2 UNESTABLISHED
  6617 00001FC4 EB0C                <1> 	JMP	SHORT TST_DET
  6618                              <1> CHK_250:
  6619 00001FC6 B000                <1> 	MOV	AL,M3D3U		; AL = 360 IN 360 UNESTABLISHED
  6620 00001FC8 80FC80              <1> 	CMP	AH,RATE_250		; RATE 250 ?
  6621 00001FCB 75E6                <1> 	JNZ	short UNKNO		; IF SO FALL IHRU
  6622 00001FCD F6C701              <1> 	TEST	BH,TRK_CAPA		; 80 TRACK CAPABILITY ?
  6623 00001FD0 75E1                <1> 	JNZ	short UNKNO		; IF SO JUMP, FALL THRU TEST DET
  6624                              <1> TST_DET:
  6625 00001FD2 F6C710              <1> 	TEST	BH,MED_DET		; DETERMINED ?
  6626 00001FD5 7402                <1> 	JZ	short AL_SET		; IF NOT THEN SET
  6627 00001FD7 0403                <1> 	ADD	AL,3			; MAKE DETERMINED/ESTABLISHED
  6628                              <1> AL_SET:
  6629 00001FD9 80A7[E1A20000]F8    <1> 	AND	byte [DSK_STATE+eDI], ~(DRV_DET+FMT_CAPA+TRK_CAPA) ; CLEAR DRIVE
  6630 00001FE0 0887[E1A20000]      <1> 	OR	[DSK_STATE+eDI], AL	; REPLACE WITH COMPATIBLE MODE
  6631                              <1> XO_OUT:
  6632 00001FE6 C3                  <1> 	RETn
  6633                              <1> 
  6634                              <1> ;-------------------------------------------------------------------------------
  6635                              <1> ; RD_WR_VF
  6636                              <1> ;	COMMON READ, WRITE AND VERIFY: 
  6637                              <1> ;	MAIN LOOP FOR STATE RETRIES.
  6638                              <1> ;
  6639                              <1> ; ON ENTRY:	AH = READ/WRITE/VERIFY NEC PARAMETER
  6640                              <1> ;		AL = READ/WRITE/VERIFY DMA PARAMETER
  6641                              <1> ;
  6642                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6643                              <1> ;-------------------------------------------------------------------------------
  6644                              <1> RD_WR_VF:
  6645 00001FE7 6650                <1> 	PUSH	AX			; SAVE DMA, NEC PARAMETERS
  6646 00001FE9 E838FFFFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  6647 00001FEE E8F3000000          <1> 	CALL	SETUP_STATE		; INITIALIZE START AND END RATE
  6648 00001FF3 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  6649                              <1> DO_AGAIN:
  6650 00001FF5 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  6651 00001FF7 E87F010000          <1> 	CALL	MED_CHANGE		; MEDIA CHANGE AND RESET IF CHANGED
  6652 00001FFC 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY
  6653 00001FFE 0F82C9000000        <1>         JC      RWV_END                 ; MEDIA CHANGE ERROR OR TIME-OUT
  6654                              <1> RWV:
  6655 00002004 6650                <1> 	PUSH	AX			; SAVE READ/WRITE/VERIFY PARAMETER
  6656 00002006 8AB7[E1A20000]      <1> 	MOV	DH, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6657 0000200C 80E6C0              <1> 	AND	DH,RATE_MSK		; KEEP ONLY RATE
  6658 0000200F E84D050000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL (AL)
  6659                              <1> 	;;20/02/2015
  6660                              <1> 	;;JC	short RWV_ASSUME	; ERROR IN CMOS
  6661 00002014 7451                <1> 	jz	short RWV_ASSUME ; 20/02/2015
  6662 00002016 3C01                <1> 	CMP	AL,1			; 40 TRACK DRIVE?
  6663 00002018 750D                <1> 	JNE	short RWV_1		; NO, BYPASS CMOS VALIDITY CHECK
  6664 0000201A F687[E1A20000]01    <1> 	TEST	byte [DSK_STATE+eDI], TRK_CAPA ; CHECK FOR 40 TRACK DRIVE
  6665 00002021 7413                <1> 	JZ	short RWV_2		; YES, CMOS IS CORRECT
  6666 00002023 B002                <1> 	MOV	AL,2			; CHANGE TO 1.2M
  6667 00002025 EB0F                <1> 	JMP	SHORT RWV_2
  6668                              <1> RWV_1:
  6669 00002027 720D                <1> 	JB	short RWV_2		; NO DRIVE SPECIFIED, CONTINUE
  6670 00002029 F687[E1A20000]01    <1> 	TEST    byte [DSK_STATE+eDI], TRK_CAPA ; IS IT REALLY 40 TRACK?
  6671 00002030 7504                <1> 	JNZ	short RWV_2		; NO, 80 TRACK
  6672 00002032 B001                <1> 	MOV	AL,1			; IT IS 40 TRACK, FIX CMOS VALUE
  6673 00002034 EB04                <1> 	jmp	short rwv_3
  6674                              <1> RWV_2:
  6675 00002036 08C0                <1> 	OR	AL,AL			; TEST FOR NO DRIVE
  6676 00002038 742D                <1> 	JZ	short RWV_ASSUME	; ASSUME TYPE, USE MAX TRACK
  6677                              <1> rwv_3:
  6678 0000203A E873FEFFFF          <1> 	CALL	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL.
  6679 0000203F 7226                <1> 	JC	short RWV_ASSUME	; TYPE NOT IN TABLE (BAD CMOS)
  6680                              <1> 
  6681                              <1> ;-----	SEARCH FOR MEDIA/DRIVE PARAMETER TABLE
  6682                              <1> 
  6683 00002041 57                  <1> 	PUSH	eDI			; SAVE DRIVE #
  6684 00002042 31DB                <1> 	XOR	eBX,eBX			; BX = INDEX TO DR_TYPE TABLE
  6685 00002044 B906000000          <1> 	MOV	eCX,DR_CNT		; CX = LOOP COUNT
  6686                              <1> RWV_DR_SEARCH:
  6687 00002049 8AA3[9C9C0000]      <1> 	MOV	AH, [DR_TYPE+eBX]	; GET DRIVE TYPE
  6688 0000204F 80E47F              <1> 	AND	AH,BIT7OFF		; MASK OUT MSB
  6689 00002052 38E0                <1> 	CMP	AL,AH			; DRIVE TYPE MATCH?
  6690 00002054 750B                <1> 	JNE	short RWV_NXT_MD	; NO, CHECK NEXT DRIVE TYPE
  6691                              <1> RWV_DR_FND:
  6692 00002056 8BBB[9D9C0000]      <1> 	MOV	eDI, [DR_TYPE+eBX+1] 	; DI = MEDIA/DRIVE PARAMETER TABLE
  6693                              <1> RWV_MD_SEARH:
  6694 0000205C 3A770C              <1>         CMP     DH, [eDI+MD.RATE]       ; MATCH?
  6695 0000205F 741B                <1> 	JE	short RWV_MD_FND	; YES, GO GET 1ST SPECIFY BYTE
  6696                              <1> RWV_NXT_MD:
  6697                              <1> 	;ADD	BX,3			; CHECK NEXT DRIVE TYPE
  6698 00002061 83C305              <1> 	add	eBX, 5
  6699 00002064 E2E3                <1> 	LOOP	RWV_DR_SEARCH
  6700 00002066 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  6701                              <1> 
  6702                              <1> ;-----	ASSUME PRIMARY DRIVE IS INSTALLED AS SHIPPED
  6703                              <1> 
  6704                              <1> RWV_ASSUME:
  6705 00002067 BB[BA9C0000]        <1> 	MOV	eBX, MD_TBL1		; POINT TO 40 TRACK 250 KBS
  6706 0000206C F687[E1A20000]01    <1> 	TEST 	byte [DSK_STATE+eDI], TRK_CAPA ; TEST FOR 80 TRACK
  6707 00002073 740A                <1> 	JZ	short RWV_MD_FND1	; MUST BE 40 TRACK
  6708 00002075 BB[D49C0000]        <1> 	MOV	eBX, MD_TBL3		; POINT TO 80 TRACK 500 KBS
  6709 0000207A EB03                <1> 	JMP	short RWV_MD_FND1	; GO SPECIFY PARAMTERS
  6710                              <1> 
  6711                              <1> ;-----	CS:BX POINTS TO MEDIA/DRIVE PARAMETER TABLE
  6712                              <1> 	 			
  6713                              <1> RWV_MD_FND:
  6714 0000207C 89FB                <1> 	MOV	eBX,eDI			; BX = MEDIA/DRIVE PARAMETER TABLE
  6715 0000207E 5F                  <1> 	POP	eDI			; RESTORE DRIVE #
  6716                              <1> 	
  6717                              <1> ;-----	SEND THE SPECIFY COMMAND TO THE CONTROLLER
  6718                              <1> 
  6719                              <1> RWV_MD_FND1:
  6720 0000207F E882FEFFFF          <1> 	CALL	SEND_SPEC_MD
  6721 00002084 E864010000          <1> 	CALL	CHK_LASTRATE		; ZF=1 ATTEMP RATE IS SAME AS LAST RATE
  6722 00002089 7405                <1> 	JZ	short RWV_DBL		; YES,SKIP SEND RATE COMMAND
  6723 0000208B E83B010000          <1> 	CALL	SEND_RATE		; SEND DATA RATE TO NEC
  6724                              <1> RWV_DBL:
  6725 00002090 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6726 00002091 E822040000          <1> 	CALL	SETUP_DBL		; CHECK FOR DOUBLE STEP
  6727 00002096 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  6728 00002097 7226                <1> 	JC	short CHK_RET		; ERROR FROM READ ID, POSSIBLE RETRY
  6729 00002099 6658                <1> 	POP	AX			; RESTORE NEC, DMA COMMAND
  6730 0000209B 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  6731 0000209D 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6732 0000209E E861010000          <1> 	CALL	DMA_SETUP		; SET UP THE DMA
  6733 000020A3 5B                  <1> 	POP	eBX 
  6734 000020A4 6658                <1> 	POP	AX			; RESTORE NEC COMMAND
  6735 000020A6 722F                <1> 	JC	short RWV_BAC		; CHECK FOR DMA BOUNDARY ERROR
  6736 000020A8 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  6737 000020AA 53                  <1> 	PUSH	eBX			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
  6738 000020AB E83C020000          <1> 	CALL	NEC_INIT		; INITIALIZE NEC
  6739 000020B0 5B                  <1> 	POP	eBX			; RESTORE ADDRESS
  6740 000020B1 720C                <1> 	JC	short CHK_RET		; ERROR - EXIT
  6741 000020B3 E866020000          <1> 	CALL	RWV_COM			; OP CODE COMMON TO READ/WRITE/VERIFY
  6742 000020B8 7205                <1> 	JC	short CHK_RET		; ERROR - EXIT
  6743 000020BA E8AB020000          <1> 	CALL	NEC_TERM		; TERMINATE, GET STATUS, ETC.
  6744                              <1> CHK_RET:
  6745 000020BF E84A030000          <1> 	CALL	RETRY			; CHECK FOR, SETUP RETRY
  6746 000020C4 6658                <1> 	POP	AX			; RESTORE READ/WRITE/VERIFY PARAMETER
  6747 000020C6 7305                <1> 	JNC	short RWV_END		; CY = 0 NO RETRY
  6748 000020C8 E928FFFFFF          <1>         JMP     DO_AGAIN                ; CY = 1 MEANS RETRY
  6749                              <1> RWV_END:
  6750 000020CD E8F4020000          <1> 	CALL	DSTATE			; ESTABLISH STATE IF SUCCESSFUL
  6751 000020D2 E887030000          <1> 	CALL	NUM_TRANS		; AL = NUMBER TRANSFERRED
  6752                              <1> RWV_BAC:				; BAD DMA ERROR ENTRY
  6753 000020D7 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  6754 000020D9 E879FEFFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  6755 000020DE 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  6756 000020E0 E8B1030000          <1> 	CALL	SETUP_END		; VARIOUS CLEANUPS
  6757 000020E5 C3                  <1> 	RETn
  6758                              <1> 
  6759                              <1> ;-------------------------------------------------------------------------------
  6760                              <1> ; SETUP_STATE:	INITIALIZES START AND END RATES.
  6761                              <1> ;-------------------------------------------------------------------------------
  6762                              <1> SETUP_STATE:
  6763 000020E6 F687[E1A20000]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; MEDIA DETERMINED ?
  6764 000020ED 7537                <1> 	JNZ	short J1C		; NO STATES IF DETERMINED
  6765 000020EF 66B84000            <1>         MOV     AX,(RATE_500*256)+RATE_300  ; AH = START RATE, AL = END RATE
  6766 000020F3 F687[E1A20000]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE ?
  6767 000020FA 740D                <1> 	JZ	short AX_SET		; DO NOT KNOW DRIVE
  6768 000020FC F687[E1A20000]02    <1> 	TEST	byte [DSK_STATE+eDI], FMT_CAPA ; MULTI-RATE?
  6769 00002103 7504                <1> 	JNZ	short AX_SET		; JUMP IF YES
  6770 00002105 66B88080            <1>         MOV     AX,RATE_250*257         ; START A END RATE 250 FOR 360 DRIVE
  6771                              <1> AX_SET:	
  6772 00002109 80A7[E1A20000]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP) ; TURN OFF THE RATE
  6773 00002110 08A7[E1A20000]      <1> 	OR	[DSK_STATE+eDI], AH	; RATE FIRST TO TRY
  6774 00002116 8025[DCA20000]F3    <1> 	AND	byte [LASTRATE], ~STRT_MSK ; ERASE LAST TO TRY RATE BITS
  6775 0000211D C0C804              <1> 	ROR	AL,4			; TO OPERATION LAST RATE LOCATION
  6776 00002120 0805[DCA20000]      <1> 	OR	[LASTRATE], AL		; LAST RATE
  6777                              <1> J1C:	
  6778 00002126 C3                  <1> 	RETn
  6779                              <1> 
  6780                              <1> ;-------------------------------------------------------------------------------
  6781                              <1> ;  FMT_INIT: ESTABLISH STATE IF UNESTABLISHED AT FORMAT TIME.
  6782                              <1> ;-------------------------------------------------------------------------------
  6783                              <1> FMT_INIT:
  6784 00002127 F687[E1A20000]10    <1> 	TEST	byte [DSK_STATE+eDI], MED_DET ; IS MEDIA ESTABLISHED
  6785 0000212E 7546                <1> 	JNZ	short F1_OUT		; IF SO RETURN
  6786 00002130 E82C040000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  6787                              <1> 	;; 20/02/2015
  6788                              <1> 	;;JC	short CL_DRV		; ERROR IN CMOS ASSUME NO DRIVE
  6789 00002135 7440                <1> 	jz	short CL_DRV ;; 20/02/2015
  6790 00002137 FEC8                <1> 	DEC	AL			; MAKE ZERO ORIGIN
  6791                              <1> 	;;JS	short CL_DRV		; NO DRIVE IF AL 0
  6792 00002139 8AA7[E1A20000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; AH = CURRENT STATE
  6793 0000213F 80E40F              <1> 	AND	AH, ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR
  6794 00002142 08C0                <1> 	OR	AL,AL			; CHECK FOR 360
  6795 00002144 7505                <1> 	JNZ	short N_360		; IF 360 WILL BE 0
  6796 00002146 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; ESTABLISH MEDIA
  6797 00002149 EB25                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  6798                              <1> N_360:	
  6799 0000214B FEC8                <1> 	DEC	AL			; 1.2 M DRIVE
  6800 0000214D 7505                <1> 	JNZ	short N_12		; JUMP IF NOT
  6801                              <1> F1_RATE:
  6802 0000214F 80CC10              <1> 	OR	AH,MED_DET+RATE_500	; SET FORMAT RATE
  6803 00002152 EB1C                <1> 	JMP	SHORT SKP_STATE		; SKIP OTHER STATE PROCESSING
  6804                              <1> N_12:	
  6805 00002154 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 3
  6806 00002156 750F                <1> 	JNZ	short N_720		; JUMP IF NOT
  6807 00002158 F6C404              <1> 	TEST	AH,DRV_DET		; IS DRIVE DETERMINED
  6808 0000215B 7410                <1> 	JZ	short ISNT_12		; TREAT AS NON 1.2 DRIVE
  6809 0000215D F6C402              <1> 	TEST	AH,FMT_CAPA		; IS 1.2M
  6810 00002160 740B                <1> 	JZ	short ISNT_12		; JUMP IF NOT
  6811 00002162 80CC50              <1> 	OR	AH,MED_DET+RATE_300	; RATE 300
  6812 00002165 EB09                <1> 	JMP	SHORT SKP_STATE		; CONTINUE
  6813                              <1> N_720:
  6814 00002167 FEC8                <1> 	DEC	AL			; CHECK FOR TYPE 4
  6815 00002169 750C                <1> 	JNZ	short CL_DRV		; NO DRIVE, CMOS BAD
  6816 0000216B EBE2                <1> 	JMP	SHORT F1_RATE
  6817                              <1> ISNT_12: 
  6818 0000216D 80CC90              <1> 	OR	AH,MED_DET+RATE_250	; MUST BE RATE 250
  6819                              <1> 
  6820                              <1> SKP_STATE:
  6821 00002170 88A7[E1A20000]      <1> 	MOV	[DSK_STATE+eDI], AH	; STORE AWAY
  6822                              <1> F1_OUT:
  6823 00002176 C3                  <1> 	RETn
  6824                              <1> CL_DRV:	
  6825 00002177 30E4                <1> 	XOR	AH,AH			; CLEAR STATE
  6826 00002179 EBF5                <1> 	JMP	SHORT SKP_STATE		; SAVE IT
  6827                              <1> 
  6828                              <1> ;-------------------------------------------------------------------------------
  6829                              <1> ; MED_CHANGE	
  6830                              <1> ;	CHECKS FOR MEDIA CHANGE, RESETS MEDIA CHANGE, 
  6831                              <1> ;	CHECKS MEDIA CHANGE AGAIN.
  6832                              <1> ;
  6833                              <1> ; ON EXIT:	CY = 1 MEANS MEDIA CHANGE OR TIMEOUT
  6834                              <1> ;		@DSKETTE_STATUS = ERROR CODE
  6835                              <1> ;-------------------------------------------------------------------------------
  6836                              <1> MED_CHANGE:
  6837 0000217B E888060000          <1> 	CALL	READ_DSKCHNG		; READ DISK CHANCE LINE STATE
  6838 00002180 7447                <1> 	JZ	short MC_OUT		; BYPASS HANDLING DISK CHANGE LINE
  6839 00002182 80A7[E1A20000]EF    <1> 	AND	byte [DSK_STATE+eDI], ~MED_DET ; CLEAR STATE FOR THIS DRIVE
  6840                              <1> 
  6841                              <1> ;	THIS SEQUENCE ENSURES WHENEVER A DISKETTE IS CHANGED THAT
  6842                              <1> ;	ON THE NEXT OPERATION THE REQUIRED MOTOR START UP TIME WILL
  6843                              <1> ;	BE WAITED. (DRIVE MOTOR MAY GO OFF UPON DOOR OPENING).
  6844                              <1> 
  6845 00002189 6689F9              <1> 	MOV	CX,DI			; CL = DRIVE 0
  6846 0000218C B001                <1> 	MOV	AL,1			; MOTOR ON BIT MASK
  6847 0000218E D2E0                <1> 	SHL	AL,CL			; TO APPROPRIATE POSITION
  6848 00002190 F6D0                <1> 	NOT	AL			; KEEP ALL BUT MOTOR ON
  6849 00002192 FA                  <1> 	CLI				; NO INTERRUPTS
  6850 00002193 2005[D2A20000]      <1> 	AND	[MOTOR_STATUS], AL	; TURN MOTOR OFF INDICATOR
  6851 00002199 FB                  <1> 	STI				; INTERRUPTS ENABLED
  6852 0000219A E810040000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON
  6853                              <1> 
  6854                              <1> ;-----	THIS SEQUENCE OF SEEKS IS USED TO RESET DISKETTE CHANGE SIGNAL
  6855                              <1> 
  6856 0000219F E884F9FFFF          <1> 	CALL	DSK_RESET		; RESET NEC
  6857 000021A4 B501                <1> 	MOV	CH,01H			; MOVE TO CYLINDER 1
  6858 000021A6 E8FF040000          <1> 	CALL	SEEK			; ISSUE SEEK
  6859 000021AB 30ED                <1> 	XOR	CH,CH			; MOVE TO CYLINDER 0
  6860 000021AD E8F8040000          <1> 	CALL	SEEK			; ISSUE SEEK
  6861 000021B2 C605[D4A20000]06    <1> 	MOV	byte [DSKETTE_STATUS], MEDIA_CHANGE ; STORE IN STATUS
  6862                              <1> OK1:
  6863 000021B9 E84A060000          <1> 	CALL	READ_DSKCHNG		; CHECK MEDIA CHANGED AGAIN
  6864 000021BE 7407                <1> 	JZ	short OK2		; IF ACTIVE, NO DISKETTE, TIMEOUT
  6865                              <1> OK4:
  6866 000021C0 C605[D4A20000]80    <1> 	MOV	byte [DSKETTE_STATUS], TIME_OUT ; TIMEOUT IF DRIVE EMPTY
  6867                              <1> OK2:		
  6868 000021C7 F9                  <1> 	STC				; MEDIA CHANGED, SET CY
  6869 000021C8 C3                  <1> 	RETn
  6870                              <1> MC_OUT:
  6871 000021C9 F8                  <1> 	CLC				; NO MEDIA CHANGED, CLEAR CY
  6872 000021CA C3                  <1> 	RETn
  6873                              <1> 
  6874                              <1> ;-------------------------------------------------------------------------------
  6875                              <1> ; SEND_RATE
  6876                              <1> ;	SENDS DATA RATE COMMAND TO NEC
  6877                              <1> ; ON ENTRY:	DI = DRIVE #
  6878                              <1> ; ON EXIT:	NONE
  6879                              <1> ; REGISTERS ALTERED: DX
  6880                              <1> ;-------------------------------------------------------------------------------
  6881                              <1> SEND_RATE:
  6882 000021CB 6650                <1> 	PUSH	AX			; SAVE REG.
  6883 000021CD 8025[DCA20000]3F    <1> 	AND	byte [LASTRATE], ~SEND_MSK ; ELSE CLEAR LAST RATE ATTEMPTED
  6884 000021D4 8A87[E1A20000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6885 000021DA 24C0                <1> 	AND	AL,SEND_MSK		; KEEP ONLY RATE BITS
  6886 000021DC 0805[DCA20000]      <1> 	OR	[LASTRATE], AL		; SAVE NEW RATE FOR NEXT CHECK
  6887 000021E2 C0C002              <1> 	ROL	AL,2			; MOVE TO BIT OUTPUT POSITIONS
  6888 000021E5 66BAF703            <1> 	MOV	DX,03F7H		; OUTPUT NEW DATA RATE
  6889 000021E9 EE                  <1> 	OUT	DX,AL
  6890 000021EA 6658                <1> 	POP	AX			; RESTORE REG.
  6891 000021EC C3                  <1> 	RETn
  6892                              <1> 
  6893                              <1> ;-------------------------------------------------------------------------------
  6894                              <1> ; CHK_LASTRATE
  6895                              <1> ;	CHECK PREVIOUS DATE RATE SNT TO THE CONTROLLER.
  6896                              <1> ; ON ENTRY:
  6897                              <1> ;	DI = DRIVE #
  6898                              <1> ; ON EXIT:
  6899                              <1> ;	ZF =  1 DATA RATE IS THE SAME AS THE LAST RATE SENT TO NEC
  6900                              <1> ;	ZF =  0 DATA RATE IS DIFFERENT FROM LAST RATE
  6901                              <1> ; REGISTERS ALTERED: DX
  6902                              <1> ;-------------------------------------------------------------------------------
  6903                              <1> CHK_LASTRATE:
  6904 000021ED 6650                <1> 	PUSH	AX			; SAVE REG
  6905 000021EF 2225[DCA20000]      <1> 	AND	AH, [LASTRATE]		; GET LAST DATA RATE SELECTED
  6906 000021F5 8A87[E1A20000]      <1> 	MOV	AL, [DSK_STATE+eDI]	; GET RATE STATE OF THIS DRIVE
  6907 000021FB 6625C0C0            <1>         AND     AX, SEND_MSK*257        ; KEEP ONLY RATE BITS OF BOTH
  6908 000021FF 38E0                <1> 	CMP	AL, AH			; COMPARE TO PREVIOUSLY TRIED
  6909                              <1> 					; ZF = 1 RATE IS THE SAME
  6910 00002201 6658                <1> 	POP	AX			; RESTORE REG.
  6911 00002203 C3                  <1> 	RETn
  6912                              <1> 
  6913                              <1> ;-------------------------------------------------------------------------------
  6914                              <1> ; DMA_SETUP
  6915                              <1> ;	THIS ROUTINE SETS UP THE DMA FOR READ/WRITE/VERIFY OPERATIONS.
  6916                              <1> ;
  6917                              <1> ; ON ENTRY:	AL = DMA COMMAND
  6918                              <1> ;
  6919                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  6920                              <1> ;-------------------------------------------------------------------------------
  6921                              <1> 
  6922                              <1> ; SI = Head #, # of Sectors or DASD Type
  6923                              <1> 
  6924                              <1> ; 22/08/2015
  6925                              <1> ; 08/02/2015 - Protected Mode Modification
  6926                              <1> ; 06/02/2015 - 07/02/2015
  6927                              <1> ; NOTE: Buffer address must be in 1st 16MB of Physical Memory (24 bit limit).
  6928                              <1> ; (DMA Addres = Physical Address)
  6929                              <1> ; (Retro UNIX 386 v1 Kernel/System Mode Virtual Address = Physical Address)
  6930                              <1> ;
  6931                              <1> 
  6932                              <1> 
  6933                              <1> ; 04/02/2016 (clc)
  6934                              <1> ; 20/02/2015 modification (source: AWARD BIOS 1999, DMA_SETUP)
  6935                              <1> ; 16/12/2014 (IODELAY)
  6936                              <1> 
  6937                              <1> DMA_SETUP:
  6938                              <1> 
  6939                              <1> ;; 20/02/2015
  6940 00002204 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  6941 00002207 F7C2000000FF        <1> 	test	edx, 0FF000000h		; 16 MB limit (22/08/2015, bugfix)
  6942 0000220D 756E                <1> 	jnz	short dma_bnd_err_stc
  6943                              <1> 	;
  6944 0000220F 6650                <1> 	push	ax			; DMA command
  6945 00002211 52                  <1> 	push	edx			; *
  6946 00002212 B203                <1> 	mov	dl, 3			; GET BYTES/SECTOR PARAMETER
  6947 00002214 E851030000          <1> 	call	GET_PARM		; 
  6948 00002219 88E1                <1> 	mov	cl, ah 			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  6949 0000221B 6689F0              <1> 	mov	ax, si			; Sector count
  6950 0000221E 88C4                <1> 	mov	ah, al			; AH =  # OF SECTORS
  6951 00002220 28C0                <1> 	sub	al, al			; AL = 0, AX = # SECTORS * 256
  6952 00002222 66D1E8              <1> 	shr	ax, 1			; AX = # SECTORS * 128
  6953 00002225 66D3E0              <1> 	shl	ax, cl			; SHIFT BY PARAMETER VALUE
  6954 00002228 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  6955 0000222A 6689C1              <1> 	mov	cx, ax
  6956 0000222D 5A                  <1> 	pop	edx			; *
  6957 0000222E 6658                <1> 	pop	ax
  6958 00002230 3C42                <1> 	cmp	al, 42h
  6959 00002232 7507                <1>         jne     short NOT_VERF
  6960 00002234 BA0000FF00          <1> 	mov	edx, 0FF0000h
  6961 00002239 EB08                <1> 	jmp	short J33
  6962                              <1> NOT_VERF:
  6963 0000223B 6601CA              <1> 	add	dx, cx			; check for overflow
  6964 0000223E 723E                <1> 	jc	short dma_bnd_err
  6965                              <1> 	;
  6966 00002240 6629CA              <1> 	sub	dx, cx			; Restore start address
  6967                              <1> J33:
  6968 00002243 FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  6969 00002244 E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  6970                              <1> 	IODELAY				; WAIT FOR I/O
  6971 00002246 EB00                <2>  jmp short $+2
  6972 00002248 EB00                <2>  jmp short $+2
  6973 0000224A E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  6974 0000224C 89D0                <1> 	mov	eax, edx		; Buffer address
  6975 0000224E E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  6976                              <1> 	IODELAY				; WAIT FOR I/O
  6977 00002250 EB00                <2>  jmp short $+2
  6978 00002252 EB00                <2>  jmp short $+2
  6979 00002254 88E0                <1> 	MOV	AL,AH
  6980 00002256 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  6981 00002258 C1E810              <1> 	shr	eax, 16
  6982                              <1> 	IODELAY				; I/O WAIT STATE
  6983 0000225B EB00                <2>  jmp short $+2
  6984 0000225D EB00                <2>  jmp short $+2
  6985 0000225F E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  6986                              <1> 	IODELAY
  6987 00002261 EB00                <2>  jmp short $+2
  6988 00002263 EB00                <2>  jmp short $+2
  6989 00002265 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  6990 00002268 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  6991                              <1> 	IODELAY				; WAIT FOR I/O
  6992 0000226A EB00                <2>  jmp short $+2
  6993 0000226C EB00                <2>  jmp short $+2
  6994 0000226E 88E0                <1> 	MOV	AL, AH
  6995 00002270 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  6996                              <1> 	IODELAY
  6997 00002272 EB00                <2>  jmp short $+2
  6998 00002274 EB00                <2>  jmp short $+2
  6999 00002276 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  7000 00002277 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  7001 00002279 E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7002                              <1> 
  7003 0000227B F8                  <1> 	clc	; 04/02/2016
  7004 0000227C C3                  <1> 	retn
  7005                              <1> 
  7006                              <1> dma_bnd_err_stc:
  7007 0000227D F9                  <1> 	stc
  7008                              <1> dma_bnd_err:
  7009 0000227E C605[D4A20000]09    <1> 	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7010 00002285 C3                  <1> 	RETn				; CY SET BY ABOVE IF ERROR
  7011                              <1> 
  7012                              <1> ;; 16/12/2014
  7013                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7014                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7015                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7016                              <1> ;;	IODELAY
  7017                              <1> ;; 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7018                              <1> ;;	;SIODELAY
  7019                              <1> ;;      ;CMP	AL, 42H			; DMA VERIFY COMMAND
  7020                              <1> ;;      ;JNE	short NOT_VERF		; NO
  7021                              <1> ;;      ;XOR	AX, AX			; START ADDRESS
  7022                              <1> ;;      ;JMP	SHORT J33
  7023                              <1> ;;;NOT_VERF:	
  7024                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  7025                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  7026                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  7027                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  7028                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  7029                              <1> ;;	mov	eax, [ebp+4] ; 06/02/2015	
  7030                              <1> ;;	;JNC	short J33
  7031                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  7032                              <1> ;;;J33:
  7033                              <1> ;;	PUSH	eAX			; SAVE START ADDRESS
  7034                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7035                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7036                              <1> ;;	IODELAY
  7037                              <1> ;;	MOV	AL,AH
  7038                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7039                              <1> ;;	shr	eax, 16	     ; 07/02/2015
  7040                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  7041                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  7042                              <1> ;;	IODELAY
  7043                              <1> ;;	;AND	AL,00001111B
  7044                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  7045                              <1> ;;	;SIODELAY
  7046                              <1> ;;
  7047                              <1> ;;;----- DETERMINE COUNT
  7048                              <1> ;;	sub	eax, eax ; 08/02/2015
  7049                              <1> ;;	MOV	AX, SI			; AL =  # OF SECTORS
  7050                              <1> ;;	XCHG	AL, AH			; AH =  # OF SECTORS
  7051                              <1> ;;	SUB	AL, AL			; AL = 0, AX = # SECTORS * 256
  7052                              <1> ;;	SHR	AX, 1			; AX = # SECTORS * 128
  7053                              <1> ;;	PUSH	AX			; SAVE # OF SECTORS * 128
  7054                              <1> ;;	MOV	DL, 3			; GET BYTES/SECTOR PARAMETER
  7055                              <1> ;;	CALL	GET_PARM		; "
  7056                              <1> ;;	MOV	CL,AH			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  7057                              <1> ;;	POP	AX			; AX = # SECTORS * 128
  7058                              <1> ;;	SHL	AX,CL			; SHIFT BY PARAMETER VALUE
  7059                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  7060                              <1> ;;	PUSH	eAX  ; 08/02/2015	; SAVE COUNT VALUE
  7061                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7062                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7063                              <1> ;;	IODELAY
  7064                              <1> ;;	MOV	AL, AH
  7065                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7066                              <1> ;;	;IODELAY
  7067                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  7068                              <1> ;;	POP	eCX  ; 08/02/2015 	; RECOVER COUNT VALUE
  7069                              <1> ;;	POP	eAX  ; 08/02/2015	; RECOVER ADDRESS VALUE
  7070                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  7071                              <1> ;;	add	ecx, eax ; 08/02/2015
  7072                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  7073                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7074                              <1> ;;	SIODELAY
  7075                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7076                              <1> ;;	;JNC	short NO_BAD		; CHECK FOR ERROR
  7077                              <1> ;;	jc	short dma_bnd_err ; 08/02/2015
  7078                              <1> ;;	and	ecx, 0FFF00000h ; 16 MB limit
  7079                              <1> ;;	jz	short NO_BAD
  7080                              <1> ;;dma_bnd_err:
  7081                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7082                              <1> ;;NO_BAD:
  7083                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  7084                              <1> 
  7085                              <1> ;-------------------------------------------------------------------------------
  7086                              <1> ; FMTDMA_SET
  7087                              <1> ;	THIS ROUTINE SETS UP THE DMA CONTROLLER FOR A FORMAT OPERATION.
  7088                              <1> ;
  7089                              <1> ; ON ENTRY:	NOTHING REQUIRED
  7090                              <1> ;
  7091                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7092                              <1> ;-------------------------------------------------------------------------------
  7093                              <1> 
  7094                              <1> FMTDMA_SET:
  7095                              <1> ;; 20/02/2015 modification	
  7096 00002286 8B5504              <1> 	mov	edx, [ebp+4] 		; Buffer address
  7097 00002289 F7C20000F0FF        <1> 	test	edx, 0FFF00000h		; 16 MB limit
  7098 0000228F 75EC                <1> 	jnz	short dma_bnd_err_stc
  7099                              <1> 	;
  7100 00002291 6652                <1> 	push	dx			; *
  7101 00002293 B204                <1> 	mov	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  7102 00002295 E8D0020000          <1> 	call	GET_PARM		; "
  7103 0000229A 88E0                <1> 	mov	al, ah			; AL = SECTORS/TRACK VALUE
  7104 0000229C 28E4                <1> 	sub	ah, ah			; AX = SECTORS/TRACK VALUE
  7105 0000229E 66C1E002            <1> 	shl	ax, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  7106 000022A2 6648                <1> 	dec	ax			; -1 FOR DMA VALUE
  7107 000022A4 6689C1              <1> 	mov	cx, ax
  7108 000022A7 665A                <1> 	pop	dx			; *
  7109 000022A9 6601CA              <1> 	add	dx, cx			; check for overflow
  7110 000022AC 72D0                <1> 	jc	short dma_bnd_err
  7111                              <1> 	;
  7112 000022AE 6629CA              <1> 	sub	dx, cx			; Restore start address
  7113                              <1> 	;
  7114 000022B1 B04A                <1> 	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  7115 000022B3 FA                  <1> 	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7116 000022B4 E60C                <1> 	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7117                              <1> 	IODELAY				; WAIT FOR I/O
  7118 000022B6 EB00                <2>  jmp short $+2
  7119 000022B8 EB00                <2>  jmp short $+2
  7120 000022BA E60B                <1> 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7121 000022BC 89D0                <1> 	mov	eax, edx		; Buffer address
  7122 000022BE E604                <1> 	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7123                              <1> 	IODELAY				; WAIT FOR I/O
  7124 000022C0 EB00                <2>  jmp short $+2
  7125 000022C2 EB00                <2>  jmp short $+2
  7126 000022C4 88E0                <1> 	MOV	AL,AH
  7127 000022C6 E604                <1> 	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7128 000022C8 C1E810              <1> 	shr	eax, 16
  7129                              <1> 	IODELAY				; I/O WAIT STATE
  7130 000022CB EB00                <2>  jmp short $+2
  7131 000022CD EB00                <2>  jmp short $+2
  7132 000022CF E681                <1> 	OUT	081H,AL			; OUTPUT highest BITS TO PAGE REGISTER
  7133                              <1> 	IODELAY
  7134 000022D1 EB00                <2>  jmp short $+2
  7135 000022D3 EB00                <2>  jmp short $+2
  7136 000022D5 6689C8              <1> 	mov	ax, cx			; Byte count - 1
  7137 000022D8 E605                <1> 	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7138                              <1> 	IODELAY				; WAIT FOR I/O
  7139 000022DA EB00                <2>  jmp short $+2
  7140 000022DC EB00                <2>  jmp short $+2
  7141 000022DE 88E0                <1> 	MOV	AL, AH
  7142 000022E0 E605                <1> 	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7143                              <1> 	IODELAY
  7144 000022E2 EB00                <2>  jmp short $+2
  7145 000022E4 EB00                <2>  jmp short $+2
  7146 000022E6 FB                  <1> 	STI				; RE-ENABLE INTERRUPTS
  7147 000022E7 B002                <1> 	MOV	AL, 2			; MODE FOR 8237
  7148 000022E9 E60A                <1> 	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7149 000022EB C3                  <1> 	retn
  7150                              <1> 
  7151                              <1> ;; 08/02/2015 - Protected Mode Modification
  7152                              <1> ;;	MOV	AL, 04AH		; WILL WRITE TO THE DISKETTE
  7153                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  7154                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  7155                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7156                              <1> ;;	IODELAY
  7157                              <1> ;;	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  7158                              <1> ;;	;MOV	AX,ES			; GET THE ES VALUE
  7159                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  7160                              <1> ;;	;MOV	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  7161                              <1> ;;	;AND	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  7162                              <1> ;;	;ADD	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  7163                              <1> ;;	;JNC	short J33A
  7164                              <1> ;;	;INC	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  7165                              <1> ;;	mov	eax, [ebp+4] ; 08/02/2015
  7166                              <1> ;;;J33A:
  7167                              <1> ;;	PUSH	eAX ; 08/02/2015	; SAVE START ADDRESS
  7168                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  7169                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7170                              <1> ;;	IODELAY
  7171                              <1> ;;	MOV	AL,AH
  7172                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  7173                              <1> ;;	shr 	eax, 16 ; 08/02/2015
  7174                              <1> ;;	;MOV	AL,CH			; GET HIGH 4 BITS
  7175                              <1> ;;	;JMP	$+2			; I/O WAIT STATE
  7176                              <1> ;;	IODELAY
  7177                              <1> ;;	;AND	AL,00001111B
  7178                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  7179                              <1> ;;
  7180                              <1> ;;;----- DETERMINE COUNT
  7181                              <1> ;;	sub	eax, eax ; 08/02/2015
  7182                              <1> ;;	MOV	DL, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  7183                              <1> ;;	CALL	GET_PARM		; "
  7184                              <1> ;;	XCHG	AL, AH			; AL = SECTORS/TRACK VALUE
  7185                              <1> ;;	SUB	AH, AH			; AX = SECTORS/TRACK VALUE
  7186                              <1> ;;	SHL	AX, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  7187                              <1> ;;	DEC	AX			; -1 FOR DMA VALUE
  7188                              <1> ;;	PUSH	eAX 	; 08/02/2015	; SAVE # OF BYTES TO BE TRANSFERED
  7189                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  7190                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7191                              <1> ;;	IODELAY
  7192                              <1> ;;	MOV	AL, AH
  7193                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  7194                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  7195                              <1> ;;	POP	eCX	; 08/02/2015	; RECOVER COUNT VALUE
  7196                              <1> ;;	POP	eAX	; 08/02/2015	; RECOVER ADDRESS VALUE
  7197                              <1> ;;	;ADD	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  7198                              <1> ;;	add	ecx, eax ; 08/02/2015
  7199                              <1> ;;	MOV	AL, 2			; MODE FOR 8237
  7200                              <1> ;;	;JMP	$+2			; WAIT FOR I/O
  7201                              <1> ;;	SIODELAY
  7202                              <1> ;;	OUT	DMA+10, AL		; INITIALIZE THE DISKETTE CHANNEL
  7203                              <1> ;;	;JNC	short FMTDMA_OK		; CHECK FOR ERROR
  7204                              <1> ;;	jc	short fmtdma_bnd_err ; 08/02/2015
  7205                              <1> ;;	and	ecx, 0FFF00000h  ; 16 MB limit
  7206                              <1> ;;	jz	short FMTDMA_OK
  7207                              <1> ;;	stc	; 20/02/2015
  7208                              <1> ;;fmtdma_bnd_err:
  7209                              <1> ;;	MOV	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  7210                              <1> ;;FMTDMA_OK:
  7211                              <1> ;;	RETn				; CY SET BY ABOVE IF ERROR
  7212                              <1> 
  7213                              <1> ;-------------------------------------------------------------------------------
  7214                              <1> ; NEC_INIT	
  7215                              <1> ;	THIS ROUTINE SEEKS TO THE REQUESTED TRACK AND INITIALIZES
  7216                              <1> ;	THE NEC FOR THE READ/WRITE/VERIFY/FORMAT OPERATION.
  7217                              <1> ;
  7218                              <1> ; ON ENTRY:	AH = NEC COMMAND TO BE PERFORMED
  7219                              <1> ;
  7220                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7221                              <1> ;-------------------------------------------------------------------------------
  7222                              <1> NEC_INIT:
  7223 000022EC 6650                <1> 	PUSH	AX			; SAVE NEC COMMAND
  7224 000022EE E8BC020000          <1> 	CALL	MOTOR_ON		; TURN MOTOR ON FOR SPECIFIC DRIVE
  7225                              <1> 
  7226                              <1> ;-----	DO THE SEEK OPERATION
  7227                              <1> 
  7228 000022F3 8A6D01              <1> 	MOV	CH,[eBP+1]		; CH = TRACK #
  7229 000022F6 E8AF030000          <1> 	CALL	SEEK			; MOVE TO CORRECT TRACK
  7230 000022FB 6658                <1> 	POP	AX			; RECOVER COMMAND
  7231 000022FD 721E                <1> 	JC	short ER_1		; ERROR ON SEEK
  7232 000022FF BB[1D230000]        <1> 	MOV	eBX, ER_1		; LOAD ERROR ADDRESS
  7233 00002304 53                  <1> 	PUSH	eBX			; PUSH NEC_OUT ERROR RETURN
  7234                              <1> 
  7235                              <1> ;-----	SEND OUT THE PARAMETERS TO THE CONTROLLER
  7236                              <1> 
  7237 00002305 E866030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE OPERATION COMMAND
  7238 0000230A 6689F0              <1> 	MOV	AX,SI			; AH = HEAD #
  7239 0000230D 89FB                <1> 	MOV	eBX,eDI			; BL = DRIVE #
  7240 0000230F C0E402              <1> 	SAL	AH,2			; MOVE IT TO BIT 2
  7241 00002312 80E404              <1> 	AND	AH,00000100B		; ISOLATE THAT BIT
  7242 00002315 08DC                <1> 	OR	AH,BL			; OR IN THE DRIVE NUMBER
  7243 00002317 E854030000          <1> 	CALL	NEC_OUTPUT		; FALL THRU CY SET IF ERROR
  7244 0000231C 5B                  <1> 	POP	eBX			; THROW AWAY ERROR RETURN
  7245                              <1> ER_1:
  7246 0000231D C3                  <1> 	RETn
  7247                              <1> 
  7248                              <1> ;-------------------------------------------------------------------------------
  7249                              <1> ; RWV_COM
  7250                              <1> ;	THIS ROUTINE SENDS PARAMETERS TO THE NEC SPECIFIC TO THE 
  7251                              <1> ;	READ/WRITE/VERIFY OPERATIONS.
  7252                              <1> ;
  7253                              <1> ; ON ENTRY:	CS:BX = ADDRESS OF MEDIA/DRIVE PARAMETER TABLE
  7254                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7255                              <1> ;-------------------------------------------------------------------------------
  7256                              <1> RWV_COM:
  7257 0000231E B8[69230000]        <1> 	MOV	eAX, ER_2		; LOAD ERROR ADDRESS
  7258 00002323 50                  <1> 	PUSH	eAX			; PUSH NEC_OUT ERROR RETURN
  7259 00002324 8A6501              <1> 	MOV	AH,[eBP+1]		; OUTPUT TRACK #
  7260 00002327 E844030000          <1> 	CALL	NEC_OUTPUT
  7261 0000232C 6689F0              <1> 	MOV	AX,SI			; OUTPUT HEAD #
  7262 0000232F E83C030000          <1> 	CALL	NEC_OUTPUT
  7263 00002334 8A6500              <1>         MOV     AH,[eBP]                ; OUTPUT SECTOR #
  7264 00002337 E834030000          <1> 	CALL	NEC_OUTPUT
  7265 0000233C B203                <1> 	MOV	DL,3			; BYTES/SECTOR PARAMETER FROM BLOCK
  7266 0000233E E827020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  7267 00002343 E828030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7268 00002348 B204                <1> 	MOV	DL,4			; EOT PARAMETER FROM BLOCK
  7269 0000234A E81B020000          <1> 	CALL	GET_PARM 		; ... TO THE NEC
  7270 0000234F E81C030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7271 00002354 8A6305              <1>         MOV     AH, [eBX+MD.GAP]        ; GET GAP LENGTH
  7272                              <1> _R15:
  7273 00002357 E814030000          <1> 	CALL	NEC_OUTPUT
  7274 0000235C B206                <1> 	MOV	DL,6			; DTL PARAMETER PROM BLOCK
  7275 0000235E E807020000          <1> 	CALL	GET_PARM		;  TO THE NEC
  7276 00002363 E808030000          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  7277 00002368 58                  <1> 	POP	eAX			; THROW AWAY ERROR EXIT
  7278                              <1> ER_2:
  7279 00002369 C3                  <1> 	RETn
  7280                              <1> 
  7281                              <1> ;-------------------------------------------------------------------------------
  7282                              <1> ; NEC_TERM
  7283                              <1> ;	THIS ROUTINE WAITS FOR THE OPERATION THEN ACCEPTS THE STATUS 
  7284                              <1> ;	FROM THE NEC FOR THE READ/WRITE/VERIFY/FORWAT OPERATION.
  7285                              <1> ;
  7286                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7287                              <1> ;-------------------------------------------------------------------------------
  7288                              <1> NEC_TERM:
  7289                              <1> 
  7290                              <1> ;-----	LET THE OPERATION HAPPEN
  7291                              <1> 
  7292 0000236A 56                  <1> 	PUSH	eSI			; SAVE HEAD #, # OF SECTORS
  7293 0000236B E80D040000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  7294 00002370 9C                  <1> 	PUSHF
  7295 00002371 E837040000          <1> 	CALL	RESULTS			; GET THE NEC STATUS
  7296 00002376 724B                <1> 	JC	short SET_END_POP
  7297 00002378 9D                  <1> 	POPF
  7298 00002379 723E                <1> 	JC	short SET_END		; LOOK FOR ERROR
  7299                              <1> 
  7300                              <1> ;-----	CHECK THE RESULTS RETURNED BY THE CONTROLLER
  7301                              <1> 
  7302 0000237B FC                  <1> 	CLD				; SET THE CORRECT DIRECTION
  7303 0000237C BE[D5A20000]        <1> 	MOV	eSI, NEC_STATUS		; POINT TO STATUS FIELD
  7304 00002381 AC                  <1> 	lodsb				; GET ST0
  7305 00002382 24C0                <1> 	AND	AL,11000000B		; TEST FOR NORMAL TERMINATION
  7306 00002384 7433                <1> 	JZ	short SET_END
  7307 00002386 3C40                <1> 	CMP	AL,01000000B		; TEST FOR ABNORMAL TERMINATION
  7308 00002388 7527                <1> 	JNZ	short J18		; NOT ABNORMAL, BAD NEC
  7309                              <1> 
  7310                              <1> ;-----	ABNORMAL TERMINATION, FIND OUT WHY
  7311                              <1> 
  7312 0000238A AC                  <1> 	lodsb				; GET ST1
  7313 0000238B D0E0                <1> 	SAL	AL,1			; TEST FOR EDT FOUND
  7314 0000238D B404                <1> 	MOV	AH,RECORD_NOT_FND
  7315 0000238F 7222                <1> 	JC	short J19
  7316 00002391 C0E002              <1> 	SAL	AL,2
  7317 00002394 B410                <1> 	MOV	AH,BAD_CRC
  7318 00002396 721B                <1> 	JC	short J19
  7319 00002398 D0E0                <1> 	SAL	AL,1			; TEST FOR DMA OVERRUN
  7320 0000239A B408                <1> 	MOV	AH,BAD_DMA
  7321 0000239C 7215                <1> 	JC	short J19
  7322 0000239E C0E002              <1> 	SAL	AL,2			; TEST FOR RECORD NOT FOUND
  7323 000023A1 B404                <1> 	MOV	AH,RECORD_NOT_FND
  7324 000023A3 720E                <1> 	JC	short J19
  7325 000023A5 D0E0                <1> 	SAL	AL,1
  7326 000023A7 B403                <1> 	MOV	AH,WRITE_PROTECT	; TEST FOR WRITE_PROTECT
  7327 000023A9 7208                <1> 	JC	short J19
  7328 000023AB D0E0                <1> 	SAL	AL,1			; TEST MISSING ADDRESS MARK
  7329 000023AD B402                <1> 	MOV	AH,BAD_ADDR_MARK
  7330 000023AF 7202                <1> 	JC	short J19
  7331                              <1> 
  7332                              <1> ;----- 	NEC MUST HAVE FAILED
  7333                              <1> J18:
  7334 000023B1 B420                <1> 	MOV	AH,BAD_NEC
  7335                              <1> J19:
  7336 000023B3 0825[D4A20000]      <1> 	OR	[DSKETTE_STATUS], AH
  7337                              <1> SET_END:
  7338 000023B9 803D[D4A20000]01    <1> 	CMP	byte [DSKETTE_STATUS], 1 ; SET ERROR CONDITION
  7339 000023C0 F5                  <1> 	CMC
  7340 000023C1 5E                  <1> 	POP	eSI
  7341 000023C2 C3                  <1> 	RETn				; RESTORE HEAD #, # OF SECTORS
  7342                              <1> 
  7343                              <1> SET_END_POP:
  7344 000023C3 9D                  <1> 	POPF
  7345 000023C4 EBF3                <1> 	JMP	SHORT SET_END
  7346                              <1> 
  7347                              <1> ;-------------------------------------------------------------------------------
  7348                              <1> ; DSTATE:	ESTABLISH STATE UPON SUCCESSFUL OPERATION.
  7349                              <1> ;-------------------------------------------------------------------------------
  7350                              <1> DSTATE:
  7351 000023C6 803D[D4A20000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  7352 000023CD 753E                <1> 	JNZ	short SETBAC		    ; IF ERROR JUMP
  7353 000023CF 808F[E1A20000]10    <1> 	OR	byte [DSK_STATE+eDI],MED_DET ; NO ERROR, MARK MEDIA AS DETERMINED
  7354 000023D6 F687[E1A20000]04    <1> 	TEST	byte [DSK_STATE+eDI],DRV_DET ; DRIVE DETERMINED ?
  7355 000023DD 752E                <1> 	JNZ	short SETBAC		; IF DETERMINED NO TRY TO DETERMINE
  7356 000023DF 8A87[E1A20000]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  7357 000023E5 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  7358 000023E7 3C80                <1> 	CMP	AL,RATE_250		; RATE 250 ?
  7359 000023E9 751B                <1> 	JNE	short M_12		; NO, MUST BE 1.2M OR 1.44M DRIVE
  7360                              <1> 
  7361                              <1> ;----- 	CHECK IF IT IS 1.44M
  7362                              <1> 
  7363 000023EB E871010000          <1> 	CALL	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  7364                              <1> 	;;20/02/2015
  7365                              <1> 	;;JC	short M_12		; CMOS BAD
  7366 000023F0 7414                <1> 	jz	short M_12 ;; 20/02/2015
  7367 000023F2 3C04                <1> 	CMP	AL, 4			; 1.44MB DRIVE ?
  7368 000023F4 7410                <1> 	JE	short M_12		; YES
  7369                              <1> M_720:
  7370 000023F6 80A7[E1A20000]FD    <1> 	AND	byte [DSK_STATE+eDI], ~FMT_CAPA ; TURN OFF FORMAT CAPABILITY
  7371 000023FD 808F[E1A20000]04    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET  ; MARK DRIVE DETERMINED
  7372 00002404 EB07                <1> 	JMP	SHORT SETBAC		; BACK
  7373                              <1> M_12:	
  7374 00002406 808F[E1A20000]06    <1> 	OR	byte [DSK_STATE+eDI],DRV_DET+FMT_CAPA 
  7375                              <1> 					; TURN ON DETERMINED & FMT CAPA
  7376                              <1> SETBAC:
  7377 0000240D C3                  <1> 	RETn
  7378                              <1> 
  7379                              <1> ;-------------------------------------------------------------------------------
  7380                              <1> ; RETRY	
  7381                              <1> ;	DETERMINES WHETHER A RETRY IS NECESSARY. 
  7382                              <1> ;	IF RETRY IS REQUIRED THEN STATE INFORMATION IS UPDATED FOR RETRY.
  7383                              <1> ;
  7384                              <1> ; ON EXIT:	CY = 1 FOR RETRY, CY = 0 FOR NO RETRY
  7385                              <1> ;-------------------------------------------------------------------------------
  7386                              <1> RETRY:
  7387 0000240E 803D[D4A20000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; GET STATUS OF OPERATION
  7388 00002415 7445                <1> 	JZ	short NO_RETRY		; SUCCESSFUL OPERATION
  7389 00002417 803D[D4A20000]80    <1> 	CMP	byte [DSKETTE_STATUS],TIME_OUT ; IF TIME OUT NO RETRY
  7390 0000241E 743C                <1> 	JZ	short NO_RETRY
  7391 00002420 8AA7[E1A20000]      <1> 	MOV	AH,[DSK_STATE+eDI]	; GET MEDIA STATE OF DRIVE
  7392 00002426 F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED/DETERMINED ?
  7393 00002429 7531                <1> 	JNZ	short NO_RETRY		; IF ESTABLISHED STATE THEN TRUE ERROR
  7394 0000242B 80E4C0              <1> 	AND	AH,RATE_MSK		; ISOLATE RATE
  7395 0000242E 8A2D[DCA20000]      <1> 	MOV	CH,[LASTRATE]		; GET START OPERATION STATE
  7396 00002434 C0C504              <1> 	ROL	CH,4			; TO CORRESPONDING BITS
  7397 00002437 80E5C0              <1> 	AND	CH,RATE_MSK		; ISOLATE RATE BITS
  7398 0000243A 38E5                <1> 	CMP	CH,AH			; ALL RATES TRIED
  7399 0000243C 741E                <1> 	JE	short NO_RETRY		; IF YES, THEN TRUE ERROR
  7400                              <1> 
  7401                              <1> ;	SETUP STATE INDICATOR FOR RETRY ATTEMPT TO NEXT RATE
  7402                              <1> ;	 00000000B (500) -> 10000000B	(250)
  7403                              <1> ;	 10000000B (250) -> 01000000B	(300)
  7404                              <1> ;	 01000000B (300) -> 00000000B	(500)
  7405                              <1> 
  7406 0000243E 80FC01              <1> 	CMP	AH,RATE_500+1		; SET CY FOR RATE 500
  7407 00002441 D0DC                <1> 	RCR	AH,1			; TO NEXT STATE
  7408 00002443 80E4C0              <1> 	AND	AH,RATE_MSK		; KEEP ONLY RATE BITS
  7409 00002446 80A7[E1A20000]1F    <1> 	AND	byte [DSK_STATE+eDI], ~(RATE_MSK+DBL_STEP)
  7410                              <1> 					; RATE, DBL STEP OFF
  7411 0000244D 08A7[E1A20000]      <1> 	OR	[DSK_STATE+eDI],AH	; TURN ON NEW RATE
  7412 00002453 C605[D4A20000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; RESET STATUS FOR RETRY
  7413 0000245A F9                  <1> 	STC				; SET CARRY FOR RETRY
  7414 0000245B C3                  <1> 	RETn				; RETRY RETURN
  7415                              <1> 
  7416                              <1> NO_RETRY:
  7417 0000245C F8                  <1> 	CLC				; CLEAR CARRY NO RETRY
  7418 0000245D C3                  <1> 	RETn				; NO RETRY RETURN
  7419                              <1> 
  7420                              <1> ;-------------------------------------------------------------------------------
  7421                              <1> ; NUM_TRANS
  7422                              <1> ;	THIS ROUTINE CALCULATES THE NUMBER OF SECTORS THAT WERE
  7423                              <1> ;	ACTUALLY TRANSFERRED TO/FROM THE DISKETTE.
  7424                              <1> ;
  7425                              <1> ; ON ENTRY:	[BP+1] = TRACK
  7426                              <1> ;		SI-HI  = HEAD
  7427                              <1> ;		[BP]   = START SECTOR
  7428                              <1> ;
  7429                              <1> ; ON EXIT:	AL = NUMBER ACTUALLY TRANSFERRED
  7430                              <1> ;-------------------------------------------------------------------------------
  7431                              <1> NUM_TRANS:
  7432 0000245E 30C0                <1> 	XOR	AL,AL			; CLEAR FOR ERROR
  7433 00002460 803D[D4A20000]00    <1> 	CMP	byte [DSKETTE_STATUS],0	; CHECK FOR ERROR
  7434 00002467 752C                <1> 	JNZ	NT_OUT			; IF ERROR 0 TRANSFERRED
  7435 00002469 B204                <1> 	MOV	DL,4			; SECTORS/TRACK OFFSET TO DL
  7436 0000246B E8FA000000          <1> 	CALL	GET_PARM		; AH = SECTORS/TRACK
  7437 00002470 8A1D[DAA20000]      <1> 	MOV	BL, [NEC_STATUS+5]	; GET ENDING SECTOR
  7438 00002476 6689F1              <1> 	MOV	CX,SI			; CH = HEAD # STARTED
  7439 00002479 3A2D[D9A20000]      <1> 	CMP	CH, [NEC_STATUS+4]	; GET HEAD ENDED UP ON
  7440 0000247F 750D                <1> 	JNZ	DIF_HD			; IF ON SAME HEAD, THEN NO ADJUST
  7441 00002481 8A2D[D8A20000]      <1> 	MOV	CH, [NEC_STATUS+3]	; GET TRACK ENDED UP ON
  7442 00002487 3A6D01              <1> 	CMP	CH,[eBP+1]		; IS IT ASKED FOR TRACK
  7443 0000248A 7404                <1> 	JZ	short SAME_TRK		; IF SAME TRACK NO INCREASE
  7444 0000248C 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  7445                              <1> DIF_HD:
  7446 0000248E 00E3                <1> 	ADD	BL,AH			; ADD SECTORS/TRACK
  7447                              <1> SAME_TRK:
  7448 00002490 2A5D00              <1> 	SUB	BL,[eBP]		; SUBTRACT START FROM END
  7449 00002493 88D8                <1> 	MOV	AL,BL			; TO AL
  7450                              <1> NT_OUT:
  7451 00002495 C3                  <1> 	RETn
  7452                              <1> 
  7453                              <1> ;-------------------------------------------------------------------------------
  7454                              <1> ; SETUP_END
  7455                              <1> ;	RESTORES @MOTOR_COUNT TO PARAMETER PROVIDED IN TABLE 
  7456                              <1> ;	AND LOADS @DSKETTE_STATUS TO AH, AND SETS CY.
  7457                              <1> ;
  7458                              <1> ; ON EXIT:
  7459                              <1> ;	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7460                              <1> ;-------------------------------------------------------------------------------
  7461                              <1> SETUP_END:
  7462 00002496 B202                <1> 	MOV	DL,2			; GET THE MOTOR WAIT PARAMETER
  7463 00002498 6650                <1> 	PUSH	AX			; SAVE NUMBER TRANSFERRED
  7464 0000249A E8CB000000          <1> 	CALL	GET_PARM
  7465 0000249F 8825[D3A20000]      <1> 	MOV	[MOTOR_COUNT],AH	; STORE UPON RETURN
  7466 000024A5 6658                <1> 	POP	AX			; RESTORE NUMBER TRANSFERRED
  7467 000024A7 8A25[D4A20000]      <1> 	MOV	AH, [DSKETTE_STATUS]	; GET STATUS OF OPERATION
  7468 000024AD 08E4                <1> 	OR	AH,AH			; CHECK FOR ERROR
  7469 000024AF 7402                <1> 	JZ	short NUN_ERR			; NO ERROR
  7470 000024B1 30C0                <1> 	XOR	AL,AL			; CLEAR NUMBER RETURNED
  7471                              <1> NUN_ERR: 
  7472 000024B3 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  7473 000024B6 F5                  <1> 	CMC				; SUCCESS OR FAILURE
  7474 000024B7 C3                  <1> 	RETn
  7475                              <1> 
  7476                              <1> ;-------------------------------------------------------------------------------
  7477                              <1> ; SETUP_DBL
  7478                              <1> ;	CHECK DOUBLE STEP.
  7479                              <1> ;
  7480                              <1> ; ON ENTRY :	DI = DRIVE
  7481                              <1> ;
  7482                              <1> ; ON EXIT :	CY = 1 MEANS ERROR
  7483                              <1> ;-------------------------------------------------------------------------------
  7484                              <1> SETUP_DBL:
  7485 000024B8 8AA7[E1A20000]      <1> 	MOV	AH, [DSK_STATE+eDI]	; ACCESS STATE
  7486 000024BE F6C410              <1> 	TEST	AH,MED_DET		; ESTABLISHED STATE ?
  7487 000024C1 757E                <1> 	JNZ	short NO_DBL			; IF ESTABLISHED THEN DOUBLE DONE
  7488                              <1> 
  7489                              <1> ;-----	CHECK FOR TRACK 0 TO SPEED UP ACKNOWLEDGE OF UNFORMATTED DISKETTE
  7490                              <1> 
  7491 000024C3 C605[D1A20000]00    <1> 	MOV	byte [SEEK_STATUS],0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  7492 000024CA E8E0000000          <1> 	CALL	MOTOR_ON		; ENSURE MOTOR STAY ON
  7493 000024CF B500                <1> 	MOV	CH,0			; LOAD TRACK 0
  7494 000024D1 E8D4010000          <1> 	CALL	SEEK			; SEEK TO TRACK 0
  7495 000024D6 E868000000          <1> 	CALL	READ_ID			; READ ID FUNCTION
  7496 000024DB 7249                <1> 	JC	short SD_ERR		; IF ERROR NO TRACK 0
  7497                              <1> 
  7498                              <1> ;-----	INITIALIZE START AND MAX TRACKS (TIMES 2 FOR BOTH HEADS)
  7499                              <1> 
  7500 000024DD 66B95004            <1> 	MOV	CX,0450H 		; START, MAX TRACKS
  7501 000024E1 F687[E1A20000]01    <1> 	TEST	byte [DSK_STATE+eDI],TRK_CAPA ; TEST FOR 80 TRACK CAPABILITY
  7502 000024E8 7402                <1> 	JZ	short CNT_OK		; IF NOT COUNT IS SETUP
  7503 000024EA B1A0                <1> 	MOV	CL,0A0H			; MAXIMUM TRACK 1.2 MB
  7504                              <1> 
  7505                              <1> ;	ATTEMPT READ ID OF ALL TRACKS, ALL HEADS UNTIL SUCCESS; UPON SUCCESS,
  7506                              <1> ;	MUST SEE IF ASKED FOR TRACK IN SINGLE STEP MODE = TRACK ID READ; IF NOT
  7507                              <1> ;	THEN SET DOUBLE STEP ON.
  7508                              <1> 
  7509                              <1> CNT_OK:
  7510 000024EC C605[D3A20000]FF    <1>         MOV     byte [MOTOR_COUNT], 0FFH ; ENSURE MOTOR STAYS ON FOR OPERATION 
  7511 000024F3 6651                <1> 	PUSH	CX			; SAVE TRACK, COUNT
  7512 000024F5 C605[D4A20000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR STATUS, EXPECT ERRORS
  7513 000024FC 6631C0              <1> 	XOR	AX,AX			; CLEAR AX
  7514 000024FF D0ED                <1> 	SHR	CH,1			; HALVE TRACK, CY = HEAD
  7515 00002501 C0D003              <1> 	RCL	AL,3			; AX = HEAD IN CORRECT BIT
  7516 00002504 6650                <1> 	PUSH	AX			; SAVE HEAD
  7517 00002506 E89F010000          <1> 	CALL	SEEK			; SEEK TO TRACK
  7518 0000250B 6658                <1> 	POP	AX			; RESTORE HEAD
  7519 0000250D 6609C7              <1> 	OR	DI,AX			; DI = HEAD OR'ED DRIVE
  7520 00002510 E82E000000          <1> 	CALL	READ_ID			; READ ID HEAD 0
  7521 00002515 9C                  <1> 	PUSHF				; SAVE RETURN FROM READ_ID
  7522 00002516 6681E7FB00          <1> 	AND	DI,11111011B		; TURN OFF HEAD 1 BIT
  7523 0000251B 9D                  <1> 	POPF				; RESTORE ERROR RETURN
  7524 0000251C 6659                <1> 	POP	CX			; RESTORE COUNT
  7525 0000251E 7308                <1> 	JNC	short DO_CHK		; IF OK, ASKED = RETURNED TRACK ?
  7526 00002520 FEC5                <1> 	INC	CH			; INC FOR NEXT TRACK
  7527 00002522 38CD                <1> 	CMP	CH,CL			; REACHED MAXIMUM YET
  7528 00002524 75C6                <1> 	JNZ	short CNT_OK		; CONTINUE TILL ALL TRIED
  7529                              <1> 
  7530                              <1> ;-----	FALL THRU, READ ID FAILED FOR ALL TRACKS
  7531                              <1> 
  7532                              <1> SD_ERR:	
  7533 00002526 F9                  <1> 	STC				; SET CARRY FOR ERROR
  7534 00002527 C3                  <1> 	RETn				; SETUP_DBL ERROR EXIT
  7535                              <1> 
  7536                              <1> DO_CHK:
  7537 00002528 8A0D[D8A20000]      <1> 	MOV	CL, [NEC_STATUS+3]	; LOAD RETURNED TRACK
  7538 0000252E 888F[E5A20000]      <1> 	MOV	[DSK_TRK+eDI], CL	; STORE TRACK NUMBER
  7539 00002534 D0ED                <1> 	SHR	CH,1			; HALVE TRACK
  7540 00002536 38CD                <1> 	CMP	CH,CL			; IS IT THE SAME AS ASKED FOR TRACK
  7541 00002538 7407                <1> 	JZ	short NO_DBL		; IF SAME THEN NO DOUBLE STEP
  7542 0000253A 808F[E1A20000]20    <1> 	OR	byte [DSK_STATE+eDI],DBL_STEP ; TURN ON DOUBLE STEP REQUIRED
  7543                              <1> NO_DBL:
  7544 00002541 F8                  <1> 	CLC				; CLEAR ERROR FLAG
  7545 00002542 C3                  <1> 	RETn
  7546                              <1> 
  7547                              <1> ;-------------------------------------------------------------------------------
  7548                              <1> ; READ_ID
  7549                              <1> ;	READ ID FUNCTION.
  7550                              <1> ;
  7551                              <1> ; ON ENTRY:	DI : BIT 2 = HEAD; BITS 1,0 = DRIVE
  7552                              <1> ;
  7553                              <1> ; ON EXIT: 	DI : BIT 2 IS RESET, BITS 1,0 = DRIVE
  7554                              <1> ;		@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  7555                              <1> ;-------------------------------------------------------------------------------
  7556                              <1> READ_ID:
  7557 00002543 B8[60250000]        <1> 	MOV	eAX, ER_3		; MOVE NEC OUTPUT ERROR ADDRESS
  7558 00002548 50                  <1> 	PUSH	eAX
  7559 00002549 B44A                <1> 	MOV	AH,4AH			; READ ID COMMAND
  7560 0000254B E820010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  7561 00002550 6689F8              <1> 	MOV	AX,DI			; DRIVE # TO AH, HEAD 0
  7562 00002553 88C4                <1> 	MOV	AH,AL
  7563 00002555 E816010000          <1> 	CALL	NEC_OUTPUT		; TO CONTROLLER
  7564 0000255A E80BFEFFFF          <1> 	CALL	NEC_TERM		; WAIT FOR OPERATION, GET STATUS
  7565 0000255F 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  7566                              <1> ER_3:
  7567 00002560 C3                  <1> 	RETn
  7568                              <1> 
  7569                              <1> ;-------------------------------------------------------------------------------
  7570                              <1> ; CMOS_TYPE
  7571                              <1> ;	RETURNS DISKETTE TYPE FROM CMOS
  7572                              <1> ;
  7573                              <1> ; ON ENTRY:	DI = DRIVE #
  7574                              <1> ;
  7575                              <1> ; ON EXIT:	AL = TYPE; CY REFLECTS STATUS
  7576                              <1> ;-------------------------------------------------------------------------------
  7577                              <1> 
  7578                              <1> CMOS_TYPE: ; 11/12/2014
  7579 00002561 8A87[1E9D0000]      <1> mov	al, [eDI+fd0_type]
  7580 00002567 20C0                <1> and 	al, al ; 18/12/2014
  7581 00002569 C3                  <1> retn
  7582                              <1> 
  7583                              <1> ;CMOS_TYPE:
  7584                              <1> ;	MOV	AL, CMOS_DIAG		; CMOS DIAGNOSTIC STATUS BYTE ADDRESS
  7585                              <1> ;	CALL	CMOS_READ		; GET CMOS STATUS
  7586                              <1> ;	TEST	AL,BAD_BAT+BAD_CKSUM	; BATTERY GOOD AND CHECKSUM VALID
  7587                              <1> ;	STC				; SET CY = 1 INDICATING ERROR FOR RETURN
  7588                              <1> ;	JNZ	short BAD_CM		; ERROR IF EITHER BIT ON
  7589                              <1> ;	MOV	AL,CMOS_DISKETTE	; ADDRESS OF DISKETTE BYTE IN CMOS
  7590                              <1> ;	CALL	CMOS_READ		; GET DISKETTE BYTE
  7591                              <1> ;	OR	DI,DI			; SEE WHICH DRIVE IN QUESTION
  7592                              <1> ;	JNZ	short TB		; IF DRIVE 1, DATA IN LOW NIBBLE
  7593                              <1> ;	ROR	AL,4			; EXCHANGE NIBBLES IF SECOND DRIVE
  7594                              <1> ;TB:
  7595                              <1> ;	AND	AL,0FH			; KEEP ONLY DRIVE DATA, RESET CY, 0
  7596                              <1> ;BAD_CM:
  7597                              <1> ;	RETn				; CY, STATUS OF READ
  7598                              <1> 
  7599                              <1> ;-------------------------------------------------------------------------------
  7600                              <1> ; GET_PARM
  7601                              <1> ;	THIS ROUTINE FETCHES THE INDEXED POINTER FROM THE DISK_BASE
  7602                              <1> ;	BLOCK POINTED TO BY THE DATA VARIABLE @DISK_POINTER. A BYTE FROM
  7603                              <1> ;	THAT TABLE IS THEN MOVED INTO AH, THE INDEX OF THAT BYTE BEING
  7604                              <1> ;	THE PARAMETER IN DL.
  7605                              <1> ;
  7606                              <1> ; ON ENTRY:	DL = INDEX OF BYTE TO BE FETCHED
  7607                              <1> ;
  7608                              <1> ; ON EXIT:	AH = THAT BYTE FROM BLOCK
  7609                              <1> ;		AL,DH DESTROYED
  7610                              <1> ;-------------------------------------------------------------------------------
  7611                              <1> GET_PARM:
  7612                              <1> 	;PUSH	DS
  7613 0000256A 56                  <1> 	PUSH	eSI
  7614                              <1>     	;SUB	AX,AX			; DS = 0, BIOS DATA AREA
  7615                              <1>     	;MOV	DS,AX
  7616                              <1> 	;;mov	ax, cs
  7617                              <1> 	;;mov	ds, ax
  7618                              <1> 	; 08/02/2015 (protected mode modifications, bx -> ebx)
  7619 0000256B 87D3                <1> 	XCHG	eDX,eBX			; BL = INDEX
  7620                              <1> 	;SUB	BH,BH			; BX = INDEX
  7621 0000256D 81E3FF000000        <1> 	and	ebx, 0FFh
  7622                              <1>     	;LDS	SI, [DISK_POINTER]	; POINT TO BLOCK
  7623                              <1> 	;
  7624                              <1> 	; 17/12/2014
  7625 00002573 66A1[119D0000]      <1> 	mov	ax, [cfd] ; current (AL) and previous fd (AH)
  7626 00002579 38E0                <1> 	cmp	al, ah
  7627 0000257B 7425                <1> 	je	short gpndc
  7628 0000257D A2[129D0000]        <1> 	mov	[pfd], al ; current drive -> previous drive
  7629 00002582 53                  <1> 	push	ebx ; 08/02/2015
  7630 00002583 88C3                <1> 	mov	bl, al 
  7631                              <1> 	; 11/12/2014
  7632 00002585 8A83[1E9D0000]      <1> 	mov	al, [eBX+fd0_type]	; Drive type (0,1,2,3,4)
  7633                              <1> 	; 18/12/2014
  7634 0000258B 20C0                <1> 	and	al, al
  7635 0000258D 7507                <1> 	jnz	short gpdtc
  7636 0000258F BB[FB9C0000]        <1> 	mov	ebx, MD_TBL6		; 1.44 MB param. tbl. (default)
  7637 00002594 EB05                <1>         jmp     short gpdpu
  7638                              <1> gpdtc:	
  7639 00002596 E817F9FFFF          <1> 	call	DR_TYPE_CHECK
  7640                              <1> 	; cf = 1 -> eBX points to 1.44MB fd parameter table (default)
  7641                              <1> gpdpu:
  7642 0000259B 891D[989C0000]      <1> 	mov	[DISK_POINTER], ebx
  7643 000025A1 5B                  <1> 	pop	ebx
  7644                              <1> gpndc:
  7645 000025A2 8B35[989C0000]      <1> 	mov	esi, [DISK_POINTER] ; 08/02/2015, si -> esi
  7646 000025A8 8A241E              <1> 	MOV	AH, [eSI+eBX]		; GET THE WORD
  7647 000025AB 87D3                <1> 	XCHG	eDX,eBX			; RESTORE BX
  7648 000025AD 5E                  <1> 	POP	eSI
  7649                              <1> 	;POP	DS
  7650 000025AE C3                  <1> 	RETn
  7651                              <1> 
  7652                              <1> ;-------------------------------------------------------------------------------
  7653                              <1> ; MOTOR_ON
  7654                              <1> ;	TURN MOTOR ON AND WAIT FOR MOTOR START UP TIME. THE @MOTOR_COUNT
  7655                              <1> ;	IS REPLACED WITH A SUFFICIENTLY HIGH NUMBER (0FFH) TO ENSURE
  7656                              <1> ;	THAT THE MOTOR DOES NOT GO OFF DURING THE OPERATION. IF THE
  7657                              <1> ;	MOTOR NEEDED TO BE TURNED ON, THE MULTI-TASKING HOOK FUNCTION
  7658                              <1> ;	(AX=90FDH, INT 15) IS CALLED TELLING THE OPERATING SYSTEM
  7659                              <1> ;	THAT THE BIOS IS ABOUT TO WAIT FOR MOTOR START UP. IF THIS
  7660                              <1> ;	FUNCTION RETURNS WITH CY = 1, IT MEANS THAT THE MINIMUM WAIT
  7661                              <1> ;	HAS BEEN COMPLETED. AT THIS POINT A CHECK IS MADE TO ENSURE
  7662                              <1> ;	THAT THE MOTOR WASN'T TURNED OFF BY THE TIMER. IF THE HOOK DID
  7663                              <1> ;	NOT WAIT, THE WAIT FUNCTION (AH=086H) IS CALLED TO WAIT THE
  7664                              <1> ;	PRESCRIBED AMOUNT OF TIME. IF THE CARRY FLAG IS SET ON RETURN,
  7665                              <1> ;	IT MEANS THAT THE FUNCTION IS IN USE AND DID NOT PERFORM THE
  7666                              <1> ;	WAIT. A TIMER 1 WAIT LOOP WILL THEN DO THE WAIT.
  7667                              <1> ;
  7668                              <1> ; ON ENTRY:	DI = DRIVE #
  7669                              <1> ; ON EXIT:	AX,CX,DX DESTROYED
  7670                              <1> ;-------------------------------------------------------------------------------
  7671                              <1> MOTOR_ON:
  7672 000025AF 53                  <1> 	PUSH	eBX			; SAVE REG.
  7673 000025B0 E82A000000          <1> 	CALL	TURN_ON			; TURN ON MOTOR
  7674 000025B5 7226                <1> 	JC	short MOT_IS_ON		; IF CY=1 NO WAIT
  7675 000025B7 E89BF9FFFF          <1> 	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  7676 000025BC E865F9FFFF          <1> 	CALL	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  7677                              <1> 	;CALL	TURN_ON 		; CHECK AGAIN IF MOTOR ON
  7678                              <1> 	;JC	MOT_IS_ON		; IF NO WAIT MEANS IT IS ON
  7679                              <1> M_WAIT:
  7680 000025C1 B20A                <1> 	MOV	DL,10			; GET THE MOTOR WAIT PARAMETER
  7681 000025C3 E8A2FFFFFF          <1> 	CALL	GET_PARM
  7682                              <1> 	;MOV	AL,AH			; AL = MOTOR WAIT PARAMETER
  7683                              <1> 	;XOR	AH,AH			; AX = MOTOR WAIT PARAMETER
  7684                              <1> 	;CMP	AL,8			; SEE IF AT LEAST A SECOND IS SPECIFIED
  7685 000025C8 80FC08              <1> 	cmp	ah, 8
  7686                              <1> 	;JAE	short GP2		; IF YES, CONTINUE
  7687 000025CB 7702                <1> 	ja	short J13
  7688                              <1> 	;MOV	AL,8			; ONE SECOND WAIT FOR MOTOR START UP
  7689 000025CD B408                <1> 	mov	ah, 8
  7690                              <1> 
  7691                              <1> ;-----	AS CONTAINS NUMBER OF 1/8 SECONDS (125000 MICROSECONDS) TO WAIT
  7692                              <1> GP2:	
  7693                              <1> ;----- 	FOLLOWING LOOPS REQUIRED WHEN RTC WAIT FUNCTION IS ALREADY IN USE
  7694                              <1> J13:					; WAIT FOR 1/8 SECOND PER (AL)
  7695 000025CF B95E200000          <1> 	MOV	eCX,8286		; COUNT FOR 1/8 SECOND AT 15.085737 US
  7696 000025D4 E816F3FFFF          <1> 	CALL	WAITF			; GO TO FIXED WAIT ROUTINE
  7697                              <1> 	;DEC	AL			; DECREMENT TIME VALUE
  7698 000025D9 FECC                <1> 	dec	ah
  7699 000025DB 75F2                <1> 	JNZ	short J13		; ARE WE DONE YET
  7700                              <1> MOT_IS_ON:
  7701 000025DD 5B                  <1> 	POP	eBX			; RESTORE REG.
  7702 000025DE C3                  <1> 	RETn
  7703                              <1> 
  7704                              <1> ;-------------------------------------------------------------------------------
  7705                              <1> ; TURN_ON
  7706                              <1> ;	TURN MOTOR ON AND RETURN WAIT STATE.
  7707                              <1> ;
  7708                              <1> ; ON ENTRY:	DI = DRIVE #
  7709                              <1> ;
  7710                              <1> ; ON EXIT:	CY = 0 MEANS WAIT REQUIRED
  7711                              <1> ;		CY = 1 MEANS NO WAIT REQUIRED
  7712                              <1> ;		AX,BX,CX,DX DESTROYED
  7713                              <1> ;-------------------------------------------------------------------------------
  7714                              <1> TURN_ON:
  7715 000025DF 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7716 000025E1 88D9                <1> 	MOV	CL,BL			; CL = DRIVE #
  7717 000025E3 C0C304              <1> 	ROL	BL,4			; BL = DRIVE SELECT
  7718 000025E6 FA                  <1> 	CLI				; NO INTERRUPTS WHILE DETERMINING STATUS
  7719 000025E7 C605[D3A20000]FF    <1> 	MOV	byte [MOTOR_COUNT],0FFH	; ENSURE MOTOR STAYS ON FOR OPERATION
  7720 000025EE A0[D2A20000]        <1> 	MOV	AL, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  7721 000025F3 2430                <1> 	AND	AL,00110000B		; KEEP ONLY DRIVE SELECT BITS
  7722 000025F5 B401                <1> 	MOV	AH,1			; MASK FOR DETERMINING MOTOR BIT
  7723 000025F7 D2E4                <1> 	SHL	AH,CL			; AH = MOTOR ON, A=00000001, B=00000010
  7724                              <1> 
  7725                              <1> ;  AL = DRIVE SELECT FROM @MOTOR_STATUS
  7726                              <1> ;  BL = DRIVE SELECT DESIRED
  7727                              <1> ;  AH = MOTOR ON MASK DESIRED
  7728                              <1> 
  7729 000025F9 38D8                <1> 	CMP	AL,BL			; REQUESTED DRIVE ALREADY SELECTED ?
  7730 000025FB 7508                <1> 	JNZ	short TURN_IT_ON	; IF NOT SELECTED JUMP
  7731 000025FD 8425[D2A20000]      <1> 	TEST	AH, [MOTOR_STATUS]	; TEST MOTOR ON BIT
  7732 00002603 7535                <1> 	JNZ	short NO_MOT_WAIT	; JUMP IF MOTOR ON AND SELECTED
  7733                              <1> 
  7734                              <1> TURN_IT_ON:
  7735 00002605 08DC                <1> 	OR	AH,BL			; AH = DRIVE SELECT AND MOTOR ON
  7736 00002607 8A3D[D2A20000]      <1> 	MOV	BH,[MOTOR_STATUS]	; SAVE COPY OF @MOTOR_STATUS BEFORE
  7737 0000260D 80E70F              <1> 	AND	BH,00001111B		; KEEP ONLY MOTOR BITS
  7738 00002610 8025[D2A20000]CF    <1> 	AND	byte [MOTOR_STATUS],11001111B ; CLEAR OUT DRIVE SELECT
  7739 00002617 0825[D2A20000]      <1> 	OR	[MOTOR_STATUS],AH	; OR IN DRIVE SELECTED AND MOTOR ON
  7740 0000261D A0[D2A20000]        <1> 	MOV	AL,[MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  7741 00002622 88C3                <1> 	MOV	BL,AL			; BL=@MOTOR_STATUS AFTER, BH=BEFORE
  7742 00002624 80E30F              <1> 	AND	BL,00001111B		; KEEP ONLY MOTOR BITS
  7743 00002627 FB                  <1> 	STI				; ENABLE INTERRUPTS AGAIN
  7744 00002628 243F                <1> 	AND	AL,00111111B		; STRIP AWAY UNWANTED BITS
  7745 0000262A C0C004              <1> 	ROL	AL,4			; PUT BITS IN DESIRED POSITIONS
  7746 0000262D 0C0C                <1> 	OR	AL,00001100B		; NO RESET, ENABLE DMA/INTERRUPT
  7747 0000262F 66BAF203            <1> 	MOV	DX,03F2H		; SELECT DRIVE AND TURN ON MOTOR
  7748 00002633 EE                  <1> 	OUT	DX,AL
  7749 00002634 38FB                <1> 	CMP	BL,BH			; NEW MOTOR TURNED ON ?
  7750                              <1> 	;JZ	short NO_MOT_WAIT	; NO WAIT REQUIRED IF JUST SELECT
  7751 00002636 7403                <1> 	je	short no_mot_w1 ; 27/02/2015 
  7752 00002638 F8                  <1> 	CLC				; (re)SET CARRY MEANING WAIT
  7753 00002639 C3                  <1> 	RETn
  7754                              <1> 
  7755                              <1> NO_MOT_WAIT:
  7756 0000263A FB                  <1> 	sti
  7757                              <1> no_mot_w1: ; 27/02/2015
  7758 0000263B F9                  <1> 	STC				; SET NO WAIT REQUIRED
  7759                              <1> 	;STI				; INTERRUPTS BACK ON
  7760 0000263C C3                  <1> 	RETn
  7761                              <1> 
  7762                              <1> ;-------------------------------------------------------------------------------
  7763                              <1> ; HD_WAIT
  7764                              <1> ;	WAIT FOR HEAD SETTLE TIME.
  7765                              <1> ;
  7766                              <1> ; ON ENTRY:	DI = DRIVE #
  7767                              <1> ;
  7768                              <1> ; ON EXIT:	AX,BX,CX,DX DESTROYED
  7769                              <1> ;-------------------------------------------------------------------------------
  7770                              <1> HD_WAIT:
  7771 0000263D B209                <1> 	MOV	DL,9			; GET HEAD SETTLE PARAMETER
  7772 0000263F E826FFFFFF          <1> 	CALL	GET_PARM
  7773 00002644 08E4                <1> 	or	ah, ah	; 17/12/2014
  7774 00002646 7519                <1> 	jnz	short DO_WAT
  7775 00002648 F605[D2A20000]80    <1>         TEST    byte [MOTOR_STATUS],10000000B ; SEE IF A WRITE OPERATION
  7776                              <1> 	;JZ	short ISNT_WRITE	; IF NOT, DO NOT ENFORCE ANY VALUES
  7777                              <1> 	;OR	AH,AH			; CHECK FOR ANY WAIT?
  7778                              <1> 	;JNZ	short DO_WAT		; IF THERE DO NOT ENFORCE
  7779 0000264F 741E                <1> 	jz	short HW_DONE
  7780 00002651 B40F                <1> 	MOV	AH,HD12_SETTLE		; LOAD 1.2M HEAD SETTLE MINIMUM
  7781 00002653 8A87[E1A20000]      <1> 	MOV	AL,[DSK_STATE+eDI]	; LOAD STATE
  7782 00002659 24C0                <1> 	AND	AL,RATE_MSK		; KEEP ONLY RATE
  7783 0000265B 3C80                <1> 	CMP	AL,RATE_250		; 1.2 M DRIVE ?
  7784 0000265D 7502                <1> 	JNZ	short DO_WAT		; DEFAULT HEAD SETTLE LOADED
  7785                              <1> ;GP3:
  7786 0000265F B414                <1> 	MOV	AH,HD320_SETTLE		; USE 320/360 HEAD SETTLE
  7787                              <1> ;	JMP	SHORT DO_WAT
  7788                              <1> 
  7789                              <1> ;ISNT_WRITE:
  7790                              <1> ;	OR	AH,AH			; CHECK FOR NO WAIT
  7791                              <1> ;	JZ	short HW_DONE		; IF NOT WRITE AND 0 ITS OK
  7792                              <1> 
  7793                              <1> ;-----	AH CONTAINS NUMBER OF MILLISECONDS TO WAIT
  7794                              <1> DO_WAT:
  7795                              <1> ;	MOV	AL,AH			; AL = # MILLISECONDS
  7796                              <1> ;	;XOR	AH,AH			; AX = # MILLISECONDS
  7797                              <1> J29:					; 	1 MILLISECOND LOOP
  7798                              <1> 	;mov	cx, WAIT_FDU_HEAD_SETTLE ; 33 ; 1 ms in 30 micro units.
  7799 00002661 B942000000          <1> 	MOV	eCX,66			; COUNT AT 15.085737 US PER COUNT
  7800 00002666 E884F2FFFF          <1> 	CALL	WAITF			; DELAY FOR 1 MILLISECOND
  7801                              <1> 	;DEC	AL			; DECREMENT THE COUNT
  7802 0000266B FECC                <1> 	dec	ah
  7803 0000266D 75F2                <1> 	JNZ	short J29		; DO AL MILLISECOND # OF TIMES
  7804                              <1> HW_DONE:
  7805 0000266F C3                  <1> 	RETn
  7806                              <1> 
  7807                              <1> ;-------------------------------------------------------------------------------
  7808                              <1> ; NEC_OUTPUT
  7809                              <1> ;	THIS ROUTINE SENDS A BYTE TO THE NEC CONTROLLER AFTER TESTING
  7810                              <1> ;	FOR CORRECT DIRECTION AND CONTROLLER READY THIS ROUTINE WILL
  7811                              <1> ;	TIME OUT IF THE BYTE IS NOT ACCEPTED WITHIN A REASONABLE AMOUNT
  7812                              <1> ;	OF TIME, SETTING THE DISKETTE STATUS ON COMPLETION.
  7813                              <1> ; 
  7814                              <1> ; ON ENTRY: 	AH = BYTE TO BE OUTPUT
  7815                              <1> ;
  7816                              <1> ; ON EXIT:	CY = 0  SUCCESS
  7817                              <1> ;		CY = 1  FAILURE -- DISKETTE STATUS UPDATED
  7818                              <1> ;		        IF A FAILURE HAS OCCURRED, THE RETURN IS MADE ONE LEVEL
  7819                              <1> ;		        HIGHER THAN THE CALLER OF NEC OUTPUT. THIS REMOVES THE
  7820                              <1> ;		        REQUIREMENT OF TESTING AFTER EVERY CALL OF NEC_OUTPUT.
  7821                              <1> ;		AX,CX,DX DESTROYED
  7822                              <1> ;-------------------------------------------------------------------------------
  7823                              <1> 
  7824                              <1> ; 09/12/2014 [Erdogan Tan] 
  7825                              <1> ;	(from 'PS2 Hardware Interface Tech. Ref. May 88', Page 09-05.)
  7826                              <1> ; Diskette Drive Controller Status Register (3F4h)
  7827                              <1> ;	This read only register facilitates the transfer of data between
  7828                              <1> ;	the system microprocessor and the controller.
  7829                              <1> ; Bit 7 - When set to 1, the Data register is ready to transfer data 
  7830                              <1> ;	  with the system micrprocessor.
  7831                              <1> ; Bit 6 - The direction of data transfer. If this bit is set to 0,
  7832                              <1> ;	  the transfer is to the controller.
  7833                              <1> ; Bit 5 - When this bit is set to 1, the controller is in the non-DMA mode.
  7834                              <1> ; Bit 4 - When this bit is set to 1, a Read or Write command is being executed.
  7835                              <1> ; Bit 3 - Reserved.
  7836                              <1> ; Bit 2 - Reserved.
  7837                              <1> ; Bit 1 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  7838                              <1> ; Bit 0 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  7839                              <1> 
  7840                              <1> ; Data Register (3F5h)
  7841                              <1> ; This read/write register passes data, commands and parameters, and provides
  7842                              <1> ; diskette status information.
  7843                              <1>   		
  7844                              <1> NEC_OUTPUT:
  7845                              <1> 	;PUSH	BX			; SAVE REG.
  7846 00002670 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  7847                              <1> 	;MOV	BL,2			; HIGH ORDER COUNTER
  7848                              <1> 	;XOR	CX,CX			; COUNT FOR TIME OUT
  7849                              <1> 	; 16/12/2014
  7850                              <1> 	; waiting for (max.) 0.5 seconds
  7851                              <1>         ;;mov     byte [wait_count], 0 ;; 27/02/2015
  7852                              <1> 	;
  7853                              <1> 	; 17/12/2014
  7854                              <1> 	; Modified from AWARD BIOS 1999 - ADISK.ASM - SEND_COMMAND
  7855                              <1> 	;
  7856                              <1> 	;WAIT_FOR_PORT:	Waits for a bit at a port pointed to by DX to
  7857                              <1> 	;		go on.
  7858                              <1> 	;INPUT:
  7859                              <1> 	;	AH=Mask for isolation bits.
  7860                              <1> 	;	AL=pattern to look for.
  7861                              <1> 	;	DX=Port to test for
  7862                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  7863                              <1> 	;	     (normally 30 microseconds per period.)
  7864                              <1> 	;
  7865                              <1> 	;WFP_SHORT:  
  7866                              <1> 	;	Wait for port if refresh cycle is short (15-80 Us range).
  7867                              <1> 	;
  7868                              <1> 
  7869                              <1> ;	mov	bl, WAIT_FDU_SEND_HI+1	; 0+1
  7870                              <1> ;	mov	cx, WAIT_FDU_SEND_LO	; 16667
  7871 00002674 B91B410000          <1> 	mov	ecx, WAIT_FDU_SEND_LH   ; 16667 (27/02/2015)
  7872                              <1> ;
  7873                              <1> ;WFPS_OUTER_LP:
  7874                              <1> ;	;
  7875                              <1> ;WFPS_CHECK_PORT:
  7876                              <1> J23:
  7877 00002679 EC                  <1> 	IN	AL,DX			; GET STATUS
  7878 0000267A 24C0                <1> 	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  7879 0000267C 3C80                <1> 	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  7880 0000267E 7418                <1> 	JZ	short J27		; STATUS AND DIRECTION OK
  7881                              <1> WFPS_HI:
  7882 00002680 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  7883 00002682 A810                <1> 	TEST	AL,010H			; transition on memory
  7884 00002684 75FA                <1> 	JNZ	SHORT WFPS_HI		; refresh.
  7885                              <1> WFPS_LO:
  7886 00002686 E461                <1> 	IN	AL, PORT_B		; SYS1
  7887 00002688 A810                <1> 	TEST	AL,010H
  7888 0000268A 74FA                <1> 	JZ	SHORT WFPS_LO
  7889                              <1> 	;LOOP	SHORT WFPS_CHECK_PORT
  7890 0000268C E2EB                <1> 	loop	J23	; 27/02/2015
  7891                              <1> ;	;
  7892                              <1> ;	dec	bl
  7893                              <1> ;	jnz	short WFPS_OUTER_LP
  7894                              <1> ;	jmp	short WFPS_TIMEOUT	; fail
  7895                              <1> ;J23:
  7896                              <1> ;	IN	AL,DX			; GET STATUS
  7897                              <1> ;	AND	AL,11000000B		; KEEP STATUS AND DIRECTION
  7898                              <1> ;	CMP	AL,10000000B		; STATUS 1 AND DIRECTION 0 ?
  7899                              <1> ;	JZ	short J27		; STATUS AND DIRECTION OK
  7900                              <1> 	;LOOP	J23			; CONTINUE TILL CX EXHAUSTED
  7901                              <1> 	;DEC	BL			; DECREMENT COUNTER
  7902                              <1> 	;JNZ	short J23		; REPEAT TILL DELAY FINISHED, CX = 0
  7903                              <1>    
  7904                              <1> 	;;27/02/2015
  7905                              <1> 	;16/12/2014
  7906                              <1>         ;;cmp     byte [wait_count], 10   ; (10/18.2 seconds)
  7907                              <1> 	;;jb	short J23
  7908                              <1> 
  7909                              <1> ;WFPS_TIMEOUT:
  7910                              <1> 
  7911                              <1> ;-----	FALL THRU TO ERROR RETURN
  7912                              <1> 
  7913 0000268E 800D[D4A20000]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  7914                              <1> 	;POP	BX			; RESTORE REG.
  7915 00002695 58                  <1> 	POP	eAX ; 08/02/2015	; DISCARD THE RETURN ADDRESS
  7916 00002696 F9                  <1> 	STC				; INDICATE ERROR TO CALLER
  7917 00002697 C3                  <1> 	RETn
  7918                              <1> 
  7919                              <1> ;-----	DIRECTION AND STATUS OK; OUTPUT BYTE
  7920                              <1> 
  7921                              <1> J27:	
  7922 00002698 88E0                <1> 	MOV	AL,AH			; GET BYTE TO OUTPUT
  7923 0000269A 6642                <1> 	INC	DX			; DATA PORT = STATUS PORT + 1
  7924 0000269C EE                  <1> 	OUT	DX,AL			; OUTPUT THE BYTE
  7925                              <1> 	;;NEWIODELAY  ;; 27/02/2015
  7926                              <1> 	; 27/02/2015
  7927 0000269D 9C                  <1> 	PUSHF				; SAVE FLAGS
  7928 0000269E B903000000          <1> 	MOV	eCX, 3			; 30 TO 45 MICROSECONDS WAIT FOR
  7929 000026A3 E847F2FFFF          <1> 	CALL 	WAITF			; NEC FLAGS UPDATE CYCLE
  7930 000026A8 9D                  <1> 	POPF				; RESTORE FLAGS FOR EXIT
  7931                              <1> 	;POP	BX			; RESTORE REG
  7932 000026A9 C3                  <1> 	RETn				; CY = 0 FROM TEST INSTRUCTION
  7933                              <1> 
  7934                              <1> ;-------------------------------------------------------------------------------
  7935                              <1> ; SEEK
  7936                              <1> ;	THIS ROUTINE WILL MOVE THE HEAD ON THE NAMED DRIVE TO THE NAMED
  7937                              <1> ;	TRACK. IF THE DRIVE HAS NOT BEEN ACCESSED SINCE THE DRIVE
  7938                              <1> ;	RESET COMMAND WAS ISSUED, THE DRIVE WILL BE RECALIBRATED.
  7939                              <1> ;
  7940                              <1> ; ON ENTRY:	DI = DRIVE #
  7941                              <1> ;		CH = TRACK #
  7942                              <1> ;
  7943                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  7944                              <1> ;		AX,BX,CX DX DESTROYED
  7945                              <1> ;-------------------------------------------------------------------------------
  7946                              <1> SEEK:
  7947 000026AA 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7948 000026AC B001                <1> 	MOV	AL,1			; ESTABLISH MASK FOR RECALIBRATE TEST
  7949 000026AE 86CB                <1> 	XCHG	CL,BL			; SET DRIVE VALULE INTO CL
  7950 000026B0 D2C0                <1> 	ROL	AL,CL			; SHIFT MASK BY THE DRIVE VALUE
  7951 000026B2 86CB                <1> 	XCHG	CL,BL			; RECOVER TRACK VALUE
  7952 000026B4 8405[D1A20000]      <1> 	TEST	AL,[SEEK_STATUS]	; TEST FOR RECALIBRATE REQUIRED
  7953 000026BA 7526                <1> 	JNZ	short J28A		; JUMP IF RECALIBRATE NOT REQUIRED
  7954                              <1> 
  7955 000026BC 0805[D1A20000]      <1> 	OR	[SEEK_STATUS],AL	; TURN ON THE NO RECALIBRATE BIT IN FLAG
  7956 000026C2 E862000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  7957 000026C7 730E                <1> 	JNC	short AFT_RECAL		; RECALIBRATE DONE
  7958                              <1> 
  7959                              <1> ;-----	ISSUE RECALIBRATE FOR 80 TRACK DISKETTES
  7960                              <1> 
  7961 000026C9 C605[D4A20000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; CLEAR OUT INVALID STATUS
  7962 000026D0 E854000000          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  7963 000026D5 7251                <1> 	JC	short RB		; IF RECALIBRATE FAILS TWICE THEN ERROR
  7964                              <1> 
  7965                              <1> AFT_RECAL:
  7966 000026D7 C687[E5A20000]00    <1>         MOV     byte [DSK_TRK+eDI],0    ; SAVE NEW CYLINDER AS PRESENT POSITION
  7967 000026DE 08ED                <1> 	OR	CH,CH			; CHECK FOR SEEK TO TRACK 0
  7968 000026E0 743F                <1> 	JZ	short DO_WAIT		; HEAD SETTLE, CY = 0 IF JUMP
  7969                              <1> 
  7970                              <1> ;-----	DRIVE IS IN SYNCHRONIZATION WITH CONTROLLER, SEEK TO TRACK
  7971                              <1> 
  7972 000026E2 F687[E1A20000]20    <1> J28A:	TEST	byte [DSK_STATE+eDI],DBL_STEP ; CHECK FOR DOUBLE STEP REQUIRED
  7973 000026E9 7402                <1> 	JZ	short _R7		; SINGLE STEP REQUIRED BYPASS DOUBLE
  7974 000026EB D0E5                <1> 	SHL	CH,1			; DOUBLE NUMBER OF STEP TO TAKE
  7975                              <1> 
  7976 000026ED 3AAF[E5A20000]      <1> _R7:	CMP	CH, [DSK_TRK+eDI]	; SEE IF ALREADY AT THE DESIRED TRACK
  7977 000026F3 7433                <1> 	JE	short RB		; IF YES, DO NOT NEED TO SEEK
  7978                              <1> 
  7979 000026F5 BA[28270000]        <1> 	MOV	eDX, NEC_ERR		; LOAD RETURN ADDRESS
  7980 000026FA 52                  <1> 	PUSH	eDX ; (*)		; ON STACK FOR NEC OUTPUT ERROR
  7981 000026FB 88AF[E5A20000]      <1> 	MOV	[DSK_TRK+eDI],CH	; SAVE NEW CYLINDER AS PRESENT POSITION
  7982 00002701 B40F                <1> 	MOV	AH,0FH			; SEEK COMMAND TO NEC
  7983 00002703 E868FFFFFF          <1> 	CALL	NEC_OUTPUT
  7984 00002708 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  7985 0000270A 88DC                <1> 	MOV	AH,BL			; OUTPUT DRIVE NUMBER
  7986 0000270C E85FFFFFFF          <1> 	CALL	NEC_OUTPUT
  7987 00002711 8AA7[E5A20000]      <1> 	MOV	AH, [DSK_TRK+eDI]	; GET CYLINDER NUMBER
  7988 00002717 E854FFFFFF          <1> 	CALL	NEC_OUTPUT
  7989 0000271C E829000000          <1> 	CALL	CHK_STAT_2		; ENDING INTERRUPT AND SENSE STATUS
  7990                              <1> 
  7991                              <1> ;-----	WAIT FOR HEAD SETTLE
  7992                              <1> 
  7993                              <1> DO_WAIT:
  7994 00002721 9C                  <1> 	PUSHF				; SAVE STATUS
  7995 00002722 E816FFFFFF          <1> 	CALL	HD_WAIT			; WAIT FOR HEAD SETTLE TIME
  7996 00002727 9D                  <1> 	POPF				; RESTORE STATUS
  7997                              <1> RB:
  7998                              <1> NEC_ERR:
  7999                              <1> 	; 08/02/2015 (code trick here from original IBM PC/AT DISKETTE.ASM)
  8000                              <1> 	; (*) nec_err -> retn (push edx -> pop edx) -> nec_err -> retn
  8001 00002728 C3                  <1> 	RETn				; RETURN TO CALLER
  8002                              <1> 
  8003                              <1> ;-------------------------------------------------------------------------------
  8004                              <1> ; RECAL
  8005                              <1> ;	RECALIBRATE DRIVE
  8006                              <1> ;
  8007                              <1> ; ON ENTRY:	DI = DRIVE #
  8008                              <1> ;
  8009                              <1> ; ON EXIT:	CY REFLECTS STATUS OF OPERATION.
  8010                              <1> ;-------------------------------------------------------------------------------
  8011                              <1> RECAL:
  8012 00002729 6651                <1> 	PUSH	CX
  8013 0000272B B8[47270000]        <1> 	MOV	eAX, RC_BACK		; LOAD NEC_OUTPUT ERROR
  8014 00002730 50                  <1> 	PUSH	eAX
  8015 00002731 B407                <1> 	MOV	AH,07H			; RECALIBRATE COMMAND
  8016 00002733 E838FFFFFF          <1> 	CALL	NEC_OUTPUT
  8017 00002738 89FB                <1> 	MOV	eBX,eDI			; BX = DRIVE #
  8018 0000273A 88DC                <1> 	MOV	AH,BL
  8019 0000273C E82FFFFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT THE DRIVE NUMBER
  8020 00002741 E804000000          <1> 	CALL	CHK_STAT_2		; GET THE INTERRUPT AND SENSE INT STATUS
  8021 00002746 58                  <1> 	POP	eAX			; THROW AWAY ERROR
  8022                              <1> RC_BACK:
  8023 00002747 6659                <1> 	POP	CX
  8024 00002749 C3                  <1> 	RETn
  8025                              <1> 
  8026                              <1> ;-------------------------------------------------------------------------------
  8027                              <1> ; CHK_STAT_2
  8028                              <1> ;	THIS ROUTINE HANDLES THE INTERRUPT RECEIVED AFTER RECALIBRATE,
  8029                              <1> ;	OR SEEK TO THE ADAPTER. THE INTERRUPT IS WAITED FOR, THE
  8030                              <1> ;	INTERRUPT STATUS SENSED, AND THE RESULT RETURNED TO THE CALLER.
  8031                              <1> ;
  8032                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8033                              <1> ;-------------------------------------------------------------------------------
  8034                              <1> CHK_STAT_2:
  8035 0000274A B8[72270000]        <1>         MOV     eAX, CS_BACK            ; LOAD NEC_OUTPUT ERROR ADDRESS
  8036 0000274F 50                  <1> 	PUSH	eAX
  8037 00002750 E828000000          <1> 	CALL	WAIT_INT		; WAIT FOR THE INTERRUPT
  8038 00002755 721A                <1> 	JC	short J34		; IF ERROR, RETURN IT
  8039 00002757 B408                <1> 	MOV	AH,08H			; SENSE INTERRUPT STATUS COMMAND
  8040 00002759 E812FFFFFF          <1> 	CALL	NEC_OUTPUT
  8041 0000275E E84A000000          <1> 	CALL	RESULTS			; READ IN THE RESULTS
  8042 00002763 720C                <1> 	JC	short J34
  8043 00002765 A0[D5A20000]        <1> 	MOV	AL,[NEC_STATUS]		; GET THE FIRST STATUS BYTE
  8044 0000276A 2460                <1> 	AND	AL,01100000B		; ISOLATE THE BITS
  8045 0000276C 3C60                <1> 	CMP	AL,01100000B		; TEST FOR CORRECT VALUE
  8046 0000276E 7403                <1> 	JZ	short J35		; IF ERROR, GO MARK IT
  8047 00002770 F8                  <1> 	CLC				; GOOD RETURN
  8048                              <1> J34:
  8049 00002771 58                  <1> 	POP	eAX			; THROW AWAY ERROR RETURN
  8050                              <1> CS_BACK:
  8051 00002772 C3                  <1> 	RETn
  8052                              <1> J35:
  8053 00002773 800D[D4A20000]40    <1> 	OR	byte [DSKETTE_STATUS], BAD_SEEK
  8054 0000277A F9                  <1> 	STC				; ERROR RETURN CODE
  8055 0000277B EBF4                <1> 	JMP	SHORT J34
  8056                              <1> 
  8057                              <1> ;-------------------------------------------------------------------------------
  8058                              <1> ; WAIT_INT
  8059                              <1> ;	THIS ROUTINE WAITS FOR AN INTERRUPT TO OCCUR A TIME OUT ROUTINE
  8060                              <1> ;	TAKES PLACE DURING THE WAIT, SO THAT AN ERROR MAY BE RETURNED
  8061                              <1> ;	IF THE DRIVE IS NOT READY.
  8062                              <1> ;
  8063                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8064                              <1> ;-------------------------------------------------------------------------------
  8065                              <1> 
  8066                              <1> ; 17/12/2014
  8067                              <1> ; 2.5 seconds waiting !
  8068                              <1> ;(AWARD BIOS - 1999, WAIT_FDU_INT_LOW, WAIT_FDU_INT_HI)
  8069                              <1> ; amount of time to wait for completion interrupt from NEC.
  8070                              <1> 
  8071                              <1> 
  8072                              <1> WAIT_INT:
  8073 0000277D FB                  <1> 	STI				; TURN ON INTERRUPTS, JUST IN CASE
  8074 0000277E F8                  <1> 	CLC				; CLEAR TIMEOUT INDICATOR
  8075                              <1>        ;MOV	BL,10			; CLEAR THE COUNTERS
  8076                              <1>        ;XOR	CX,CX			; FOR 2 SECOND WAIT
  8077                              <1> 
  8078                              <1> 	; Modification from AWARD BIOS - 1999 (ATORGS.ASM, WAIT
  8079                              <1> 	;
  8080                              <1> 	;WAIT_FOR_MEM:	
  8081                              <1> 	;	Waits for a bit at a specified memory location pointed
  8082                              <1> 	;	to by ES:[DI] to become set.
  8083                              <1> 	;INPUT:
  8084                              <1> 	;	AH=Mask to test with.
  8085                              <1> 	;	ES:[DI] = memory location to watch.
  8086                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  8087                              <1> 	;	     (normally 30 microseconds per period.)
  8088                              <1> 
  8089                              <1> 	; waiting for (max.) 2.5 secs in 30 micro units.
  8090                              <1> ;	mov 	cx, WAIT_FDU_INT_LO		; 017798
  8091                              <1> ;;	mov 	bl, WAIT_FDU_INT_HI
  8092                              <1> ;	mov 	bl, WAIT_FDU_INT_HI + 1
  8093                              <1> 	; 27/02/2015
  8094 0000277F B986450100          <1> 	mov 	ecx, WAIT_FDU_INT_LH	; 83334 (2.5 seconds)		
  8095                              <1> WFMS_CHECK_MEM:
  8096 00002784 F605[D1A20000]80    <1> 	test	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  8097 0000278B 7516                <1>         jnz     short J37
  8098                              <1> WFMS_HI:
  8099 0000278D E461                <1> 	IN	AL,PORT_B  ; 061h	; SYS1, wait for lo to hi
  8100 0000278F A810                <1> 	TEST	AL,010H			; transition on memory
  8101 00002791 75FA                <1> 	JNZ	SHORT WFMS_HI		; refresh.
  8102                              <1> WFMS_LO:
  8103 00002793 E461                <1> 	IN	AL,PORT_B		;SYS1
  8104 00002795 A810                <1> 	TEST	AL,010H
  8105 00002797 74FA                <1> 	JZ	SHORT WFMS_LO
  8106 00002799 E2E9                <1>         LOOP    WFMS_CHECK_MEM
  8107                              <1> ;WFMS_OUTER_LP:
  8108                              <1> ;;	or	bl, bl			; check outer counter
  8109                              <1> ;;	jz	short J36A		; WFMS_TIMEOUT
  8110                              <1> ;	dec	bl
  8111                              <1> ;	jz	short J36A	
  8112                              <1> ;	jmp	short WFMS_CHECK_MEM
  8113                              <1> 
  8114                              <1> 	;17/12/2014
  8115                              <1> 	;16/12/2014
  8116                              <1> ;        mov     byte [wait_count], 0    ; Reset (INT 08H) counter
  8117                              <1> ;J36:
  8118                              <1> ;	TEST	byte [SEEK_STATUS],INT_FLAG ; TEST FOR INTERRUPT OCCURRING
  8119                              <1> ;	JNZ	short J37
  8120                              <1> 	;16/12/2014
  8121                              <1> 	;LOOP	J36			; COUNT DOWN WHILE WAITING
  8122                              <1> 	;DEC	BL			; SECOND LEVEL COUNTER
  8123                              <1> 	;JNZ	short J36
  8124                              <1> ;       cmp     byte [wait_count], 46   ; (46/18.2 seconds)
  8125                              <1> ;	jb	short J36
  8126                              <1> 
  8127                              <1> ;WFMS_TIMEOUT:
  8128                              <1> ;J36A:
  8129 0000279B 800D[D4A20000]80    <1> 	OR	byte [DSKETTE_STATUS], TIME_OUT ; NOTHING HAPPENED
  8130 000027A2 F9                  <1> 	STC				; ERROR RETURN
  8131                              <1> J37:
  8132 000027A3 9C                  <1> 	PUSHF				; SAVE CURRENT CARRY
  8133 000027A4 8025[D1A20000]7F    <1> 	AND	byte [SEEK_STATUS], ~INT_FLAG ; TURN OFF INTERRUPT FLAG
  8134 000027AB 9D                  <1> 	POPF				; RECOVER CARRY
  8135 000027AC C3                  <1> 	RETn				; GOOD RETURN CODE
  8136                              <1> 
  8137                              <1> ;-------------------------------------------------------------------------------
  8138                              <1> ; RESULTS
  8139                              <1> ;	THIS ROUTINE WILL READ ANYTHING THAT THE NEC CONTROLLER RETURNS 
  8140                              <1> ;	FOLLOWING AN INTERRUPT.
  8141                              <1> ;
  8142                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  8143                              <1> ;		AX,BX,CX,DX DESTROYED
  8144                              <1> ;-------------------------------------------------------------------------------
  8145                              <1> RESULTS:
  8146 000027AD 57                  <1> 	PUSH	eDI
  8147 000027AE BF[D5A20000]        <1> 	MOV	eDI, NEC_STATUS		; POINTER TO DATA AREA
  8148 000027B3 B307                <1> 	MOV	BL,7			; MAX STATUS BYTES
  8149 000027B5 66BAF403            <1> 	MOV	DX,03F4H		; STATUS PORT
  8150                              <1> 
  8151                              <1> ;-----	WAIT FOR REQUEST FOR MASTER
  8152                              <1> 
  8153                              <1> _R10: 
  8154                              <1> 	; 16/12/2014
  8155                              <1> 	; wait for (max) 0.5 seconds
  8156                              <1> 	;MOV	BH,2			; HIGH ORDER COUNTER
  8157                              <1> 	;XOR	CX,CX			; COUNTER
  8158                              <1> 
  8159                              <1> 	;Time to wait while waiting for each byte of NEC results = .5
  8160                              <1> 	;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  8161                              <1> 	; 27/02/2015
  8162 000027B9 B91B410000          <1> 	mov 	ecx, WAIT_FDU_RESULTS_LH ; 16667  
  8163                              <1> 	;mov	cx, WAIT_FDU_RESULTS_LO  ; 16667
  8164                              <1> 	;mov	bh, WAIT_FDU_RESULTS_HI+1 ; 0+1
  8165                              <1> 
  8166                              <1> WFPSR_OUTER_LP:
  8167                              <1> 	;
  8168                              <1> WFPSR_CHECK_PORT:
  8169                              <1> J39:					; WAIT FOR MASTER
  8170 000027BE EC                  <1> 	IN	AL,DX			; GET STATUS
  8171 000027BF 24C0                <1> 	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  8172 000027C1 3CC0                <1> 	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  8173 000027C3 7418                <1> 	JZ	short J42		; STATUS AND DIRECTION OK
  8174                              <1> WFPSR_HI:
  8175 000027C5 E461                <1> 	IN	AL, PORT_B	;061h	; SYS1	; wait for hi to lo
  8176 000027C7 A810                <1> 	TEST	AL,010H			; transition on memory
  8177 000027C9 75FA                <1> 	JNZ	SHORT WFPSR_HI		; refresh.
  8178                              <1> WFPSR_LO:
  8179 000027CB E461                <1> 	IN	AL, PORT_B		; SYS1
  8180 000027CD A810                <1> 	TEST	AL,010H
  8181 000027CF 74FA                <1> 	JZ	SHORT WFPSR_LO
  8182 000027D1 E2EB                <1>         LOOP    WFPSR_CHECK_PORT
  8183                              <1> 	;; 27/02/2015
  8184                              <1> 	;;dec	bh
  8185                              <1> 	;;jnz	short WFPSR_OUTER_LP
  8186                              <1> 	;jmp	short WFPSR_TIMEOUT	; fail
  8187                              <1> 
  8188                              <1> 	;;mov	byte [wait_count], 0
  8189                              <1> ;J39:					; WAIT FOR MASTER
  8190                              <1> ;	IN	AL,DX			; GET STATUS
  8191                              <1> ;	AND	AL,11000000B		; KEEP ONLY STATUS AND DIRECTION
  8192                              <1> ;	CMP	AL,11000000B		; STATUS 1 AND DIRECTION 1 ?
  8193                              <1> ;	JZ	short J42		; STATUS AND DIRECTION OK
  8194                              <1> 	;LOOP	J39			; LOOP TILL TIMEOUT
  8195                              <1> 	;DEC	BH			; DECREMENT HIGH ORDER COUNTER
  8196                              <1> 	;JNZ	short J39		; REPEAT TILL DELAY DONE
  8197                              <1> 	;
  8198                              <1> 	;;cmp	byte [wait_count], 10  ; (10/18.2 seconds)
  8199                              <1> 	;;jb	short J39	
  8200                              <1> 
  8201                              <1> ;WFPSR_TIMEOUT:
  8202 000027D3 800D[D4A20000]80    <1> 	OR	byte [DSKETTE_STATUS],TIME_OUT
  8203 000027DA F9                  <1> 	STC				; SET ERROR RETURN
  8204 000027DB EB29                <1> 	JMP	SHORT POPRES		; POP REGISTERS AND RETURN
  8205                              <1> 
  8206                              <1> ;-----	READ IN THE STATUS
  8207                              <1> 
  8208                              <1> J42:
  8209 000027DD EB00                <1> 	JMP	$+2			; I/O DELAY
  8210 000027DF 6642                <1> 	INC	DX			; POINT AT DATA PORT
  8211 000027E1 EC                  <1> 	IN	AL,DX			; GET THE DATA
  8212                              <1> 	; 16/12/2014
  8213                              <1> 	NEWIODELAY
  8214 000027E2 E6EB                <2>  out 0ebh,al
  8215 000027E4 8807                <1>         MOV     [eDI],AL                ; STORE THE BYTE
  8216 000027E6 47                  <1> 	INC	eDI			; INCREMENT THE POINTER
  8217                              <1> 	; 16/12/2014
  8218                              <1> ;	push	cx
  8219                              <1> ;	mov	cx, 30
  8220                              <1> ;wdw2:
  8221                              <1> ;	NEWIODELAY
  8222                              <1> ;	loop	wdw2
  8223                              <1> ;	pop	cx
  8224                              <1> 
  8225 000027E7 B903000000          <1> 	MOV	eCX,3			; MINIMUM 24 MICROSECONDS FOR NEC
  8226 000027EC E8FEF0FFFF          <1> 	CALL	WAITF			; WAIT 30 TO 45 MICROSECONDS
  8227 000027F1 664A                <1> 	DEC	DX			; POINT AT STATUS PORT
  8228 000027F3 EC                  <1> 	IN	AL,DX			; GET STATUS
  8229                              <1> 	; 16/12/2014
  8230                              <1> 	NEWIODELAY
  8231 000027F4 E6EB                <2>  out 0ebh,al
  8232                              <1> 	;
  8233 000027F6 A810                <1> 	TEST	AL,00010000B		; TEST FOR NEC STILL BUSY
  8234 000027F8 740C                <1> 	JZ	short POPRES		; RESULTS DONE ?
  8235                              <1> 
  8236 000027FA FECB                <1> 	DEC	BL			; DECREMENT THE STATUS COUNTER
  8237 000027FC 75BB                <1>         JNZ     short _R10              ; GO BACK FOR MORE
  8238 000027FE 800D[D4A20000]20    <1> 	OR	byte [DSKETTE_STATUS],BAD_NEC ; TOO MANY STATUS BYTES
  8239 00002805 F9                  <1> 	STC				; SET ERROR FLAG
  8240                              <1> 
  8241                              <1> ;-----	RESULT OPERATION IS DONE
  8242                              <1> POPRES:
  8243 00002806 5F                  <1> 	POP	eDI
  8244 00002807 C3                  <1> 	RETn				; RETURN WITH CARRY SET
  8245                              <1> 
  8246                              <1> ;-------------------------------------------------------------------------------
  8247                              <1> ; READ_DSKCHNG
  8248                              <1> ;	READS THE STATE OF THE DISK CHANGE LINE.
  8249                              <1> ;
  8250                              <1> ; ON ENTRY:	DI = DRIVE #
  8251                              <1> ;
  8252                              <1> ; ON EXIT:	DI = DRIVE #
  8253                              <1> ;		ZF = 0 : DISK CHANGE LINE INACTIVE
  8254                              <1> ;		ZF = 1 : DISK CHANGE LINE ACTIVE
  8255                              <1> ;		AX,CX,DX DESTROYED
  8256                              <1> ;-------------------------------------------------------------------------------
  8257                              <1> READ_DSKCHNG:
  8258 00002808 E8A2FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON THE MOTOR IF OFF
  8259 0000280D 66BAF703            <1> 	MOV	DX,03F7H		; ADDRESS DIGITAL INPUT REGISTER
  8260 00002811 EC                  <1> 	IN	AL,DX			; INPUT DIGITAL INPUT REGISTER
  8261 00002812 A880                <1> 	TEST	AL,DSK_CHG		; CHECK FOR DISK CHANGE LINE ACTIVE
  8262 00002814 C3                  <1> 	RETn				; RETURN TO CALLER WITH ZERO FLAG SET
  8263                              <1> 
  8264                              <1> ;-------------------------------------------------------------------------------
  8265                              <1> ; DRIVE_DET
  8266                              <1> ;	DETERMINES WHETHER DRIVE IS 80 OR 40 TRACKS AND
  8267                              <1> ;	UPDATES STATE INFORMATION ACCORDINGLY.
  8268                              <1> ; ON ENTRY:	DI = DRIVE #
  8269                              <1> ;-------------------------------------------------------------------------------
  8270                              <1> DRIVE_DET:
  8271 00002815 E895FDFFFF          <1> 	CALL	MOTOR_ON		; TURN ON MOTOR IF NOT ALREADY ON
  8272 0000281A E80AFFFFFF          <1> 	CALL	RECAL			; RECALIBRATE DRIVE
  8273 0000281F 7251                <1> 	JC	short DD_BAC		; ASSUME NO DRIVE PRESENT
  8274 00002821 B530                <1> 	MOV	CH,TRK_SLAP		; SEEK TO TRACK 48
  8275 00002823 E882FEFFFF          <1> 	CALL	SEEK
  8276 00002828 7248                <1> 	JC	short DD_BAC		; ERROR NO DRIVE
  8277 0000282A B50B                <1> 	MOV	CH,QUIET_SEEK+1		; SEEK TO TRACK 10
  8278                              <1> SK_GIN:
  8279 0000282C FECD                <1> 	DEC	CH			; DECREMENT TO NEXT TRACK
  8280 0000282E 6651                <1> 	PUSH	CX			; SAVE TRACK
  8281 00002830 E875FEFFFF          <1> 	CALL	SEEK
  8282 00002835 723C                <1> 	JC	short POP_BAC		; POP AND RETURN
  8283 00002837 B8[73280000]        <1> 	MOV	eAX, POP_BAC		; LOAD NEC OUTPUT ERROR ADDRESS
  8284 0000283C 50                  <1> 	PUSH	eAX
  8285 0000283D B404                <1> 	MOV	AH,SENSE_DRV_ST		; SENSE DRIVE STATUS COMMAND BYTE
  8286 0000283F E82CFEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  8287 00002844 6689F8              <1> 	MOV	AX,DI			; AL = DRIVE
  8288 00002847 88C4                <1> 	MOV	AH,AL			; AH = DRIVE
  8289 00002849 E822FEFFFF          <1> 	CALL	NEC_OUTPUT		; OUTPUT TO NEC
  8290 0000284E E85AFFFFFF          <1> 	CALL	RESULTS			; GO GET STATUS
  8291 00002853 58                  <1> 	POP	eAX			; THROW AWAY ERROR ADDRESS
  8292 00002854 6659                <1> 	POP	CX			; RESTORE TRACK
  8293 00002856 F605[D5A20000]10    <1> 	TEST	byte [NEC_STATUS], HOME	; TRACK 0 ?
  8294 0000285D 74CD                <1> 	JZ	short SK_GIN		; GO TILL TRACK 0
  8295 0000285F 08ED                <1> 	OR	CH,CH			; IS HOME AT TRACK 0
  8296 00002861 7408                <1> 	JZ	short IS_80		; MUST BE 80 TRACK DRIVE
  8297                              <1> 
  8298                              <1> ;	DRIVE IS A 360; SET DRIVE TO DETERMINED;
  8299                              <1> ;	SET MEDIA TO DETERMINED AT RATE 250.
  8300                              <1> 
  8301 00002863 808F[E1A20000]94    <1> 	OR	byte [DSK_STATE+eDI], DRV_DET+MED_DET+RATE_250
  8302 0000286A C3                  <1> 	RETn				; ALL INFORMATION SET
  8303                              <1> IS_80:
  8304 0000286B 808F[E1A20000]01    <1> 	OR	byte [DSK_STATE+eDI], TRK_CAPA ; SETUP 80 TRACK CAPABILITY
  8305                              <1> DD_BAC:
  8306 00002872 C3                  <1> 	RETn
  8307                              <1> POP_BAC:
  8308 00002873 6659                <1> 	POP	CX			; THROW AWAY
  8309 00002875 C3                  <1> 	RETn
  8310                              <1> 
  8311                              <1> fdc_int:  
  8312                              <1> 	  ; 30/07/2015	
  8313                              <1> 	  ; 16/02/2015
  8314                              <1> ;int_0Eh: ; 11/12/2014
  8315                              <1> 
  8316                              <1> ;--- HARDWARE INT 0EH -- ( IRQ LEVEL  6 ) --------------------------------------
  8317                              <1> ; DISK_INT
  8318                              <1> ;	THIS ROUTINE HANDLES THE DISKETTE INTERRUPT.
  8319                              <1> ;
  8320                              <1> ; ON EXIT:	THE INTERRUPT FLAG IS SET IN @SEEK_STATUS.
  8321                              <1> ;-------------------------------------------------------------------------------
  8322                              <1> DISK_INT_1:
  8323                              <1> 
  8324 00002876 6650                <1> 	PUSH	AX			; SAVE WORK REGISTER
  8325 00002878 1E                  <1> 	push	ds
  8326 00002879 66B81000            <1> 	mov	ax, KDATA
  8327 0000287D 8ED8                <1> 	mov 	ds, ax
  8328 0000287F 800D[D1A20000]80    <1>         OR      byte [SEEK_STATUS], INT_FLAG ; TURN ON INTERRUPT OCCURRED
  8329 00002886 B020                <1> 	MOV     AL,EOI                  ; END OF INTERRUPT MARKER
  8330 00002888 E620                <1> 	OUT	INTA00,AL		; INTERRUPT CONTROL PORT
  8331 0000288A 1F                  <1> 	pop	ds
  8332 0000288B 6658                <1> 	POP	AX			; RECOVER REGISTER
  8333 0000288D CF                  <1> 	IRET				; RETURN FROM INTERRUPT
  8334                              <1> 
  8335                              <1> ;-------------------------------------------------------------------------------
  8336                              <1> ; DSKETTE_SETUP
  8337                              <1> ;	THIS ROUTINE DOES A PRELIMINARY CHECK TO SEE WHAT TYPE OF
  8338                              <1> ;	DISKETTE DRIVES ARE ATTACH TO THE SYSTEM.
  8339                              <1> ;-------------------------------------------------------------------------------
  8340                              <1> DSKETTE_SETUP:
  8341                              <1> 	;PUSH	AX			; SAVE REGISTERS
  8342                              <1> 	;PUSH	BX
  8343                              <1> 	;PUSH	CX
  8344 0000288E 52                  <1> 	PUSH	eDX
  8345                              <1> 	;PUSH	DI
  8346                              <1> 	;;PUSH	DS
  8347                              <1> 	; 14/12/2014
  8348                              <1> 	;mov	word [DISK_POINTER], MD_TBL6
  8349                              <1> 	;mov	[DISK_POINTER+2], cs
  8350                              <1> 	;
  8351                              <1> 	;OR	byte [RTC_WAIT_FLAG], 1	; NO RTC WAIT, FORCE USE OF LOOP
  8352 0000288F 31FF                <1> 	XOR	eDI,eDI			; INITIALIZE DRIVE POINTER
  8353 00002891 66C705[E1A20000]00- <1> 	MOV	WORD [DSK_STATE],0	; INITIALIZE STATES
  8354 00002899 00                  <1>
  8355 0000289A 8025[DCA20000]33    <1> 	AND	byte [LASTRATE],~(STRT_MSK+SEND_MSK) ; CLEAR START & SEND
  8356 000028A1 800D[DCA20000]C0    <1> 	OR	byte [LASTRATE],SEND_MSK ; INITIALIZE SENT TO IMPOSSIBLE
  8357 000028A8 C605[D1A20000]00    <1> 	MOV	byte [SEEK_STATUS],0	; INDICATE RECALIBRATE NEEDED
  8358 000028AF C605[D3A20000]00    <1> 	MOV	byte [MOTOR_COUNT],0	; INITIALIZE MOTOR COUNT
  8359 000028B6 C605[D2A20000]00    <1> 	MOV	byte [MOTOR_STATUS],0	; INITIALIZE DRIVES TO OFF STATE
  8360 000028BD C605[D4A20000]00    <1> 	MOV	byte [DSKETTE_STATUS],0	; NO ERRORS
  8361                              <1> 	;
  8362                              <1> 	; 28/02/2015
  8363                              <1> 	;mov	word [cfd], 100h 
  8364 000028C4 E85FF2FFFF          <1> 	call	DSK_RESET
  8365 000028C9 5A                  <1> 	pop	edx
  8366 000028CA C3                  <1> 	retn
  8367                              <1> 
  8368                              <1> ;SUP0:
  8369                              <1> ;	CALL	DRIVE_DET		; DETERMINE DRIVE
  8370                              <1> ;	CALL	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  8371                              <1> ;	; 02/01/2015
  8372                              <1> ;	;INC	DI			; POINT TO NEXT DRIVE
  8373                              <1> ;	;CMP	DI,MAX_DRV		; SEE IF DONE
  8374                              <1> ;	;JNZ	short SUP0		; REPEAT FOR EACH ORIVE
  8375                              <1> ;       cmp     byte [fd1_type], 0	
  8376                              <1> ;	jna	short sup1
  8377                              <1> ;	or	di, di
  8378                              <1> ;	jnz	short sup1
  8379                              <1> ;	inc	di
  8380                              <1> ;       jmp     short SUP0
  8381                              <1> ;sup1:
  8382                              <1> ;	MOV	byte [SEEK_STATUS],0	; FORCE RECALIBRATE
  8383                              <1> ;	;AND	byte [RTC_WAIT_FLAG],0FEH ; ALLOW FOR RTC WAIT
  8384                              <1> ;	CALL	SETUP_END		; VARIOUS CLEANUPS
  8385                              <1> ;	;;POP	DS			; RESTORE CALLERS REGISTERS
  8386                              <1> ;	;POP	DI
  8387                              <1> ;	POP	eDX
  8388                              <1> ;	;POP	CX
  8389                              <1> ;	;POP	BX
  8390                              <1> ;	;POP	AX
  8391                              <1> ;	RETn
  8392                              <1> 
  8393                              <1> ;//////////////////////////////////////////////////////
  8394                              <1> ;; END OF DISKETTE I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8395                              <1> ;
  8396                              <1> 
  8397                              <1> int13h: ; 21/02/2015
  8398 000028CB 9C                  <1> 	pushfd
  8399 000028CC 0E                  <1> 	push 	cs
  8400 000028CD E859000000          <1> 	call 	DISK_IO
  8401 000028D2 C3                  <1> 	retn
  8402                              <1> 
  8403                              <1> ;;;;;; DISK I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 21/02/2015 ;;;
  8404                              <1> ;/////////////////////////////////////////////////////////////////////
  8405                              <1> 
  8406                              <1> ; DISK I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  8407                              <1> ; 18/02/2016
  8408                              <1> ; 17/02/2016
  8409                              <1> ; 23/02/2015
  8410                              <1> ; 21/02/2015 (unix386.s)
  8411                              <1> ; 22/12/2014 - 14/02/2015 (dsectrm2.s)
  8412                              <1> ;
  8413                              <1> ; Original Source Code:
  8414                              <1> ; DISK ----- 09/25/85 FIXED DISK BIOS
  8415                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  8416                              <1> ;
  8417                              <1> ; Modifications: by reference of AWARD BIOS 1999 (D1A0622) 
  8418                              <1> ;		 Source Code - ATORGS.ASM, AHDSK.ASM
  8419                              <1> ;
  8420                              <1> 
  8421                              <1> 
  8422                              <1> ;The wait for controller to be not busy is 10 seconds.
  8423                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  8424                              <1> ;;WAIT_HDU_CTLR_BUSY_LO	equ	1615h		
  8425                              <1> ;;WAIT_HDU_CTLR_BUSY_HI	equ	  05h
  8426                              <1> WAIT_HDU_CTRL_BUSY_LH	equ	51615h	 ;21/02/2015		
  8427                              <1> 
  8428                              <1> ;The wait for controller to issue completion interrupt is 10 seconds.
  8429                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  8430                              <1> ;;WAIT_HDU_INT_LO	equ	1615h
  8431                              <1> ;;WAIT_HDU_INT_HI	equ	  05h
  8432                              <1> WAIT_HDU_INT_LH		equ	51615h	; 21/02/2015
  8433                              <1> 
  8434                              <1> ;The wait for Data request on read and write longs is
  8435                              <1> ;2000 us. (?)
  8436                              <1> ;;WAIT_HDU_DRQ_LO	equ	1000	; 03E8h
  8437                              <1> ;;WAIT_HDU_DRQ_HI	equ	0
  8438                              <1> WAIT_HDU_DRQ_LH		equ	1000	; 21/02/2015
  8439                              <1> 
  8440                              <1> ; Port 61h (PORT_B)
  8441                              <1> SYS1		equ	61h	; PORT_B  (diskette.inc)
  8442                              <1> 
  8443                              <1> ; 23/12/2014
  8444                              <1> %define CMD_BLOCK       eBP-8  ; 21/02/2015
  8445                              <1> 
  8446                              <1> 
  8447                              <1> ;--- INT 13H -------------------------------------------------------------------
  8448                              <1> ;									       :
  8449                              <1> ; FIXED DISK I/O INTERFACE						       :
  8450                              <1> ;									       :
  8451                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO 5 1/4" FIXED DISKS THROUGH           :
  8452                              <1> ;	THE IBM FIXED DISK CONTROLLER.					       :
  8453                              <1> ;									       :
  8454                              <1> ;	THE  BIOS  ROUTINES  ARE  MEANT  TO  BE  ACCESSED  THROUGH	       :
  8455                              <1> ;	SOFTWARE  INTERRUPTS  ONLY.    ANY  ADDRESSES  PRESENT	IN	       :
  8456                              <1> ;	THESE  LISTINGS  ARE  INCLUDED	 ONLY	FOR  COMPLETENESS,	       :
  8457                              <1> ;	NOT  FOR  REFERENCE.  APPLICATIONS   WHICH  REFERENCE  ANY	       :
  8458                              <1> ;	ABSOLUTE  ADDRESSES  WITHIN  THE  CODE	SEGMENTS  OF  BIOS	       :
  8459                              <1> ;	VIOLATE  THE  STRUCTURE  AND  DESIGN  OF  BIOS. 		       :
  8460                              <1> ;									       :
  8461                              <1> ;------------------------------------------------------------------------------:
  8462                              <1> ;									       :
  8463                              <1> ; INPUT  (AH)= HEX COMMAND VALUE					       :
  8464                              <1> ;									       :
  8465                              <1> ;	(AH)= 00H  RESET DISK (DL = 80H,81H) / DISKETTE 		       :
  8466                              <1> ;	(AH)= 01H  READ THE STATUS OF THE LAST DISK OPERATION INTO (AL)        :
  8467                              <1> ;		    NOTE: DL < 80H - DISKETTE				       :
  8468                              <1> ;			  DL > 80H - DISK				       :
  8469                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY 		       :
  8470                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY		       :
  8471                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS				       :
  8472                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK				       :
  8473                              <1> ;	(AH)= 06H  UNUSED						       :
  8474                              <1> ;	(AH)= 07H  UNUSED						       :
  8475                              <1> ;	(AH)= 08H  RETURN THE CURRENT DRIVE PARAMETERS			       :
  8476                              <1> ;	(AH)= 09H  INITIALIZE DRIVE PAIR CHARACTERISTICS		       :
  8477                              <1> ;		    INTERRUPT 41 POINTS TO DATA BLOCK FOR DRIVE 0	       :
  8478                              <1> ;		    INTERRUPT 46 POINTS TO DATA BLOCK FOR DRIVE 1	       :
  8479                              <1> ;	(AH)= 0AH  READ LONG						       :
  8480                              <1> ;	(AH)= 0BH  WRITE LONG  (READ & WRITE LONG ENCOMPASS 512 + 4 BYTES ECC) :
  8481                              <1> ;	(AH)= 0CH  SEEK 						       :
  8482                              <1> ;	(AH)= 0DH  ALTERNATE DISK RESET (SEE DL)			       :
  8483                              <1> ;	(AH)= 0EH  UNUSED						       :
  8484                              <1> ;	(AH)= 0FH  UNUSED						       :
  8485                              <1> ;	(AH)= 10H  TEST DRIVE READY					       :
  8486                              <1> ;	(AH)= 11H  RECALIBRATE						       :
  8487                              <1> ;	(AH)= 12H  UNUSED						       :
  8488                              <1> ;	(AH)= 13H  UNUSED						       :
  8489                              <1> ;	(AH)= 14H  CONTROLLER INTERNAL DIAGNOSTIC			       :
  8490                              <1> ;	(AH)= 15H  READ DASD TYPE					       :
  8491                              <1> ;									       :
  8492                              <1> ;-------------------------------------------------------------------------------
  8493                              <1> ;									       :
  8494                              <1> ;	REGISTERS USED FOR FIXED DISK OPERATIONS			       :
  8495                              <1> ;									       :
  8496                              <1> ;		(DL)	-  DRIVE NUMBER     (80H-81H FOR DISK. VALUE CHECKED)  :
  8497                              <1> ;		(DH)	-  HEAD NUMBER	    (0-15 ALLOWED, NOT VALUE CHECKED)  :
  8498                              <1> ;		(CH)	-  CYLINDER NUMBER  (0-1023, NOT VALUE CHECKED)(SEE CL):
  8499                              <1> ;		(CL)	-  SECTOR NUMBER    (1-17, NOT VALUE CHECKED)	       :
  8500                              <1> ;									       :
  8501                              <1> ;			   NOTE: HIGH 2 BITS OF CYLINDER NUMBER ARE PLACED     :
  8502                              <1> ;				 IN THE HIGH 2 BITS OF THE CL REGISTER	       :
  8503                              <1> ;				 (10 BITS TOTAL)			       :
  8504                              <1> ;									       :
  8505                              <1> ;		(AL)	-  NUMBER OF SECTORS (MAXIMUM POSSIBLE RANGE 1-80H,    :
  8506                              <1> ;					      FOR READ/WRITE LONG 1-79H)       :
  8507                              <1> ;									       :
  8508                              <1> ;		(ES:BX) -  ADDRESS OF BUFFER FOR READS AND WRITES,	       :
  8509                              <1> ;			   (NOT REQUIRED FOR VERIFY)			       :
  8510                              <1> ;									       :
  8511                              <1> ;		FORMAT (AH=5) ES:BX POINTS TO A 512 BYTE BUFFER. THE FIRST     :
  8512                              <1> ;			   2*(SECTORS/TRACK) BYTES CONTAIN F,N FOR EACH SECTOR.:
  8513                              <1> ;			   F = 00H FOR A GOOD SECTOR			       :
  8514                              <1> ;			       80H FOR A BAD SECTOR			       :
  8515                              <1> ;			   N = SECTOR NUMBER				       :
  8516                              <1> ;			   FOR AN INTERLEAVE OF 2 AND 17 SECTORS/TRACK	       :
  8517                              <1> ;			   THE TABLE SHOULD BE: 			       :
  8518                              <1> ;									       :
  8519                              <1> ;		   DB	   00H,01H,00H,0AH,00H,02H,00H,0BH,00H,03H,00H,0CH     :
  8520                              <1> ;		   DB	   00H,04H,00H,0DH,00H,05H,00H,0EH,00H,06H,00H,0FH     :
  8521                              <1> ;		   DB	   00H,07H,00H,10H,00H,08H,00H,11H,00H,09H	       :
  8522                              <1> ;									       :
  8523                              <1> ;-------------------------------------------------------------------------------
  8524                              <1> 
  8525                              <1> ;-------------------------------------------------------------------------------
  8526                              <1> ; OUTPUT								       :
  8527                              <1> ;	AH = STATUS OF CURRENT OPERATION				       :
  8528                              <1> ;	     STATUS BITS ARE DEFINED IN THE EQUATES BELOW		       :
  8529                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN)			       :
  8530                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)			       :
  8531                              <1> ;									       :
  8532                              <1> ;	NOTE:	ERROR 11H  INDICATES THAT THE DATA READ HAD A RECOVERABLE      :
  8533                              <1> ;		ERROR WHICH WAS CORRECTED BY THE ECC ALGORITHM.  THE DATA      :
  8534                              <1> ;		IS PROBABLY GOOD,   HOWEVER THE BIOS ROUTINE INDICATES AN      :
  8535                              <1> ;		ERROR TO ALLOW THE CONTROLLING PROGRAM A CHANCE TO DECIDE      :
  8536                              <1> ;		FOR ITSELF.  THE  ERROR  MAY  NOT  RECUR  IF  THE DATA IS      :
  8537                              <1> ;		REWRITTEN.						       :
  8538                              <1> ;									       :
  8539                              <1> ;	IF DRIVE PARAMETERS WERE REQUESTED (DL >= 80H), 		       :
  8540                              <1> ;	   INPUT:							       :
  8541                              <1> ;	     (DL) = DRIVE NUMBER					       :
  8542                              <1> ;	   OUTPUT:							       :
  8543                              <1> ;	     (DL) = NUMBER OF CONSECUTIVE ACKNOWLEDGING DRIVES ATTACHED (1-2)  :
  8544                              <1> ;		    (CONTROLLER CARD ZERO TALLY ONLY)			       :
  8545                              <1> ;	     (DH) = MAXIMUM USEABLE VALUE FOR HEAD NUMBER		       :
  8546                              <1> ;	     (CH) = MAXIMUM USEABLE VALUE FOR CYLINDER NUMBER		       :
  8547                              <1> ;	     (CL) = MAXIMUM USEABLE VALUE FOR SECTOR NUMBER		       :
  8548                              <1> ;		    AND CYLINDER NUMBER HIGH BITS			       :
  8549                              <1> ;									       :
  8550                              <1> ;	IF READ DASD TYPE WAS REQUESTED,				       :
  8551                              <1> ;									       :
  8552                              <1> ;	AH = 0 - NOT PRESENT						       :
  8553                              <1> ;	     1 - DISKETTE - NO CHANGE LINE AVAILABLE			       :
  8554                              <1> ;	     2 - DISKETTE - CHANGE LINE AVAILABLE			       :
  8555                              <1> ;	     3 - FIXED DISK						       :
  8556                              <1> ;									       :
  8557                              <1> ;	CX,DX = NUMBER OF 512 BYTE BLOCKS WHEN AH = 3			       :
  8558                              <1> ;									       :
  8559                              <1> ;	REGISTERS WILL BE PRESERVED EXCEPT WHEN THEY ARE USED TO RETURN        :
  8560                              <1> ;	INFORMATION.							       :
  8561                              <1> ;									       :
  8562                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISK CODE, THE APPROPRIATE        :
  8563                              <1> ;		ACTION IS TO RESET THE DISK, THEN RETRY THE OPERATION.	       :
  8564                              <1> ;									       :
  8565                              <1> ;-------------------------------------------------------------------------------
  8566                              <1> 
  8567                              <1> SENSE_FAIL	EQU	0FFH		; NOT IMPLEMENTED
  8568                              <1> NO_ERR		EQU	0E0H		; STATUS ERROR/ERROR REGISTER=0
  8569                              <1> WRITE_FAULT	EQU	0CCH		; WRITE FAULT ON SELECTED DRIVE
  8570                              <1> UNDEF_ERR	EQU	0BBH		; UNDEFINED ERROR OCCURRED
  8571                              <1> NOT_RDY 	EQU	0AAH		; DRIVE NOT READY
  8572                              <1> TIME_OUT	EQU	80H		; ATTACHMENT FAILED TO RESPOND
  8573                              <1> BAD_SEEK	EQU	40H		; SEEK OPERATION FAILED
  8574                              <1> BAD_CNTLR	EQU	20H		; CONTROLLER HAS FAILED
  8575                              <1> DATA_CORRECTED	EQU	11H		; ECC CORRECTED DATA ERROR
  8576                              <1> BAD_ECC 	EQU	10H		; BAD ECC ON DISK READ
  8577                              <1> BAD_TRACK	EQU	0BH		; NOT IMPLEMENTED
  8578                              <1> BAD_SECTOR	EQU	0AH		; BAD SECTOR FLAG DETECTED
  8579                              <1> ;DMA_BOUNDARY	EQU	09H		; DATA EXTENDS TOO FAR
  8580                              <1> INIT_FAIL	EQU	07H		; DRIVE PARAMETER ACTIVITY FAILED
  8581                              <1> BAD_RESET	EQU	05H		; RESET FAILED
  8582                              <1> ;RECORD_NOT_FND	EQU	04H		; REQUESTED SECTOR NOT FOUND
  8583                              <1> ;BAD_ADDR_MARK	EQU	02H		; ADDRESS MARK NOT FOUND
  8584                              <1> ;BAD_CMD 	EQU	01H		; BAD COMMAND PASSED TO DISK I/O
  8585                              <1> 
  8586                              <1> ;--------------------------------------------------------
  8587                              <1> ;							:
  8588                              <1> ; FIXED DISK PARAMETER TABLE				:
  8589                              <1> ;  -  THE TABLE IS COMPOSED OF A BLOCK DEFINED AS:	:
  8590                              <1> ;							:
  8591                              <1> ;  +0	(1 WORD) - MAXIMUM NUMBER OF CYLINDERS		:
  8592                              <1> ;  +2	(1 BYTE) - MAXIMUM NUMBER OF HEADS		:
  8593                              <1> ;  +3	(1 WORD) - NOT USED/SEE PC-XT			:
  8594                              <1> ;  +5	(1 WORD) - STARTING WRITE PRECOMPENSATION CYL	:
  8595                              <1> ;  +7	(1 BYTE) - MAXIMUM ECC DATA BURST LENGTH	:
  8596                              <1> ;  +8	(1 BYTE) - CONTROL BYTE 			:
  8597                              <1> ;		   BIT	  7 DISABLE RETRIES -OR-	:
  8598                              <1> ;		   BIT	  6 DISABLE RETRIES		:
  8599                              <1> ;		   BIT	  3 MORE THAN 8 HEADS		:
  8600                              <1> ;  +9	(3 BYTES)- NOT USED/SEE PC-XT			:
  8601                              <1> ; +12	(1 WORD) - LANDING ZONE 			:
  8602                              <1> ; +14	(1 BYTE) - NUMBER OF SECTORS/TRACK		:
  8603                              <1> ; +15	(1 BYTE) - RESERVED FOR FUTURE USE		:
  8604                              <1> ;							:
  8605                              <1> ;	 - TO DYNAMICALLY DEFINE A SET OF PARAMETERS	:
  8606                              <1> ;	   BUILD A TABLE FOR UP TO 15 TYPES AND PLACE	:
  8607                              <1> ;	   THE CORRESPONDING VECTOR INTO INTERRUPT 41	:
  8608                              <1> ;	   FOR DRIVE 0 AND INTERRUPT 46 FOR DRIVE 1.	:
  8609                              <1> ;							:
  8610                              <1> ;--------------------------------------------------------
  8611                              <1> 
  8612                              <1> ;--------------------------------------------------------
  8613                              <1> ;							:
  8614                              <1> ; HARDWARE SPECIFIC VALUES				:
  8615                              <1> ;							:
  8616                              <1> ;  -  CONTROLLER I/O PORT				:
  8617                              <1> ;							:
  8618                              <1> ;     > WHEN READ FROM: 				:
  8619                              <1> ;	HF_PORT+0 - READ DATA (FROM CONTROLLER TO CPU)	:
  8620                              <1> ;	HF_PORT+1 - GET ERROR REGISTER			:
  8621                              <1> ;	HF_PORT+2 - GET SECTOR COUNT			:
  8622                              <1> ;	HF_PORT+3 - GET SECTOR NUMBER			:
  8623                              <1> ;	HF_PORT+4 - GET CYLINDER LOW			:
  8624                              <1> ;	HF_PORT+5 - GET CYLINDER HIGH (2 BITS)		:
  8625                              <1> ;	HF_PORT+6 - GET SIZE/DRIVE/HEAD 		:
  8626                              <1> ;	HF_PORT+7 - GET STATUS REGISTER 		:
  8627                              <1> ;							:
  8628                              <1> ;     > WHEN WRITTEN TO:				:
  8629                              <1> ;	HF_PORT+0 - WRITE DATA (FROM CPU TO CONTROLLER) :
  8630                              <1> ;	HF_PORT+1 - SET PRECOMPENSATION CYLINDER	:
  8631                              <1> ;	HF_PORT+2 - SET SECTOR COUNT			:
  8632                              <1> ;	HF_PORT+3 - SET SECTOR NUMBER			:
  8633                              <1> ;	HF_PORT+4 - SET CYLINDER LOW			:
  8634                              <1> ;	HF_PORT+5 - SET CYLINDER HIGH (2 BITS)		:
  8635                              <1> ;	HF_PORT+6 - SET SIZE/DRIVE/HEAD 		:
  8636                              <1> ;	HF_PORT+7 - SET COMMAND REGISTER		:
  8637                              <1> ;							:
  8638                              <1> ;--------------------------------------------------------
  8639                              <1> 
  8640                              <1> ;HF_PORT 	EQU	01F0H	; DISK PORT
  8641                              <1> ;HF1_PORT	equ	0170h	
  8642                              <1> ;HF_REG_PORT	EQU	03F6H
  8643                              <1> ;HF1_REG_PORT	equ	0376h
  8644                              <1> 
  8645                              <1> HDC1_BASEPORT	equ	1F0h
  8646                              <1> HDC2_BASEPORT	equ	170h		
  8647                              <1> 
  8648 000028D3 90                  <1> align 2
  8649                              <1> 
  8650                              <1> ;-----		STATUS REGISTER
  8651                              <1> 
  8652                              <1> ST_ERROR	EQU	00000001B	;
  8653                              <1> ST_INDEX	EQU	00000010B	;
  8654                              <1> ST_CORRCTD	EQU	00000100B	; ECC CORRECTION SUCCESSFUL
  8655                              <1> ST_DRQ		EQU	00001000B	;
  8656                              <1> ST_SEEK_COMPL	EQU	00010000B	; SEEK COMPLETE
  8657                              <1> ST_WRT_FLT	EQU	00100000B	; WRITE FAULT
  8658                              <1> ST_READY	EQU	01000000B	;
  8659                              <1> ST_BUSY 	EQU	10000000B	;
  8660                              <1> 
  8661                              <1> ;-----		ERROR REGISTER
  8662                              <1> 
  8663                              <1> ERR_DAM 	EQU	00000001B	; DATA ADDRESS MARK NOT FOUND
  8664                              <1> ERR_TRK_0	EQU	00000010B	; TRACK 0 NOT FOUND ON RECAL
  8665                              <1> ERR_ABORT	EQU	00000100B	; ABORTED COMMAND
  8666                              <1> ;		EQU	00001000B	; NOT USED
  8667                              <1> ERR_ID		EQU	00010000B	; ID NOT FOUND
  8668                              <1> ;		EQU	00100000B	; NOT USED
  8669                              <1> ERR_DATA_ECC	EQU	01000000B
  8670                              <1> ERR_BAD_BLOCK	EQU	10000000B
  8671                              <1> 
  8672                              <1> 
  8673                              <1> RECAL_CMD	EQU	00010000B	; DRIVE RECAL	(10H)
  8674                              <1> READ_CMD	EQU	00100000B	;	READ	(20H)
  8675                              <1> WRITE_CMD	EQU	00110000B	;	WRITE	(30H)
  8676                              <1> VERIFY_CMD	EQU	01000000B	;	VERIFY	(40H)
  8677                              <1> FMTTRK_CMD	EQU	01010000B	; FORMAT TRACK	(50H)
  8678                              <1> INIT_CMD	EQU	01100000B	;   INITIALIZE	(60H)
  8679                              <1> SEEK_CMD	EQU	01110000B	;	SEEK	(70H)
  8680                              <1> DIAG_CMD	EQU	10010000B	; DIAGNOSTIC	(90H)
  8681                              <1> SET_PARM_CMD	EQU	10010001B	; DRIVE PARMS	(91H)
  8682                              <1> NO_RETRIES	EQU	00000001B	; CHD MODIFIER	(01H)
  8683                              <1> ECC_MODE	EQU	00000010B	; CMD MODIFIER	(02H)
  8684                              <1> BUFFER_MODE	EQU	00001000B	; CMD MODIFIER	(08H)
  8685                              <1> 
  8686                              <1> ;MAX_FILE	EQU	2
  8687                              <1> ;S_MAX_FILE	EQU	2
  8688                              <1> MAX_FILE	equ	4		; 22/12/2014
  8689                              <1> S_MAX_FILE	equ	4		; 22/12/2014
  8690                              <1> 
  8691                              <1> DELAY_1 	EQU	25H		; DELAY FOR OPERATION COMPLETE
  8692                              <1> DELAY_2 	EQU	0600H		; DELAY FOR READY
  8693                              <1> DELAY_3 	EQU	0100H		; DELAY FOR DATA REQUEST
  8694                              <1> 
  8695                              <1> HF_FAIL 	EQU	08H		; CMOS FLAG IN BYTE 0EH
  8696                              <1> 
  8697                              <1> ;-----		COMMAND BLOCK REFERENCE
  8698                              <1> 
  8699                              <1> ;CMD_BLOCK      EQU     BP-8            ; @CMD_BLOCK REFERENCES BLOCK HEAD IN SS
  8700                              <1> 					;  (BP) POINTS TO COMMAND BLOCK TAIL
  8701                              <1> 					;	AS DEFINED BY THE "ENTER" PARMS
  8702                              <1> ; 19/12/2014
  8703                              <1> ORG_VECTOR	equ	4*13h		; INT 13h vector
  8704                              <1> DISK_VECTOR	equ	4*40h		; INT 40h vector (for floppy disks)
  8705                              <1> ;HDISK_INT	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  8706                              <1> ;HDISK_INT1	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  8707                              <1> ;HDISK_INT2	equ	4*77h		; Secondary HDC - Hardware interrupt (IRQ15)
  8708                              <1> ;HF_TBL_VEC	equ	4*41h		; Pointer to 1st fixed disk parameter table
  8709                              <1> ;HF1_TBL_VEC	equ	4*46h		; Pointer to 2nd fixed disk parameter table
  8710                              <1> 
  8711                              <1> align 2
  8712                              <1> 
  8713                              <1> ;----------------------------------------------------------------
  8714                              <1> ; FIXED DISK I/O SETUP						:
  8715                              <1> ;								:
  8716                              <1> ;  -  ESTABLISH TRANSFER VECTORS FOR THE FIXED DISK		:
  8717                              <1> ;  -  PERFORM POWER ON DIAGNOSTICS				:
  8718                              <1> ;     SHOULD AN ERROR OCCUR A "1701" MESSAGE IS DISPLAYED       :
  8719                              <1> ;								:
  8720                              <1> ;----------------------------------------------------------------
  8721                              <1> 
  8722                              <1> DISK_SETUP:
  8723                              <1> 	;CLI
  8724                              <1> 	;;MOV	AX,ABS0 			; GET ABSOLUTE SEGMENT
  8725                              <1> 	;xor	ax,ax
  8726                              <1> 	;MOV	DS,AX				; SET SEGMENT REGISTER
  8727                              <1> 	;MOV	AX, [ORG_VECTOR] 		; GET DISKETTE VECTOR
  8728                              <1> 	;MOV	[DISK_VECTOR],AX		;  INTO INT 40H
  8729                              <1> 	;MOV	AX, [ORG_VECTOR+2]
  8730                              <1> 	;MOV	[DISK_VECTOR+2],AX
  8731                              <1> 	;MOV	word [ORG_VECTOR],DISK_IO	; FIXED DISK HANDLER
  8732                              <1> 	;MOV	[ORG_VECTOR+2],CS
  8733                              <1> 	; 1st controller (primary master, slave)   - IRQ 14
  8734                              <1> 	;;MOV	word [HDISK_INT],HD_INT		; FIXED DISK INTERRUPT
  8735                              <1> 	;mov	word [HDISK_INT1],HD_INT	;
  8736                              <1> 	;;MOV	[HDISK_INT+2],CS
  8737                              <1> 	;mov	[HDISK_INT1+2],CS
  8738                              <1> 	; 2nd controller (secondary master, slave) - IRQ 15
  8739                              <1> 	;mov	word [HDISK_INT2],HD1_INT	;
  8740                              <1> 	;mov	[HDISK_INT2+2],CS
  8741                              <1> 	;
  8742                              <1> 	;;MOV	word [HF_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80
  8743                              <1> 	;;MOV	word [HF_TBL_VEC+2],DPT_SEGM
  8744                              <1> 	;;MOV	word [HF1_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81
  8745                              <1> 	;;MOV	word [HF1_TBL_VEC+2],DPT_SEGM
  8746                              <1> 	;push	cs
  8747                              <1> 	;pop	ds
  8748                              <1> 	;mov	word [HDPM_TBL_VEC],HD0_DPT	; PARM TABLE DRIVE 80h
  8749                              <1> 	;mov	word [HDPM_TBL_VEC+2],DPT_SEGM
  8750 000028D4 C705[ECA20000]0000- <1> 	mov 	dword [HDPM_TBL_VEC], (DPT_SEGM*16)+HD0_DPT
  8751 000028DC 0900                <1>
  8752                              <1> 	;mov	word [HDPS_TBL_VEC],HD1_DPT	; PARM TABLE DRIVE 81h
  8753                              <1> 	;mov	word [HDPS_TBL_VEC+2],DPT_SEGM
  8754 000028DE C705[F0A20000]2000- <1> 	mov 	dword [HDPS_TBL_VEC], (DPT_SEGM*16)+HD1_DPT
  8755 000028E6 0900                <1>
  8756                              <1> 	;mov	word [HDSM_TBL_VEC],HD2_DPT	; PARM TABLE DRIVE 82h
  8757                              <1> 	;mov	word [HDSM_TBL_VEC+2],DPT_SEGM
  8758 000028E8 C705[F4A20000]4000- <1> 	mov 	dword [HDSM_TBL_VEC], (DPT_SEGM*16)+HD2_DPT
  8759 000028F0 0900                <1>
  8760                              <1> 	;mov	word [HDSS_TBL_VEC],HD3_DPT	; PARM TABLE DRIVE 83h
  8761                              <1> 	;mov	word [HDSS_TBL_VEC+2],DPT_SEGM
  8762 000028F2 C705[F8A20000]6000- <1> 	mov 	dword [HDSS_TBL_VEC], (DPT_SEGM*16)+HD3_DPT
  8763 000028FA 0900                <1>
  8764                              <1> 	;
  8765                              <1> 	;;IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  8766                              <1> 	;;;AND	AL,0BFH
  8767                              <1> 	;;and	al, 3Fh			; enable IRQ 14 and IRQ 15
  8768                              <1> 	;;;JMP	$+2
  8769                              <1> 	;;IODELAY
  8770                              <1> 	;;OUT	INTB01,AL
  8771                              <1> 	;;IODELAY
  8772                              <1> 	;;IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  8773                              <1> 	;;AND	AL,0FBH 		;  SECOND CHIP
  8774                              <1> 	;;;JMP	$+2
  8775                              <1> 	;;IODELAY
  8776                              <1> 	;;OUT	INTA01,AL
  8777                              <1> 	;
  8778                              <1> 	;STI
  8779                              <1> 	;;PUSH	DS			; MOVE ABS0 POINTER TO
  8780                              <1> 	;;POP	ES			; EXTRA SEGMENT POINTER
  8781                              <1> 	;;;CALL	DDS			; ESTABLISH DATA SEGMENT
  8782                              <1> 	;;MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  8783                              <1> 	;;MOV	byte [HF_NUM],0		; ZERO NUMBER OF FIXED DISKS
  8784                              <1> 	;;MOV	byte [CONTROL_BYTE],0
  8785                              <1> 	;;MOV	byte [PORT_OFF],0	; ZERO CARD OFFSET
  8786                              <1> 	; 20/12/2014 - private code by Erdogan Tan
  8787                              <1> 		      ; (out of original PC-AT, PC-XT BIOS code)
  8788                              <1> 	;mov	si, hd0_type
  8789 000028FC BE[209D0000]        <1> 	mov	esi, hd0_type
  8790                              <1> 	;mov	cx, 4
  8791 00002901 B904000000          <1> 	mov	ecx, 4
  8792                              <1> hde_l:
  8793 00002906 AC                  <1> 	lodsb
  8794 00002907 3C80                <1> 	cmp	al, 80h			; 8?h = existing
  8795 00002909 7206                <1> 	jb	short _L4
  8796 0000290B FE05[E8A20000]      <1> 	inc	byte [HF_NUM]		; + 1 hard (fixed) disk drives
  8797                              <1> _L4: ; 26/02/2015
  8798 00002911 E2F3                <1> 	loop	hde_l	
  8799                              <1> ;_L4:					; 0 <= [HF_NUM] =< 4
  8800                              <1> ;L4:
  8801                              <1> 	; 
  8802                              <1> 	;; 31/12/2014 - cancel controller diagnostics here
  8803                              <1> 	;;;mov 	cx, 3  ; 26/12/2014 (Award BIOS 1999)
  8804                              <1> 	;;mov 	cl, 3
  8805                              <1> 	;;
  8806                              <1> 	;;MOV	DL,80H			; CHECK THE CONTROLLER
  8807                              <1> ;;hdc_dl:
  8808                              <1> 	;;MOV	AH,14H			; USE CONTROLLER DIAGNOSTIC COMMAND
  8809                              <1> 	;;INT	13H			; CALL BIOS WITH DIAGNOSTIC COMMAND
  8810                              <1> 	;;;JC	short CTL_ERRX		; DISPLAY ERROR MESSAGE IF BAD RETURN
  8811                              <1> 	;;;jc	short POD_DONE ;22/12/2014
  8812                              <1> 	;;jnc	short hdc_reset0
  8813                              <1> 	;;loop	hdc_dl
  8814                              <1> 	;;; 27/12/2014
  8815                              <1> 	;;stc
  8816                              <1> 	;;retn
  8817                              <1> 	;
  8818                              <1> ;;hdc_reset0:
  8819                              <1> 	; 18/01/2015
  8820 00002913 8A0D[E8A20000]      <1> 	mov	cl, [HF_NUM]
  8821 00002919 20C9                <1> 	and	cl, cl
  8822 0000291B 740D                <1> 	jz	short POD_DONE
  8823                              <1> 	;
  8824 0000291D B27F                <1> 	mov	dl, 7Fh
  8825                              <1> hdc_reset1:
  8826 0000291F FEC2                <1> 	inc	dl
  8827                              <1> 	;; 31/12/2015
  8828                              <1> 	;;push	dx
  8829                              <1> 	;;push	cx
  8830                              <1> 	;;push	ds
  8831                              <1> 	;;sub	ax, ax
  8832                              <1> 	;;mov	ds, ax
  8833                              <1> 	;;MOV	AX, [TIMER_LOW]		; GET START TIMER COUNTS
  8834                              <1> 	;;pop	ds
  8835                              <1> 	;;MOV	BX,AX
  8836                              <1> 	;;ADD	AX,6*182		; 60 SECONDS* 18.2
  8837                              <1> 	;;MOV	CX,AX
  8838                              <1> 	;;mov	word [wait_count], 0	; 22/12/2014 (reset wait counter)
  8839                              <1> 	;;
  8840                              <1> 	;; 31/12/2014 - cancel HD_RESET_1
  8841                              <1> 	;;CALL	HD_RESET_1		; SET UP DRIVE 0, (1,2,3)
  8842                              <1> 	;;pop	cx
  8843                              <1> 	;;pop	dx
  8844                              <1> 	;;
  8845                              <1> 	; 18/01/2015
  8846 00002921 B40D                <1> 	mov	ah, 0Dh ; ALTERNATE RESET
  8847                              <1> 	;int	13h
  8848 00002923 E8A3FFFFFF          <1> 	call	int13h
  8849 00002928 E2F5                <1> 	loop	hdc_reset1
  8850                              <1> POD_DONE:
  8851 0000292A C3                  <1> 	RETn
  8852                              <1> 
  8853                              <1> ;;-----	POD_ERROR
  8854                              <1> 
  8855                              <1> ;;CTL_ERRX:
  8856                              <1> ;	;MOV	SI,OFFSET F1782 	; CONTROLLER ERROR
  8857                              <1> ;	;CALL	SET_FAIL		; DO NOT IPL FROM DISK
  8858                              <1> ;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  8859                              <1> ;	;JMP	short POD_DONE
  8860                              <1> 
  8861                              <1> ;;HD_RESET_1:
  8862                              <1> ;;	;PUSH	BX			; SAVE TIMER LIMITS
  8863                              <1> ;;	;PUSH	CX
  8864                              <1> ;;RES_1: MOV	AH,09H			; SET DRIVE PARAMETERS
  8865                              <1> ;;	INT	13H
  8866                              <1> ;;	JC	short RES_2
  8867                              <1> ;;	MOV	AH,11H			; RECALIBRATE DRIVE
  8868                              <1> ;;	INT	13H
  8869                              <1> ;;	JNC	short RES_CK		; DRIVE OK
  8870                              <1> ;;RES_2: ;CALL	POD_TCHK		; CHECK TIME OUT
  8871                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  8872                              <1> ;;					; (30 seconds)		
  8873                              <1> ;;	;cmc
  8874                              <1> ;;	;JNC	short RES_1
  8875                              <1> ;;	jb	short RES_1
  8876                              <1> ;;;RES_FL: ;MOV	SI,OFFSET F1781 	; INDICATE DISK 1 FAILURE;
  8877                              <1> ;;	;TEST	DL,1
  8878                              <1> ;;	;JNZ	RES_E1
  8879                              <1> ;;	;MOV	SI,OFFSET F1780 	; INDICATE DISK 0 FAILURE
  8880                              <1> ;;	;CALL	SET_FAIL		; DO NOT TRY TO IPL DISK 0
  8881                              <1> ;;	;JMP	SHORT RES_E1
  8882                              <1> ;;RES_ER: ; 22/12/2014
  8883                              <1> ;;RES_OK:
  8884                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  8885                              <1> ;;	;POP	BX
  8886                              <1> ;;	RETn
  8887                              <1> ;;
  8888                              <1> ;;RES_RS: MOV	AH,00H			; RESET THE DRIVE
  8889                              <1> ;;	INT	13H
  8890                              <1> ;;RES_CK: MOV	AH,08H			; GET MAX CYLINDER,HEAD,SECTOR
  8891                              <1> ;;	MOV	BL,DL			; SAVE DRIVE CODE
  8892                              <1> ;;	INT	13H
  8893                              <1> ;;	JC	short RES_ER
  8894                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE MAX CYLINDER, SECTOR
  8895                              <1> ;;	MOV	DL,BL			; RESTORE DRIVE CODE
  8896                              <1> ;;RES_3: MOV	AX,0401H		; VERIFY THE LAST SECTOR
  8897                              <1> ;;	INT	13H
  8898                              <1> ;;	JNC	short RES_OK		; VERIFY OK
  8899                              <1> ;;	CMP	AH,BAD_SECTOR		; OK ALSO IF JUST ID READ
  8900                              <1> ;;	JE	short RES_OK
  8901                              <1> ;;	CMP	AH,DATA_CORRECTED
  8902                              <1> ;;	JE	short RES_OK
  8903                              <1> ;;	CMP	AH,BAD_ECC
  8904                              <1> ;;	JE	short RES_OK
  8905                              <1> ;;	;CALL	POD_TCHK		; CHECK FOR TIME OUT
  8906                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  8907                              <1> ;;					; (60 seconds)		
  8908                              <1> ;;	cmc
  8909                              <1> ;;	JC	short RES_ER		; FAILED
  8910                              <1> ;;	MOV	CX,[NEC_STATUS] 	; GET SECTOR ADDRESS, AND CYLINDER
  8911                              <1> ;;	MOV	AL,CL			; SEPARATE OUT SECTOR NUMBER
  8912                              <1> ;;	AND	AL,3FH
  8913                              <1> ;;	DEC	AL			; TRY PREVIOUS ONE
  8914                              <1> ;;	JZ	short RES_RS		; WE'VE TRIED ALL SECTORS ON TRACK
  8915                              <1> ;;	AND	CL,0C0H 		; KEEP CYLINDER BITS
  8916                              <1> ;;	OR	CL,AL			; MERGE SECTOR WITH CYLINDER BITS
  8917                              <1> ;;	MOV	[NEC_STATUS],CX 	; SAVE CYLINDER, NEW SECTOR NUMBER
  8918                              <1> ;;	JMP	short RES_3		; TRY AGAIN
  8919                              <1> ;;;RES_ER: MOV	SI,OFFSET F1791 	; INDICATE DISK 1 ERROR
  8920                              <1> ;;	;TEST	DL,1
  8921                              <1> ;;	;JNZ	short RES_E1
  8922                              <1> ;;	;MOV	SI,OFFSET F1790 	; INDICATE DISK 0 ERROR
  8923                              <1> ;;;RES_E1:
  8924                              <1> ;;	;CALL	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  8925                              <1> ;;;RES_OK:
  8926                              <1> ;;	;POP	CX			; RESTORE TIMER LIMITS
  8927                              <1> ;;	;POP	BX
  8928                              <1> ;;	;RETn
  8929                              <1> ;
  8930                              <1> ;;SET_FAIL:
  8931                              <1> ;	;MOV	AX,X*(CMOS_DIAG+NMI)	; GET CMOS ERROR BYTE
  8932                              <1> ;	;CALL	CMOS_READ
  8933                              <1> ;	;OR	AL,HF_FAIL		; SET DO NOT IPL FROM DISK FLAG
  8934                              <1> ;	;XCHG	AH,AL			; SAVE IT
  8935                              <1> ;	;CALL	CMOS_WRITE		; PUT IT OUT
  8936                              <1> ;	;RETn
  8937                              <1> ;
  8938                              <1> ;;POD_TCHK:				; CHECK FOR 30 SECOND TIME OUT
  8939                              <1> ;	;POP	AX			; SAVE RETURN
  8940                              <1> ;	;POP	CX			; GET TIME OUT LIMITS
  8941                              <1> ;	;POP	BX
  8942                              <1> ;	;PUSH	BX			; AND SAVE THEM AGAIN
  8943                              <1> ;	;PUSH	CX
  8944                              <1> ;	;PUSH	AX
  8945                              <1> ;	;push	ds
  8946                              <1> ;	;xor	ax, ax
  8947                              <1> ;	;mov	ds, ax			; RESTORE RETURN
  8948                              <1> ;	;MOV	AX, [TIMER_LOW]		; AX = CURRENT TIME
  8949                              <1> ;	;				; BX = START TIME
  8950                              <1> ;	;				; CX = END TIME
  8951                              <1> ;	;pop	ds
  8952                              <1> ;	;CMP	BX,CX
  8953                              <1> ;	;JB	short TCHK1		; START < END
  8954                              <1> ;	;CMP	BX,AX
  8955                              <1> ;	;JB	short TCHKG		; END < START < CURRENT
  8956                              <1> ;	;JMP	SHORT TCHK2		; END, CURRENT < START
  8957                              <1> ;;TCHK1: CMP	AX,BX
  8958                              <1> ;;	JB	short TCHKNG		; CURRENT < START < END
  8959                              <1> ;;TCHK2: CMP	AX,CX
  8960                              <1> ;;	JB	short TCHKG		; START < CURRENT < END
  8961                              <1> ;;					; OR CURRENT < END < START
  8962                              <1> ;;TCHKNG: STC				; CARRY SET INDICATES TIME OUT
  8963                              <1> ;;	RETn
  8964                              <1> ;;TCHKG: CLC				; INDICATE STILL TIME
  8965                              <1> ;;	RETn
  8966                              <1> ;;
  8967                              <1> ;;int_13h:
  8968                              <1> 
  8969                              <1> ;----------------------------------------
  8970                              <1> ;	FIXED DISK BIOS ENTRY POINT	:
  8971                              <1> ;----------------------------------------
  8972                              <1> 
  8973                              <1> DISK_IO:
  8974 0000292B 80FA80              <1> 	CMP	DL,80H			; TEST FOR FIXED DISK DRIVE
  8975                              <1> 	;JAE	short A1		; YES, HANDLE HERE
  8976                              <1> 	;;;INT	40H			; DISKETTE HANDLER
  8977                              <1> 	;;call	int40h
  8978 0000292E 0F8224F1FFFF        <1> 	jb	DISKETTE_IO_1
  8979                              <1> ;RET_2:
  8980                              <1> 	;RETf	2			; BACK TO CALLER
  8981                              <1> ;	retf	4
  8982                              <1> A1:
  8983 00002934 FB                  <1> 	STI				; ENABLE INTERRUPTS
  8984                              <1> 	;; 04/01/2015
  8985                              <1> 	;;OR	AH,AH
  8986                              <1> 	;;JNZ	short A2
  8987                              <1> 	;;INT	40H			; RESET NEC WHEN AH=0
  8988                              <1> 	;;SUB	AH,AH
  8989 00002935 80FA83              <1> 	CMP	DL,(80H + S_MAX_FILE - 1)
  8990 00002938 772C                <1> 	JA	short RET_2
  8991                              <1> 	; 18/01/2015
  8992 0000293A 08E4                <1> 	or	ah,ah
  8993 0000293C 742B                <1> 	jz	short A4
  8994 0000293E 80FC0D              <1> 	cmp	ah, 0Dh	; Alternate reset
  8995 00002941 7504                <1> 	jne	short A2
  8996 00002943 28E4                <1> 	sub	ah,ah	; Reset
  8997 00002945 EB22                <1> 	jmp	short A4
  8998                              <1> A2:
  8999 00002947 80FC08              <1> 	CMP	AH,08H			; GET PARAMETERS IS A SPECIAL CASE
  9000                              <1> 	;JNZ	short A3
  9001                              <1>         ;JMP    GET_PARM_N
  9002 0000294A 0F841C030000        <1> 	je	GET_PARM_N
  9003 00002950 80FC15              <1> A3:	CMP	AH,15H			; READ DASD TYPE IS ALSO
  9004                              <1> 	;JNZ	short A4
  9005                              <1>         ;JMP    READ_DASD_TYPE
  9006 00002953 0F84C7020000        <1>         je      READ_DASD_TYPE
  9007                              <1> 	; 02/02/2015
  9008 00002959 80FC1D              <1> 	cmp	ah, 1Dh			;(Temporary for Retro UNIX 386 v1)
  9009                              <1> 	; 12/01/2015
  9010 0000295C F5                  <1> 	cmc
  9011 0000295D 730A                <1> 	jnc	short A4
  9012                              <1> 	; 30/01/2015
  9013                              <1> 	;mov     byte [CS:DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  9014 0000295F C605[E7A20000]01    <1>         mov     byte [DISK_STATUS1], BAD_CMD
  9015                              <1> 	;jmp	short RET_2
  9016                              <1> RET_2:
  9017 00002966 CA0400              <1> 	retf	4
  9018                              <1> A4:					; SAVE REGISTERS DURING OPERATION
  9019 00002969 C8080000            <1> 	ENTER	8,0			; SAVE (BP) AND MAKE ROOM FOR @CMD_BLOCK
  9020 0000296D 53                  <1> 	PUSH	eBX			;  IN THE STACK, THE COMMAND BLOCK IS:
  9021 0000296E 51                  <1> 	PUSH	eCX			;   @CMD_BLOCK == BYTE PTR [BP]-8
  9022 0000296F 52                  <1> 	PUSH	eDX
  9023 00002970 1E                  <1> 	PUSH	DS
  9024 00002971 06                  <1> 	PUSH	ES
  9025 00002972 56                  <1> 	PUSH	eSI
  9026 00002973 57                  <1> 	PUSH	eDI
  9027                              <1> 	;;04/01/2015
  9028                              <1> 	;;OR	AH,AH			; CHECK FOR RESET
  9029                              <1> 	;;JNZ	short A5
  9030                              <1> 	;;MOV	DL,80H			; FORCE DRIVE 80 FOR RESET
  9031                              <1> ;;A5:	
  9032                              <1> 	;push	cs
  9033                              <1> 	;pop	ds
  9034                              <1> 	; 21/02/2015
  9035 00002974 6650                <1> 	push	ax
  9036 00002976 66B81000            <1> 	mov	ax, KDATA
  9037 0000297A 8ED8                <1> 	mov	ds, ax
  9038 0000297C 8EC0                <1> 	mov	es, ax	
  9039 0000297E 6658                <1> 	pop	ax
  9040 00002980 E889000000          <1> 	CALL	DISK_IO_CONT		; PERFORM THE OPERATION
  9041                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  9042 00002985 8A25[E7A20000]      <1> 	MOV	AH,[DISK_STATUS1]	; GET STATUS FROM OPERATION
  9043 0000298B 80FC01              <1> 	CMP	AH,1			; SET THE CARRY FLAG TO INDICATE
  9044 0000298E F5                  <1> 	CMC				; SUCCESS OR FAILURE
  9045 0000298F 5F                  <1> 	POP	eDI			; RESTORE REGISTERS
  9046 00002990 5E                  <1> 	POP	eSI
  9047 00002991 07                  <1>         POP     ES
  9048 00002992 1F                  <1>         POP     DS
  9049 00002993 5A                  <1> 	POP	eDX
  9050 00002994 59                  <1> 	POP	eCX
  9051 00002995 5B                  <1> 	POP	eBX
  9052 00002996 C9                  <1> 	LEAVE				; ADJUST (SP) AND RESTORE (BP)
  9053                              <1> 	;RETf	2			; THROW AWAY SAVED FLAGS
  9054 00002997 CA0400              <1> 	retf	4
  9055                              <1> 
  9056                              <1> ; 21/02/2015
  9057                              <1> ;       dw --> dd
  9058                              <1> D1:					; FUNCTION TRANSFER TABLE
  9059 0000299A [5C2B0000]          <1> 	dd	DISK_RESET		; 000H
  9060 0000299E [D32B0000]          <1> 	dd	RETURN_STATUS		; 001H
  9061 000029A2 [E02B0000]          <1> 	dd	DISK_READ		; 002H
  9062 000029A6 [E92B0000]          <1> 	dd	DISK_WRITE		; 003H
  9063 000029AA [F22B0000]          <1> 	dd	DISK_VERF		; 004H
  9064 000029AE [0A2C0000]          <1> 	dd	FMT_TRK 		; 005H
  9065 000029B2 [522B0000]          <1> 	dd	BAD_COMMAND		; 006H	FORMAT BAD SECTORS
  9066 000029B6 [522B0000]          <1> 	dd	BAD_COMMAND		; 007H	FORMAT DRIVE
  9067 000029BA [522B0000]          <1> 	dd	BAD_COMMAND		; 008H	RETURN PARAMETERS
  9068 000029BE [D12C0000]          <1> 	dd	INIT_DRV		; 009H
  9069 000029C2 [302D0000]          <1> 	dd	RD_LONG 		; 00AH
  9070 000029C6 [392D0000]          <1> 	dd	WR_LONG 		; 00BH
  9071 000029CA [422D0000]          <1> 	dd	DISK_SEEK		; 00CH
  9072 000029CE [5C2B0000]          <1> 	dd	DISK_RESET		; 00DH
  9073 000029D2 [522B0000]          <1> 	dd	BAD_COMMAND		; 00EH	READ BUFFER
  9074 000029D6 [522B0000]          <1> 	dd	BAD_COMMAND		; 00FH	WRITE BUFFER
  9075 000029DA [6A2D0000]          <1> 	dd	TST_RDY 		; 010H
  9076 000029DE [8E2D0000]          <1> 	dd	HDISK_RECAL		; 011H
  9077 000029E2 [522B0000]          <1> 	dd	BAD_COMMAND		; 012H	MEMORY DIAGNOSTIC
  9078 000029E6 [522B0000]          <1> 	dd	BAD_COMMAND		; 013H	DRIVE DIAGNOSTIC
  9079 000029EA [C42D0000]          <1> 	dd	CTLR_DIAGNOSTIC 	; 014H	CONTROLLER DIAGNOSTIC
  9080                              <1> 	; 02/02/2015 (Temporary - Retro UNIX 386 v1 - DISK I/O test)
  9081 000029EE [522B0000]          <1> 	dd	BAD_COMMAND		; 015h
  9082 000029F2 [522B0000]          <1> 	dd	BAD_COMMAND		; 016h
  9083 000029F6 [522B0000]          <1> 	dd	BAD_COMMAND		; 017h
  9084 000029FA [522B0000]          <1> 	dd	BAD_COMMAND		; 018h
  9085 000029FE [522B0000]          <1> 	dd	BAD_COMMAND		; 019h
  9086 00002A02 [522B0000]          <1> 	dd	BAD_COMMAND		; 01Ah
  9087 00002A06 [E02B0000]          <1> 	dd	DISK_READ		; 01Bh ; LBA read
  9088 00002A0A [E92B0000]          <1> 	dd	DISK_WRITE		; 01Ch ; LBA write
  9089                              <1> D1L     EQU    $ - D1
  9090                              <1> 
  9091                              <1> DISK_IO_CONT:
  9092                              <1> 	;;CALL	DDS			; ESTABLISH SEGMENT
  9093 00002A0E 80FC01              <1> 	CMP	AH,01H			; RETURN STATUS
  9094                              <1> 	;;JNZ	short SU0
  9095                              <1>         ;;JMP    RETURN_STATUS
  9096 00002A11 0F84BC010000        <1> 	je	RETURN_STATUS
  9097                              <1> SU0:
  9098 00002A17 C605[E7A20000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; RESET THE STATUS INDICATOR
  9099                              <1> 	;;PUSH	BX			; SAVE DATA ADDRESS
  9100                              <1> 	;mov	si, bx ;; 14/02/2015
  9101 00002A1E 89DE                <1> 	mov	esi, ebx ; 21/02/2015
  9102 00002A20 8A1D[E8A20000]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  9103                              <1> 	;; 04/01/2015
  9104                              <1> 	;;PUSH	AX
  9105 00002A26 80E27F              <1> 	AND	DL,7FH			; GET DRIVE AS 0 OR 1
  9106                              <1> 					; (get drive number as 0 to 3)
  9107 00002A29 38D3                <1> 	CMP	BL,DL
  9108                              <1>         ;;JBE   BAD_COMMAND_POP         ; INVALID DRIVE
  9109 00002A2B 0F8621010000        <1>         jbe     BAD_COMMAND ;; 14/02/2015
  9110                              <1>         ;
  9111                              <1> 	;;03/01/2015
  9112 00002A31 29DB                <1> 	sub	ebx, ebx
  9113 00002A33 88D3                <1> 	mov	bl, dl
  9114                              <1> 	;sub	bh, bh
  9115 00002A35 883D[FCA20000]      <1> 	mov	[LBAMode], bh 	; 0
  9116                              <1> 	;;test	byte [bx+hd0_type], 1	; LBA ready ?
  9117                              <1> 	;test	byte [ebx+hd0_type], 1
  9118                              <1> 	;jz	short su1		; no
  9119                              <1> 	;inc	byte [LBAMode]
  9120                              <1> ;su1:
  9121                              <1> 	; 21/02/2015 (32 bit modification)
  9122                              <1> 	;04/01/2015
  9123 00002A3B 6650                <1> 	push	ax ; ***
  9124                              <1> 	;PUSH	ES ; **
  9125 00002A3D 6652                <1> 	PUSH	DX ; *
  9126 00002A3F 6650                <1> 	push	ax
  9127 00002A41 E864060000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS
  9128                              <1> 	; 02/02/2015
  9129                              <1> 	;mov	ax, [ES:BX+16] ; I/O port base address (1F0h, 170h)
  9130 00002A46 668B4310            <1> 	mov	ax, [ebx+16]
  9131 00002A4A 66A3[149D0000]      <1> 	mov	[HF_PORT], ax
  9132                              <1> 	;mov	dx, [ES:BX+18] ; control port address (3F6h, 376h)
  9133 00002A50 668B5312            <1> 	mov	dx, [ebx+18]
  9134 00002A54 668915[169D0000]    <1> 	mov	[HF_REG_PORT], dx
  9135                              <1> 	;mov	al, [ES:BX+20] ; head register upper nibble (A0h,B0h,E0h,F0h)
  9136 00002A5B 8A4314              <1> 	mov	al, [ebx+20]
  9137                              <1> 	; 23/02/2015
  9138 00002A5E A840                <1> 	test	al, 40h	 ; LBA bit (bit 6)
  9139 00002A60 7406                <1> 	jz 	short su1
  9140 00002A62 FE05[FCA20000]      <1> 	inc	byte [LBAMode] ; 1 
  9141                              <1> su1: 	 
  9142 00002A68 C0E804              <1> 	shr 	al, 4
  9143 00002A6B 2401                <1> 	and	al, 1			
  9144 00002A6D A2[189D0000]        <1> 	mov	[hf_m_s], al 
  9145                              <1> 	;
  9146                              <1> 	; 03/01/2015
  9147                              <1> 	;MOV	AL,byte [ES:BX+8]	; GET CONTROL BYTE MODIFIER
  9148 00002A72 8A4308              <1> 	mov	al, [ebx+8]
  9149                              <1> 	;MOV	DX,[HF_REG_PORT]	; Device Control register	
  9150 00002A75 EE                  <1> 	OUT	DX,AL			; SET EXTRA HEAD OPTION
  9151                              <1> 					; Control Byte:  (= 08h, here)
  9152                              <1> 					; bit 0 - 0
  9153                              <1> 					; bit 1 - nIEN (1 = disable irq)
  9154                              <1> 					; bit 2 - SRST (software RESET)
  9155                              <1> 					; bit 3 - use extra heads (8 to 15)
  9156                              <1> 					;         -always set to 1-	
  9157                              <1> 					; (bits 3 to 7 are reserved
  9158                              <1> 					;          for ATA devices)
  9159 00002A76 8A25[E9A20000]      <1> 	MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  9160 00002A7C 80E4C0              <1> 	AND	AH,0C0H 		; CONTROL BYTE
  9161 00002A7F 08C4                <1> 	OR	AH,AL
  9162 00002A81 8825[E9A20000]      <1> 	MOV	[CONTROL_BYTE],AH	
  9163                              <1> 	; 04/01/2015
  9164 00002A87 6658                <1> 	pop	ax
  9165 00002A89 665A                <1> 	pop	dx ; * ;; 14/02/2015
  9166 00002A8B 20E4                <1> 	and	ah, ah	; Reset function ?
  9167 00002A8D 7507                <1> 	jnz	short su2
  9168                              <1> 	;;pop	dx ; * ;; 14/02/2015
  9169                              <1> 	;pop	es ; **
  9170 00002A8F 6658                <1> 	pop	ax ; ***
  9171                              <1> 	;;pop	bx
  9172 00002A91 E9C6000000          <1>         jmp     DISK_RESET
  9173                              <1> su2:
  9174 00002A96 803D[FCA20000]00    <1> 	cmp	byte [LBAMode], 0
  9175 00002A9D 7661                <1> 	jna	short su3
  9176                              <1> 	;
  9177                              <1> 	; 02/02/2015 (LBA read/write function calls)
  9178 00002A9F 80FC1B              <1> 	cmp	ah, 1Bh
  9179 00002AA2 720B                <1> 	jb	short lbarw1
  9180 00002AA4 80FC1C              <1> 	cmp	ah, 1Ch
  9181 00002AA7 775C                <1> 	ja 	short invldfnc
  9182                              <1> 	;;pop	dx ; * ; 14/02/2015
  9183                              <1> 	;mov	ax, cx ; Lower word of LBA address (bits 0-15)
  9184 00002AA9 89C8                <1> 	mov	eax, ecx ; LBA address (21/02/2015)
  9185                              <1> 	;; 14/02/2015
  9186 00002AAB 88D1                <1> 	mov	cl, dl ; 14/02/2015
  9187                              <1> 	;;mov	dx, bx
  9188                              <1> 	;mov	dx, si ; higher word of LBA address (bits 16-23)
  9189                              <1> 	;;mov	bx, di
  9190                              <1> 	;mov	si, di ; Buffer offset
  9191 00002AAD EB31                <1> 	jmp	short lbarw2
  9192                              <1> lbarw1:
  9193                              <1> 	; convert CHS to LBA
  9194                              <1> 	;
  9195                              <1> 	; LBA calculation - AWARD BIOS - 1999 - AHDSK.ASM
  9196                              <1> 	; LBA = "# of Heads" * Sectors/Track * Cylinder + Head * Sectors/Track
  9197                              <1> 	;	+ Sector - 1
  9198 00002AAF 6652                <1> 	push	dx ; * ;; 14/02/2015
  9199                              <1> 	;xor	dh, dh
  9200 00002AB1 31D2                <1> 	xor	edx, edx
  9201                              <1> 	;mov	dl, [ES:BX+14]	; sectors per track (logical)
  9202 00002AB3 8A530E              <1> 	mov	dl, [ebx+14]
  9203                              <1> 	;xor	ah, ah
  9204 00002AB6 31C0                <1> 	xor	eax, eax
  9205                              <1> 	;mov	al, [ES:BX+2]	; heads (logical) 	
  9206 00002AB8 8A4302              <1> 	mov	al, [ebx+2]
  9207 00002ABB FEC8                <1> 	dec	al
  9208 00002ABD 6640                <1> 	inc	ax		; 0 =  256
  9209 00002ABF 66F7E2              <1> 	mul 	dx
  9210                              <1> 		; AX = # of Heads" * Sectors/Track
  9211 00002AC2 6689CA              <1> 	mov	dx, cx
  9212                              <1> 	;and	cx, 3Fh	 ; sector  (1 to 63)
  9213 00002AC5 83E13F              <1> 	and	ecx, 3fh
  9214 00002AC8 86D6                <1> 	xchg	dl, dh
  9215 00002ACA C0EE06              <1> 	shr	dh, 6
  9216                              <1> 		; DX = cylinder (0 to 1023)
  9217                              <1> 	;mul 	dx
  9218                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder
  9219 00002ACD F7E2                <1> 	mul	edx
  9220 00002ACF FEC9                <1> 	dec	cl  ; sector - 1
  9221                              <1> 	;add	ax, cx
  9222                              <1> 	;adc	dx, 0
  9223                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder + Sector -1
  9224 00002AD1 01C8                <1> 	add	eax, ecx
  9225 00002AD3 6659                <1> 	pop	cx ; * ; ch = head, cl = drive number (zero based)
  9226                              <1> 	;push	dx
  9227                              <1> 	;push	ax
  9228 00002AD5 50                  <1> 	push	eax
  9229                              <1> 	;mov	al, [ES:BX+14]	; sectors per track (logical)	
  9230 00002AD6 8A430E              <1> 	mov	al, [ebx+14]
  9231 00002AD9 F6E5                <1> 	mul	ch
  9232                              <1> 		;  AX = Head * Sectors/Track
  9233 00002ADB 6699                <1>         cwd
  9234                              <1> 	;pop	dx
  9235 00002ADD 5A                  <1> 	pop	edx
  9236                              <1> 	;add	ax, dx
  9237                              <1> 	;pop	dx
  9238                              <1> 	;adc	dx, 0 ; add carry bit
  9239 00002ADE 01D0                <1> 	add	eax, edx
  9240                              <1> lbarw2:
  9241 00002AE0 29D2                <1> 	sub	edx, edx ; 21/02/2015
  9242 00002AE2 88CA                <1> 	mov	dl, cl ; 21/02/2015
  9243 00002AE4 C645F800            <1>         mov     byte [CMD_BLOCK], 0 ; Features Register
  9244                              <1> 				; NOTE: Features register (1F1h, 171h)
  9245                              <1> 				; is not used for ATA device R/W functions. 
  9246                              <1> 				; It is old/obsolete 'write precompensation'
  9247                              <1> 				; register and error register
  9248                              <1> 				; for old ATA/IDE devices.
  9249                              <1> 	; 18/01/2014
  9250                              <1> 	;mov	ch, [hf_m_s]	; Drive 0 (master) or 1 (slave)
  9251 00002AE8 8A0D[189D0000]      <1> 	mov	cl, [hf_m_s]
  9252                              <1> 	;shl	ch, 4		; bit 4 (drive bit)
  9253                              <1> 	;or	ch, 0E0h	; bit 5 = 1
  9254                              <1> 				; bit 6 = 1 = LBA mode
  9255                              <1> 				; bit 7 = 1
  9256 00002AEE 80C90E              <1> 	or	cl, 0Eh ; 1110b
  9257                              <1> 	;and	dh, 0Fh		; LBA byte 4 (bits 24 to 27)
  9258 00002AF1 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh
  9259 00002AF6 C1E11C              <1> 	shl	ecx, 28 ; 21/02/2015
  9260                              <1> 	;or	dh, ch
  9261 00002AF9 09C8                <1> 	or	eax, ecx	
  9262                              <1> 	;;mov	[CMD_BLOCK+2], al ; LBA byte 1 (bits 0 to 7)
  9263                              <1> 				  ; (Sector Number Register)
  9264                              <1> 	;;mov	[CMD_BLOCK+3], ah ; LBA byte 2 (bits 8 to 15)
  9265                              <1> 				  ; (Cylinder Low Register)
  9266                              <1> 	;mov	[CMD_BLOCK+2], ax ; LBA byte 1, 2
  9267                              <1> 	;mov	[CMD_BLOCK+4], dl ; LBA byte 3 (bits 16 to 23)
  9268                              <1> 				  ; (Cylinder High Register)
  9269                              <1> 	;;mov	[CMD_BLOCK+5], dh ; LBA byte 4 (bits 24 to 27)
  9270                              <1> 				  ; (Drive/Head Register)
  9271                              <1> 	
  9272                              <1> 	;mov	[CMD_BLOCK+4], dx ; LBA byte 4, LBA & DEV select bits
  9273 00002AFB 8945FA              <1> 	mov	[CMD_BLOCK+2], eax ; 21/02/2015
  9274                              <1> 	;14/02/2015
  9275                              <1> 	;mov	dl, cl ; Drive number (INIT_DRV)		
  9276 00002AFE EB38                <1> 	jmp	short su4
  9277                              <1> su3:
  9278                              <1> 	; 02/02/2015 
  9279                              <1> 	; (Temporary functions 1Bh & 1Ch are not valid for CHS mode) 
  9280 00002B00 80FC14              <1> 	cmp 	ah, 14h
  9281 00002B03 7604                <1> 	jna 	short chsfnc
  9282                              <1> invldfnc:
  9283                              <1>         ; 14/02/2015  
  9284                              <1> 	;pop	es ; **
  9285 00002B05 6658                <1>         pop     ax ; ***
  9286                              <1>         ;jmp     short BAD_COMMAND_POP
  9287 00002B07 EB49                <1>         jmp     short BAD_COMMAND
  9288                              <1> chsfnc:	
  9289                              <1> 	;MOV	AX,[ES:BX+5]		; GET WRITE PRE-COMPENSATION CYLINDER
  9290 00002B09 668B4305            <1> 	mov	ax, [ebx+5]
  9291 00002B0D 66C1E802            <1> 	SHR	AX,2
  9292 00002B11 8845F8              <1> 	MOV	[CMD_BLOCK],AL
  9293                              <1> 	;;MOV	AL,[ES:BX+8]		; GET CONTROL BYTE MODIFIER
  9294                              <1> 	;;PUSH	DX
  9295                              <1> 	;;MOV	DX,[HF_REG_PORT]
  9296                              <1> 	;;OUT	DX,AL			; SET EXTRA HEAD OPTION
  9297                              <1> 	;;POP	DX ; * 
  9298                              <1> 	;;POP	ES ; **
  9299                              <1> 	;;MOV	AH,[CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  9300                              <1> 	;;AND	AH,0C0H 		; CONTROL BYTE	
  9301                              <1> 	;;OR	AH,AL
  9302                              <1> 	;;MOV	[CONTROL_BYTE],AH
  9303                              <1> 	;
  9304 00002B14 88C8                <1> 	MOV	AL,CL			; GET SECTOR NUMBER
  9305 00002B16 243F                <1> 	AND	AL,3FH
  9306 00002B18 8845FA              <1> 	MOV	[CMD_BLOCK+2],AL
  9307 00002B1B 886DFB              <1> 	MOV	[CMD_BLOCK+3],CH 	; GET CYLINDER NUMBER
  9308 00002B1E 88C8                <1> 	MOV	AL,CL
  9309 00002B20 C0E806              <1> 	SHR	AL,6
  9310 00002B23 8845FC              <1> 	MOV	[CMD_BLOCK+4],AL 	; CYLINDER HIGH ORDER 2 BITS
  9311                              <1> 	;;05/01/2015
  9312                              <1> 	;;MOV	AL,DL			; DRIVE NUMBER
  9313 00002B26 A0[189D0000]        <1> 	mov	al, [hf_m_s]
  9314 00002B2B C0E004              <1> 	SHL	AL,4
  9315 00002B2E 80E60F              <1> 	AND	DH,0FH			; HEAD NUMBER
  9316 00002B31 08F0                <1> 	OR	AL,DH
  9317                              <1> 	;OR	AL,80H or 20H
  9318 00002B33 0CA0                <1> 	OR	AL,80h+20h		; ECC AND 512 BYTE SECTORS
  9319 00002B35 8845FD              <1> 	MOV	[CMD_BLOCK+5],AL 	; ECC/SIZE/DRIVE/HEAD
  9320                              <1> su4:
  9321                              <1> 	;POP	ES ; **
  9322                              <1>         ;; 14/02/2015
  9323                              <1>         ;;POP   AX
  9324                              <1>         ;;MOV   [CMD_BLOCK+1],AL        ; SECTOR COUNT
  9325                              <1>         ;;PUSH  AX
  9326                              <1>         ;;MOV   AL,AH                   ; GET INTO LOW BYTE
  9327                              <1>         ;;XOR   AH,AH                   ; ZERO HIGH BYTE
  9328                              <1>         ;;SAL   AX,1                    ; *2 FOR TABLE LOOKUP
  9329 00002B38 6658                <1>         pop     ax ; ***
  9330 00002B3A 8845F9              <1>         mov     [CMD_BLOCK+1], al
  9331 00002B3D 29DB                <1>         sub	ebx, ebx
  9332 00002B3F 88E3                <1> 	mov     bl, ah
  9333                              <1>         ;xor     bh, bh
  9334                              <1>         ;sal     bx, 1
  9335 00002B41 66C1E302            <1>         sal	bx, 2	; 32 bit offset (21/02/2015)
  9336                              <1> 	;;MOV   SI,AX                   ; PUT INTO SI FOR BRANCH
  9337                              <1>         ;;CMP   AX,D1L                  ; TEST WITHIN RANGE
  9338                              <1>         ;;JNB   short BAD_COMMAND_POP
  9339                              <1>         ;cmp     bx, D1L
  9340 00002B45 83FB74              <1> 	cmp	ebx, D1L
  9341 00002B48 7308                <1> 	jnb	short BAD_COMMAND
  9342                              <1>         ;xchg    bx, si
  9343 00002B4A 87DE                <1>         xchg	ebx, esi
  9344                              <1> 	;;;POP	AX			; RESTORE AX
  9345                              <1> 	;;;POP	BX			; AND DATA ADDRESS
  9346                              <1> 	
  9347                              <1> 	;;PUSH	CX
  9348                              <1> 	;;PUSH	AX			; ADJUST ES:BX
  9349                              <1> 	;MOV	CX,BX			; GET 3 HIGH ORDER NIBBLES OF BX
  9350                              <1> 	;SHR	CX,4
  9351                              <1> 	;MOV	AX,ES
  9352                              <1> 	;ADD	AX,CX
  9353                              <1> 	;MOV	ES,AX
  9354                              <1> 	;AND	BX,000FH		; ES:BX CHANGED TO ES:000X
  9355                              <1> 	;;POP	AX
  9356                              <1> 	;;POP	CX
  9357                              <1> 	;;JMP	word [CS:SI+D1]
  9358                              <1> 	;jmp	word [SI+D1]
  9359 00002B4C FFA6[9A290000]      <1> 	jmp	dword [esi+D1]
  9360                              <1> ;;BAD_COMMAND_POP:
  9361                              <1> ;;	POP	AX
  9362                              <1> ;;	POP	BX
  9363                              <1> BAD_COMMAND:
  9364 00002B52 C605[E7A20000]01    <1>         MOV     byte [DISK_STATUS1],BAD_CMD  ; COMMAND ERROR
  9365 00002B59 B000                <1> 	MOV	AL,0
  9366 00002B5B C3                  <1> 	RETn
  9367                              <1> 
  9368                              <1> ;----------------------------------------
  9369                              <1> ;	RESET THE DISK SYSTEM  (AH=00H) :
  9370                              <1> ;----------------------------------------
  9371                              <1> 
  9372                              <1> ; 18-1-2015 : one controller reset (not other one)
  9373                              <1> 
  9374                              <1> DISK_RESET:
  9375 00002B5C FA                  <1> 	CLI
  9376 00002B5D E4A1                <1> 	IN	AL,INTB01		; GET THE MASK REGISTER
  9377                              <1> 	;JMP	$+2
  9378                              <1> 	IODELAY
  9379 00002B5F EB00                <2>  jmp short $+2
  9380 00002B61 EB00                <2>  jmp short $+2
  9381                              <1> 	;AND	AL,0BFH 		; ENABLE FIXED DISK INTERRUPT
  9382 00002B63 243F                <1> 	and	al,3Fh			; 22/12/2014 (IRQ 14 & IRQ 15)
  9383 00002B65 E6A1                <1> 	OUT	INTB01,AL
  9384 00002B67 FB                  <1> 	STI				; START INTERRUPTS
  9385                              <1> 	; 14/02/2015
  9386 00002B68 6689D7              <1> 	mov	di, dx	
  9387                              <1> 	; 04/01/2015
  9388                              <1> 	;xor	di,di
  9389                              <1> drst0:
  9390 00002B6B B004                <1> 	MOV	AL,04H  ; bit 2 - SRST 
  9391                              <1> 	;MOV	DX,HF_REG_PORT
  9392 00002B6D 668B15[169D0000]    <1> 	MOV	DX,[HF_REG_PORT]
  9393 00002B74 EE                  <1> 	OUT	DX,AL			; RESET
  9394                              <1> ;	MOV	CX,10			; DELAY COUNT
  9395                              <1> ;DRD:	DEC	CX
  9396                              <1> ;	JNZ	short DRD		; WAIT 4.8 MICRO-SEC
  9397                              <1> 	;mov	cx,2			; wait for 30 micro seconds	
  9398 00002B75 B902000000          <1>         mov	ecx, 2 ; 21/02/2015
  9399 00002B7A E870EDFFFF          <1> 	call    WAITF                   ; (Award Bios 1999 - WAIT_REFRESH,
  9400                              <1>                                         ; 40 micro seconds)
  9401 00002B7F A0[E9A20000]        <1> 	mov	al,[CONTROL_BYTE]
  9402 00002B84 240F                <1> 	AND	AL,0FH			; SET HEAD OPTION
  9403 00002B86 EE                  <1> 	OUT	DX,AL			; TURN RESET OFF
  9404 00002B87 E814040000          <1> 	CALL	NOT_BUSY
  9405 00002B8C 7515                <1> 	JNZ	short DRERR		; TIME OUT ON RESET
  9406 00002B8E 668B15[149D0000]    <1> 	MOV	DX,[HF_PORT]
  9407 00002B95 FEC2                <1> 	inc	dl  ; HF_PORT+1
  9408                              <1> 	; 02/01/2015 - Award BIOS 1999 - AHDSK.ASM
  9409                              <1>         ;mov     cl, 10
  9410 00002B97 B90A000000          <1>         mov     ecx, 10 ; 21/02/2015 
  9411                              <1> drst1:
  9412 00002B9C EC                  <1> 	IN	AL,DX			; GET RESET STATUS
  9413 00002B9D 3C01                <1> 	CMP	AL,1
  9414                              <1> 	; 04/01/2015
  9415 00002B9F 740A                <1> 	jz	short drst2
  9416                              <1> 	;JNZ	short DRERR		; BAD RESET STATUS
  9417                              <1>         	; Drive/Head Register - bit 4
  9418 00002BA1 E2F9                <1> 	loop	drst1
  9419                              <1> DRERR:	
  9420 00002BA3 C605[E7A20000]05    <1> 	MOV	byte [DISK_STATUS1],BAD_RESET ; CARD FAILED
  9421 00002BAA C3                  <1> 	RETn
  9422                              <1> drst2:
  9423                              <1> 	; 14/02/2015
  9424 00002BAB 6689FA              <1> 	mov	dx,di
  9425                              <1> ;drst3:
  9426                              <1> ;	; 05/01/2015
  9427                              <1> ;	shl 	di,1
  9428                              <1> ;	; 04/01/2015
  9429                              <1> ;	mov	ax,[di+hd_cports]
  9430                              <1> ;	cmp	ax,[HF_REG_PORT]
  9431                              <1> ;	je	short drst4
  9432                              <1> ;	mov	[HF_REG_PORT], ax
  9433                              <1> ;	; 03/01/2015
  9434                              <1> ;	mov	ax,[di+hd_ports]
  9435                              <1> ;       mov     [HF_PORT], ax
  9436                              <1> ;	; 05/01/2014
  9437                              <1> ;	shr	di,1
  9438                              <1> ;	; 04/01/2015
  9439                              <1> ;	jmp	short drst0	; reset other controller
  9440                              <1> ;drst4:
  9441                              <1> ;	; 05/01/2015
  9442                              <1> ;	shr	di,1
  9443                              <1> ;	mov	al,[di+hd_dregs]
  9444                              <1> ;	and	al,10h ; bit 4 only
  9445                              <1> ;	shr	al,4 ; bit 4  -> bit 0
  9446                              <1> ;	mov	[hf_m_s], al ; (0 = master, 1 = slave)
  9447                              <1> 	;
  9448 00002BAE A0[189D0000]        <1> 	mov	al, [hf_m_s] ; 18/01/2015
  9449 00002BB3 A801                <1> 	test	al,1
  9450                              <1> ;	jnz	short drst6
  9451 00002BB5 7516                <1>         jnz     short drst4
  9452 00002BB7 8065FDEF            <1> 	AND     byte [CMD_BLOCK+5],0EFH ; SET TO DRIVE 0
  9453                              <1> ;drst5:
  9454                              <1> drst3:
  9455 00002BBB E811010000          <1> 	CALL	INIT_DRV		; SET MAX HEADS
  9456                              <1> 	;mov	dx,di
  9457 00002BC0 E8C9010000          <1> 	CALL	HDISK_RECAL		; RECAL TO RESET SEEK SPEED
  9458                              <1> 	; 04/01/2014
  9459                              <1> ;	inc	di
  9460                              <1> ;	mov	dx,di
  9461                              <1> ;	cmp	dl,[HF_NUM]
  9462                              <1> ;	jb	short drst3
  9463                              <1> ;DRE:
  9464 00002BC5 C605[E7A20000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; IGNORE ANY SET UP ERRORS
  9465 00002BCC C3                  <1> 	RETn
  9466                              <1> ;drst6:
  9467                              <1> drst4:		; Drive/Head Register - bit 4
  9468 00002BCD 804DFD10            <1> 	OR      byte [CMD_BLOCK+5],010H ; SET TO DRIVE 1     
  9469                              <1>         ;jmp    short drst5
  9470 00002BD1 EBE8                <1>         jmp     short drst3
  9471                              <1> 
  9472                              <1> ;----------------------------------------
  9473                              <1> ;	DISK STATUS ROUTINE  (AH = 01H) :
  9474                              <1> ;----------------------------------------
  9475                              <1> 
  9476                              <1> RETURN_STATUS:
  9477 00002BD3 A0[E7A20000]        <1> 	MOV	AL,[DISK_STATUS1]	; OBTAIN PREVIOUS STATUS
  9478 00002BD8 C605[E7A20000]00    <1>         MOV     byte [DISK_STATUS1],0   ; RESET STATUS
  9479 00002BDF C3                  <1> 	RETn
  9480                              <1> 
  9481                              <1> ;----------------------------------------
  9482                              <1> ;	DISK READ ROUTINE    (AH = 02H) :
  9483                              <1> ;----------------------------------------
  9484                              <1> 
  9485                              <1> DISK_READ:
  9486 00002BE0 C645FE20            <1> 	MOV	byte [CMD_BLOCK+6],READ_CMD
  9487 00002BE4 E930020000          <1>         JMP     COMMANDI
  9488                              <1> 
  9489                              <1> ;----------------------------------------
  9490                              <1> ;	DISK WRITE ROUTINE   (AH = 03H) :
  9491                              <1> ;----------------------------------------
  9492                              <1> 
  9493                              <1> DISK_WRITE:
  9494 00002BE9 C645FE30            <1> 	MOV	byte [CMD_BLOCK+6],WRITE_CMD
  9495 00002BED E982020000          <1>         JMP     COMMANDO
  9496                              <1> 
  9497                              <1> ;----------------------------------------
  9498                              <1> ;	DISK VERIFY	     (AH = 04H) :
  9499                              <1> ;----------------------------------------
  9500                              <1> 
  9501                              <1> DISK_VERF:
  9502 00002BF2 C645FE40            <1> 	MOV	byte [CMD_BLOCK+6],VERIFY_CMD
  9503 00002BF6 E8F0020000          <1> 	CALL	COMMAND
  9504 00002BFB 750C                <1> 	JNZ	short VERF_EXIT		; CONTROLLER STILL BUSY
  9505 00002BFD E862030000          <1> 	CALL	_WAIT			; (Original: CALL WAIT)	
  9506 00002C02 7505                <1> 	JNZ	short VERF_EXIT		; TIME OUT
  9507 00002C04 E8EF030000          <1> 	CALL	CHECK_STATUS
  9508                              <1> VERF_EXIT:
  9509 00002C09 C3                  <1> 	RETn
  9510                              <1> 
  9511                              <1> ;----------------------------------------
  9512                              <1> ;	FORMATTING	     (AH = 05H) :
  9513                              <1> ;----------------------------------------
  9514                              <1> 
  9515                              <1> FMT_TRK:				; FORMAT TRACK	(AH = 005H)
  9516 00002C0A C645FE50            <1> 	MOV	byte [CMD_BLOCK+6],FMTTRK_CMD
  9517                              <1> 	;PUSH	ES
  9518                              <1> 	;PUSH	BX
  9519 00002C0E 53                  <1> 	push	ebx
  9520 00002C0F E896040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETERS ADDRESS
  9521                              <1> 	;MOV	AL,[ES:BX+14]		; GET SECTORS/TRACK
  9522 00002C14 8A430E              <1> 	mov	al, [ebx+14]
  9523 00002C17 8845F9              <1> 	MOV	[CMD_BLOCK+1],AL 	; SET SECTOR COUNT IN COMMAND
  9524 00002C1A 5B                  <1> 	pop	ebx
  9525                              <1> 	;POP	BX
  9526                              <1> 	;POP	ES
  9527 00002C1B E95B020000          <1>         JMP     CMD_OF                  ; GO EXECUTE THE COMMAND
  9528                              <1> 
  9529                              <1> ;----------------------------------------
  9530                              <1> ;	READ DASD TYPE	     (AH = 15H) :
  9531                              <1> ;----------------------------------------
  9532                              <1> 
  9533                              <1> READ_DASD_TYPE:
  9534                              <1> READ_D_T:				; GET DRIVE PARAMETERS
  9535 00002C20 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  9536                              <1> 	;PUSH	ES
  9537 00002C21 53                  <1> 	PUSH	eBX
  9538                              <1> 	;CALL	DDS			; ESTABLISH ADDRESSING
  9539                              <1> 	;push	cs
  9540                              <1> 	;pop	ds
  9541 00002C22 66BB1000            <1>         mov	bx, KDATA
  9542 00002C26 8EDB                <1> 	mov	ds, bx
  9543                              <1> 	;mov	es, bx
  9544 00002C28 C605[E7A20000]00    <1> 	MOV     byte [DISK_STATUS1],0
  9545 00002C2F 8A1D[E8A20000]      <1> 	MOV	BL,[HF_NUM]		; GET NUMBER OF DRIVES
  9546 00002C35 80E27F              <1> 	AND	DL,7FH			; GET DRIVE NUMBER
  9547 00002C38 38D3                <1> 	CMP	BL,DL
  9548 00002C3A 7625                <1> 	JBE	short RDT_NOT_PRESENT 	; RETURN DRIVE NOT PRESENT
  9549 00002C3C E869040000          <1> 	CALL	GET_VEC 		; GET DISK PARAMETER ADDRESS
  9550                              <1> 	;MOV	AL,[ES:BX+2]		; HEADS
  9551 00002C41 8A4302              <1> 	mov	al, [ebx+2]
  9552                              <1> 	;MOV	CL,[ES:BX+14]
  9553 00002C44 8A4B0E              <1> 	mov	cl, [ebx+14]
  9554 00002C47 F6E9                <1> 	IMUL	CL			; * NUMBER OF SECTORS
  9555                              <1> 	;MOV	CX,[ES:BX]		; MAX NUMBER OF CYLINDERS
  9556 00002C49 668B0B              <1> 	mov	cx ,[ebx]
  9557                              <1> 	;
  9558                              <1> 	; 02/01/2015 
  9559                              <1> 	; ** leave the last cylinder as reserved for diagnostics **
  9560                              <1> 	; (Also in Award BIOS - 1999, AHDSK.ASM, FUN15 -> sub ax, 1)
  9561 00002C4C 6649                <1> 	DEC	CX			; LEAVE ONE FOR DIAGNOSTICS
  9562                              <1> 	;
  9563 00002C4E 66F7E9              <1> 	IMUL	CX			; NUMBER OF SECTORS
  9564 00002C51 6689D1              <1> 	MOV	CX,DX			; HIGH ORDER HALF
  9565 00002C54 6689C2              <1> 	MOV	DX,AX			; LOW ORDER HALF
  9566                              <1> 	;SUB	AX,AX
  9567 00002C57 28C0                <1> 	sub	al, al
  9568 00002C59 B403                <1> 	MOV	AH,03H			; INDICATE FIXED DISK
  9569 00002C5B 5B                  <1> RDT2:	POP	eBX			; RESTORE REGISTERS
  9570                              <1> 	;POP	ES
  9571 00002C5C 1F                  <1> 	POP	DS
  9572 00002C5D F8                  <1> 	CLC				; CLEAR CARRY
  9573                              <1> 	;RETf	2
  9574 00002C5E CA0400              <1> 	retf	4
  9575                              <1> RDT_NOT_PRESENT:
  9576 00002C61 6629C0              <1> 	SUB	AX,AX			; DRIVE NOT PRESENT RETURN
  9577 00002C64 6689C1              <1> 	MOV	CX,AX			; ZERO BLOCK COUNT
  9578 00002C67 6689C2              <1> 	MOV	DX,AX
  9579 00002C6A EBEF                <1> 	JMP	short RDT2
  9580                              <1> 
  9581                              <1> ;----------------------------------------
  9582                              <1> ;	GET PARAMETERS	     (AH = 08H) :
  9583                              <1> ;----------------------------------------
  9584                              <1> 
  9585                              <1> GET_PARM_N:
  9586                              <1> ;GET_PARM:				; GET DRIVE PARAMETERS
  9587 00002C6C 1E                  <1> 	PUSH	DS			; SAVE REGISTERS
  9588                              <1> 	;PUSH	ES
  9589 00002C6D 53                  <1> 	PUSH	eBX
  9590                              <1> 	;MOV	AX,ABS0 		; ESTABLISH ADDRESSING
  9591                              <1> 	;MOV	DS,AX
  9592                              <1> 	;TEST	DL,1			; CHECK FOR DRIVE 1
  9593                              <1> 	;JZ	short G0
  9594                              <1> 	;LES	BX,@HF1_TBL_VEC
  9595                              <1> 	;JMP	SHORT G1
  9596                              <1> ;G0:	LES	BX,@HF_TBL_VEC
  9597                              <1> ;G1:
  9598                              <1> 	;CALL	DDS			; ESTABLISH SEGMENT
  9599                              <1> 	; 22/12/2014
  9600                              <1> 	;push	cs
  9601                              <1> 	;pop	ds
  9602 00002C6E 66BB1000            <1> 	mov	bx, KDATA
  9603 00002C72 8EDB                <1> 	mov	ds, bx
  9604                              <1> 	;mov	es, bx
  9605                              <1> 	;
  9606 00002C74 80EA80              <1> 	SUB	DL,80H
  9607 00002C77 80FA04              <1> 	CMP	DL,MAX_FILE		; TEST WITHIN RANGE
  9608 00002C7A 7341                <1> 	JAE	short G4
  9609                              <1> 	;
  9610 00002C7C 31DB                <1> 	xor	ebx, ebx ; 21/02/2015
  9611                              <1> 	; 22/12/2014
  9612 00002C7E 88D3                <1> 	mov	bl, dl
  9613                              <1> 	;xor	bh, bh  
  9614 00002C80 C0E302              <1> 	shl	bl, 2			; convert index to offset
  9615                              <1> 	;add	bx, HF_TBL_VEC
  9616 00002C83 81C3[ECA20000]      <1> 	add	ebx, HF_TBL_VEC
  9617                              <1> 	;mov	ax, [bx+2]
  9618                              <1> 	;mov	es, ax			; dpt segment
  9619                              <1> 	;mov	bx, [bx]		; dpt offset
  9620 00002C89 8B1B                <1> 	mov	ebx, [ebx] ; 32 bit offset	
  9621                              <1> 
  9622 00002C8B C605[E7A20000]00    <1> 	MOV	byte [DISK_STATUS1],0
  9623                              <1>         ;MOV     AX,[ES:BX]              ; MAX NUMBER OF CYLINDERS
  9624 00002C92 668B03              <1> 	mov	ax, [ebx]
  9625                              <1> 	;;SUB	AX,2			; ADJUST FOR 0-N
  9626 00002C95 6648                <1> 	dec	ax			; max. cylinder number
  9627 00002C97 88C5                <1> 	MOV	CH,AL
  9628 00002C99 66250003            <1> 	AND	AX,0300H		; HIGH TWO BITS OF CYLINDER
  9629 00002C9D 66D1E8              <1> 	SHR	AX,1
  9630 00002CA0 66D1E8              <1> 	SHR	AX,1
  9631                              <1> 	;OR	AL,[ES:BX+14]		; SECTORS
  9632 00002CA3 0A430E              <1> 	or	al, [ebx+14]
  9633 00002CA6 88C1                <1> 	MOV	CL,AL
  9634                              <1> 	;MOV	DH,[ES:BX+2]		; HEADS
  9635 00002CA8 8A7302              <1> 	mov	dh, [ebx+2]
  9636 00002CAB FECE                <1> 	DEC	DH			; 0-N RANGE
  9637 00002CAD 8A15[E8A20000]      <1> 	MOV	DL,[HF_NUM]		; DRIVE COUNT
  9638 00002CB3 6629C0              <1> 	SUB	AX,AX
  9639                              <1>         ;27/12/2014 
  9640                              <1> 	; ES:DI = Address of disk parameter table from BIOS
  9641                              <1> 	;(Programmer's Guide to the AMIBIOS - 1993)
  9642                              <1> 	;mov	di, bx			; HDPT offset
  9643 00002CB6 89DF                <1> 	mov	edi, ebx
  9644                              <1> G5:
  9645 00002CB8 5B                  <1> 	POP	eBX			; RESTORE REGISTERS
  9646                              <1> 	;POP	ES
  9647 00002CB9 1F                  <1> 	POP	DS
  9648                              <1> 	;RETf	2
  9649 00002CBA CA0400              <1> 	retf	4
  9650                              <1> G4:
  9651 00002CBD C605[E7A20000]07    <1> 	MOV     byte [DISK_STATUS1],INIT_FAIL ; OPERATION FAILED
  9652 00002CC4 B407                <1> 	MOV	AH,INIT_FAIL
  9653 00002CC6 28C0                <1> 	SUB	AL,AL
  9654 00002CC8 6629D2              <1> 	SUB	DX,DX
  9655 00002CCB 6629C9              <1> 	SUB	CX,CX
  9656 00002CCE F9                  <1> 	STC				; SET ERROR FLAG
  9657 00002CCF EBE7                <1> 	JMP	short G5
  9658                              <1> 
  9659                              <1> ;----------------------------------------
  9660                              <1> ;	INITIALIZE DRIVE     (AH = 09H) :
  9661                              <1> ;----------------------------------------
  9662                              <1> 	; 03/01/2015
  9663                              <1> 	; According to ATA-ATAPI specification v2.0 to v5.0
  9664                              <1> 	; logical sector per logical track
  9665                              <1> 	; and logical heads - 1 would be set but
  9666                              <1> 	; it is seen as it will be good
  9667                              <1> 	; if physical parameters will be set here
  9668                              <1> 	; because, number of heads <= 16.
  9669                              <1> 	; (logical heads usually more than 16)
  9670                              <1> 	; NOTE: ATA logical parameters (software C, H, S)
  9671                              <1> 	;	== INT 13h physical parameters
  9672                              <1> 
  9673                              <1> ;INIT_DRV:
  9674                              <1> ;	MOV	byte [CMD_BLOCK+6],SET_PARM_CMD
  9675                              <1> ;	CALL	GET_VEC 		; ES:BX -> PARAMETER BLOCK
  9676                              <1> ;	MOV	AL,[ES:BX+2]		; GET NUMBER OF HEADS
  9677                              <1> ;	DEC	AL			; CONVERT TO 0-INDEX
  9678                              <1> ;	MOV	AH,[CMD_BLOCK+5] 	; GET SDH REGISTER
  9679                              <1> ;	AND	AH,0F0H 		; CHANGE HEAD NUMBER
  9680                              <1> ;	OR	AH,AL			; TO MAX HEAD
  9681                              <1> ;	MOV	[CMD_BLOCK+5],AH
  9682                              <1> ;	MOV	AL,[ES:BX+14]		; MAX SECTOR NUMBER
  9683                              <1> ;	MOV	[CMD_BLOCK+1],AL
  9684                              <1> ;	SUB	AX,AX
  9685                              <1> ;	MOV	[CMD_BLOCK+3],AL 	; ZERO FLAGS
  9686                              <1> ;	CALL	COMMAND 		; TELL CONTROLLER
  9687                              <1> ;	JNZ	short INIT_EXIT		; CONTROLLER BUSY ERROR
  9688                              <1> ;	CALL	NOT_BUSY		; WAIT FOR IT TO BE DONE
  9689                              <1> ;	JNZ	short INIT_EXIT		; TIME OUT
  9690                              <1> ;	CALL	CHECK_STATUS
  9691                              <1> ;INIT_EXIT:
  9692                              <1> ;	RETn
  9693                              <1> 
  9694                              <1> ; 04/01/2015
  9695                              <1> ; 02/01/2015 - Derived from from AWARD BIOS 1999
  9696                              <1> ;				 AHDSK.ASM - INIT_DRIVE
  9697                              <1> INIT_DRV:
  9698                              <1> 	;xor	ah,ah
  9699 00002CD1 31C0                <1> 	xor	eax, eax ; 21/02/2015
  9700 00002CD3 B00B                <1> 	mov	al,11 ; Physical heads from translated HDPT
  9701 00002CD5 3825[FCA20000]      <1>         cmp     [LBAMode], ah   ; 0
  9702 00002CDB 7702                <1> 	ja	short idrv0
  9703 00002CDD B002                <1> 	mov	al,2  ; Physical heads from standard HDPT
  9704                              <1> idrv0:
  9705                              <1> 	; DL = drive number (0 based)
  9706 00002CDF E8C6030000          <1> 	call	GET_VEC
  9707                              <1> 	;push	bx
  9708 00002CE4 53                  <1> 	push	ebx ; 21/02/2015
  9709                              <1> 	;add	bx,ax
  9710 00002CE5 01C3                <1> 	add	ebx, eax
  9711                              <1> 	;; 05/01/2015
  9712 00002CE7 8A25[189D0000]      <1> 	mov	ah, [hf_m_s] ; drive number (0= master, 1= slave)
  9713                              <1> 	;;and 	ah,1 
  9714 00002CED C0E404              <1> 	shl	ah,4
  9715 00002CF0 80CCA0              <1> 	or	ah,0A0h  ; Drive/Head register - 10100000b (A0h)	
  9716                              <1> 	;mov	al,[es:bx]
  9717 00002CF3 8A03                <1> 	mov	al, [ebx] ; 21/02/2015
  9718 00002CF5 FEC8                <1> 	dec	al	 ; last head number 
  9719                              <1> 	;and	al,0Fh
  9720 00002CF7 08E0                <1> 	or	al,ah	 ; lower 4 bits for head number
  9721                              <1> 	;
  9722 00002CF9 C645FE91            <1> 	mov	byte [CMD_BLOCK+6],SET_PARM_CMD
  9723 00002CFD 8845FD              <1> 	mov	[CMD_BLOCK+5],al
  9724                              <1> 	;pop	bx
  9725 00002D00 5B                  <1> 	pop	ebx
  9726 00002D01 29C0                <1> 	sub	eax, eax ; 21/02/2015
  9727 00002D03 B004                <1> 	mov	al,4 ; Physical sec per track from translated HDPT
  9728 00002D05 803D[FCA20000]00    <1> 	cmp	byte [LBAMode], 0
  9729 00002D0C 7702                <1> 	ja	short idrv1
  9730 00002D0E B00E                <1> 	mov	al,14 ; Physical sec per track from standard HDPT
  9731                              <1> idrv1:
  9732                              <1> 	;xor	ah,ah
  9733                              <1> 	;add	bx,ax
  9734 00002D10 01C3                <1> 	add	ebx, eax ; 21/02/2015
  9735                              <1> 	;mov	al,[es:bx]
  9736                              <1> 			; sector number
  9737 00002D12 8A03                <1> 	mov	al, [ebx]
  9738 00002D14 8845F9              <1> 	mov	[CMD_BLOCK+1],al
  9739 00002D17 28C0                <1> 	sub	al,al
  9740 00002D19 8845FB              <1> 	mov	[CMD_BLOCK+3],al  ; ZERO FLAGS
  9741 00002D1C E8CA010000          <1> 	call	COMMAND 	  ; TELL CONTROLLER
  9742 00002D21 750C                <1> 	jnz	short INIT_EXIT	  ; CONTROLLER BUSY ERROR
  9743 00002D23 E878020000          <1> 	call	NOT_BUSY	  ; WAIT FOR IT TO BE DONE
  9744 00002D28 7505                <1> 	jnz	short INIT_EXIT	  ; TIME OUT
  9745 00002D2A E8C9020000          <1> 	call	CHECK_STATUS
  9746                              <1> INIT_EXIT:
  9747 00002D2F C3                  <1> 	RETn
  9748                              <1> 
  9749                              <1> ;----------------------------------------
  9750                              <1> ;	READ LONG	     (AH = 0AH) :
  9751                              <1> ;----------------------------------------
  9752                              <1> 
  9753                              <1> RD_LONG:
  9754                              <1> 	;MOV	@CMD_BLOCK+6,READ_CMD OR ECC_MODE
  9755 00002D30 C645FE22            <1>         mov     byte [CMD_BLOCK+6],READ_CMD + ECC_MODE 
  9756 00002D34 E9E0000000          <1>         JMP     COMMANDI
  9757                              <1> 
  9758                              <1> ;----------------------------------------
  9759                              <1> ;	WRITE LONG	     (AH = 0BH) :
  9760                              <1> ;----------------------------------------
  9761                              <1> 
  9762                              <1> WR_LONG:
  9763                              <1> 	;MOV	@CMD_BLOCK+6,WRITE_CMD OR ECC_MODE
  9764 00002D39 C645FE32            <1>         MOV     byte [CMD_BLOCK+6],WRITE_CMD + ECC_MODE
  9765 00002D3D E932010000          <1>         JMP     COMMANDO
  9766                              <1> 
  9767                              <1> ;----------------------------------------
  9768                              <1> ;	SEEK		     (AH = 0CH) :
  9769                              <1> ;----------------------------------------
  9770                              <1> 
  9771                              <1> DISK_SEEK:
  9772 00002D42 C645FE70            <1>         MOV     byte [CMD_BLOCK+6],SEEK_CMD
  9773 00002D46 E8A0010000          <1> 	CALL	COMMAND
  9774 00002D4B 751C                <1> 	JNZ	short DS_EXIT 		; CONTROLLER BUSY ERROR
  9775 00002D4D E812020000          <1> 	CALL	_WAIT
  9776 00002D52 7515                <1>         JNZ     DS_EXIT                 ; TIME OUT ON SEEK
  9777 00002D54 E89F020000          <1> 	CALL	CHECK_STATUS
  9778 00002D59 803D[E7A20000]40    <1>         CMP     byte [DISK_STATUS1],BAD_SEEK
  9779 00002D60 7507                <1> 	JNE	short DS_EXIT
  9780 00002D62 C605[E7A20000]00    <1>         MOV     byte [DISK_STATUS1],0
  9781                              <1> DS_EXIT:
  9782 00002D69 C3                  <1> 	RETn
  9783                              <1> 
  9784                              <1> ;----------------------------------------
  9785                              <1> ;	TEST DISK READY      (AH = 10H) :
  9786                              <1> ;----------------------------------------
  9787                              <1> 
  9788                              <1> TST_RDY:				; WAIT FOR CONTROLLER
  9789 00002D6A E831020000          <1> 	CALL	NOT_BUSY
  9790 00002D6F 751C                <1> 	JNZ	short TR_EX
  9791 00002D71 8A45FD              <1> 	MOV	AL,[CMD_BLOCK+5] 	; SELECT DRIVE
  9792 00002D74 668B15[149D0000]    <1> 	MOV	DX,[HF_PORT]
  9793 00002D7B 80C206              <1> 	add	dl,6
  9794 00002D7E EE                  <1> 	OUT	DX,AL
  9795 00002D7F E88C020000          <1> 	CALL	CHECK_ST		; CHECK STATUS ONLY
  9796 00002D84 7507                <1> 	JNZ	short TR_EX
  9797 00002D86 C605[E7A20000]00    <1> 	MOV	byte [DISK_STATUS1],0 	; WIPE OUT DATA CORRECTED ERROR
  9798                              <1> TR_EX:	
  9799 00002D8D C3                  <1> 	RETn
  9800                              <1> 
  9801                              <1> ;----------------------------------------
  9802                              <1> ;	RECALIBRATE	     (AH = 11H) :
  9803                              <1> ;----------------------------------------
  9804                              <1> 
  9805                              <1> HDISK_RECAL:
  9806 00002D8E C645FE10            <1>         MOV     byte [CMD_BLOCK+6],RECAL_CMD ; 10h, 16
  9807 00002D92 E854010000          <1> 	CALL	COMMAND 		; START THE OPERATION
  9808 00002D97 7523                <1> 	JNZ	short RECAL_EXIT	; ERROR
  9809 00002D99 E8C6010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION
  9810 00002D9E 7407                <1> 	JZ	short RECAL_X 		; TIME OUT ONE OK ?
  9811 00002DA0 E8BF010000          <1> 	CALL	_WAIT			; WAIT FOR COMPLETION LONGER
  9812 00002DA5 7515                <1> 	JNZ	short RECAL_EXIT	; TIME OUT TWO TIMES IS ERROR
  9813                              <1> RECAL_X:
  9814 00002DA7 E84C020000          <1> 	CALL	CHECK_STATUS
  9815 00002DAC 803D[E7A20000]40    <1> 	CMP	byte [DISK_STATUS1],BAD_SEEK ; SEEK NOT COMPLETE
  9816 00002DB3 7507                <1> 	JNE	short RECAL_EXIT	; IS OK
  9817 00002DB5 C605[E7A20000]00    <1> 	MOV	byte [DISK_STATUS1],0
  9818                              <1> RECAL_EXIT:
  9819 00002DBC 803D[E7A20000]00    <1>         CMP     byte [DISK_STATUS1],0
  9820 00002DC3 C3                  <1> 	RETn
  9821                              <1> 
  9822                              <1> ;----------------------------------------
  9823                              <1> ;      CONTROLLER DIAGNOSTIC (AH = 14H) :
  9824                              <1> ;----------------------------------------
  9825                              <1> 
  9826                              <1> CTLR_DIAGNOSTIC:
  9827 00002DC4 FA                  <1>         CLI                             ; DISABLE INTERRUPTS WHILE CHANGING MASK
  9828 00002DC5 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
  9829                              <1> 	;AND	AL,0BFH
  9830 00002DC7 243F                <1> 	and	al, 3Fh			; enable IRQ 14 & IRQ 15
  9831                              <1> 	;JMP	$+2
  9832                              <1> 	IODELAY
  9833 00002DC9 EB00                <2>  jmp short $+2
  9834 00002DCB EB00                <2>  jmp short $+2
  9835 00002DCD E6A1                <1> 	OUT	INTB01,AL
  9836                              <1> 	IODELAY
  9837 00002DCF EB00                <2>  jmp short $+2
  9838 00002DD1 EB00                <2>  jmp short $+2
  9839 00002DD3 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
  9840 00002DD5 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
  9841                              <1> 	;JMP	$+2
  9842                              <1> 	IODELAY
  9843 00002DD7 EB00                <2>  jmp short $+2
  9844 00002DD9 EB00                <2>  jmp short $+2
  9845 00002DDB E621                <1> 	OUT	INTA01,AL
  9846 00002DDD FB                  <1> 	STI
  9847 00002DDE E8BD010000          <1> 	CALL	NOT_BUSY		; WAIT FOR CARD
  9848 00002DE3 752B                <1> 	JNZ	short CD_ERR		; BAD CARD
  9849                              <1> 	;MOV	DX, HF_PORT+7
  9850 00002DE5 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
  9851 00002DEC 80C207              <1> 	add	dl, 7
  9852 00002DEF B090                <1> 	MOV	AL,DIAG_CMD		; START DIAGNOSE
  9853 00002DF1 EE                  <1> 	OUT	DX,AL
  9854 00002DF2 E8A9010000          <1> 	CALL	NOT_BUSY		; WAIT FOR IT TO COMPLETE
  9855 00002DF7 B480                <1> 	MOV	AH,TIME_OUT
  9856 00002DF9 7517                <1> 	JNZ	short CD_EXIT 		; TIME OUT ON DIAGNOSTIC
  9857                              <1> 	;MOV	DX,HF_PORT+1		; GET ERROR REGISTER
  9858 00002DFB 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
  9859 00002E02 FEC2                <1> 	inc	dl
  9860 00002E04 EC                  <1> 	IN	AL,DX
  9861 00002E05 A2[DEA20000]        <1> 	MOV	[HF_ERROR],AL		; SAVE IT
  9862 00002E0A B400                <1> 	MOV	AH,0
  9863 00002E0C 3C01                <1> 	CMP	AL,1			; CHECK FOR ALL OK
  9864 00002E0E 7402                <1> 	JE	SHORT CD_EXIT
  9865 00002E10 B420                <1> CD_ERR: MOV	AH,BAD_CNTLR
  9866                              <1> CD_EXIT:
  9867 00002E12 8825[E7A20000]      <1> 	MOV	[DISK_STATUS1],AH
  9868 00002E18 C3                  <1> 	RETn
  9869                              <1> 
  9870                              <1> ;----------------------------------------
  9871                              <1> ; COMMANDI				:
  9872                              <1> ;	REPEATEDLY INPUTS DATA TILL	:
  9873                              <1> ;	NSECTOR RETURNS ZERO		:
  9874                              <1> ;----------------------------------------
  9875                              <1> COMMANDI:
  9876 00002E19 E862020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  9877 00002E1E 7253                <1> 	JC	short CMD_ABORT
  9878                              <1> 	;MOV	DI,BX
  9879 00002E20 89DF                <1> 	mov	edi, ebx ; 21/02/2015
  9880 00002E22 E8C4000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  9881 00002E27 754A                <1> 	JNZ	short CMD_ABORT
  9882                              <1> CMD_I1:
  9883 00002E29 E836010000          <1> 	CALL	_WAIT			; WAIT FOR DATA REQUEST INTERRUPT
  9884 00002E2E 7543                <1> 	JNZ	short TM_OUT		; TIME OUT
  9885                              <1> cmd_i1x: ; 18/02/2016
  9886                              <1> 	;MOV	CX,256			; SECTOR SIZE IN WORDS
  9887 00002E30 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015	
  9888                              <1> 	;MOV	DX,HF_PORT
  9889 00002E35 668B15[149D0000]    <1> 	mov	dx,[HF_PORT]
  9890 00002E3C FA                  <1> 	CLI
  9891 00002E3D FC                  <1> 	CLD
  9892 00002E3E F3666D              <1> 	REP	INSW			; GET THE SECTOR
  9893 00002E41 FB                  <1> 	STI
  9894 00002E42 F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL INPUT
  9895 00002E46 7419                <1> 	JZ	short CMD_I3
  9896 00002E48 E880010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9897 00002E4D 7224                <1> 	JC	short TM_OUT
  9898                              <1> 	;MOV	DX,HF_PORT
  9899 00002E4F 668B15[149D0000]    <1> 	mov	dx,[HF_PORT]
  9900                              <1> 	;MOV	CX,4			; GET ECC BYTES
  9901 00002E56 B904000000          <1> 	mov 	ecx, 4 ; mov cx, 4 
  9902 00002E5B EC                  <1> CMD_I2: IN	AL,DX
  9903                              <1> 	;MOV	[ES:DI],AL		; GO SLOW FOR BOARD
  9904 00002E5C 8807                <1> 	mov 	[edi], al ; 21/02/2015
  9905 00002E5E 47                  <1> 	INC	eDI
  9906 00002E5F E2FA                <1> 	LOOP	CMD_I2
  9907                              <1> CMD_I3: 
  9908                              <1> 	; wait for 400 ns
  9909 00002E61 80C207              <1> 	add 	dl, 7
  9910 00002E64 EC                  <1> 	in	al, dx
  9911 00002E65 EC                  <1> 	in	al, dx
  9912 00002E66 EC                  <1> 	in	al, dx
  9913                              <1> 	;
  9914 00002E67 E88C010000          <1> 	CALL	CHECK_STATUS
  9915 00002E6C 7505                <1> 	JNZ	short CMD_ABORT		; ERROR RETURNED
  9916 00002E6E FE4DF9              <1> 	DEC	byte [CMD_BLOCK+1]	; CHECK FOR MORE
  9917                              <1> 	;JNZ	SHORT CMD_I1
  9918 00002E71 75BD                <1> 	jnz	short cmd_i1x ; 18/02/2016
  9919                              <1> CMD_ABORT:
  9920 00002E73 C3                  <1> TM_OUT: RETn
  9921                              <1> 
  9922                              <1> ;----------------------------------------
  9923                              <1> ; COMMANDO				:
  9924                              <1> ;	REPEATEDLY OUTPUTS DATA TILL	:
  9925                              <1> ;	NSECTOR RETURNS ZERO		:
  9926                              <1> ;----------------------------------------
  9927                              <1> COMMANDO:
  9928 00002E74 E807020000          <1> 	CALL	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  9929 00002E79 72F8                <1> 	JC	short CMD_ABORT
  9930 00002E7B 89DE                <1> CMD_OF: MOV	eSI,eBX ; 21/02/2015
  9931 00002E7D E869000000          <1> 	CALL	COMMAND 		; OUTPUT COMMAND
  9932 00002E82 75EF                <1> 	JNZ	short CMD_ABORT
  9933 00002E84 E844010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9934 00002E89 72E8                <1> 	JC	short TM_OUT			; TOO LONG
  9935                              <1> CMD_O1: ;PUSH	DS
  9936                              <1> 	;PUSH	ES			; MOVE ES TO DS
  9937                              <1> 	;POP	DS
  9938                              <1> 	;MOV	CX,256			; PUT THE DATA OUT TO THE CARD
  9939                              <1> 	;MOV	DX,HF_PORT
  9940                              <1> 	; 01/02/2015
  9941 00002E8B 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
  9942                              <1> 	;push	es
  9943                              <1> 	;pop	ds
  9944                              <1> 	;mov	cx, 256
  9945 00002E92 B900010000          <1> 	mov	ecx, 256 ; 21/02/2015
  9946 00002E97 FA                  <1> 	CLI
  9947 00002E98 FC                  <1> 	CLD
  9948 00002E99 F3666F              <1> 	REP	OUTSW
  9949 00002E9C FB                  <1> 	STI
  9950                              <1> 	;POP	DS			; RESTORE DS
  9951 00002E9D F645FE02            <1> 	TEST	byte [CMD_BLOCK+6],ECC_MODE ; CHECK FOR NORMAL OUTPUT
  9952 00002EA1 7419                <1> 	JZ	short CMD_O3
  9953 00002EA3 E825010000          <1> 	CALL	WAIT_DRQ		; WAIT FOR DATA REQUEST
  9954 00002EA8 72C9                <1> 	JC	short TM_OUT
  9955                              <1> 	;MOV	DX,HF_PORT
  9956 00002EAA 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
  9957                              <1> 	;MOV	CX,4			; OUTPUT THE ECC BYTES
  9958 00002EB1 B904000000          <1> 	mov	ecx, 4  ; mov cx, 4
  9959                              <1> CMD_O2: ;MOV	AL,[ES:SI]
  9960 00002EB6 8A06                <1> 	mov	al, [esi]
  9961 00002EB8 EE                  <1> 	OUT	DX,AL
  9962 00002EB9 46                  <1> 	INC	eSI
  9963 00002EBA E2FA                <1> 	LOOP	CMD_O2
  9964                              <1> CMD_O3:
  9965 00002EBC E8A3000000          <1> 	CALL	_WAIT			; WAIT FOR SECTOR COMPLETE INTERRUPT
  9966 00002EC1 75B0                <1> 	JNZ	short TM_OUT		; ERROR RETURNED
  9967 00002EC3 E830010000          <1> 	CALL	CHECK_STATUS
  9968 00002EC8 75A9                <1> 	JNZ	short CMD_ABORT
  9969 00002ECA F605[DDA20000]08    <1> 	TEST	byte [HF_STATUS],ST_DRQ	; CHECK FOR MORE
  9970 00002ED1 75B8                <1> 	JNZ	SHORT CMD_O1
  9971                              <1> 	;MOV	DX,HF_PORT+2		; CHECK RESIDUAL SECTOR COUNT
  9972 00002ED3 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
  9973                              <1> 	;add	dl, 2
  9974 00002EDA FEC2                <1> 	inc	dl
  9975 00002EDC FEC2                <1> 	inc	dl
  9976 00002EDE EC                  <1> 	IN	AL,DX			;
  9977 00002EDF A8FF                <1> 	TEST	AL,0FFH 		;
  9978 00002EE1 7407                <1> 	JZ	short CMD_O4			; COUNT = 0  OK
  9979 00002EE3 C605[E7A20000]BB    <1> 	MOV	byte [DISK_STATUS1],UNDEF_ERR 
  9980                              <1> 					; OPERATION ABORTED - PARTIAL TRANSFER
  9981                              <1> CMD_O4:
  9982 00002EEA C3                  <1> 	RETn
  9983                              <1> 
  9984                              <1> ;--------------------------------------------------------
  9985                              <1> ; COMMAND						:
  9986                              <1> ;	THIS ROUTINE OUTPUTS THE COMMAND BLOCK		:
  9987                              <1> ; OUTPUT						:
  9988                              <1> ;	BL = STATUS					:
  9989                              <1> ;	BH = ERROR REGISTER				:
  9990                              <1> ;--------------------------------------------------------
  9991                              <1> 
  9992                              <1> COMMAND:
  9993 00002EEB 53                  <1> 	PUSH	eBX			; WAIT FOR SEEK COMPLETE AND READY
  9994                              <1> 	;;MOV	CX,DELAY_2		; SET INITIAL DELAY BEFORE TEST
  9995                              <1> COMMAND1:
  9996                              <1> 	;;PUSH	CX			; SAVE LOOP COUNT
  9997 00002EEC E879FEFFFF          <1> 	CALL	TST_RDY 		; CHECK DRIVE READY
  9998                              <1> 	;;POP	CX
  9999 00002EF1 7419                <1> 	JZ	short COMMAND2		; DRIVE IS READY
 10000 00002EF3 803D[E7A20000]80    <1>         CMP     byte [DISK_STATUS1],TIME_OUT ; TST_RDY TIMED OUT--GIVE UP
 10001                              <1> 	;JZ	short CMD_TIMEOUT
 10002                              <1> 	;;LOOP	COMMAND1		; KEEP TRYING FOR A WHILE
 10003                              <1> 	;JMP	SHORT COMMAND4		; ITS NOT GOING TO GET READY
 10004 00002EFA 7507                <1> 	jne	short COMMAND4
 10005                              <1> CMD_TIMEOUT:
 10006 00002EFC C605[E7A20000]20    <1> 	MOV	byte [DISK_STATUS1],BAD_CNTLR
 10007                              <1> COMMAND4:
 10008 00002F03 5B                  <1> 	POP	eBX
 10009 00002F04 803D[E7A20000]00    <1>         CMP     byte [DISK_STATUS1],0   ; SET CONDITION CODE FOR CALLER
 10010 00002F0B C3                  <1> 	RETn
 10011                              <1> COMMAND2:
 10012 00002F0C 5B                  <1> 	POP	eBX
 10013 00002F0D 57                  <1> 	PUSH	eDI
 10014 00002F0E C605[DFA20000]00    <1> 	MOV	byte [HF_INT_FLAG],0	; RESET INTERRUPT FLAG
 10015 00002F15 FA                  <1> 	CLI				; INHIBIT INTERRUPTS WHILE CHANGING MASK
 10016 00002F16 E4A1                <1> 	IN	AL,INTB01		; TURN ON SECOND INTERRUPT CHIP
 10017                              <1> 	;AND	AL,0BFH
 10018 00002F18 243F                <1> 	and	al, 3Fh			; Enable IRQ 14 & 15
 10019                              <1> 	;JMP	$+2
 10020                              <1> 	IODELAY
 10021 00002F1A EB00                <2>  jmp short $+2
 10022 00002F1C EB00                <2>  jmp short $+2
 10023 00002F1E E6A1                <1> 	OUT	INTB01,AL
 10024 00002F20 E421                <1> 	IN	AL,INTA01		; LET INTERRUPTS PASS THRU TO
 10025 00002F22 24FB                <1> 	AND	AL,0FBH 		;  SECOND CHIP
 10026                              <1> 	;JMP	$+2
 10027                              <1> 	IODELAY
 10028 00002F24 EB00                <2>  jmp short $+2
 10029 00002F26 EB00                <2>  jmp short $+2
 10030 00002F28 E621                <1> 	OUT	INTA01,AL
 10031 00002F2A FB                  <1> 	STI
 10032 00002F2B 31FF                <1> 	XOR	eDI,eDI			; INDEX THE COMMAND TABLE
 10033                              <1> 	;MOV	DX,HF_PORT+1		; DISK ADDRESS
 10034 00002F2D 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
 10035 00002F34 FEC2                <1> 	inc	dl
 10036 00002F36 F605[E9A20000]C0    <1> 	TEST	byte [CONTROL_BYTE],0C0H ; CHECK FOR RETRY SUPPRESSION
 10037 00002F3D 7411                <1> 	JZ	short COMMAND3
 10038 00002F3F 8A45FE              <1> 	MOV	AL, [CMD_BLOCK+6] 	; YES-GET OPERATION CODE
 10039 00002F42 24F0                <1> 	AND	AL,0F0H 		; GET RID OF MODIFIERS
 10040 00002F44 3C20                <1> 	CMP	AL,20H			; 20H-40H IS READ, WRITE, VERIFY
 10041 00002F46 7208                <1> 	JB	short COMMAND3
 10042 00002F48 3C40                <1> 	CMP	AL,40H
 10043 00002F4A 7704                <1> 	JA	short COMMAND3
 10044 00002F4C 804DFE01            <1> 	OR	byte [CMD_BLOCK+6],NO_RETRIES 
 10045                              <1> 					; VALID OPERATION FOR RETRY SUPPRESS
 10046                              <1> COMMAND3:
 10047 00002F50 8A443DF8            <1> 	MOV	AL,[CMD_BLOCK+eDI]	; GET THE COMMAND STRING BYTE
 10048 00002F54 EE                  <1> 	OUT	DX,AL			; GIVE IT TO CONTROLLER
 10049                              <1> 	IODELAY
 10050 00002F55 EB00                <2>  jmp short $+2
 10051 00002F57 EB00                <2>  jmp short $+2
 10052 00002F59 47                  <1> 	INC	eDI			; NEXT BYTE IN COMMAND BLOCK
 10053 00002F5A 6642                <1> 	INC	DX			; NEXT DISK ADAPTER REGISTER
 10054 00002F5C 6683FF07            <1> 	cmp	di, 7	; 1/1/2015	; ALL DONE?
 10055 00002F60 75EE                <1> 	JNZ	short COMMAND3		; NO--GO DO NEXT ONE
 10056 00002F62 5F                  <1> 	POP	eDI
 10057 00002F63 C3                  <1> 	RETn				; ZERO FLAG IS SET
 10058                              <1> 
 10059                              <1> ;CMD_TIMEOUT:
 10060                              <1> ;	MOV	byte [DISK_STATUS1],BAD_CNTLR
 10061                              <1> ;COMMAND4:
 10062                              <1> ;	POP	BX
 10063                              <1> ;	CMP	[DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10064                              <1> ;	RETn
 10065                              <1> 
 10066                              <1> ;----------------------------------------
 10067                              <1> ;	WAIT FOR INTERRUPT		:
 10068                              <1> ;----------------------------------------
 10069                              <1> ;WAIT:
 10070                              <1> _WAIT:
 10071 00002F64 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
 10072                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
 10073                              <1> 	;CLC
 10074                              <1> 	;MOV	AX,9000H		; DEVICE WAIT INTERRUPT
 10075                              <1> 	;INT	15H
 10076                              <1> 	;JC	WT2			; DEVICE TIMED OUT
 10077                              <1> 	;MOV	BL,DELAY_1		; SET DELAY COUNT
 10078                              <1> 
 10079                              <1> 	;mov	bl, WAIT_HDU_INT_HI
 10080                              <1> 	;; 21/02/2015
 10081                              <1> 	;;mov	bl, WAIT_HDU_INT_HI + 1
 10082                              <1> 	;;mov	cx, WAIT_HDU_INT_LO
 10083 00002F65 B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH
 10084                              <1> 					; (AWARD BIOS -> WAIT_FOR_MEM)
 10085                              <1> ;-----	WAIT LOOP
 10086                              <1> 
 10087                              <1> WT1:	
 10088                              <1> 	;TEST	byte [HF_INT_FLAG],80H	; TEST FOR INTERRUPT
 10089 00002F6A F605[DFA20000]C0    <1> 	test 	byte [HF_INT_FLAG],0C0h
 10090                              <1> 	;LOOPZ	WT1
 10091 00002F71 7517                <1> 	JNZ	short WT3		; INTERRUPT--LETS GO
 10092                              <1> 	;DEC	BL
 10093                              <1> 	;JNZ	short WT1		; KEEP TRYING FOR A WHILE
 10094                              <1> 
 10095                              <1> WT1_hi:
 10096 00002F73 E461                <1> 	in	al, SYS1 ; 61h (PORT_B)	; wait for lo to hi
 10097 00002F75 A810                <1> 	test	al, 10h			; transition on memory
 10098 00002F77 75FA                <1> 	jnz	short WT1_hi		; refresh.
 10099                              <1> WT1_lo:
 10100 00002F79 E461                <1> 	in	al, SYS1 		; 061h (PORT_B)	
 10101 00002F7B A810                <1> 	test	al, 10h			
 10102 00002F7D 74FA                <1> 	jz	short WT1_lo
 10103 00002F7F E2E9                <1> 	loop	WT1
 10104                              <1> 	;;or	bl, bl
 10105                              <1> 	;;jz	short WT2	
 10106                              <1> 	;;dec	bl
 10107                              <1> 	;;jmp	short WT1
 10108                              <1> 	;dec	bl
 10109                              <1> 	;jnz	short WT1	
 10110                              <1> 
 10111 00002F81 C605[E7A20000]80    <1> WT2:	MOV	byte [DISK_STATUS1],TIME_OUT ; REPORT TIME OUT ERROR
 10112 00002F88 EB0E                <1> 	JMP	SHORT WT4
 10113 00002F8A C605[E7A20000]00    <1> WT3:	MOV	byte [DISK_STATUS1],0
 10114 00002F91 C605[DFA20000]00    <1> 	MOV	byte [HF_INT_FLAG],0
 10115 00002F98 803D[E7A20000]00    <1> WT4:	CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10116 00002F9F C3                  <1> 	RETn
 10117                              <1> 
 10118                              <1> ;----------------------------------------
 10119                              <1> ;	WAIT FOR CONTROLLER NOT BUSY	:
 10120                              <1> ;----------------------------------------
 10121                              <1> NOT_BUSY:
 10122 00002FA0 FB                  <1> 	STI				; MAKE SURE INTERRUPTS ARE ON
 10123                              <1> 	;PUSH	eBX
 10124                              <1> 	;SUB	CX,CX			; SET INITIAL DELAY BEFORE TEST
 10125 00002FA1 668B15[149D0000]    <1> 	mov	DX, [HF_PORT]
 10126 00002FA8 80C207              <1> 	add	dl, 7			; Status port (HF_PORT+7)
 10127                              <1> 	;MOV	BL,DELAY_1
 10128                              <1> 					; wait for 10 seconds
 10129                              <1> 	;mov 	cx, WAIT_HDU_INT_LO	; 1615h
 10130                              <1> 	;;mov 	bl, WAIT_HDU_INT_HI	;   05h
 10131                              <1> 	;mov	bl, WAIT_HDU_INT_HI + 1
 10132 00002FAB B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH  ; 21/02/2015
 10133                              <1> 	;
 10134                              <1> ;;      mov     byte [wait_count], 0    ; Reset wait counter
 10135                              <1> NB1:	
 10136 00002FB0 EC                  <1> 	IN	AL,DX			; CHECK STATUS
 10137                              <1> 	;TEST	AL,ST_BUSY
 10138 00002FB1 2480                <1> 	and	al, ST_BUSY
 10139                              <1> 	;LOOPNZ	NB1
 10140 00002FB3 7410                <1> 	JZ	short NB2		; NOT BUSY--LETS GO
 10141                              <1> 	;DEC	BL			
 10142                              <1> 	;JNZ	short NB1		; KEEP TRYING FOR A WHILE
 10143                              <1> 
 10144 00002FB5 E461                <1> NB1_hi: IN	AL,SYS1			; wait for hi to lo
 10145 00002FB7 A810                <1> 	TEST	AL,010H			; transition on memory
 10146 00002FB9 75FA                <1> 	JNZ	SHORT NB1_hi		; refresh.
 10147 00002FBB E461                <1> NB1_lo: IN	AL,SYS1
 10148 00002FBD A810                <1> 	TEST	AL,010H
 10149 00002FBF 74FA                <1> 	JZ	short NB1_lo
 10150 00002FC1 E2ED                <1> 	LOOP	NB1
 10151                              <1> 	;dec	bl
 10152                              <1> 	;jnz	short NB1
 10153                              <1> 	;
 10154                              <1> ;;      cmp     byte [wait_count], 182  ; 10 seconds (182 timer ticks)
 10155                              <1> ;;	jb	short NB1
 10156                              <1> 	;
 10157                              <1> 	;MOV	[DISK_STATUS1],TIME_OUT	; REPORT TIME OUT ERROR
 10158                              <1> 	;JMP	SHORT NB3
 10159 00002FC3 B080                <1> 	mov	al, TIME_OUT
 10160                              <1> NB2:	
 10161                              <1> 	;MOV	byte [DISK_STATUS1],0
 10162                              <1> ;NB3:	
 10163                              <1> 	;POP	eBX
 10164 00002FC5 A2[E7A20000]        <1> 	mov	[DISK_STATUS1], al	;;; will be set after return
 10165                              <1> 	;CMP	byte [DISK_STATUS1],0 	; SET CONDITION CODE FOR CALLER
 10166 00002FCA 08C0                <1> 	or	al, al			; (zf = 0 --> timeout)
 10167 00002FCC C3                  <1> 	RETn
 10168                              <1> 
 10169                              <1> ;----------------------------------------
 10170                              <1> ;	WAIT FOR DATA REQUEST		:
 10171                              <1> ;----------------------------------------
 10172                              <1> WAIT_DRQ:
 10173                              <1> 	;MOV	CX,DELAY_3
 10174                              <1> 	;MOV	DX,HF_PORT+7
 10175 00002FCD 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
 10176 00002FD4 80C207              <1> 	add	dl, 7
 10177                              <1> 	;;MOV	bl, WAIT_HDU_DRQ_HI	; 0
 10178                              <1> 	;MOV	cx, WAIT_HDU_DRQ_LO	; 1000 (30 milli seconds)
 10179                              <1> 					; (but it is written as 2000
 10180                              <1> 					; micro seconds in ATORGS.ASM file
 10181                              <1> 					; of Award Bios - 1999, D1A0622)
 10182 00002FD7 B9E8030000          <1> 	mov 	ecx, WAIT_HDU_DRQ_LH ; 21/02/2015 
 10183 00002FDC EC                  <1> WQ_1:	IN	AL,DX			; GET STATUS
 10184 00002FDD A808                <1> 	TEST	AL,ST_DRQ		; WAIT FOR DRQ
 10185 00002FDF 7516                <1> 	JNZ	short WQ_OK
 10186                              <1> 	;LOOP	WQ_1			; KEEP TRYING FOR A SHORT WHILE
 10187                              <1> WQ_hi:	
 10188 00002FE1 E461                <1> 	IN	AL,SYS1			; wait for hi to lo
 10189 00002FE3 A810                <1> 	TEST	AL,010H			; transition on memory
 10190 00002FE5 75FA                <1> 	JNZ	SHORT WQ_hi		; refresh.
 10191 00002FE7 E461                <1> WQ_lo:  IN      AL,SYS1
 10192 00002FE9 A810                <1> 	TEST	AL,010H
 10193 00002FEB 74FA                <1> 	JZ	SHORT WQ_lo
 10194 00002FED E2ED                <1> 	LOOP	WQ_1
 10195                              <1> 
 10196 00002FEF C605[E7A20000]80    <1>         MOV     byte [DISK_STATUS1],TIME_OUT ; ERROR
 10197 00002FF6 F9                  <1> 	STC
 10198                              <1> WQ_OK:
 10199 00002FF7 C3                  <1> 	RETn
 10200                              <1> ;WQ_OK:	;CLC
 10201                              <1> ;	RETn
 10202                              <1> 
 10203                              <1> ;----------------------------------------
 10204                              <1> ;	CHECK FIXED DISK STATUS 	:
 10205                              <1> ;----------------------------------------
 10206                              <1> CHECK_STATUS:
 10207 00002FF8 E813000000          <1> 	CALL	CHECK_ST		; CHECK THE STATUS BYTE
 10208 00002FFD 7509                <1> 	JNZ	short CHECK_S1		; AN ERROR WAS FOUND
 10209 00002FFF A801                <1> 	TEST	AL,ST_ERROR		; WERE THERE ANY OTHER ERRORS
 10210 00003001 7405                <1> 	JZ	short CHECK_S1		; NO ERROR REPORTED
 10211 00003003 E849000000          <1> 	CALL	CHECK_ER		; ERROR REPORTED
 10212                              <1> CHECK_S1:
 10213 00003008 803D[E7A20000]00    <1> 	CMP	byte [DISK_STATUS1],0 	; SET STATUS FOR CALLER
 10214 0000300F C3                  <1> 	RETn
 10215                              <1> 
 10216                              <1> ;----------------------------------------
 10217                              <1> ;	CHECK FIXED DISK STATUS BYTE	:
 10218                              <1> ;----------------------------------------
 10219                              <1> CHECK_ST:
 10220                              <1> 	;MOV	DX,HF_PORT+7		; GET THE STATUS
 10221 00003010 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]
 10222 00003017 80C207              <1> 	add	dl, 7
 10223                              <1> 	
 10224                              <1> 	; 17/02/2016
 10225                              <1> 	;(http://wiki.osdev.org/ATA_PIO_Mode)
 10226                              <1> 	;"delay 400ns to allow drive to set new values of BSY and DRQ"
 10227 0000301A EC                  <1> 	IN	AL,DX
 10228                              <1> 	;in	al, dx ; 100ns
 10229                              <1> 	;in	al, dx ; 100ns
 10230                              <1>  	;in	al, dx ; 100ns
 10231                              <1> 	NEWIODELAY ; 18/02/2016 (AWARD BIOS - 1999, 'CKST' in AHSDK.ASM)
 10232 0000301B E6EB                <2>  out 0ebh,al
 10233                              <1> 	;
 10234 0000301D A2[DDA20000]        <1> 	MOV	[HF_STATUS],AL
 10235 00003022 B400                <1> 	MOV	AH,0
 10236 00003024 A880                <1> 	TEST	AL,ST_BUSY		; IF STILL BUSY
 10237 00003026 751A                <1> 	JNZ	short CKST_EXIT		;  REPORT OK
 10238 00003028 B4CC                <1> 	MOV	AH,WRITE_FAULT
 10239 0000302A A820                <1> 	TEST	AL,ST_WRT_FLT		; CHECK FOR WRITE FAULT
 10240 0000302C 7514                <1> 	JNZ	short CKST_EXIT
 10241 0000302E B4AA                <1> 	MOV	AH,NOT_RDY
 10242 00003030 A840                <1> 	TEST	AL,ST_READY		; CHECK FOR NOT READY
 10243 00003032 740E                <1> 	JZ	short CKST_EXIT
 10244 00003034 B440                <1> 	MOV	AH,BAD_SEEK
 10245 00003036 A810                <1> 	TEST	AL,ST_SEEK_COMPL	; CHECK FOR SEEK NOT COMPLETE
 10246 00003038 7408                <1> 	JZ	short CKST_EXIT
 10247 0000303A B411                <1> 	MOV	AH,DATA_CORRECTED
 10248 0000303C A804                <1> 	TEST	AL,ST_CORRCTD		; CHECK FOR CORRECTED ECC
 10249 0000303E 7502                <1> 	JNZ	short CKST_EXIT
 10250 00003040 B400                <1> 	MOV	AH,0
 10251                              <1> CKST_EXIT:
 10252 00003042 8825[E7A20000]      <1> 	MOV	[DISK_STATUS1],AH	; SET ERROR FLAG
 10253 00003048 80FC11              <1> 	CMP	AH,DATA_CORRECTED	; KEEP GOING WITH DATA CORRECTED
 10254 0000304B 7403                <1> 	JZ	short CKST_EX1
 10255 0000304D 80FC00              <1> 	CMP	AH,0
 10256                              <1> CKST_EX1:
 10257 00003050 C3                  <1> 	RETn
 10258                              <1> 
 10259                              <1> ;----------------------------------------
 10260                              <1> ;	CHECK FIXED DISK ERROR REGISTER :
 10261                              <1> ;----------------------------------------
 10262                              <1> CHECK_ER:
 10263                              <1> 	;MOV	DX, HF_PORT+1		; GET THE ERROR REGISTER
 10264 00003051 668B15[149D0000]    <1> 	mov	dx, [HF_PORT]		;
 10265 00003058 FEC2                <1> 	inc	dl
 10266 0000305A EC                  <1> 	IN	AL,DX
 10267 0000305B A2[DEA20000]        <1> 	MOV	[HF_ERROR],AL
 10268 00003060 53                  <1> 	PUSH	eBX ; 21/02/2015
 10269 00003061 B908000000          <1> 	MOV	eCX,8			; TEST ALL 8 BITS
 10270 00003066 D0E0                <1> CK1:	SHL	AL,1			; MOVE NEXT ERROR BIT TO CARRY
 10271 00003068 7202                <1> 	JC	short CK2		; FOUND THE ERROR
 10272 0000306A E2FA                <1> 	LOOP	CK1			; KEEP TRYING
 10273 0000306C BB[089D0000]        <1> CK2:	MOV	eBX, ERR_TBL		; COMPUTE ADDRESS OF
 10274 00003071 01CB                <1> 	ADD	eBX,eCX			; ERROR CODE
 10275                              <1> 	;;MOV	AH,BYTE [CS:BX]		; GET ERROR CODE
 10276                              <1> 	;mov	ah, [bx]
 10277 00003073 8A23                <1> 	mov	ah, [ebx] ; 21/02/2015	
 10278 00003075 8825[E7A20000]      <1> CKEX:	MOV	[DISK_STATUS1],AH	; SAVE ERROR CODE
 10279 0000307B 5B                  <1> 	POP	eBX
 10280 0000307C 80FC00              <1> 	CMP	AH,0
 10281 0000307F C3                  <1> 	RETn
 10282                              <1> 
 10283                              <1> ;--------------------------------------------------------
 10284                              <1> ; CHECK_DMA						:
 10285                              <1> ;  -CHECK ES:BX AND # SECTORS TO MAKE SURE THAT IT WILL :
 10286                              <1> ;   FIT WITHOUT SEGMENT OVERFLOW.			:
 10287                              <1> ;  -ES:BX HAS BEEN REVISED TO THE FORMAT SSSS:000X	:
 10288                              <1> ;  -OK IF # SECTORS < 80H (7FH IF LONG READ OR WRITE)	:
 10289                              <1> ;  -OK IF # SECTORS = 80H (7FH) AND BX <= 00H (04H)	:
 10290                              <1> ;  -ERROR OTHERWISE					:
 10291                              <1> ;--------------------------------------------------------
 10292                              <1> CHECK_DMA:
 10293 00003080 6650                <1> 	PUSH	AX			; SAVE REGISTERS
 10294 00003082 66B80080            <1> 	MOV	AX,8000H		; AH = MAX # SECTORS AL = MAX OFFSET
 10295 00003086 F645FE02            <1>         TEST    byte [CMD_BLOCK+6],ECC_MODE
 10296 0000308A 7404                <1> 	JZ	short CKD1
 10297 0000308C 66B8047F            <1> 	MOV	AX,7F04H		; ECC IS 4 MORE BYTES
 10298 00003090 3A65F9              <1> CKD1:	CMP	AH, [CMD_BLOCK+1] 	; NUMBER OF SECTORS
 10299 00003093 7706                <1> 	JA	short CKDOK		; IT WILL FIT
 10300 00003095 7208                <1> 	JB	short CKDERR		; TOO MANY
 10301 00003097 38D8                <1> 	CMP	AL,BL			; CHECK OFFSET ON MAX SECTORS
 10302 00003099 7204                <1> 	JB	short CKDERR		; ERROR
 10303 0000309B F8                  <1> CKDOK:	CLC				; CLEAR CARRY
 10304 0000309C 6658                <1> 	POP	AX
 10305 0000309E C3                  <1> 	RETn				; NORMAL RETURN
 10306 0000309F F9                  <1> CKDERR: STC				; INDICATE ERROR
 10307 000030A0 C605[E7A20000]09    <1>         MOV     byte [DISK_STATUS1],DMA_BOUNDARY
 10308 000030A7 6658                <1> 	POP	AX
 10309 000030A9 C3                  <1> 	RETn
 10310                              <1> 
 10311                              <1> ;----------------------------------------
 10312                              <1> ;	SET UP ES:BX-> DISK PARMS	:
 10313                              <1> ;----------------------------------------
 10314                              <1> 					
 10315                              <1> ; INPUT -> DL = 0 based drive number
 10316                              <1> ; OUTPUT -> ES:BX = disk parameter table address
 10317                              <1> 
 10318                              <1> GET_VEC:
 10319                              <1> 	;SUB	AX,AX			; GET DISK PARAMETER ADDRESS
 10320                              <1> 	;MOV	ES,AX
 10321                              <1> 	;TEST	DL,1
 10322                              <1> 	;JZ	short GV_0
 10323                              <1> ;	LES	BX,[HF1_TBL_VEC] 	; ES:BX -> DRIVE PARAMETERS
 10324                              <1> ;	JMP	SHORT GV_EXIT
 10325                              <1> ;GV_0:
 10326                              <1> ;	LES	BX,[HF_TBL_VEC]		; ES:BX -> DRIVE PARAMETERS
 10327                              <1> ;
 10328                              <1> 	;xor	bh, bh
 10329 000030AA 31DB                <1> 	xor	ebx, ebx
 10330 000030AC 88D3                <1> 	mov	bl, dl
 10331                              <1> 	;;02/01/2015
 10332                              <1> 	;;shl	bl, 1			; port address offset
 10333                              <1> 	;;mov	ax, [bx+hd_ports]	; Base port address (1F0h, 170h)
 10334                              <1> 	;;shl	bl, 1			; dpt pointer offset
 10335 000030AE C0E302              <1> 	shl	bl, 2	;;
 10336                              <1> 	;add	bx, HF_TBL_VEC		; Disk parameter table pointer
 10337 000030B1 81C3[ECA20000]      <1> 	add	ebx, HF_TBL_VEC ; 21/02/2015
 10338                              <1> 	;push	word [bx+2]		; dpt segment
 10339                              <1> 	;pop	es
 10340                              <1> 	;mov	bx, [bx]		; dpt offset
 10341 000030B7 8B1B                <1> 	mov	ebx, [ebx]		
 10342                              <1> ;GV_EXIT:
 10343 000030B9 C3                  <1> 	RETn
 10344                              <1> 
 10345                              <1> hdc1_int: ; 21/02/2015
 10346                              <1> ;--- HARDWARE INT 76H -- ( IRQ LEVEL  14 ) ----------------------
 10347                              <1> ;								:
 10348                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
 10349                              <1> ;								:
 10350                              <1> ;----------------------------------------------------------------
 10351                              <1> 
 10352                              <1> ; 22/12/2014
 10353                              <1> ; IBM PC-XT Model 286 System BIOS Source Code - DISK.ASM (HD_INT)
 10354                              <1> ;	 '11/15/85'
 10355                              <1> ; AWARD BIOS 1999 (D1A0622) 
 10356                              <1> ;	Source Code - ATORGS.ASM (INT_HDISK, INT_HDISK1)
 10357                              <1> 
 10358                              <1> ;int_76h:
 10359                              <1> HD_INT:
 10360 000030BA 6650                <1> 	PUSH	AX
 10361 000030BC 1E                  <1> 	PUSH	DS
 10362                              <1> 	;CALL	DDS
 10363                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
 10364 000030BD 66B81000            <1> 	mov	ax, KDATA
 10365 000030C1 8ED8                <1> 	mov 	ds, ax
 10366                              <1> 	;
 10367                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
 10368                              <1>         ;mov     byte [CS:HF_INT_FLAG], 0FFh
 10369 000030C3 C605[DFA20000]FF    <1> 	mov	byte [HF_INT_FLAG], 0FFh
 10370                              <1> 	;
 10371 000030CA 6652                <1> 	push	dx
 10372 000030CC 66BAF701            <1> 	mov	dx, HDC1_BASEPORT+7	; Status Register (1F7h)
 10373                              <1> 					; Clear Controller
 10374                              <1> Clear_IRQ1415:				; (Award BIOS - 1999)
 10375 000030D0 EC                  <1> 	in	al, dx			;
 10376 000030D1 665A                <1> 	pop	dx
 10377                              <1> 	NEWIODELAY
 10378 000030D3 E6EB                <2>  out 0ebh,al
 10379                              <1> 	;
 10380 000030D5 B020                <1> 	MOV	AL,EOI			; NON-SPECIFIC END OF INTERRUPT
 10381 000030D7 E6A0                <1> 	OUT	INTB00,AL		; FOR CONTROLLER #2
 10382                              <1> 	;JMP	$+2			; WAIT
 10383                              <1> 	NEWIODELAY
 10384 000030D9 E6EB                <2>  out 0ebh,al
 10385 000030DB E620                <1> 	OUT	INTA00,AL		; FOR CONTROLLER #1
 10386 000030DD 1F                  <1> 	POP	DS
 10387                              <1> 	;STI				; RE-ENABLE INTERRUPTS
 10388                              <1> 	;MOV	AX,9100H		; DEVICE POST
 10389                              <1> 	;INT	15H			;  INTERRUPT
 10390                              <1> irq15_iret: ; 25/02/2015
 10391 000030DE 6658                <1> 	POP	AX
 10392 000030E0 CF                  <1> 	IRETd				; RETURN FROM INTERRUPT
 10393                              <1> 
 10394                              <1> hdc2_int: ; 21/02/2015
 10395                              <1> ;++++ HARDWARE INT 77H ++ ( IRQ LEVEL  15 ) +++++++++++++++++++++
 10396                              <1> ;								:
 10397                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
 10398                              <1> ;								:
 10399                              <1> ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 10400                              <1> 
 10401                              <1> ;int_77h:
 10402                              <1> HD1_INT:
 10403 000030E1 6650                <1> 	PUSH	AX
 10404                              <1> 	; Check if that is a spurious IRQ (from slave PIC)
 10405                              <1> 	; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
 10406 000030E3 B00B                <1> 	mov	al, 0Bh  ; In-Service Register
 10407 000030E5 E6A0                <1> 	out	0A0h, al
 10408 000030E7 EB00                <1>         jmp short $+2
 10409 000030E9 EB00                <1> 	jmp short $+2
 10410 000030EB E4A0                <1> 	in	al, 0A0h
 10411 000030ED 2480                <1> 	and 	al, 80h ; bit 7 (is it real IRQ 15 or fake?)
 10412 000030EF 74ED                <1> 	jz	short irq15_iret ; Fake (spurious)IRQ, do not send EOI)
 10413                              <1> 	;
 10414 000030F1 1E                  <1> 	PUSH	DS
 10415                              <1> 	;CALL	DDS
 10416                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
 10417 000030F2 66B81000            <1> 	mov	ax, KDATA
 10418 000030F6 8ED8                <1> 	mov 	ds, ax
 10419                              <1> 	;
 10420                              <1> 	;;MOV	@HF_INT_FLAG,0FFH	; ALL DONE
 10421                              <1>         ;or      byte [CS:HF_INT_FLAG],0C0h 
 10422 000030F8 800D[DFA20000]C0    <1> 	or	byte [HF_INT_FLAG], 0C0h
 10423                              <1> 	;
 10424 000030FF 6652                <1> 	push	dx
 10425 00003101 66BA7701            <1> 	mov	dx, HDC2_BASEPORT+7	; Status Register (177h)
 10426                              <1> 					; Clear Controller (Award BIOS 1999)
 10427 00003105 EBC9                <1> 	jmp	short Clear_IRQ1415
 10428                              <1> 
 10429                              <1> 
 10430                              <1> ;%include 'diskdata.inc' ; 11/03/2015
 10431                              <1> ;%include 'diskbss.inc' ; 11/03/2015
 10432                              <1> 
 10433                              <1> 
 10434                              <1> ;////////////////////////////////////////////////////////////////////
 10435                              <1> ;; END OF DISK I/O SYTEM ///
 10436                                  %include 'memory.s'  ; 09/03/2015
 10437                              <1> ; ****************************************************************************
 10438                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - memory.s
 10439                              <1> ; ----------------------------------------------------------------------------
 10440                              <1> ; Last Update: 24/01/2016
 10441                              <1> ; ----------------------------------------------------------------------------
 10442                              <1> ; Beginning: 24/01/2016
 10443                              <1> ; ----------------------------------------------------------------------------
 10444                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 10445                              <1> ; ----------------------------------------------------------------------------
 10446                              <1> ; Turkish Rational DOS
 10447                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 10448                              <1> ;
 10449                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 10450                              <1> ; memory.inc (18/10/2015)
 10451                              <1> ; ****************************************************************************
 10452                              <1> 
 10453                              <1> ; MEMORY.ASM - Retro UNIX 386 v1 MEMORY MANAGEMENT FUNCTIONS (PROCEDURES)
 10454                              <1> ; Retro UNIX 386 v1 Kernel (unix386.s, v0.2.0.14) - MEMORY.INC
 10455                              <1> ; Last Modification: 18/10/2015
 10456                              <1> 
 10457                              <1> ; ///////// MEMORY MANAGEMENT FUNCTIONS (PROCEDURES) ///////////////
 10458                              <1> 
 10459                              <1> ;;04/11/2014 (unix386.s)	
 10460                              <1> ;PDE_A_PRESENT	equ	1		; Present flag for PDE
 10461                              <1> ;PDE_A_WRITE	equ 	2		; Writable (write permission) flag
 10462                              <1> ;PDE_A_USER	equ	4		; User (non-system/kernel) page flag
 10463                              <1> ;;
 10464                              <1> ;PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
 10465                              <1> ;PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
 10466                              <1> ;PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
 10467                              <1> ;PTE_A_ACCESS   equ	32		; Accessed flag (bit 5) ; 09/03/2015
 10468                              <1> 
 10469                              <1> ; 27/04/2015
 10470                              <1> ; 09/03/2015
 10471                              <1> PAGE_SIZE 	equ 4096		; page size in bytes
 10472                              <1> PAGE_SHIFT 	equ 12			; page table shift count
 10473                              <1> PAGE_D_SHIFT 	equ 22	; 12 + 10	; page directory shift count
 10474                              <1> PAGE_OFF	equ 0FFFh		; 12 bit byte offset in page frame
 10475                              <1> PTE_MASK 	equ 03FFh		; page table entry mask
 10476                              <1> PTE_DUPLICATED  equ 200h		; duplicated page sign (AVL bit 0)
 10477                              <1> PDE_A_CLEAR	equ 0F000h		; to clear PDE attribute bits
 10478                              <1> PTE_A_CLEAR	equ 0F000h		; to clear PTE attribute bits
 10479                              <1> LOGIC_SECT_SIZE equ 512			; logical sector size
 10480                              <1> ERR_MAJOR_PF	equ 0E0h		; major error: page fault
 10481                              <1> ERR_MINOR_IM	equ 1			; insufficient (out of) memory
 10482                              <1> ERR_MINOR_DSK	equ 2			; disk read/write error
 10483                              <1> ERR_MINOR_PV	equ 3			; protection violation
 10484                              <1> SWP_DISK_READ_ERR equ 4
 10485                              <1> SWP_DISK_NOT_PRESENT_ERR equ 5
 10486                              <1> SWP_SECTOR_NOT_PRESENT_ERR equ 6
 10487                              <1> SWP_NO_FREE_SPACE_ERR equ 7
 10488                              <1> SWP_DISK_WRITE_ERR equ 8
 10489                              <1> SWP_NO_PAGE_TO_SWAP_ERR equ 9
 10490                              <1> PTE_A_ACCESS_BIT equ 5  ; Bit 5 (accessed flag)        
 10491                              <1> SECTOR_SHIFT    equ 3   ; sector shift (to convert page block number)
 10492                              <1> 
 10493                              <1> ;
 10494                              <1> ;; Retro Unix 386 v1 - paging method/principles
 10495                              <1> ;;
 10496                              <1> ;; 10/10/2014
 10497                              <1> ;; RETRO UNIX 386 v1 - PAGING METHOD/PRINCIPLES
 10498                              <1> ;;
 10499                              <1> ;; KERNEL PAGE MAP: 1 to 1 physical memory page map
 10500                              <1> ;;	(virtual address = physical address)
 10501                              <1> ;; KERNEL PAGE TABLES:
 10502                              <1> ;;	Kernel page directory and all page tables are
 10503                              <1> ;;	on memory as initialized, as equal to physical memory
 10504                              <1> ;;	layout. Kernel pages can/must not be swapped out/in.
 10505                              <1> ;;
 10506                              <1> ;;	what for: User pages may be swapped out, when accessing
 10507                              <1> ;;	a page in kernel/system mode, if it would be swapped out,
 10508                              <1> ;;	kernel would have to swap it in! But it is also may be
 10509                              <1> ;;	in use by a user process. (In system/kernel mode
 10510                              <1> ;;	kernel can access all memory pages even if they are
 10511                              <1> ;;	reserved/allocated for user processes. Swap out/in would
 10512                              <1> ;;	cause conflicts.) 
 10513                              <1> ;;	
 10514                              <1> ;;	As result of these conditions,
 10515                              <1> ;;	all kernel pages must be initialized as equal to 
 10516                              <1> ;;	physical layout for preventing page faults. 
 10517                              <1> ;;	Also, calling "allocate page" procedure after
 10518                              <1> ;;	a page fault can cause another page fault (double fault)
 10519                              <1> ;;	if all kernel page tables would not be initialized.
 10520                              <1> ;;
 10521                              <1> ;;	[first_page] = Beginning of users space, as offset to 
 10522                              <1> ;;	memory allocation table. (double word aligned)
 10523                              <1> ;;
 10524                              <1> ;;	[next_page] = first/next free space to be searched
 10525                              <1> ;;	as offset to memory allocation table. (dw aligned)
 10526                              <1> ;;
 10527                              <1> ;;	[last_page] = End of memory (users space), as offset
 10528                              <1> ;;	to memory allocation table. (double word aligned)
 10529                              <1> ;;
 10530                              <1> ;; USER PAGE TABLES:
 10531                              <1> ;;	Demand paging (& 'copy on write' allocation method) ...
 10532                              <1> ;;		'ready only' marked copies of the 
 10533                              <1> ;;		parent process's page table entries (for
 10534                              <1> ;;		same physical memory).
 10535                              <1> ;;		(A page will be copied to a new page after
 10536                              <1> ;;		 if it causes R/W page fault.)
 10537                              <1> ;;
 10538                              <1> ;;	Every user process has own (different)
 10539                              <1> ;;	page directory and page tables.	
 10540                              <1> ;;
 10541                              <1> ;;	Code starts at virtual address 0, always.
 10542                              <1> ;;	(Initial value of EIP is 0 in user mode.)
 10543                              <1> ;;	(Programs can be written/developed as simple
 10544                              <1> ;;	 flat memory programs.)
 10545                              <1> ;;
 10546                              <1> ;; MEMORY ALLOCATION STRATEGY:
 10547                              <1> ;;	Memory page will be allocated by kernel only 
 10548                              <1> ;;		(in kernel/system mode only).
 10549                              <1> ;;	* After a
 10550                              <1> ;;	  - 'not present' page fault
 10551                              <1> ;;	  - 'writing attempt on read only page' page fault 	 	
 10552                              <1> ;;	* For loading (opening, reading) a file or disk/drive
 10553                              <1> ;;	* As responce to 'allocate additional memory blocks' 
 10554                              <1> ;;	  request by running process.
 10555                              <1> ;;	* While creating a process, allocating a new buffer,
 10556                              <1> ;;	  new page tables etc.
 10557                              <1> ;;
 10558                              <1> ;;	At first,
 10559                              <1> ;;	- 'allocate page' procedure will be called;
 10560                              <1> ;,	   if it will return with a valid (>0) physical address
 10561                              <1> ;;	   (that means the relevant M.A.T. bit has been RESET)	
 10562                              <1> ;;	   relevant memory page/block will be cleared (zeroed).
 10563                              <1> ;;	- 'allocate page' will be called for allocating page
 10564                              <1> ;;	   directory, page table and running space (data/code).
 10565                              <1> ;;	- every successful 'allocate page' call will decrease
 10566                              <1> ;;	  'free_pages' count (pointer).
 10567                              <1> ;;	- 'out of (insufficient) memory error' will be returned
 10568                              <1> ;;	  if 'free_pages' points to a ZERO.
 10569                              <1> ;;	- swapping out and swapping in (if it is not a new page)
 10570                              <1> ;;	  procedures will be called as responce to 'out of memory'
 10571                              <1> ;;	  error except errors caused by attribute conflicts.
 10572                              <1> ;;	 (swapper functions)	 
 10573                              <1> ;;					
 10574                              <1> ;;	At second,
 10575                              <1> ;;	- page directory entry will be updated then page table
 10576                              <1> ;;	  entry will be updated.		
 10577                              <1> ;;
 10578                              <1> ;; MEMORY ALLOCATION TABLE FORMAT:
 10579                              <1> ;;	- M.A.T. has a size according to available memory as
 10580                              <1> ;;	  follows:
 10581                              <1> ;;		  - 1 (allocation) bit per 1 page (4096 bytes)
 10582                              <1> ;;		  - a bit with value of 0 means allocated page
 10583                              <1> ;;		  - a bit with value of 1 means a free page
 10584                              <1> ;,	- 'free_pages' pointer holds count of free pages
 10585                              <1> ;;	  depending on M.A.T.
 10586                              <1> ;;		(NOTE: Free page count will not be checked
 10587                              <1> ;;		again -on M.A.T.- after initialization. 
 10588                              <1> ;;		Kernel will trust on initial count.)
 10589                              <1> ;,	- 'free_pages' count will be decreased by allocation
 10590                              <1> ;;	  and it will be increased by deallocation procedures.
 10591                              <1> ;;	
 10592                              <1> ;;	- Available memory will be calculated during
 10593                              <1> ;;	  the kernel's initialization stage (in real mode).
 10594                              <1> ;;	  Memory allocation table and kernel page tables 
 10595                              <1> ;;	  will be formatted/sized as result of available
 10596                              <1> ;;	  memory calculation before paging is enabled.
 10597                              <1> ;;
 10598                              <1> ;; For 4GB Available/Present Memory: (max. possible memory size)
 10599                              <1> ;;	- Memory Allocation Table size will be 128 KB.
 10600                              <1> ;;	- Memory allocation for kernel page directory size 
 10601                              <1> ;;	  is always 4 KB. (in addition to total allocation size
 10602                              <1> ;;	  for page tables)
 10603                              <1> ;;	- Memory allocation for kernel page tables (1024 tables)
 10604                              <1> ;;	  is 4 MB (1024*4*1024 bytes).
 10605                              <1> ;;	- User (available) space will be started 
 10606                              <1> ;;	  at 6th MB of the memory (after 1MB+4MB).
 10607                              <1> ;;	- The first 640 KB is for kernel's itself plus
 10608                              <1> ;;	  memory allocation table and kernel's page directory
 10609                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
 10610                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
 10611                              <1> ;; 	  for buffers.
 10612                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
 10613                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
 10614                              <1> ;;	- Kernel page tables start at 100000h (2nd MB)
 10615                              <1> ;;
 10616                              <1> ;; For 1GB Available Memory:
 10617                              <1> ;;	- Memory Allocation Table size will be 32 KB.
 10618                              <1> ;;	- Memory allocation for kernel page directory size 
 10619                              <1> ;;	  is always 4 KB. (in addition to total allocation size
 10620                              <1> ;;	  for page tables)
 10621                              <1> ;;	- Memory allocation for kernel page tables (256 tables)
 10622                              <1> ;;	  is 1 MB (256*4*1024 bytes).
 10623                              <1> ;;	- User (available) space will be started 
 10624                              <1> ;;	  at 3th MB of the memory (after 1MB+1MB).
 10625                              <1> ;;	- The first 640 KB is for kernel's itself plus
 10626                              <1> ;;	  memory allocation table and kernel's page directory
 10627                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
 10628                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
 10629                              <1> ;; 	  for buffers.
 10630                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
 10631                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
 10632                              <1> ;;	- Kernel page tables start at 100000h (2nd MB).	
 10633                              <1> ;;
 10634                              <1> ;;
 10635                              <1> 
 10636                              <1> 
 10637                              <1> ;;************************************************************************************
 10638                              <1> ;; 
 10639                              <1> ;; RETRO UNIX 386 v1 - Paging (Method for Copy On Write paging principle)
 10640                              <1> ;; DEMAND PAGING - PARENT&CHILD PAGE TABLE DUPLICATION PRINCIPLES (23/04/2015)
 10641                              <1> 
 10642                              <1> ;; Main factor: "sys fork" system call 
 10643                              <1> ;;	
 10644                              <1> ;; 		FORK
 10645                              <1> ;;                      |----> parent - duplicated PTEs, read only pages
 10646                              <1> ;;  writable pages ---->|
 10647                              <1> ;;                      |----> child - duplicated PTEs, read only pages
 10648                              <1> ;; 
 10649                              <1> ;; AVL bit (0) of Page Table Entry is used as duplication sign 
 10650                              <1> ;; 
 10651                              <1> ;; AVL Bit 0 [PTE Bit 9] = 'Duplicated PTE belongs to child' sign/flag (if it is set)
 10652                              <1> ;; Note: Dirty bit (PTE bit 6) may be used instead of AVL bit 0 (PTE bit 9)
 10653                              <1> ;;       -while R/W bit is 0-. 
 10654                              <1> ;; 
 10655                              <1> ;; Duplicate page tables with writable pages (the 1st sys fork in the process):
 10656                              <1> ;; # Parent's Page Table Entries are updated to point same pages as read only, 
 10657                              <1> ;;   as duplicated PTE bit  -AVL bit 0, PTE bit 9- are reset/clear.
 10658                              <1> ;; # Then Parent's Page Table is copied to Child's Page Table.
 10659                              <1> ;; # Child's Page Table Entries are updated as duplicated child bit
 10660                              <1> ;;   -AVL bit 0, PTE bit 9- is set.	  
 10661                              <1> ;; 
 10662                              <1> ;; Duplicate page tables with read only pages (several sys fork system calls):
 10663                              <1> ;; # Parent's read only pages are copied to new child pages. 
 10664                              <1> ;;   Parent's PTE attributes are not changed.
 10665                              <1> ;;   (Because, there is another parent-child fork before this fork! We must not
 10666                              <1> ;;    destroy/mix previous fork result).
 10667                              <1> ;; # Child's Page Table Entries (which are corresponding to Parent's 
 10668                              <1> ;;   read only pages) are set as writable (while duplicated PTE bit is clear). 
 10669                              <1> ;; # Parent's PTEs with writable page attribute are updated to point same pages 
 10670                              <1> ;;   as read only, (while) duplicated PTE bit is reset (clear).
 10671                              <1> ;; # Parent's Page Table Entries (with writable page attribute) are duplicated 
 10672                              <1> ;;   as Child's Page Table Entries without copying actual page.
 10673                              <1> ;; # Child 's Page Table Entries (which are corresponding to Parent's writable 
 10674                              <1> ;;   pages) are updated as duplicated PTE bit (AVL bit 0, PTE bit 9- is set.
 10675                              <1> ;; 
 10676                              <1> ;; !? WHAT FOR (duplication after duplication):
 10677                              <1> ;; In UNIX method for sys fork (a typical 'fork' application in /etc/init)
 10678                              <1> ;; program/executable code continues from specified location as child process, 
 10679                              <1> ;; returns back previous code location as parent process, every child after 
 10680                              <1> ;; every sys fork uses last image of code and data just prior the fork.
 10681                              <1> ;; Even if the parent code changes data, the child will not see the changed data 
 10682                              <1> ;; after the fork. In Retro UNIX 8086 v1, parent's process segment (32KB)
 10683                              <1> ;; was copied to child's process segment (all of code and data) according to
 10684                              <1> ;; original UNIX v1 which copies all of parent process code and data -core- 
 10685                              <1> ;; to child space -core- but swaps that core image -of child- on to disk.
 10686                              <1> ;; If I (Erdogan Tan) would use a method of to copy parent's core
 10687                              <1> ;; (complete running image of parent process) to the child process; 
 10688                              <1> ;; for big sizes, i would force Retro UNIX 386 v1 to spend many memory pages 
 10689                              <1> ;; and times only for a sys fork. (It would excessive reservation for sys fork,
 10690                              <1> ;; because sys fork usually is prior to sys exec; sys exec always establishes
 10691                              <1> ;; a new/fresh core -running space-, by clearing all code/data content). 
 10692                              <1> ;; 'Read Only' page flag ensures page fault handler is needed only for a few write
 10693                              <1> ;; attempts between sys fork and sys exec, not more... (I say so by thinking 
 10694                              <1> ;; of "/etc/init" content, specially.) sys exec will clear page tables and
 10695                              <1> ;; new/fresh pages will be used to load and run new executable/program.
 10696                              <1> ;; That is what for i have preferred "copy on write", "duplication" method
 10697                              <1> ;; for sharing same read only pages between parent and child processes.
 10698                              <1> ;; That is a pitty i have to use new private flag (AVL bit 0, "duplicated PTE 
 10699                              <1> ;; belongs to child" sign) for cooperation on duplicated pages between a parent 
 10700                              <1> ;; and it's child processes; otherwise parent process would destroy data belongs
 10701                              <1> ;; to its child or vice versa; or some pages would remain unclaimed 
 10702                              <1> ;; -deallocation problem-.
 10703                              <1> ;; Note: to prevent conflicts, read only pages must not be swapped out... 
 10704                              <1> ;; 
 10705                              <1> ;; WHEN PARENT TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
 10706                              <1> ;; # Page fault handler will do those:
 10707                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
 10708                              <1> ;;   - If it is reset/clear, there is a child uses same page.
 10709                              <1> ;;   - Parent's read only page -previous page- is copied to a new writable page. 
 10710                              <1> ;;   - Parent's PTE is updated as writable page, as unique page (AVL=0)
 10711                              <1> ;;   - (Page fault handler whill check this PTE later, if child process causes to
 10712                              <1> ;;     page fault due to write attempt on read only page. Of course, the previous 
 10713                              <1> ;;     read only page will be converted to writable and unique page which belongs
 10714                              <1> ;;     to child process.)	
 10715                              <1> ;; WHEN CHILD TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
 10716                              <1> ;; # Page fault handler will do those:
 10717                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
 10718                              <1> ;;   - If it is set, there is a parent uses -or was using- same page.
 10719                              <1> ;;   - Same PTE address within parent's page table is checked if it has same page
 10720                              <1> ;;     address or not. 
 10721                              <1> ;;   - If parent's PTE has same address, child will continue with a new writable page.
 10722                              <1> ;;     Parent's PTE will point to same (previous) page as writable, unique (AVL=0).	
 10723                              <1> ;;   - If parent's PTE has different address, child will continue with it's 
 10724                              <1> ;;     own/same page but read only flag (0) will be changed to writable flag (1) and
 10725                              <1> ;;     'duplicated PTE (belongs to child)' flag/sign will be cleared/reset. 	  	
 10726                              <1> ;; 
 10727                              <1> ;; NOTE: When a child process is terminated, read only flags of parent's page tables
 10728                              <1> ;;       will be set as writable (and unique) in case of child process was using 
 10729                              <1> ;;       same pages with duplicated child PTE sign... Depending on sys fork and 
 10730                              <1> ;;       duplication method details, it is not possible multiple child processes
 10731                              <1> ;;       were using same page with duplicated PTEs.
 10732                              <1> ;; 
 10733                              <1> ;;************************************************************************************   
 10734                              <1> 
 10735                              <1> ;; 08/10/2014
 10736                              <1> ;; 11/09/2014 - Retro UNIX 386 v1 PAGING (further) draft
 10737                              <1> ;;		by Erdogan Tan (Based on KolibriOS 'memory.inc')
 10738                              <1> 
 10739                              <1> ;; 'allocate_page' code is derived and modified from KolibriOS
 10740                              <1> ;; 'alloc_page' procedure in 'memory.inc' 
 10741                              <1> ;; (25/08/2014, Revision: 5057) file 
 10742                              <1> ;; by KolibriOS Team (2004-2012)
 10743                              <1> 
 10744                              <1> allocate_page:
 10745                              <1> 	; 01/07/2015
 10746                              <1> 	; 05/05/2015
 10747                              <1> 	; 30/04/2015
 10748                              <1> 	; 16/10/2014
 10749                              <1> 	; 08/10/2014
 10750                              <1> 	; 09/09/2014 (Retro UNIX 386 v1 - beginning)
 10751                              <1> 	;
 10752                              <1> 	; INPUT -> none
 10753                              <1> 	;
 10754                              <1> 	; OUTPUT ->
 10755                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 10756                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is RESET)
 10757                              <1> 	;
 10758                              <1> 	;	CF = 1 and EAX = 0 
 10759                              <1> 	; 		   if there is not a free page to be allocated	
 10760                              <1> 	;
 10761                              <1> 	; Modified Registers -> none (except EAX)
 10762                              <1> 	;
 10763 00003107 A1[50A20000]        <1> 	mov	eax, [free_pages]
 10764 0000310C 21C0                <1> 	and	eax, eax
 10765 0000310E 7438                <1> 	jz	short out_of_memory
 10766                              <1> 	;
 10767 00003110 53                  <1> 	push	ebx
 10768 00003111 51                  <1> 	push	ecx
 10769                              <1> 	;
 10770 00003112 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table offset
 10771 00003117 89D9                <1> 	mov	ecx, ebx
 10772                              <1>  				     ; NOTE: 32 (first_page) is initial
 10773                              <1> 				     ; value of [next_page].
 10774                              <1> 				     ; It points to the first available
 10775                              <1> 				     ; page block for users (ring 3) ...	
 10776                              <1> 				     ; (MAT offset 32 = 1024/32)	
 10777                              <1> 				     ; (at the of the first 4 MB)		
 10778 00003119 031D[54A20000]      <1> 	add	ebx, [next_page] ; Free page searching starts from here
 10779                              <1> 				 ; next_free_page >> 5
 10780 0000311F 030D[58A20000]      <1> 	add	ecx, [last_page] ; Free page searching ends here
 10781                              <1> 				 ; (total_pages - 1) >> 5
 10782                              <1> al_p_scan:
 10783 00003125 39CB                <1> 	cmp	ebx, ecx
 10784 00003127 770A                <1> 	ja	short al_p_notfound
 10785                              <1> 	;
 10786                              <1> 	; 01/07/2015
 10787                              <1> 	; AMD64 Architecture Programmers Manual
 10788                              <1> 	; Volume 3:
 10789                              <1> 	; General-Purpose and System Instructions
 10790                              <1> 	;
 10791                              <1> 	; BSF - Bit Scan Forward
 10792                              <1> 	;
 10793                              <1> 	;   Searches the value in a register or a memory location
 10794                              <1> 	;   (second operand) for the least-significant set bit. 
 10795                              <1> 	;   If a set bit is found, the instruction clears the zero flag (ZF)
 10796                              <1> 	;   and stores the index of the least-significant set bit in a destination
 10797                              <1> 	;   register (first operand). If the second operand contains 0, 
 10798                              <1> 	;   the instruction sets ZF to 1 and does not change the contents of the 
 10799                              <1> 	;   destination register. The bit index is an unsigned offset from bit 0 
 10800                              <1> 	;   of the searched value
 10801                              <1> 	;
 10802 00003129 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
 10803                              <1> 			   ; Clear ZF if a bit is found set (1) and 
 10804                              <1> 			   ; loads the destination with an index to
 10805                              <1> 			   ; first set bit. (0 -> 31) 
 10806                              <1> 			   ; Sets ZF to 1 if no bits are found set.
 10807 0000312C 7525                <1> 	jnz	short al_p_found ; ZF = 0 -> a free page has been found
 10808                              <1> 			 ;
 10809                              <1> 			 ; NOTE:  a Memory Allocation Table bit 
 10810                              <1> 			 ;	  with value of 1 means 
 10811                              <1> 			 ;	  the corresponding page is free 
 10812                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
 10813 0000312E 83C304              <1> 	add	ebx, 4
 10814                              <1> 			 ; We return back for searching next page block
 10815                              <1> 			 ; NOTE: [free_pages] is not ZERO; so, 
 10816                              <1> 			 ;	 we always will find at least 1 free page here.
 10817 00003131 EBF2                <1>         jmp     short al_p_scan
 10818                              <1> 	;
 10819                              <1> al_p_notfound:
 10820 00003133 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
 10821 00003139 890D[54A20000]      <1> 	mov	[next_page], ecx ; next/first free page = last page 
 10822                              <1> 				 ; (deallocate_page procedure will change it)
 10823 0000313F 31C0                <1> 	xor	eax, eax
 10824 00003141 A3[50A20000]        <1> 	mov	[free_pages], eax ; 0
 10825 00003146 59                  <1> 	pop	ecx
 10826 00003147 5B                  <1> 	pop	ebx
 10827                              <1> 	;
 10828                              <1> out_of_memory:
 10829 00003148 E857040000          <1> 	call	swap_out
 10830 0000314D 7325                <1> 	jnc	short al_p_ok  ; [free_pages] = 0, re-allocation by swap_out
 10831                              <1> 	;
 10832 0000314F 29C0                <1> 	sub 	eax, eax ; 0
 10833 00003151 F9                  <1> 	stc
 10834 00003152 C3                  <1> 	retn
 10835                              <1> 
 10836                              <1> al_p_found:
 10837 00003153 89D9                <1> 	mov	ecx, ebx
 10838 00003155 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
 10839 0000315B 890D[54A20000]      <1> 	mov	[next_page], ecx ; Set first free page searching start
 10840                              <1> 				 ; address/offset (to the next)
 10841 00003161 FF0D[50A20000]      <1>         dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
 10842                              <1> 	;
 10843 00003167 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 10844                              <1> 				 ; is copied into the Carry Flag and then cleared
 10845                              <1> 				 ; in the destination.
 10846                              <1> 				 ;
 10847                              <1> 				 ; Reset the bit which is corresponding to the 
 10848                              <1> 				 ; (just) allocated page.
 10849                              <1> 	; 01/07/2015 (4*8 = 32, 1 allocation byte = 8 pages)	
 10850 0000316A C1E103              <1> 	shl	ecx, 3		 ; (page block offset * 32) + page index
 10851 0000316D 01C8                <1> 	add	eax, ecx	 ; = page number
 10852 0000316F C1E00C              <1> 	shl	eax, 12		 ; physical address of the page (flat/real value)
 10853                              <1> 	; EAX = physical address of memory page
 10854                              <1> 	;
 10855                              <1> 	; NOTE: The relevant page directory and page table entry will be updated
 10856                              <1> 	;       according to this EAX value...
 10857 00003172 59                  <1> 	pop	ecx
 10858 00003173 5B                  <1> 	pop	ebx
 10859                              <1> al_p_ok:
 10860 00003174 C3                  <1> 	retn
 10861                              <1> 
 10862                              <1> 
 10863                              <1> make_page_dir:
 10864                              <1> 	; 18/04/2015
 10865                              <1> 	; 12/04/2015
 10866                              <1> 	; 23/10/2014
 10867                              <1> 	; 16/10/2014
 10868                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10869                              <1> 	;
 10870                              <1> 	; INPUT ->
 10871                              <1> 	;	none
 10872                              <1> 	; OUTPUT ->
 10873                              <1> 	;	(EAX = 0)
 10874                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10875                              <1> 	;	cf = 0 ->
 10876                              <1> 	;	u.pgdir = page directory (physical) address of the current
 10877                              <1> 	;		  process/user.
 10878                              <1> 	;
 10879                              <1> 	; Modified Registers -> EAX
 10880                              <1> 	;
 10881 00003175 E88DFFFFFF          <1> 	call	allocate_page
 10882 0000317A 7216                <1> 	jc	short mkpd_error
 10883                              <1> 	;
 10884 0000317C A3[69B10000]        <1> 	mov	[u.pgdir], eax    ; Page dir address for current user/process
 10885                              <1> 				  ; (Physical address)
 10886                              <1> clear_page:
 10887                              <1> 	; 18/04/2015
 10888                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10889                              <1> 	;
 10890                              <1> 	; INPUT ->
 10891                              <1> 	;	EAX = physical address of the page
 10892                              <1> 	; OUTPUT ->
 10893                              <1> 	;	all bytes of the page will be cleared
 10894                              <1> 	;
 10895                              <1> 	; Modified Registers -> none
 10896                              <1> 	;
 10897 00003181 57                  <1> 	push	edi
 10898 00003182 51                  <1> 	push	ecx
 10899 00003183 50                  <1> 	push	eax
 10900 00003184 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
 10901 00003189 89C7                <1> 	mov	edi, eax
 10902 0000318B 31C0                <1> 	xor	eax, eax
 10903 0000318D F3AB                <1> 	rep	stosd
 10904 0000318F 58                  <1> 	pop	eax
 10905 00003190 59                  <1> 	pop	ecx
 10906 00003191 5F                  <1> 	pop	edi
 10907                              <1> mkpd_error:
 10908                              <1> mkpt_error:
 10909 00003192 C3                  <1> 	retn
 10910                              <1> 
 10911                              <1> make_page_table:
 10912                              <1> 	; 23/06/2015
 10913                              <1> 	; 18/04/2015
 10914                              <1> 	; 12/04/2015
 10915                              <1> 	; 16/10/2014
 10916                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10917                              <1> 	;
 10918                              <1> 	; INPUT ->
 10919                              <1> 	;	EBX = virtual (linear) address
 10920                              <1> 	;	ECX = page table attributes (lower 12 bits)
 10921                              <1> 	;	      (higher 20 bits must be ZERO)
 10922                              <1> 	;	      (bit 0 must be 1)	 
 10923                              <1> 	;	u.pgdir = page directory (physical) address
 10924                              <1> 	; OUTPUT ->
 10925                              <1> 	;	EDX = Page directory entry address
 10926                              <1> 	;	EAX = Page table address
 10927                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10928                              <1> 	;	cf = 0 -> page table address in the PDE (EDX)
 10929                              <1> 	;
 10930                              <1> 	; Modified Registers -> EAX, EDX
 10931                              <1> 	;
 10932 00003193 E86FFFFFFF          <1> 	call	allocate_page
 10933 00003198 72F8                <1> 	jc	short mkpt_error
 10934 0000319A E811000000          <1> 	call	set_pde	
 10935 0000319F EBE0                <1> 	jmp	short clear_page
 10936                              <1> 
 10937                              <1> make_page:
 10938                              <1> 	; 24/07/2015
 10939                              <1> 	; 23/06/2015 ; (Retro UNIX 386 v1 - beginning)
 10940                              <1> 	;
 10941                              <1> 	; INPUT ->
 10942                              <1> 	;	EBX = virtual (linear) address
 10943                              <1> 	;	ECX = page attributes (lower 12 bits)
 10944                              <1> 	;	      (higher 20 bits must be ZERO)
 10945                              <1> 	;	      (bit 0 must be 1)	 
 10946                              <1> 	;	u.pgdir = page directory (physical) address
 10947                              <1> 	; OUTPUT ->
 10948                              <1> 	;	EBX = Virtual address
 10949                              <1> 	;	(EDX = PTE value)
 10950                              <1> 	;	EAX = Physical address
 10951                              <1> 	;	cf = 1 -> insufficient (out of) memory error
 10952                              <1> 	;
 10953                              <1> 	; Modified Registers -> EAX, EDX
 10954                              <1> 	;
 10955 000031A1 E861FFFFFF          <1> 	call	allocate_page
 10956 000031A6 7207                <1> 	jc	short mkp_err
 10957 000031A8 E821000000          <1> 	call	set_pte	
 10958 000031AD 73D2                <1> 	jnc	short clear_page ; 18/04/2015
 10959                              <1> mkp_err:
 10960 000031AF C3                  <1> 	retn
 10961                              <1> 
 10962                              <1> 
 10963                              <1> set_pde:	; Set page directory entry (PDE)
 10964                              <1> 	; 20/07/2015
 10965                              <1> 	; 18/04/2015
 10966                              <1> 	; 12/04/2015
 10967                              <1> 	; 23/10/2014
 10968                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 10969                              <1> 	;
 10970                              <1> 	; INPUT ->
 10971                              <1> 	;	EAX = physical address
 10972                              <1> 	;	      (use present value if EAX = 0)
 10973                              <1> 	;	EBX = virtual (linear) address
 10974                              <1> 	;	ECX = page table attributes (lower 12 bits)
 10975                              <1> 	;	      (higher 20 bits must be ZERO)
 10976                              <1> 	;	      (bit 0 must be 1)	 
 10977                              <1> 	;	u.pgdir = page directory (physical) address
 10978                              <1> 	; OUTPUT ->
 10979                              <1> 	;	EDX = PDE address
 10980                              <1> 	;	EAX = page table address (physical)
 10981                              <1> 	;	;(CF=1 -> Invalid page address)
 10982                              <1> 	;
 10983                              <1> 	; Modified Registers -> EDX
 10984                              <1> 	;
 10985 000031B0 89DA                <1> 	mov	edx, ebx
 10986 000031B2 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22
 10987 000031B5 C1E202              <1> 	shl	edx, 2 ; offset to page directory (1024*4)
 10988 000031B8 0315[69B10000]      <1> 	add	edx, [u.pgdir]
 10989                              <1> 	;
 10990 000031BE 21C0                <1> 	and	eax, eax
 10991 000031C0 7506                <1> 	jnz	short spde_1
 10992                              <1> 	;
 10993 000031C2 8B02                <1> 	mov	eax, [edx]  ; old PDE value
 10994                              <1> 	;test	al, 1
 10995                              <1> 	;jz	short spde_2
 10996 000031C4 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h  ; clear lower 12 bits
 10997                              <1> spde_1:
 10998                              <1> 	;and	cx, 0FFFh
 10999 000031C8 8902                <1> 	mov	[edx], eax
 11000 000031CA 66090A              <1> 	or	[edx], cx
 11001 000031CD C3                  <1> 	retn
 11002                              <1> ;spde_2: ; error
 11003                              <1> ;	stc
 11004                              <1> ;	retn
 11005                              <1> 
 11006                              <1> set_pte:	; Set page table entry (PTE)
 11007                              <1> 	; 24/07/2015
 11008                              <1> 	; 20/07/2015
 11009                              <1> 	; 23/06/2015
 11010                              <1> 	; 18/04/2015
 11011                              <1> 	; 12/04/2015
 11012                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11013                              <1> 	;
 11014                              <1> 	; INPUT ->
 11015                              <1> 	;	EAX = physical page address
 11016                              <1> 	;	      (use present value if EAX = 0)
 11017                              <1> 	;	EBX = virtual (linear) address
 11018                              <1> 	;	ECX = page attributes (lower 12 bits)
 11019                              <1> 	;	      (higher 20 bits must be ZERO)
 11020                              <1> 	;	      (bit 0 must be 1)	 
 11021                              <1> 	;	u.pgdir = page directory (physical) address
 11022                              <1> 	; OUTPUT ->
 11023                              <1> 	;	EAX = physical page address
 11024                              <1> 	;	(EDX = PTE value)
 11025                              <1> 	;	EBX = virtual address
 11026                              <1> 	;
 11027                              <1> 	;	CF = 1 -> error
 11028                              <1> 	;
 11029                              <1> 	; Modified Registers -> EAX, EDX
 11030                              <1> 	;
 11031 000031CE 50                  <1> 	push	eax
 11032 000031CF A1[69B10000]        <1> 	mov	eax, [u.pgdir] ; 20/07/2015
 11033 000031D4 E837000000          <1> 	call 	get_pde
 11034                              <1> 		; EDX = PDE address
 11035                              <1> 		; EAX = PDE value
 11036 000031D9 5A                  <1> 	pop	edx ; physical page address
 11037 000031DA 722A                <1> 	jc	short spte_err ; PDE not present
 11038                              <1> 	;
 11039 000031DC 53                  <1> 	push	ebx ; 24/07/2015
 11040 000031DD 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11041                              <1> 			    ; EDX = PT address (physical)	
 11042 000031E1 C1EB0C              <1> 	shr	ebx, PAGE_SHIFT ; 12
 11043 000031E4 81E3FF030000        <1> 	and	ebx, PTE_MASK	; 03FFh
 11044                              <1> 			 ; clear higher 10 bits (PD bits)
 11045 000031EA C1E302              <1> 	shl	ebx, 2   ; offset to page table (1024*4)
 11046 000031ED 01C3                <1> 	add	ebx, eax
 11047                              <1> 	;
 11048 000031EF 8B03                <1> 	mov	eax, [ebx] ; Old PTE value
 11049 000031F1 A801                <1> 	test	al, 1
 11050 000031F3 740C                <1> 	jz	short spte_0
 11051 000031F5 09D2                <1> 	or	edx, edx
 11052 000031F7 750F                <1> 	jnz	short spte_1
 11053 000031F9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11054 000031FD 89C2                <1> 	mov	edx, eax
 11055 000031FF EB09                <1> 	jmp	short spte_2	
 11056                              <1> spte_0:
 11057                              <1> 	; If this PTE contains a swap (disk) address,
 11058                              <1> 	; it can be updated by using 'swap_in' procedure
 11059                              <1> 	; only!
 11060 00003201 21C0                <1> 	and	eax, eax
 11061 00003203 7403                <1> 	jz	short spte_1
 11062                              <1> 	; 24/07/2015
 11063                              <1> 	; swapped page ! (on disk)
 11064 00003205 5B                  <1> 	pop	ebx
 11065                              <1> spte_err:
 11066 00003206 F9                  <1> 	stc
 11067 00003207 C3                  <1> 	retn
 11068                              <1> spte_1: 
 11069 00003208 89D0                <1> 	mov	eax, edx
 11070                              <1> spte_2:
 11071 0000320A 09CA                <1> 	or	edx, ecx
 11072                              <1> 	; 23/06/2015
 11073 0000320C 8913                <1> 	mov	[ebx], edx ; PTE value in EDX
 11074                              <1> 	; 24/07/2015
 11075 0000320E 5B                  <1> 	pop	ebx
 11076 0000320F C3                  <1> 	retn
 11077                              <1> 
 11078                              <1> get_pde:	; Get present value of the relevant PDE
 11079                              <1> 	; 20/07/2015
 11080                              <1> 	; 18/04/2015
 11081                              <1> 	; 12/04/2015
 11082                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11083                              <1> 	;
 11084                              <1> 	; INPUT ->
 11085                              <1> 	;	EBX = virtual (linear) address
 11086                              <1> 	;	EAX = page directory (physical) address
 11087                              <1> 	; OUTPUT ->
 11088                              <1> 	;	EDX = Page directory entry address
 11089                              <1> 	;	EAX = Page directory entry value
 11090                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
 11091                              <1> 	; Modified Registers -> EDX, EAX
 11092                              <1> 	;
 11093 00003210 89DA                <1> 	mov	edx, ebx
 11094 00003212 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22  (12+10)
 11095 00003215 C1E202              <1> 	shl 	edx, 2 ; offset to page directory (1024*4)
 11096 00003218 01C2                <1> 	add	edx, eax ; page directory address (physical)
 11097 0000321A 8B02                <1> 	mov	eax, [edx]
 11098 0000321C A801                <1> 	test	al, PDE_A_PRESENT ; page table is present or not !
 11099 0000321E 751F                <1> 	jnz	short gpte_retn
 11100 00003220 F9                  <1> 	stc
 11101                              <1> gpde_retn:	
 11102 00003221 C3                  <1> 	retn
 11103                              <1> 
 11104                              <1> get_pte:
 11105                              <1> 		; Get present value of the relevant PTE
 11106                              <1> 	; 29/07/2015
 11107                              <1> 	; 20/07/2015
 11108                              <1> 	; 18/04/2015
 11109                              <1> 	; 12/04/2015
 11110                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
 11111                              <1> 	;
 11112                              <1> 	; INPUT ->
 11113                              <1> 	;	EBX = virtual (linear) address
 11114                              <1> 	;	EAX = page directory (physical) address
 11115                              <1> 	; OUTPUT ->
 11116                              <1> 	;	EDX = Page table entry address (if CF=0)
 11117                              <1> 	;	      Page directory entry address (if CF=1)
 11118                              <1> 	;            (Bit 0 value is 0 if PT is not present)
 11119                              <1> 	;	EAX = Page table entry value (page address)
 11120                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
 11121                              <1> 	; Modified Registers -> EAX, EDX
 11122                              <1> 	;
 11123 00003222 E8E9FFFFFF          <1> 	call 	get_pde
 11124 00003227 72F8                <1> 	jc	short gpde_retn	; page table is not present
 11125                              <1> 	;jnc	short gpte_1
 11126                              <1> 	;retn
 11127                              <1> ;gpte_1:
 11128 00003229 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
 11129 0000322D 89DA                <1> 	mov	edx, ebx
 11130 0000322F C1EA0C              <1> 	shr	edx, PAGE_SHIFT ; 12
 11131 00003232 81E2FF030000        <1> 	and	edx, PTE_MASK	; 03FFh
 11132                              <1> 			 ; clear higher 10 bits (PD bits)
 11133 00003238 C1E202              <1> 	shl	edx, 2 ; offset from start of page table (1024*4)
 11134 0000323B 01C2                <1> 	add	edx, eax
 11135 0000323D 8B02                <1> 	mov	eax, [edx]
 11136                              <1> gpte_retn:
 11137 0000323F C3                  <1> 	retn
 11138                              <1> 
 11139                              <1> deallocate_page_dir:
 11140                              <1> 	; 15/09/2015
 11141                              <1> 	; 05/08/2015
 11142                              <1> 	; 30/04/2015
 11143                              <1> 	; 28/04/2015
 11144                              <1> 	; 17/10/2014
 11145                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11146                              <1> 	;
 11147                              <1> 	; INPUT ->
 11148                              <1> 	;	EAX = PHYSICAL ADDRESS OF THE PAGE DIRECTORY (CHILD)
 11149                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
 11150                              <1> 	; OUTPUT ->
 11151                              <1> 	;	All of page tables in the page directory
 11152                              <1> 	;	and page dir's itself will be deallocated
 11153                              <1> 	;	except 'read only' duplicated pages (will be converted
 11154                              <1> 	;	to writable pages).
 11155                              <1> 	;
 11156                              <1> 	; Modified Registers -> EAX
 11157                              <1> 	;
 11158                              <1> 	;
 11159 00003240 56                  <1> 	push	esi
 11160 00003241 51                  <1> 	push	ecx
 11161 00003242 50                  <1> 	push	eax
 11162 00003243 89C6                <1> 	mov	esi, eax 
 11163 00003245 31C9                <1> 	xor	ecx, ecx
 11164                              <1> 	; The 1st PDE points to Kernel Page Table 0 (the 1st 4MB),
 11165                              <1> 	; it must not be deallocated
 11166 00003247 890E                <1> 	mov	[esi], ecx ; 0 ; clear PDE 0
 11167                              <1> dapd_0:
 11168 00003249 AD                  <1> 	lodsd
 11169 0000324A A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
 11170 0000324C 7409                <1> 	jz	short dapd_1	
 11171 0000324E 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
 11172 00003252 E812000000          <1> 	call	deallocate_page_table			
 11173                              <1> dapd_1:
 11174 00003257 41                  <1> 	inc	ecx ; page directory entry index
 11175 00003258 81F900040000        <1> 	cmp	ecx, PAGE_SIZE / 4 ; 1024
 11176 0000325E 72E9                <1> 	jb	short dapd_0
 11177                              <1> dapd_2:
 11178 00003260 58                  <1> 	pop	eax
 11179 00003261 E879000000          <1> 	call	deallocate_page	; deallocate the page dir's itself
 11180 00003266 59                  <1> 	pop	ecx
 11181 00003267 5E                  <1> 	pop	esi
 11182 00003268 C3                  <1> 	retn
 11183                              <1> 
 11184                              <1> deallocate_page_table:
 11185                              <1> 	; 19/09/2015
 11186                              <1> 	; 15/09/2015
 11187                              <1> 	; 05/08/2015
 11188                              <1> 	; 30/04/2015
 11189                              <1> 	; 28/04/2015
 11190                              <1> 	; 24/10/2014
 11191                              <1> 	; 23/10/2014
 11192                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11193                              <1> 	;
 11194                              <1> 	; INPUT ->
 11195                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE PAGE TABLE
 11196                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
 11197                              <1> 	;	(ECX = page directory entry index)
 11198                              <1> 	; OUTPUT ->
 11199                              <1> 	;	All of pages in the page table and page table's itself
 11200                              <1> 	;	will be deallocated except 'read only' duplicated pages
 11201                              <1> 	;	(will be converted to writable pages).
 11202                              <1> 	;
 11203                              <1> 	; Modified Registers -> EAX
 11204                              <1> 	;
 11205 00003269 56                  <1> 	push	esi
 11206 0000326A 57                  <1> 	push	edi
 11207 0000326B 52                  <1> 	push	edx
 11208 0000326C 50                  <1> 	push	eax ; *
 11209 0000326D 89C6                <1> 	mov	esi, eax 
 11210 0000326F 31FF                <1> 	xor	edi, edi ; 0
 11211                              <1> dapt_0:
 11212 00003271 AD                  <1> 	lodsd
 11213 00003272 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
 11214 00003274 7441                <1> 	jz	short dapt_1
 11215                              <1> 	;
 11216 00003276 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
 11217                              <1> 				  ; (must be 1)
 11218 00003278 754C                <1> 	jnz	short dapt_3
 11219                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
 11220 0000327A 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
 11221                              <1> 				   ; as child's page ?
 11222 0000327E 744B                <1> 	jz	short dapt_4 ; Clear PTE but don't deallocate the page!
 11223                              <1> 	; check the parent's PTE value is read only & same page or not.. 
 11224                              <1> 	; ECX = page directory entry index (0-1023)
 11225 00003280 53                  <1> 	push	ebx
 11226 00003281 51                  <1> 	push	ecx
 11227 00003282 66C1E102            <1> 	shl	cx, 2 ; *4 
 11228 00003286 01CB                <1> 	add	ebx, ecx ; PDE offset (for the parent)
 11229 00003288 8B0B                <1> 	mov	ecx, [ebx]
 11230 0000328A F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
 11231 0000328D 7435                <1> 	jz	short dapt_2	; parent process does not use this page
 11232 0000328F 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
 11233                              <1> 	; EDI = page table entry index (0-1023)
 11234 00003294 89FA                <1> 	mov	edx, edi 
 11235 00003296 66C1E202            <1> 	shl	dx, 2 ; *4 
 11236 0000329A 01CA                <1> 	add	edx, ecx ; PTE offset (for the parent)
 11237 0000329C 8B1A                <1> 	mov	ebx, [edx]
 11238 0000329E F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
 11239 000032A1 7421                <1> 	jz	short dapt_2	; parent process does not use this page
 11240 000032A3 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
 11241 000032A7 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
 11242 000032AC 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
 11243 000032AE 7514                <1> 	jne	short dapt_2	; not same page
 11244                              <1> 				; deallocate the child's page
 11245 000032B0 800A02              <1>         or      byte [edx], PTE_A_WRITE ; convert to writable page (parent)
 11246 000032B3 59                  <1> 	pop	ecx
 11247 000032B4 5B                  <1> 	pop	ebx
 11248 000032B5 EB14                <1> 	jmp	short dapt_4
 11249                              <1> dapt_1:
 11250 000032B7 09C0                <1> 	or	eax, eax	; swapped page ?
 11251 000032B9 7417                <1> 	jz	short dapt_5	; no
 11252                              <1> 				; yes
 11253 000032BB D1E8                <1> 	shr	eax, 1
 11254 000032BD E848040000          <1> 	call	unlink_swap_block ; Deallocate swapped page block
 11255                              <1> 				  ; on the swap disk (or in file)
 11256 000032C2 EB0E                <1> 	jmp	short dapt_5
 11257                              <1> dapt_2:
 11258 000032C4 59                  <1> 	pop	ecx
 11259 000032C5 5B                  <1> 	pop	ebx
 11260                              <1> dapt_3:	
 11261                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
 11262 000032C6 E814000000          <1> 	call	deallocate_page
 11263                              <1> dapt_4:
 11264 000032CB C746FC00000000      <1> 	mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
 11265                              <1> dapt_5:
 11266 000032D2 47                  <1> 	inc	edi ; page table entry index
 11267 000032D3 81FF00040000        <1> 	cmp	edi, PAGE_SIZE / 4 ; 1024
 11268 000032D9 7296                <1> 	jb	short dapt_0
 11269                              <1> 	;
 11270 000032DB 58                  <1> 	pop	eax ; *
 11271 000032DC 5A                  <1> 	pop	edx
 11272 000032DD 5F                  <1> 	pop	edi	
 11273 000032DE 5E                  <1> 	pop	esi
 11274                              <1> 	;
 11275                              <1> 	;call	deallocate_page	; deallocate the page table's itself
 11276                              <1> 	;retn
 11277                              <1> 
 11278                              <1> deallocate_page:
 11279                              <1> 	; 15/09/2015
 11280                              <1> 	; 28/04/2015
 11281                              <1> 	; 10/03/2015
 11282                              <1> 	; 17/10/2014
 11283                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
 11284                              <1> 	;
 11285                              <1> 	; INPUT -> 
 11286                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 11287                              <1> 	; OUTPUT ->
 11288                              <1> 	;	[free_pages] is increased
 11289                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is SET)
 11290                              <1> 	;	CF = 1 if the page is already deallocated
 11291                              <1> 	; 	       (or not allocated) before.  
 11292                              <1> 	;
 11293                              <1> 	; Modified Registers -> EAX
 11294                              <1> 	;
 11295 000032DF 53                  <1> 	push	ebx
 11296 000032E0 52                  <1> 	push	edx
 11297                              <1> 	;
 11298 000032E1 C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; shift physical address to 
 11299                              <1> 				     ; 12 bits right
 11300                              <1> 				     ; to get page number
 11301 000032E4 89C2                <1> 	mov	edx, eax
 11302                              <1> 	; 15/09/2015
 11303 000032E6 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
 11304                              <1> 				     ; (1 allocation bit = 1 page)
 11305                              <1> 				     ; (1 allocation bytes = 8 pages)
 11306 000032E9 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 11307                              <1> 				     ; (to get 32 bit position)			
 11308                              <1> 	;
 11309 000032EC BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address
 11310 000032F1 01D3                <1> 	add	ebx, edx
 11311 000032F3 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
 11312                              <1> 				     ; (allocation bit position)	 
 11313 000032F6 3B15[54A20000]      <1> 	cmp 	edx, [next_page]     ; is the new free page address lower
 11314                              <1> 				     ; than the address in 'next_page' ?
 11315                              <1> 				     ; (next/first free page value)		
 11316 000032FC 7306                <1> 	jnb	short dap_1	     ; no	
 11317 000032FE 8915[54A20000]      <1> 	mov	[next_page], edx     ; yes
 11318                              <1> dap_1:
 11319 00003304 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
 11320                              <1> 				     ; set relevant bit to 1.
 11321                              <1> 				     ; set CF to the previous bit value	
 11322                              <1> 	;cmc			     ; complement carry flag	
 11323                              <1> 	;jc	short dap_2	     ; do not increase free_pages count
 11324                              <1> 				     ; if the page is already deallocated
 11325                              <1> 				     ; before.	
 11326 00003307 FF05[50A20000]      <1>         inc     dword [free_pages]
 11327                              <1> dap_2:
 11328 0000330D 5A                  <1> 	pop	edx
 11329 0000330E 5B                  <1> 	pop	ebx
 11330 0000330F C3                  <1> 	retn
 11331                              <1> 
 11332                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 11333                              <1> ;;                                                              ;;
 11334                              <1> ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
 11335                              <1> ;; Distributed under terms of the GNU General Public License    ;;
 11336                              <1> ;;                                                              ;;
 11337                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 11338                              <1> 
 11339                              <1> ;;$Revision: 5057 $
 11340                              <1> 
 11341                              <1> 
 11342                              <1> ;;align 4
 11343                              <1> ;;proc alloc_page
 11344                              <1> 
 11345                              <1> ;;        pushfd
 11346                              <1> ;;        cli
 11347                              <1> ;;        push    ebx
 11348                              <1> ;;;//-
 11349                              <1> ;;        cmp     [pg_data.pages_free], 1
 11350                              <1> ;;        jle     .out_of_memory
 11351                              <1> ;;;//-
 11352                              <1> ;;
 11353                              <1> ;;        mov     ebx, [page_start]
 11354                              <1> ;;        mov     ecx, [page_end]
 11355                              <1> ;;.l1:
 11356                              <1> ;;        bsf     eax, [ebx];
 11357                              <1> ;;        jnz     .found
 11358                              <1> ;;        add     ebx, 4
 11359                              <1> ;;        cmp     ebx, ecx
 11360                              <1> ;;        jb      .l1
 11361                              <1> ;;        pop     ebx
 11362                              <1> ;;        popfd
 11363                              <1> ;;        xor     eax, eax
 11364                              <1> ;;        ret
 11365                              <1> ;;.found:
 11366                              <1> ;;;//-
 11367                              <1> ;;        dec     [pg_data.pages_free]
 11368                              <1> ;;        jz      .out_of_memory
 11369                              <1> ;;;//-
 11370                              <1> ;;        btr     [ebx], eax
 11371                              <1> ;;        mov     [page_start], ebx
 11372                              <1> ;;        sub     ebx, sys_pgmap
 11373                              <1> ;;        lea     eax, [eax+ebx*8]
 11374                              <1> ;;        shl     eax, 12
 11375                              <1> ;;;//-       dec [pg_data.pages_free]
 11376                              <1> ;;        pop     ebx
 11377                              <1> ;;        popfd
 11378                              <1> ;;        ret
 11379                              <1> ;;;//-
 11380                              <1> ;;.out_of_memory:
 11381                              <1> ;;        mov     [pg_data.pages_free], 1
 11382                              <1> ;;        xor     eax, eax
 11383                              <1> ;;        pop     ebx
 11384                              <1> ;;        popfd
 11385                              <1> ;;        ret
 11386                              <1> ;;;//-
 11387                              <1> ;;endp
 11388                              <1> 
 11389                              <1> duplicate_page_dir:
 11390                              <1> 	; 21/09/2015
 11391                              <1> 	; 31/08/2015
 11392                              <1> 	; 20/07/2015
 11393                              <1> 	; 28/04/2015
 11394                              <1> 	; 27/04/2015
 11395                              <1> 	; 18/04/2015
 11396                              <1> 	; 12/04/2015
 11397                              <1> 	; 18/10/2014
 11398                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
 11399                              <1> 	;
 11400                              <1> 	; INPUT -> 
 11401                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
 11402                              <1> 	;		    page directory.
 11403                              <1> 	; OUTPUT ->
 11404                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
 11405                              <1> 	;	       page directory.
 11406                              <1> 	;	(New page directory with new page table entries.)
 11407                              <1> 	;	(New page tables with read only copies of the parent's
 11408                              <1> 	;	pages.)
 11409                              <1> 	;	EAX = 0 -> Error (CF = 1)
 11410                              <1> 	;
 11411                              <1> 	; Modified Registers -> none (except EAX)
 11412                              <1> 	;
 11413 00003310 E8F2FDFFFF          <1> 	call	allocate_page
 11414 00003315 723E                <1> 	jc	short dpd_err
 11415                              <1> 	;
 11416 00003317 55                  <1> 	push	ebp ; 20/07/2015
 11417 00003318 56                  <1> 	push	esi
 11418 00003319 57                  <1> 	push	edi
 11419 0000331A 53                  <1> 	push	ebx
 11420 0000331B 51                  <1> 	push	ecx
 11421 0000331C 8B35[69B10000]      <1> 	mov	esi, [u.pgdir]
 11422 00003322 89C7                <1> 	mov	edi, eax
 11423 00003324 50                  <1> 	push	eax ; save child's page directory address
 11424                              <1> 	; 31/08/2015
 11425                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
 11426                              <1> 	; (use same system space for all user page tables) 
 11427 00003325 A5                  <1> 	movsd
 11428 00003326 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
 11429 0000332B B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
 11430                              <1> dpd_0:	
 11431 00003330 AD                  <1> 	lodsd
 11432                              <1> 	;or	eax, eax
 11433                              <1>         ;jnz     short dpd_1
 11434 00003331 A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
 11435 00003333 7508                <1> 	jnz	short dpd_1
 11436                              <1>  	; 20/07/2015 (virtual address at the end of the page table)	
 11437 00003335 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
 11438 0000333B EB0F                <1> 	jmp	short dpd_2
 11439                              <1> dpd_1:	
 11440 0000333D 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
 11441 00003341 89C3                <1> 	mov	ebx, eax
 11442                              <1> 	; EBX = Parent's page table address
 11443 00003343 E81F000000          <1> 	call	duplicate_page_table
 11444 00003348 720C                <1> 	jc	short dpd_p_err
 11445                              <1> 	; EAX = Child's page table address
 11446 0000334A 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
 11447                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
 11448                              <1> 			 ; (present, writable, user)
 11449                              <1> dpd_2:
 11450 0000334C AB                  <1> 	stosd
 11451 0000334D E2E1                <1> 	loop	dpd_0
 11452                              <1> 	;
 11453 0000334F 58                  <1> 	pop	eax  ; restore child's page directory address
 11454                              <1> dpd_3:
 11455 00003350 59                  <1> 	pop	ecx
 11456 00003351 5B                  <1> 	pop	ebx
 11457 00003352 5F                  <1> 	pop	edi
 11458 00003353 5E                  <1> 	pop	esi
 11459 00003354 5D                  <1> 	pop	ebp ; 20/07/2015
 11460                              <1> dpd_err:
 11461 00003355 C3                  <1> 	retn
 11462                              <1> dpd_p_err:
 11463                              <1> 	; release the allocated pages missing (recover free space)
 11464 00003356 58                  <1> 	pop	eax  ; the new page directory address (physical)
 11465 00003357 8B1D[69B10000]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
 11466 0000335D E8DEFEFFFF          <1> 	call 	deallocate_page_dir
 11467 00003362 29C0                <1> 	sub	eax, eax ; 0
 11468 00003364 F9                  <1> 	stc
 11469 00003365 EBE9                <1> 	jmp	short dpd_3	
 11470                              <1> 
 11471                              <1> duplicate_page_table:
 11472                              <1> 	; 21/09/2015
 11473                              <1> 	; 20/07/2015
 11474                              <1> 	; 05/05/2015
 11475                              <1> 	; 28/04/2015
 11476                              <1> 	; 27/04/2015
 11477                              <1> 	; 18/04/2015
 11478                              <1> 	; 18/10/2014
 11479                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
 11480                              <1> 	;
 11481                              <1> 	; INPUT -> 
 11482                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
 11483                              <1> 	;	EBP = page table entry index (from 'duplicate_page_dir')
 11484                              <1> 	; OUTPUT ->
 11485                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
 11486                              <1> 	;	      (with 'read only' attribute of page table entries)
 11487                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
 11488                              <1> 	;	CF = 1 -> error 
 11489                              <1> 	;
 11490                              <1> 	; Modified Registers -> EBP (except EAX)
 11491                              <1> 	;
 11492 00003367 E89BFDFFFF          <1> 	call	allocate_page
 11493 0000336C 726A                <1> 	jc	short dpt_err
 11494                              <1> 	;
 11495 0000336E 50                  <1> 	push	eax ; *
 11496 0000336F 56                  <1> 	push	esi
 11497 00003370 57                  <1> 	push	edi
 11498 00003371 52                  <1> 	push	edx
 11499 00003372 51                  <1> 	push	ecx
 11500                              <1> 	;
 11501 00003373 89DE                <1> 	mov	esi, ebx
 11502 00003375 89C7                <1> 	mov	edi, eax
 11503 00003377 89C2                <1> 	mov	edx, eax
 11504 00003379 81C200100000        <1> 	add	edx, PAGE_SIZE 	
 11505                              <1> dpt_0:
 11506 0000337F AD                  <1> 	lodsd
 11507 00003380 21C0                <1> 	and	eax, eax
 11508 00003382 7444                <1> 	jz	short dpt_3
 11509 00003384 A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
 11510 00003386 7507                <1> 	jnz	short dpt_1
 11511                              <1> 	; 20/07/2015
 11512                              <1> 	; ebp = virtual (linear) address of the memory page
 11513 00003388 E887040000          <1> 	call	reload_page ; 28/04/2015
 11514 0000338D 7244                <1> 	jc	short dpt_p_err
 11515                              <1> dpt_1:
 11516                              <1> 	; 21/09/2015
 11517 0000338F 89C1                <1> 	mov	ecx, eax
 11518 00003391 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 11519 00003395 F6C102              <1> 	test	cl, PTE_A_WRITE ; writable page ?
 11520 00003398 7525                <1> 	jnz	short dpt_2
 11521                              <1> 	; Read only (parent) page
 11522                              <1> 	; 	- there is a third process which uses this page -
 11523                              <1> 	; Allocate a new page for the child process
 11524 0000339A E868FDFFFF          <1> 	call	allocate_page
 11525 0000339F 7232                <1> 	jc	short dpt_p_err
 11526 000033A1 57                  <1> 	push	edi
 11527 000033A2 56                  <1> 	push	esi
 11528 000033A3 89CE                <1> 	mov	esi, ecx
 11529 000033A5 89C7                <1> 	mov	edi, eax
 11530 000033A7 B900040000          <1> 	mov	ecx, PAGE_SIZE/4
 11531 000033AC F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
 11532 000033AE 5E                  <1> 	pop	esi
 11533 000033AF 5F                  <1> 	pop	edi
 11534                              <1> 	; 
 11535 000033B0 53                  <1> 	push	ebx
 11536 000033B1 50                  <1> 	push	eax
 11537                              <1> 	; 20/07/2015
 11538 000033B2 89EB                <1> 	mov	ebx, ebp
 11539                              <1> 	; ebx = virtual address of the memory page
 11540 000033B4 E80B030000          <1> 	call	add_to_swap_queue
 11541 000033B9 58                  <1> 	pop	eax
 11542 000033BA 5B                  <1> 	pop	ebx
 11543                              <1> 	; 21/09/2015
 11544 000033BB 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
 11545                              <1> 		; user + writable + present page
 11546 000033BD EB09                <1> 	jmp	short dpt_3
 11547                              <1> dpt_2:
 11548                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
 11549 000033BF 0C05                <1> 	or	al, PTE_A_USER+PTE_A_PRESENT 
 11550                              <1> 		    ; (read only page!)
 11551 000033C1 8946FC              <1> 	mov	[esi-4], eax ; update parent's PTE
 11552 000033C4 660D0002            <1> 	or      ax, PTE_DUPLICATED  ; (read only page & duplicated PTE!)
 11553                              <1> dpt_3:
 11554 000033C8 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
 11555                              <1> 	;
 11556 000033C9 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
 11557                              <1> 	;
 11558 000033CF 39D7                <1> 	cmp	edi, edx
 11559 000033D1 72AC                <1> 	jb	short dpt_0
 11560                              <1> dpt_p_err:
 11561 000033D3 59                  <1> 	pop	ecx
 11562 000033D4 5A                  <1> 	pop	edx
 11563 000033D5 5F                  <1> 	pop	edi
 11564 000033D6 5E                  <1> 	pop	esi
 11565 000033D7 58                  <1> 	pop	eax ; *
 11566                              <1> dpt_err:
 11567 000033D8 C3                  <1> 	retn
 11568                              <1> 
 11569                              <1> page_fault_handler:	; CPU EXCEPTION 0Eh (14) : Page Fault !
 11570                              <1> 	; 21/09/2015
 11571                              <1> 	; 19/09/2015
 11572                              <1> 	; 17/09/2015
 11573                              <1> 	; 28/08/2015
 11574                              <1> 	; 20/07/2015
 11575                              <1> 	; 28/06/2015
 11576                              <1> 	; 03/05/2015
 11577                              <1> 	; 30/04/2015
 11578                              <1> 	; 18/04/2015
 11579                              <1> 	; 12/04/2015
 11580                              <1> 	; 30/10/2014
 11581                              <1> 	; 11/09/2014
 11582                              <1> 	; 10/09/2014 (Retro UNIX 386 v1 - beginning)
 11583                              <1> 	;
 11584                              <1> 	; Note: This is not an interrupt/exception handler.
 11585                              <1> 	;	This is a 'page fault remedy' subroutine 
 11586                              <1> 	;	which will be called by standard/uniform
 11587                              <1> 	;	exception handler.
 11588                              <1> 	;
 11589                              <1> 	; INPUT -> 
 11590                              <1> 	;	[error_code] = 32 bit ERROR CODE (lower 5 bits are valid)
 11591                              <1> 	;
 11592                              <1> 	;	cr2 = the virtual (linear) address 
 11593                              <1> 	;	      which has caused to page fault (19/09/2015)
 11594                              <1> 	;
 11595                              <1> 	; OUTPUT ->
 11596                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
 11597                              <1> 	;	EAX = 0 -> no error
 11598                              <1> 	;	EAX > 0 -> error code in EAX (also CF = 1)
 11599                              <1> 	;
 11600                              <1> 	; Modified Registers -> none (except EAX)
 11601                              <1> 	;	
 11602                              <1>         ;
 11603                              <1>         ; ERROR CODE:
 11604                              <1> 	;	 31  .....	4   3	2   1	0
 11605                              <1> 	;	+---+-- --+---+---+---+---+---+---+
 11606                              <1> 	;	|   Reserved  | I | R | U | W | P |
 11607                              <1> 	;	+---+-- --+---+---+---+---+---+---+
 11608                              <1> 	;
 11609                              <1> 	; P : PRESENT -	When set, the page fault was caused by 
 11610                              <1>     	;		a page-protection violation. When not set,
 11611                              <1> 	;		it was caused by a non-present page.
 11612                              <1> 	; W : WRITE   -	When set, the page fault was caused by
 11613                              <1> 	;		a page write. When not set, it was caused
 11614                              <1> 	;		by a page read.
 11615                              <1> 	; U : USER    -	When set, the page fault was caused 
 11616                              <1> 	;		while CPL = 3. 
 11617                              <1> 	;		This does not necessarily mean that
 11618                              <1> 	;		the page fault was a privilege violation.
 11619                              <1> 	; R : RESERVD -	When set, the page fault was caused by
 11620                              <1> 	;     WRITE	reading a 1 in a reserved field.
 11621                              <1> 	; I : INSTRUC -	When set, the page fault was caused by
 11622                              <1> 	;     FETCH	an instruction fetch
 11623                              <1> 	;
 11624                              <1> 	;; x86 (32 bit) VIRTUAL ADDRESS TRANSLATION
 11625                              <1> 	;  31               22                  12 11                    0
 11626                              <1> 	; +-------------------+-------------------+-----------------------+
 11627                              <1>        	; | PAGE DIR. ENTRY # | PAGE TAB. ENTRY # |        OFFSET         |
 11628                              <1>        	; +-------------------+-------------------+-----------------------+
 11629                              <1> 	;
 11630                              <1> 
 11631                              <1> 	;; CR3 REGISTER (Control Register 3)
 11632                              <1> 	;  31                                   12             5 4 3 2   0
 11633                              <1> 	; +---------------------------------------+-------------+---+-----+
 11634                              <1>       	; |                                       |  		|P|P|     |
 11635                              <1>       	; |   PAGE DIRECTORY TABLE BASE ADDRESS   |  reserved	|C|W|rsvrd|
 11636                              <1>       	; |                                       | 		|D|T|     |
 11637                              <1>    	; +---------------------------------------+-------------+---+-----+
 11638                              <1> 	;
 11639                              <1> 	;	PWT    - WRITE THROUGH
 11640                              <1> 	;	PCD    - CACHE DISABLE		
 11641                              <1> 	;
 11642                              <1> 	;
 11643                              <1> 	;; x86 PAGE DIRECTORY ENTRY (4 KByte Page)
 11644                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11645                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11646                              <1>       	; |                                       |     | | | | |P|P|U|R| |
 11647                              <1>       	; |     PAGE TABLE BASE ADDRESS 31..12    | AVL |G|0|D|A|C|W|/|/|P|
 11648                              <1>       	; |                                       |     | | | | |D|T|S|W| |
 11649                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11650                              <1> 	;
 11651                              <1>         ;       P      - PRESENT
 11652                              <1>         ;       R/W    - READ/WRITE
 11653                              <1>         ;       U/S    - USER/SUPERVISOR
 11654                              <1> 	;	PWT    - WRITE THROUGH
 11655                              <1> 	;	PCD    - CACHE DISABLE	
 11656                              <1> 	;	A      - ACCESSED	
 11657                              <1>         ;       D      - DIRTY (IGNORED)
 11658                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
 11659                              <1> 	;	G      - GLOBAL	(IGNORED) 
 11660                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11661                              <1> 	;
 11662                              <1> 	;
 11663                              <1> 	;; x86 PAGE TABLE ENTRY (4 KByte Page)
 11664                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11665                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11666                              <1>       	; |                                       |     | |P| | |P|P|U|R| |
 11667                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |G|A|D|A|C|W|/|/|P|
 11668                              <1>       	; |                                       |     | |T| | |D|T|S|W| |
 11669                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
 11670                              <1> 	;
 11671                              <1>         ;       P      - PRESENT
 11672                              <1>         ;       R/W    - READ/WRITE
 11673                              <1>         ;       U/S    - USER/SUPERVISOR
 11674                              <1> 	;	PWT    - WRITE THROUGH
 11675                              <1> 	;	PCD    - CACHE DISABLE	
 11676                              <1> 	;	A      - ACCESSED	
 11677                              <1>         ;       D      - DIRTY
 11678                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
 11679                              <1> 	;	G      - GLOBAL	 
 11680                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11681                              <1> 	;
 11682                              <1> 	;
 11683                              <1> 	;; 80386 PAGE TABLE ENTRY (4 KByte Page)
 11684                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
 11685                              <1> 	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
 11686                              <1>       	; |                                       |     | | | | | | |U|R| |
 11687                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |0|0|D|A|0|0|/|/|P|
 11688                              <1>       	; |                                       |     | | | | | | |S|W| |
 11689                              <1>       	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
 11690                              <1> 	;
 11691                              <1>         ;       P      - PRESENT
 11692                              <1>         ;       R/W    - READ/WRITE
 11693                              <1>         ;       U/S    - USER/SUPERVISOR
 11694                              <1>         ;       D      - DIRTY
 11695                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
 11696                              <1> 	;
 11697                              <1>         ;       NOTE: 0 INDICATES INTEL RESERVED. DO NOT DEFINE.
 11698                              <1> 	;
 11699                              <1> 	;
 11700                              <1> 	;; Invalid Page Table Entry
 11701                              <1> 	; 31                                                           1 0
 11702                              <1>       	; +-------------------------------------------------------------+-+
 11703                              <1>       	; |                                                             | |
 11704                              <1>       	; |                          AVAILABLE                          |0|
 11705                              <1>       	; |                                                             | |
 11706                              <1>       	; +-------------------------------------------------------------+-+
 11707                              <1> 	;
 11708                              <1> 
 11709 000033D9 53                  <1> 	push	ebx
 11710 000033DA 52                  <1> 	push	edx
 11711 000033DB 51                  <1> 	push	ecx
 11712                              <1> 	;
 11713                              <1> 	; 21/09/2015 (debugging)
 11714 000033DC FF05[79B10000]      <1> 	inc	dword [u.pfcount] ; page fault count for running process
 11715 000033E2 FF05[E4BD0000]      <1> 	inc	dword [PF_Count] ; total page fault count	
 11716                              <1> 	; 28/06/2015
 11717                              <1> 	;mov	edx, [error_code] ; Lower 5 bits are valid
 11718 000033E8 8A15[DCBD0000]      <1> 	mov	dl, [error_code]
 11719                              <1> 	;
 11720 000033EE F6C201              <1> 	test	dl, 1	; page fault was caused by a non-present page
 11721                              <1> 			; sign
 11722 000033F1 7422                <1> 	jz	short pfh_alloc_np
 11723                              <1> 	; 
 11724                              <1> 	; If it is not a 'write on read only page' type page fault
 11725                              <1> 	; major page fault error with minor reason must be returned without 
 11726                              <1> 	; fixing the problem. 'sys_exit with error' will be needed
 11727                              <1> 	; after return here!
 11728                              <1> 	; Page fault will be remedied, by copying page contents
 11729                              <1> 	; to newly allocated page with write permission;
 11730                              <1> 	; sys_fork -> sys_exec -> copy on write, demand paging method is 
 11731                              <1> 	; used for working with minimum possible memory usage. 
 11732                              <1> 	; sys_fork will duplicate page directory and tables of parent  
 11733                              <1> 	; process with 'read only' flag. If the child process attempts to
 11734                              <1> 	; write on these read only pages, page fault will be directed here
 11735                              <1> 	; for allocating a new page with same data/content. 
 11736                              <1> 	;
 11737                              <1> 	; IMPORTANT : Retro UNIX 386 v1 (and SINGLIX and TR-DOS)
 11738                              <1> 	; will not force to separate CODE and DATA space 
 11739                              <1> 	; in a process/program... 
 11740                              <1> 	; CODE segment/section may contain DATA!
 11741                              <1> 	; It is flat, smoth and simplest programming method already as in 
 11742                              <1> 	; Retro UNIX 8086 v1 and MS-DOS programs.
 11743                              <1> 	;	
 11744 000033F3 F6C202              <1> 	test	dl, 2	; page fault was caused by a page write
 11745                              <1> 			; sign
 11746 000033F6 0F84AB000000        <1>         jz      pfh_p_err
 11747                              <1> 	; 31/08/2015
 11748 000033FC F6C204              <1> 	test	dl, 4	; page fault was caused while CPL = 3 (user mode)
 11749                              <1> 			; sign.  (U+W+P = 4+2+1 = 7)
 11750 000033FF 0F84A2000000        <1>         jz	pfh_pv_err
 11751                              <1> 	;
 11752                              <1> 	; make a new page and copy the parent's page content
 11753                              <1> 	; as the child's new page content
 11754                              <1> 	;
 11755 00003405 0F20D3              <1> 	mov	ebx, cr2 ; CR2 contains the linear address 
 11756                              <1> 			 ; which has caused to page fault
 11757 00003408 E8A2000000          <1> 	call 	copy_page
 11758 0000340D 0F828D000000        <1>         jc      pfh_im_err ; insufficient memory
 11759                              <1> 	;
 11760 00003413 EB7D                <1>         jmp     pfh_cpp_ok
 11761                              <1> 	;
 11762                              <1> pfh_alloc_np:
 11763 00003415 E8EDFCFFFF          <1> 	call	allocate_page	; (allocate a new page)
 11764 0000341A 0F8280000000        <1>         jc      pfh_im_err	; 'insufficient memory' error
 11765                              <1> pfh_chk_cpl:
 11766                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 11767                              <1> 		; (Lower 12 bits are ZERO, because 
 11768                              <1> 		;	the address is on a page boundary)
 11769 00003420 80E204              <1> 	and	dl, 4	; CPL = 3 ?
 11770 00003423 7505                <1> 	jnz	short pfh_um
 11771                              <1> 			; Page fault handler for kernel/system mode (CPL=0)		
 11772 00003425 0F20DB              <1> 	mov	ebx, cr3 ; CR3 (Control Register 3) contains physical address
 11773                              <1> 			 ; of the current/active page directory
 11774                              <1> 			 ; (Always kernel/system mode page directory, here!)
 11775                              <1> 			 ; Note: Lower 12 bits are 0. (page boundary)
 11776 00003428 EB06                <1> 	jmp	short pfh_get_pde
 11777                              <1> 	;
 11778                              <1> pfh_um:			; Page fault handler for user/appl. mode (CPL=3)
 11779 0000342A 8B1D[69B10000]      <1>  	mov	ebx, [u.pgdir] ; Page directory of current/active process
 11780                              <1> 			; Physical address of the USER's page directory
 11781                              <1> 			; Note: Lower 12 bits are 0. (page boundary)
 11782                              <1> pfh_get_pde:
 11783 00003430 80CA03              <1> 	or	dl, 3	; USER + WRITE + PRESENT or SYSTEM + WRITE + PRESENT
 11784 00003433 0F20D1              <1> 	mov	ecx, cr2 ; CR2 contains the virtual address 
 11785                              <1> 			 ; which has been caused to page fault
 11786                              <1> 			 ;
 11787 00003436 C1E914              <1> 	shr	ecx, 20	 ; shift 20 bits right
 11788 00003439 80E1FC              <1> 	and	cl, 0FCh ; mask lower 2 bits to get PDE offset		
 11789                              <1> 	;
 11790 0000343C 01CB                <1> 	add	ebx, ecx ; now, EBX points to the relevant page dir entry 
 11791 0000343E 8B0B                <1> 	mov	ecx, [ebx] ; physical (base) address of the page table 	
 11792 00003440 F6C101              <1> 	test	cl, 1	 ; check bit 0 is set (1) or not (0).
 11793 00003443 740B                <1> 	jz	short pfh_set_pde ; Page directory entry is not valid,
 11794                              <1> 			  	  ; set/validate page directory entry
 11795 00003445 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
 11796 0000344A 89CB                <1> 	mov	ebx, ecx ; Physical address of the page table
 11797 0000344C 89C1                <1> 	mov	ecx, eax ; new page address (physical) 	
 11798 0000344E EB16                <1> 	jmp	short pfh_get_pte
 11799                              <1> pfh_set_pde:
 11800                              <1> 	;; NOTE: Page directories and page tables never be swapped out!
 11801                              <1> 	;;	 (So, we know this PDE is empty or invalid)
 11802                              <1> 	;
 11803 00003450 08D0                <1> 	or	al, dl	 ; lower 3 bits are used as U/S, R/W, P flags
 11804 00003452 8903                <1> 	mov	[ebx], eax ; Let's put the new page directory entry here !
 11805 00003454 30C0                <1> 	xor	al, al	 ; clear lower (3..8) bits
 11806 00003456 89C3                <1> 	mov	ebx, eax
 11807 00003458 E8AAFCFFFF          <1> 	call	allocate_page	 ; (allocate a new page)
 11808 0000345D 7241                <1> 	jc	short pfh_im_err   ; 'insufficient memory' error
 11809                              <1> pfh_spde_1:
 11810                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 11811 0000345F 89C1                <1> 	mov	ecx, eax
 11812 00003461 E81BFDFFFF          <1> 	call	clear_page ; Clear page content
 11813                              <1> pfh_get_pte:
 11814 00003466 0F20D0              <1> 	mov	eax, cr2 ; virtual address
 11815                              <1> 			 ; which has been caused to page fault
 11816 00003469 89C7                <1> 	mov	edi, eax ; 20/07/2015
 11817 0000346B C1E80C              <1> 	shr	eax, 12	 ; shift 12 bit right to get 
 11818                              <1> 			 ; higher 20 bits of the page fault address 
 11819 0000346E 25FF030000          <1> 	and	eax, 3FFh ; mask PDE# bits, the result is PTE# (0 to 1023)
 11820 00003473 C1E002              <1> 	shl	eax, 2	; shift 2 bits left to get PTE offset
 11821 00003476 01C3                <1> 	add	ebx, eax ; now, EBX points to the relevant page table entry 
 11822 00003478 8B03                <1> 	mov	eax, [ebx] ; get previous value of pte
 11823                              <1> 		; bit 0 of EAX is always 0 (otherwise we would not be here)
 11824 0000347A 21C0                <1> 	and	eax, eax
 11825 0000347C 7410                <1> 	jz	short pfh_gpte_1
 11826                              <1> 	; 20/07/2015
 11827 0000347E 87D9                <1> 	xchg	ebx, ecx ; new page address (physical)
 11828 00003480 55                  <1> 	push	ebp ; 20/07/2015
 11829 00003481 0F20D5              <1> 	mov	ebp, cr2
 11830                              <1> 		; ECX = physical address of the page table entry
 11831                              <1> 		; EBX = Memory page address (physical!)
 11832                              <1> 		; EAX = Swap disk (offset) address
 11833                              <1> 		; EBP = virtual address (page fault address)
 11834 00003484 E8B7000000          <1> 	call	swap_in
 11835 00003489 5D                  <1> 	pop	ebp
 11836 0000348A 7210                <1> 	jc      short pfh_err_retn
 11837 0000348C 87CB                <1> 	xchg	ecx, ebx
 11838                              <1> 		; EBX = physical address of the page table entry
 11839                              <1> 		; ECX = new page
 11840                              <1> pfh_gpte_1:
 11841 0000348E 08D1                <1> 	or	cl, dl	; lower 3 bits are used as U/S, R/W, P flags
 11842 00003490 890B                <1> 	mov	[ebx], ecx ; Let's put the new page table entry here !
 11843                              <1> pfh_cpp_ok:
 11844                              <1> 	; 20/07/2015
 11845 00003492 0F20D3              <1> 	mov	ebx, cr2
 11846 00003495 E82A020000          <1> 	call 	add_to_swap_queue
 11847                              <1> 	;
 11848                              <1> 	; The new PTE (which contains the new page) will be added to 
 11849                              <1> 	; the swap queue, here. 
 11850                              <1> 	; (Later, if memory will become insufficient, 
 11851                              <1> 	; one page will be swapped out which is at the head of 
 11852                              <1> 	; the swap queue by using FIFO and access check methods.)
 11853                              <1> 	;
 11854 0000349A 31C0                <1> 	xor	eax, eax  ; 0
 11855                              <1> 	;
 11856                              <1> pfh_err_retn:
 11857 0000349C 59                  <1> 	pop	ecx
 11858 0000349D 5A                  <1> 	pop	edx
 11859 0000349E 5B                  <1> 	pop	ebx
 11860 0000349F C3                  <1> 	retn 
 11861                              <1> 	
 11862                              <1> pfh_im_err:
 11863 000034A0 B8E1000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_IM ; Error code in AX
 11864                              <1> 			; Major (Primary) Error: Page Fault
 11865                              <1> 			; Minor (Secondary) Error: Insufficient Memory !
 11866 000034A5 EBF5                <1> 	jmp	short pfh_err_retn
 11867                              <1> 
 11868                              <1> 
 11869                              <1> pfh_p_err: ; 09/03/2015
 11870                              <1> pfh_pv_err:
 11871                              <1> 	; Page fault was caused by a protection-violation
 11872 000034A7 B8E3000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_PV ; Error code in AX
 11873                              <1> 			; Major (Primary) Error: Page Fault
 11874                              <1> 			; Minor (Secondary) Error: Protection violation !
 11875 000034AC F9                  <1> 	stc
 11876 000034AD EBED                <1> 	jmp	short pfh_err_retn
 11877                              <1> 
 11878                              <1> copy_page:
 11879                              <1> 	; 22/09/2015
 11880                              <1> 	; 21/09/2015
 11881                              <1> 	; 19/09/2015
 11882                              <1> 	; 07/09/2015
 11883                              <1> 	; 31/08/2015
 11884                              <1> 	; 20/07/2015
 11885                              <1> 	; 05/05/2015
 11886                              <1> 	; 03/05/2015
 11887                              <1> 	; 18/04/2015
 11888                              <1> 	; 12/04/2015
 11889                              <1> 	; 30/10/2014
 11890                              <1> 	; 18/10/2014 (Retro UNIX 386 v1 - beginning)
 11891                              <1> 	;
 11892                              <1> 	; INPUT -> 
 11893                              <1> 	;	EBX = Virtual (linear) address of source page
 11894                              <1> 	;	     (Page fault address)
 11895                              <1> 	; OUTPUT ->
 11896                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
 11897                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
 11898                              <1> 	;	EAX = 0 (CF = 1) 
 11899                              <1> 	;		if there is not a free page to be allocated
 11900                              <1> 	;	(page content of the source page will be copied
 11901                              <1> 	;	onto the target/new page) 	
 11902                              <1> 	;
 11903                              <1> 	; Modified Registers -> ecx, ebx (except EAX)
 11904                              <1> 	;	
 11905 000034AF 56                  <1> 	push	esi
 11906 000034B0 57                  <1> 	push	edi
 11907                              <1> 	;push	ebx
 11908                              <1> 	;push	ecx
 11909 000034B1 31F6                <1> 	xor 	esi, esi
 11910 000034B3 C1EB0C              <1> 	shr	ebx, 12 ; shift 12 bits right to get PDE & PTE numbers
 11911 000034B6 89D9                <1> 	mov	ecx, ebx ; save page fault address (as 12 bit shifted)
 11912 000034B8 C1EB08              <1> 	shr	ebx, 8	 ; shift 8 bits right and then
 11913 000034BB 80E3FC              <1> 	and	bl, 0FCh ; mask lower 2 bits to get PDE offset	
 11914 000034BE 89DF                <1> 	mov 	edi, ebx ; save it for the parent of current process
 11915 000034C0 031D[69B10000]      <1> 	add	ebx, [u.pgdir] ; EBX points to the relevant page dir entry 
 11916 000034C6 8B03                <1> 	mov	eax, [ebx] ; physical (base) address of the page table
 11917 000034C8 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits 	
 11918 000034CC 89CB                <1> 	mov	ebx, ecx   ; (restore higher 20 bits of page fault address)
 11919 000034CE 81E3FF030000        <1> 	and	ebx, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
 11920 000034D4 66C1E302            <1> 	shl	bx, 2	   ; shift 2 bits left to get PTE offset
 11921 000034D8 01C3                <1> 	add	ebx, eax   ; EBX points to the relevant page table entry 
 11922                              <1> 	; 07/09/2015
 11923 000034DA 66F7030002          <1>         test    word [ebx], PTE_DUPLICATED ; (Does current process share this
 11924                              <1> 				     ; read only page as a child process?)	
 11925 000034DF 7509                <1> 	jnz	short cpp_0 ; yes
 11926 000034E1 8B0B                <1> 	mov	ecx, [ebx] ; PTE value
 11927 000034E3 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h  ; clear page attributes
 11928 000034E8 EB32                <1> 	jmp	short cpp_1
 11929                              <1> cpp_0:
 11930 000034EA 89FE                <1> 	mov	esi, edi
 11931 000034EC 0335[6DB10000]      <1> 	add	esi, [u.ppgdir] ; the parent's page directory entry
 11932 000034F2 8B06                <1> 	mov	eax, [esi] ; physical (base) address of the page table
 11933 000034F4 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 11934 000034F8 89CE                <1> 	mov	esi, ecx   ; (restore higher 20 bits of page fault address)	
 11935 000034FA 81E6FF030000        <1> 	and	esi, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
 11936 00003500 66C1E602            <1> 	shl	si, 2	   ; shift 2 bits left to get PTE offset
 11937 00003504 01C6                <1> 	add	esi, eax   ; EDX points to the relevant page table entry  	
 11938 00003506 8B0E                <1> 	mov	ecx, [esi] ; PTE value of the parent process
 11939                              <1> 	; 21/09/2015
 11940 00003508 8B03                <1> 	mov	eax, [ebx] ; PTE value of the child process
 11941 0000350A 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear page attributes	
 11942                              <1> 	;
 11943 0000350E F6C101              <1> 	test	cl, PTE_A_PRESENT ; is it a present/valid page ?
 11944 00003511 7424                <1> 	jz	short cpp_3 ; the parent's page is not same page  	
 11945                              <1> 	;
 11946 00003513 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h ; clear page attributes
 11947 00003518 39C8                <1> 	cmp	eax, ecx   ; Same page?	
 11948 0000351A 751B                <1> 	jne	short cpp_3 ; Parent page and child page are not same 
 11949                              <1> 			    ; Convert child's page to writable page
 11950                              <1> cpp_1:
 11951 0000351C E8E6FBFFFF          <1> 	call	allocate_page
 11952 00003521 721A                <1> 	jc	short cpp_4 ; 'insufficient memory' error
 11953 00003523 21F6                <1> 	and	esi, esi    ; check ESI is valid or not
 11954 00003525 7405                <1> 	jz	short cpp_2
 11955                              <1> 		; Convert read only page to writable page 
 11956                              <1> 		;(for the parent of the current process)
 11957                              <1> 	;and	word [esi], PTE_A_CLEAR ; 0F000h
 11958                              <1> 	; 22/09/2015
 11959 00003527 890E                <1> 	mov	[esi], ecx
 11960 00003529 800E07              <1> 	or	byte [esi], PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER
 11961                              <1> 				 ; 1+2+4 = 7
 11962                              <1> cpp_2:
 11963 0000352C 89C7                <1> 	mov	edi, eax ; new page address of the child process
 11964                              <1> 	; 07/09/2015
 11965 0000352E 89CE                <1> 	mov	esi, ecx ; the page address of the parent process
 11966 00003530 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
 11967 00003535 F3A5                <1> 	rep	movsd ; 31/08/2015
 11968                              <1> cpp_3:		
 11969 00003537 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 1+2+4 = 7
 11970 00003539 8903                <1> 	mov	[ebx], eax ; Update PTE
 11971 0000353B 28C0                <1> 	sub	al, al ; clear attributes
 11972                              <1> cpp_4:
 11973                              <1> 	;pop	ecx
 11974                              <1> 	;pop	ebx
 11975 0000353D 5F                  <1> 	pop	edi
 11976 0000353E 5E                  <1> 	pop	esi
 11977 0000353F C3                  <1> 	retn
 11978                              <1> 
 11979                              <1> ;; 28/04/2015
 11980                              <1> ;; 24/10/2014
 11981                              <1> ;; 21/10/2014 (Retro UNIX 386 v1 - beginning)
 11982                              <1> ;; SWAP_PAGE_QUEUE (4096 bytes)
 11983                              <1> ;;
 11984                              <1> ;;   0000   0001   0002   0003   ....   1020   1021   1022   1023	
 11985                              <1> ;; +------+------+------+------+-    -+------+------+------+------+
 11986                              <1> ;; |  pg1 |  pg2 |  pg3 |  pg4 | .... |pg1021|pg1022|pg1023|pg1024|
 11987                              <1> ;; +------+------+------+------+-    -+------+------+------+------+    
 11988                              <1> ;;
 11989                              <1> ;; [swpq_last] = 0 to 4096 (step 4) -> the last position on the queue
 11990                              <1> ;;
 11991                              <1> ;; Method:
 11992                              <1> ;;	Swap page queue is a list of allocated pages with physical
 11993                              <1> ;;	addresses (system mode virtual adresses = physical addresses).
 11994                              <1> ;;	It is used for 'swap_in' and 'swap_out' procedures.
 11995                              <1> ;;	When a new page is being allocated, swap queue is updated
 11996                              <1> ;;	by 'swap_queue_shift' procedure, header of the queue (offset 0)
 11997                              <1> ;;	is checked for 'accessed' flag. If the 1st page on the queue
 11998                              <1> ;;	is 'accessed' or 'read only', it is dropped from the list;
 11999                              <1> ;;	other pages from the 2nd to the last (in [swpq_last]) shifted
 12000                              <1> ;; 	to head then the 2nd page becomes the 1st and '[swpq_last]' 
 12001                              <1> ;;	offset value becomes it's previous offset value - 4.
 12002                              <1> ;;	If the 1st page of the swap page queue is not 'accessed'	
 12003                              <1> ;;	the queue/list is not shifted.
 12004                              <1> ;;	After the queue/list shift, newly allocated page is added
 12005                              <1> ;;	to the tail of the queue at the [swpq_count*4] position.
 12006                              <1> ;;	But, if [swpq_count] > 1023, the newly allocated page
 12007                              <1> ;;	will not be added to the tail of swap page queue.  		 
 12008                              <1> ;;	
 12009                              <1> ;;	During 'swap_out' procedure, swap page queue is checked for
 12010                              <1> ;;	the first non-accessed, writable page in the list, 
 12011                              <1> ;;	from the head to the tail. The list is shifted to left 
 12012                              <1> ;;	(to the head) till a non-accessed page will be found in the list.
 12013                              <1> ;;	Then, this page	is swapped out (to disk) and then it is dropped
 12014                              <1> ;;	from the list by a final swap queue shift. [swpq_count] value
 12015                              <1> ;;	is changed. If all pages on the queue' are 'accessed', 
 12016                              <1> ;;	'insufficient memory' error will be returned ('swap_out' 
 12017                              <1> ;;	procedure will be failed)...
 12018                              <1> ;;
 12019                              <1> ;;	Note: If the 1st page of the queue is an 'accessed' page,
 12020                              <1> ;;	'accessed' flag of the page will be reset (0) and that page
 12021                              <1> ;;	(PTE) will be added to the tail of the queue after
 12022                              <1> ;;	the check, if [swpq_count] < 1023. If [swpq_count] = 1024
 12023                              <1> ;;	the queue will be rotated and the PTE in the head will be
 12024                              <1> ;;	added to the tail after resetting 'accessed' bit. 
 12025                              <1> ;;
 12026                              <1> ;;
 12027                              <1> ;;	
 12028                              <1> ;; SWAP DISK/FILE (with 4096 bytes swapped page blocks)
 12029                              <1> ;;
 12030                              <1> ;;  00000000  00000004  00000008  0000000C   ...   size-8    size-4
 12031                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+
 12032                              <1> ;; |descriptr| page(1) | page(2) | page(3) | ... |page(n-1)| page(n) |
 12033                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+    
 12034                              <1> ;;
 12035                              <1> ;; [swpd_next] = the first free block address in swapped page records
 12036                              <1> ;;    		 for next free block search by 'swap_out' procedure.
 12037                              <1> ;; [swpd_size] = swap disk/file size in sectors (512 bytes)
 12038                              <1> ;;		 NOTE: max. possible swap disk size is 1024 GB
 12039                              <1> ;; 		 (entire swap space must be accessed by using
 12040                              <1> ;;		 31 bit offset address) 
 12041                              <1> ;; [swpd_free] = free block (4096 bytes) count in swap disk/file space
 12042                              <1> ;; [swpd_start] = absolute/start address of the swap disk/file
 12043                              <1> ;;		  0 for file, or beginning sector of the swap partition
 12044                              <1> ;; [swp_drv] = logical drive description table addr. of swap disk/file
 12045                              <1> ;;
 12046                              <1> ;; 					
 12047                              <1> ;; Method:
 12048                              <1> ;;	When the memory (ram) becomes insufficient, page allocation
 12049                              <1> ;;	procedure swaps out a page from memory to the swap disk 
 12050                              <1> ;;	(partition) or swap file to get a new free page at the memory.
 12051                              <1> ;;	Swapping out is performed by using swap page queue.
 12052                              <1> ;;
 12053                              <1> ;; 	Allocation block size of swap disk/file is equal to page size
 12054                              <1> ;;	(4096 bytes). Swapping address (in sectors) is recorded
 12055                              <1> ;;	into relevant page file entry as 31 bit physical (logical)
 12056                              <1> ;;	offset address as 1 bit shifted to left for present flag (0).
 12057                              <1> ;;	Swapped page address is between 1 and swap disk/file size - 4.	  
 12058                              <1> ;;	Absolute physical (logical) address of the swapped page is 
 12059                              <1> ;;	calculated by adding offset value to the swap partition's 
 12060                              <1> ;;	start address. If the swap device (disk) is a virtual disk 
 12061                              <1> ;;	or it is a file, start address of the swap disk/volume is 0, 
 12062                              <1> ;;	and offset value is equal to absolute (physical or logical)
 12063                              <1> ;;	address/position. (It has not to be ZERO if the swap partition 
 12064                              <1> ;;	is in a partitioned virtual hard disk.) 
 12065                              <1> ;;
 12066                              <1> ;;	Note: Swap addresses are always specified/declared in sectors, 
 12067                              <1> ;;	not in bytes or	in blocks/zones/clusters (4096 bytes) as unit.
 12068                              <1> ;;
 12069                              <1> ;;	Swap disk/file allocation is mapped via 'Swap Allocation Table'
 12070                              <1> ;;	at memory as similar to 'Memory Allocation Table'.
 12071                              <1> ;;
 12072                              <1> ;;	Every bit of Swap Allocation Table repsesents one swap block
 12073                              <1> ;;	(equal to page size) respectively. Bit 0 of the S.A.T. byte 0
 12074                              <1> ;;	is reserved for swap disk/file block 0 as descriptor block
 12075                              <1> ;;	(also for compatibility with PTE). If bit value is ZERO,
 12076                              <1> ;;	it means relevant (respective) block is in use, and, 
 12077                              <1> ;;	of course, if bit value is 1, it means relevant (respective)
 12078                              <1> ;;      swap disk/file block is free.
 12079                              <1> ;;	For example: bit 1 of the byte 128 repsesents block 1025 
 12080                              <1> ;;	(128*8+1) or sector (offset) 8200 on the swap disk or
 12081                              <1> ;;	byte (offset/position) 4198400 in the swap file. 
 12082                              <1> ;;	4GB swap space is represented via 128KB Swap Allocation Table.
 12083                              <1> ;;	Initial layout of Swap Allocation Table is as follows:
 12084                              <1> ;;	------------------------------------------------------------
 12085                              <1> ;;	0111111111111111111111111 .... 11111111111111111111111111111
 12086                              <1> ;;	------------------------------------------------------------
 12087                              <1> ;;	(0 is reserved block, 1s represent free blocks respectively.)
 12088                              <1> ;;	(Note: Allocation cell/unit of the table is bit, not byte)
 12089                              <1> ;;
 12090                              <1> ;;	..............................................................
 12091                              <1> ;;
 12092                              <1> ;;	'swap_out' procedure checks 'free_swap_blocks' count at first,
 12093                              <1> ;;	then it searches Swap Allocation Table if free count is not
 12094                              <1> ;;	zero. From begining the [swpd_next] dword value, the first bit 
 12095                              <1> ;;	position with value of 1 on the table is converted to swap
 12096                              <1> ;;	disk/file offset address, in sectors (not 4096 bytes block).
 12097                              <1> ;;	'ldrv_write' procedure is called with ldrv (logical drive
 12098                              <1> ;;	number of physical swap disk or virtual swap disk)
 12099                              <1> ;;	number, sector offset (not absolute sector -LBA- number),
 12100                              <1> ;;	and sector count (8, 512*8 = 4096) and buffer adress
 12101                              <1> ;;	(memory page). That will be a direct disk write procedure.
 12102                              <1> ;;	(for preventing late memory allocation, significant waiting). 
 12103                              <1> ;;	If disk write procedure returns with error or free count of 
 12104                              <1> ;;	swap blocks is ZERO, 'swap_out' procedure will return with
 12105                              <1> ;;	'insufficient memory error' (cf=1). 
 12106                              <1> ;;
 12107                              <1> ;;	(Note: Even if free swap disk/file blocks was not zero,
 12108                              <1> ;;	any disk write error will not be fixed by 'swap_out' procedure,
 12109                              <1> ;;	in other words, 'swap_out' will not check the table for other
 12110                              <1> ;;	free blocks after a disk write error. It will return to 
 12111                              <1> ;;	the caller with error (CF=1) which means swapping is failed. 
 12112                              <1> ;;
 12113                              <1> ;;	After writing the page on to swap disk/file address/sector,
 12114                              <1> ;;	'swap_out' procesure returns with that swap (offset) sector
 12115                              <1> ;;	address (cf=0). 
 12116                              <1> ;;
 12117                              <1> ;;	..............................................................
 12118                              <1> ;;
 12119                              <1> ;;	'swap_in' procedure loads addressed (relevant) swap disk or
 12120                              <1> ;;	file sectors at specified memory page. Then page allocation
 12121                              <1> ;;	procedure updates relevant page table entry with 'present' 
 12122                              <1> ;;	attribute. If swap disk or file reading fails there is nothing
 12123                              <1> ;;	to do, except to terminate the process which is the owner of
 12124                              <1> ;;	the swapped page.
 12125                              <1> ;;
 12126                              <1> ;;	'swap_in' procedure sets the relevant/respective bit value
 12127                              <1> ;;	in the Swap Allocation Table (as free block). 'swap_in' also
 12128                              <1> ;;	updates [swpd_first] pointer if it is required.
 12129                              <1> ;;
 12130                              <1> ;;	..............................................................	 
 12131                              <1> ;;
 12132                              <1> ;;	Note: If [swap_enabled] value is ZERO, that means there is not
 12133                              <1> ;;	a swap disk or swap file in use... 'swap_in' and 'swap_out'
 12134                              <1> ;;	procedures ans 'swap page que' procedures will not be active...
 12135                              <1> ;;	'Insufficient memory' error will be returned by 'swap_out'
 12136                              <1> ;;	and 'general protection fault' will be returned by 'swap_in'
 12137                              <1> ;;	procedure, if it is called mistakenly (a wrong value in a PTE).		
 12138                              <1> ;;
 12139                              <1> 
 12140                              <1> swap_in:
 12141                              <1> 	; 31/08/2015
 12142                              <1> 	; 20/07/2015
 12143                              <1> 	; 28/04/2015
 12144                              <1> 	; 18/04/2015
 12145                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12146                              <1> 	;
 12147                              <1> 	; INPUT -> 
 12148                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS OF THE MEMORY PAGE
 12149                              <1> 	;	EBP = VIRTUAL (LINEAR) ADDRESS (page fault address)
 12150                              <1> 	;	EAX = Offset Address for the swapped page on the
 12151                              <1> 	;	      swap disk or in the swap file.
 12152                              <1> 	;
 12153                              <1> 	; OUTPUT ->
 12154                              <1> 	;	EAX = 0 if loading at memory has been successful
 12155                              <1> 	;
 12156                              <1> 	;	CF = 1 -> swap disk reading error (disk/file not present
 12157                              <1> 	;		  or sector not present or drive not ready
 12158                              <1> 	;	     EAX = Error code
 12159                              <1> 	;	     [u.error] = EAX 
 12160                              <1> 	;		       = The last error code for the process
 12161                              <1> 	;		         (will be reset after returning to user)	  
 12162                              <1> 	;
 12163                              <1> 	; Modified Registers -> EAX
 12164                              <1> 	;
 12165                              <1> 
 12166 00003540 833D[C7BD0000]00    <1>         cmp     dword [swp_drv], 0
 12167 00003547 7648                <1> 	jna	short swpin_dnp_err
 12168                              <1> 
 12169 00003549 3B05[CBBD0000]      <1> 	cmp	eax, [swpd_size]
 12170 0000354F 734C                <1> 	jnb	short swpin_snp_err
 12171                              <1> 
 12172 00003551 56                  <1> 	push	esi
 12173 00003552 53                  <1> 	push	ebx
 12174 00003553 51                  <1> 	push	ecx
 12175 00003554 8B35[C7BD0000]      <1> 	mov	esi, [swp_drv]	
 12176 0000355A B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
 12177                              <1> 		; Note: Even if corresponding physical disk's sector 
 12178                              <1> 		; size different than 512 bytes, logical disk sector
 12179                              <1> 		; size is 512 bytes and disk reading procedure
 12180                              <1> 		; will be performed for reading 4096 bytes
 12181                              <1> 		; (2*2048, 8*512). 
 12182                              <1> 	; ESI = Logical disk description table address
 12183                              <1> 	; EBX = Memory page (buffer) address (physical!)
 12184                              <1> 	; EAX = Sector adress (offset address, logical sector number)
 12185                              <1> 	; ECX = Sector count ; 8 sectors
 12186 0000355F 50                  <1> 	push	eax
 12187 00003560 E833020000          <1> 	call	logical_disk_read
 12188 00003565 58                  <1> 	pop	eax
 12189 00003566 730C                <1> 	jnc	short swpin_read_ok
 12190                              <1> 	;
 12191 00003568 B804000000          <1> 	mov	eax, SWP_DISK_READ_ERR ; drive not ready or read error
 12192 0000356D A3[65B10000]        <1> 	mov	[u.error], eax
 12193 00003572 EB19                <1> 	jmp	short swpin_retn
 12194                              <1> 	;
 12195                              <1> swpin_read_ok:
 12196                              <1> 	; EAX = Offset address (logical sector number)
 12197 00003574 E891010000          <1> 	call	unlink_swap_block  ; Deallocate swap block	
 12198                              <1> 	;
 12199                              <1> 	; EBX = Memory page (buffer) address (physical!)
 12200                              <1> 	; 20/07/2015
 12201 00003579 89EB                <1> 	mov	ebx, ebp ; virtual address (page fault address)
 12202 0000357B 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
 12203 00003580 8A1D[5FB10000]      <1> 	mov	bl, [u.uno] ; current process number
 12204                              <1> 	; EBX = Virtual address & process number combination
 12205 00003586 E89E000000          <1> 	call	swap_queue_shift
 12206 0000358B 29C0                <1> 	sub	eax, eax  ; 0 ; Error Code = 0  (no error)
 12207                              <1> 	;
 12208                              <1> swpin_retn:
 12209 0000358D 59                  <1> 	pop	ecx
 12210 0000358E 5B                  <1> 	pop	ebx
 12211 0000358F 5E                  <1> 	pop	esi
 12212 00003590 C3                  <1> 	retn
 12213                              <1> 
 12214                              <1> swpin_dnp_err:
 12215 00003591 B805000000          <1> 	mov	eax, SWP_DISK_NOT_PRESENT_ERR
 12216                              <1> swpin_err_retn:
 12217 00003596 A3[65B10000]        <1> 	mov	[u.error], eax
 12218 0000359B F9                  <1> 	stc
 12219 0000359C C3                  <1> 	retn
 12220                              <1> 
 12221                              <1> swpin_snp_err:
 12222 0000359D B806000000          <1> 	mov	eax, SWP_SECTOR_NOT_PRESENT_ERR
 12223 000035A2 EBF2                <1> 	jmp	short swpin_err_retn
 12224                              <1> 
 12225                              <1> swap_out:
 12226                              <1> 	; 31/08/2015
 12227                              <1> 	; 05/05/2015
 12228                              <1> 	; 30/04/2015
 12229                              <1> 	; 28/04/2015
 12230                              <1> 	; 18/04/2015
 12231                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12232                              <1> 	;
 12233                              <1> 	; INPUT -> 
 12234                              <1> 	;	none
 12235                              <1> 	;
 12236                              <1> 	; OUTPUT ->
 12237                              <1> 	;	EAX = Physical page address (which is swapped out
 12238                              <1> 	;	      for allocating a new page)
 12239                              <1> 	;	CF = 1 -> swap disk writing error (disk/file not present
 12240                              <1> 	;		  or sector not present or drive not ready
 12241                              <1> 	;	     EAX = Error code
 12242                              <1> 	;	     [u.error] = EAX 
 12243                              <1> 	;		       = The last error code for the process
 12244                              <1> 	;		         (will be reset after returning to user)	  
 12245                              <1> 	;
 12246                              <1> 	; Modified Registers -> non (except EAX)
 12247                              <1> 	;
 12248 000035A4 66833D[C5BD0000]01  <1> 	cmp 	word [swpq_count], 1
 12249 000035AC 7274                <1>         jc      short swpout_im_err ; 'insufficient memory'
 12250                              <1> 
 12251                              <1>         ;cmp     dword [swp_drv], 1
 12252                              <1> 	;jc	short swpout_dnp_err ; 'swap disk/file not present'
 12253                              <1> 
 12254 000035AE 833D[CFBD0000]01    <1>         cmp     dword [swpd_free], 1
 12255 000035B5 7258                <1> 	jc	short swpout_nfspc_err ; 'no free space on swap disk'
 12256                              <1> 
 12257 000035B7 53                  <1> 	push	ebx
 12258                              <1> swpout_1:
 12259 000035B8 31DB                <1> 	xor	ebx, ebx
 12260 000035BA E86A000000          <1> 	call	swap_queue_shift
 12261 000035BF 21C0                <1> 	and	eax, eax	; entry count (before shifting)
 12262 000035C1 7457                <1> 	jz	short swpout_npts_err  ; There is no any PTE in
 12263                              <1> 				       ; the swap queue
 12264 000035C3 BB00E00800          <1> 	mov	ebx, swap_queue	       ; Addres of the head of 
 12265                              <1> 				       ; the swap queue		
 12266 000035C8 8B03                <1> 	mov	eax, [ebx]	       ; The PTE in the queue head	
 12267                              <1> 
 12268                              <1> 	;test	al, PTE_A_PRESENT      ; bit 0 = 1
 12269                              <1> 	;jz	short swpout_1	       ; non-present page already
 12270                              <1> 				       ; must not be in the queue
 12271                              <1> 
 12272                              <1> 	;test	al, PTE_A_WRITE	       ; bit 1 = 0
 12273                              <1> 	;jz	short swpout_1 	       ; read only page (must not be
 12274                              <1> 				       ; swapped out)
 12275                              <1> 	
 12276 000035CA A820                <1> 	test	al, PTE_A_ACCESS       ; bit 5 = 1 (Accessed)
 12277 000035CC 75EA                <1> 	jnz	short swpout_1 	       ; accessed page (must not be
 12278                              <1> 				       ; swapped out, at this stage)
 12279                              <1> 	;
 12280 000035CE 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 12281                              <1> 	;
 12282 000035D2 52                  <1> 	push	edx
 12283 000035D3 89DA                <1> 	mov	edx, ebx	       ; Page table entry address	
 12284 000035D5 89C3                <1> 	mov	ebx, eax	       ; Buffer (Page) Address				
 12285                              <1> 	;
 12286 000035D7 E861010000          <1> 	call	link_swap_block
 12287 000035DC 7304                <1> 	jnc	short swpout_2	       ; It may not be needed here	
 12288 000035DE 5A                  <1> 	pop	edx		       ; because [swpd_free] value	
 12289 000035DF 5B                  <1> 	pop	ebx
 12290 000035E0 EB2D                <1> 	jmp	short swpout_nfspc_err ; was checked at the beginging. 	
 12291                              <1> swpout_2:	
 12292 000035E2 56                  <1> 	push	esi
 12293 000035E3 51                  <1> 	push	ecx
 12294 000035E4 50                  <1> 	push	eax ; sector address
 12295 000035E5 8B35[C7BD0000]      <1> 	mov	esi, [swp_drv]	
 12296 000035EB B908000000          <1> 	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
 12297                              <1> 		; Note: Even if corresponding physical disk's sector 
 12298                              <1> 		; size different than 512 bytes, logical disk sector
 12299                              <1> 		; size is 512 bytes and disk writing procedure
 12300                              <1> 		; will be performed for writing 4096 bytes
 12301                              <1> 		; (2*2048, 8*512). 
 12302                              <1> 	; ESI = Logical disk description table address
 12303                              <1> 	; EBX = Buffer address
 12304                              <1> 	; EAX = Sector adress (offset address, logical sector number)
 12305                              <1> 	; ECX = Sector count ; 8 sectors
 12306 000035F0 E8A4010000          <1> 	call	logical_disk_write
 12307 000035F5 59                  <1> 	pop	ecx ; sector address	
 12308 000035F6 730C                <1> 	jnc	short swpout_write_ok
 12309                              <1> 	;
 12310                              <1> 	;; call	unlink_swap_block ; this block must be left as 'in use'
 12311                              <1> swpout_dw_err:
 12312 000035F8 B808000000          <1> 	mov	eax, SWP_DISK_WRITE_ERR ; drive not ready or write error
 12313 000035FD A3[65B10000]        <1> 	mov	[u.error], eax
 12314 00003602 EB06                <1> 	jmp	short swpout_retn
 12315                              <1> 	;
 12316                              <1> swpout_write_ok:
 12317                              <1> 	; EBX = Buffer (page) address
 12318                              <1> 	; EDX = Page Table entry address
 12319                              <1> 	; ECX = Swap disk sector (file block) address (31 bit)
 12320 00003604 D1E1                <1> 	shl 	ecx, 1  ; 31 bit sector address from bit 1 to bit 31 
 12321 00003606 890A                <1> 	mov 	[edx], ecx 
 12322                              <1> 		; bit 0 = 0 (swapped page)
 12323 00003608 89D8                <1> 	mov	eax, ebx
 12324                              <1> swpout_retn:
 12325 0000360A 59                  <1> 	pop	ecx
 12326 0000360B 5E                  <1> 	pop	esi
 12327 0000360C 5A                  <1> 	pop	edx
 12328 0000360D 5B                  <1> 	pop	ebx
 12329 0000360E C3                  <1> 	retn
 12330                              <1> 
 12331                              <1> ; Note: Swap_queue will not be updated in 'swap_out' procedure
 12332                              <1> ;	after the page is swapped out. (the PTE at the queue head
 12333                              <1> ;	-with 'non-present' attribute- will be dropped from the
 12334                              <1> ;	the queue in next 'swap_out' or in next 'swap_queue_shift'.
 12335                              <1> 	
 12336                              <1> ;swpout_dnp_err:
 12337                              <1> ;	mov	eax, SWP_DISK_NOT_PRESENT_ERR ; disk not present
 12338                              <1> ;	jmp	short swpout_err_retn
 12339                              <1> swpout_nfspc_err:
 12340 0000360F B807000000          <1> 	mov	eax, SWP_NO_FREE_SPACE_ERR ; no free space
 12341                              <1> swpout_err_retn:
 12342 00003614 A3[65B10000]        <1> 	mov	[u.error], eax
 12343                              <1> 	;stc
 12344 00003619 C3                  <1> 	retn
 12345                              <1> swpout_npts_err:
 12346 0000361A B809000000          <1> 	mov	eax, SWP_NO_PAGE_TO_SWAP_ERR
 12347 0000361F 5B                  <1> 	pop	ebx
 12348 00003620 EBF2                <1> 	jmp	short swpout_err_retn
 12349                              <1> swpout_im_err:
 12350 00003622 B801000000          <1> 	mov	eax, ERR_MINOR_IM ; insufficient (out of) memory
 12351 00003627 EBEB                <1> 	jmp	short swpout_err_retn
 12352                              <1> 
 12353                              <1> swap_queue_shift:
 12354                              <1> 	; 20/07/2015
 12355                              <1> 	; 28/04/2015
 12356                              <1> 	; 18/04/2015
 12357                              <1> 	; 23/10/2014 (Retro UNIX 386 v1 - beginning)
 12358                              <1> 	;
 12359                              <1> 	; INPUT ->
 12360                              <1> 	;	EBX = Virtual (linear) address (bit 12 to 31) 
 12361                              <1> 	;	      and process number combination (bit 0 to 11)
 12362                              <1> 	;	EBX = 0 -> shift/drop from the head (offset 0)
 12363                              <1> 	; OUTPUT ->
 12364                              <1> 	;	If EBX input > 0 
 12365                              <1> 	;	    the queue will be shifted 4 bytes (dword),
 12366                              <1> 	; 	    from the tail to the head, up to entry offset
 12367                              <1> 	; 	    which points to EBX input value or nothing
 12368                              <1> 	;	    to do if EBX value is not found in the queue.
 12369                              <1> 	;	    (The entry -with EBX value- will be removed
 12370                              <1> 	;	     from the queue if it is found.)	
 12371                              <1> 	;	If EBX input = 0
 12372                              <1> 	;	    the queue will be shifted 4 bytes (dword),
 12373                              <1> 	; 	    from the tail to the head, if the PTE address
 12374                              <1> 	;	    in head of the queue is marked as "accessed"
 12375                              <1> 	;	    or it is marked as "non present".
 12376                              <1> 	;	    (If "accessed" flag of the PTE -in the head-
 12377                              <1> 	; 	    is set -to 1-, it will be reset -to 0- and then, 
 12378                              <1> 	;	    the queue will be rotated -without dropping
 12379                              <1> 	; 	    the PTE from the queue-, for 4 bytes on head
 12380                              <1> 	; 	    to tail direction. The PTE in the head will be
 12381                              <1> 	;	    moved in the tail, other PTEs will be shifted on
 12382                              <1> 	;	    head direction.)	
 12383                              <1> 	;
 12384                              <1> 	;	EAX = [swpq_count] (before the shifting)
 12385                              <1> 	;	    (EAX = 0 -> next 'swap_out' stage 
 12386                              <1> 	; 	     is not applicable)	
 12387                              <1> 	;
 12388                              <1> 	; Modified Registers -> EAX
 12389                              <1> 	;
 12390 00003629 0FB705[C5BD0000]    <1> 	movzx   eax, word [swpq_count]  ; Max. 1024
 12391 00003630 6621C0              <1> 	and	ax, ax
 12392 00003633 7433                <1> 	jz	short swpqs_retn
 12393 00003635 57                  <1> 	push	edi
 12394 00003636 56                  <1> 	push	esi
 12395 00003637 53                  <1> 	push	ebx
 12396 00003638 51                  <1> 	push	ecx
 12397 00003639 50                  <1> 	push	eax
 12398 0000363A BE00E00800          <1> 	mov	esi, swap_queue
 12399 0000363F 89C1                <1> 	mov	ecx, eax
 12400 00003641 09DB                <1> 	or	ebx, ebx
 12401 00003643 7424                <1> 	jz	short swpqs_7
 12402                              <1> swpqs_1:
 12403 00003645 AD                  <1> 	lodsd
 12404 00003646 39D8                <1> 	cmp	eax, ebx
 12405 00003648 7404                <1> 	je	short swpqs_2
 12406 0000364A E2F9                <1> 	loop	swpqs_1
 12407 0000364C EB15                <1> 	jmp	short swpqs_6
 12408                              <1> swpqs_2:
 12409 0000364E 89F7                <1> 	mov	edi, esi
 12410 00003650 83EF04              <1> 	sub 	edi, 4
 12411                              <1> swpqs_3:
 12412 00003653 66FF0D[C5BD0000]    <1> 	dec	word [swpq_count]
 12413 0000365A 7403                <1> 	jz	short swpqs_5
 12414                              <1> swpqs_4:
 12415 0000365C 49                  <1> 	dec 	ecx
 12416 0000365D F3A5                <1> 	rep	movsd	; shift up (to the head)
 12417                              <1> swpqs_5:
 12418 0000365F 31C0                <1> 	xor	eax, eax
 12419 00003661 8907                <1> 	mov	[edi], eax
 12420                              <1> swpqs_6:
 12421 00003663 58                  <1> 	pop	eax
 12422 00003664 59                  <1> 	pop	ecx
 12423 00003665 5B                  <1> 	pop	ebx
 12424 00003666 5E                  <1> 	pop	esi
 12425 00003667 5F                  <1> 	pop	edi
 12426                              <1> swpqs_retn:
 12427 00003668 C3                  <1> 	retn		
 12428                              <1> swpqs_7:
 12429 00003669 89F7                <1> 	mov	edi, esi ; head
 12430 0000366B AD                  <1> 	lodsd
 12431                              <1> 	; 20/07/2015
 12432 0000366C 89C3                <1> 	mov	ebx, eax
 12433 0000366E 81E300F0FFFF        <1> 	and	ebx, ~PAGE_OFF ; ~0FFFh 
 12434                              <1> 		      ; ebx = virtual address (at page boundary)	
 12435 00003674 25FF0F0000          <1> 	and	eax, PAGE_OFF ; 0FFFh
 12436                              <1> 		      ; ax = process number (1 to 4095)
 12437 00003679 3A05[5FB10000]      <1> 	cmp	al, [u.uno]
 12438                              <1> 		; Max. 16 (nproc) processes for Retro UNIX 386 v1
 12439 0000367F 7507                <1> 	jne	short swpqs_8
 12440 00003681 A1[69B10000]        <1> 	mov	eax, [u.pgdir]
 12441 00003686 EB16                <1> 	jmp	short swpqs_9
 12442                              <1> swpqs_8:
 12443                              <1> 	;shl	ax, 2
 12444 00003688 C0E002              <1> 	shl	al, 2
 12445 0000368B 8B80[A0AE0000]      <1> 	mov 	eax, [eax+p.upage-4]
 12446 00003691 09C0                <1> 	or	eax, eax
 12447 00003693 74BE                <1> 	jz	short swpqs_3 ; invalid upage
 12448 00003695 83C061              <1> 	add	eax, u.pgdir - user
 12449                              <1> 			 ; u.pgdir value for the process
 12450                              <1> 			 ; is in [eax]
 12451 00003698 8B00                <1> 	mov	eax, [eax]
 12452 0000369A 21C0                <1> 	and	eax, eax
 12453 0000369C 74B5                <1> 	jz	short swpqs_3 ; invalid page directory
 12454                              <1> swpqs_9:
 12455 0000369E 52                  <1> 	push	edx
 12456                              <1> 	; eax = page directory
 12457                              <1> 	; ebx = virtual address
 12458 0000369F E87EFBFFFF          <1> 	call	get_pte
 12459 000036A4 89D3                <1> 	mov	ebx, edx ; PTE address
 12460 000036A6 5A                  <1> 	pop	edx
 12461 000036A7 72AA                <1> 	jc	short swpqs_3 ; empty PDE
 12462                              <1> 	; EAX = PTE value
 12463 000036A9 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0 = 1
 12464 000036AB 74A6                <1> 	jz	short swpqs_3 ; Drop non-present page
 12465                              <1> 			      ; from the queue (head)
 12466 000036AD A802                <1> 	test	al, PTE_A_WRITE	  ; bit 1 = 0
 12467 000036AF 74A2                <1> 	jz	short swpqs_3 ; Drop read only page
 12468                              <1> 			      ; from the queue (head) 	
 12469                              <1> 	;test	al, PTE_A_ACCESS  ; bit 5 = 1 (Accessed)
 12470                              <1> 	;jz	short swpqs_6 ; present
 12471                              <1> 			      ; non-accessed page
 12472 000036B1 0FBAF005            <1>         btr     eax, PTE_A_ACCESS_BIT ; reset 'accessed' bit
 12473 000036B5 73AC                <1> 	jnc	short swpqs_6  ; non-accessed page
 12474 000036B7 8903                <1> 	mov	[ebx], eax     ; save changed attribute
 12475                              <1> 	;
 12476                              <1> 	; Rotation (head -> tail)
 12477 000036B9 49                  <1> 	dec	ecx     ; entry count -> last entry number		
 12478 000036BA 74A7                <1> 	jz	short swpqs_6
 12479                              <1> 		; esi = head + 4
 12480                              <1> 		; edi = head
 12481 000036BC 8B07                <1> 	mov	eax, [edi] ; 20/07/2015
 12482 000036BE F3A5                <1> 	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
 12483 000036C0 8907                <1> 	mov	[edi], eax ; head -> tail ; [k] = [1] 		
 12484 000036C2 EB9F                <1> 	jmp	short swpqs_6
 12485                              <1> 
 12486                              <1> add_to_swap_queue:
 12487                              <1> ; temporary - 16/09/2015
 12488 000036C4 C3                  <1> retn
 12489                              <1> 	; 20/07/2015
 12490                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12491                              <1> 	;
 12492                              <1> 	; Adds new page to swap queue
 12493                              <1> 	; (page directories and page tables must not be added
 12494                              <1> 	; to swap queue)	
 12495                              <1> 	;
 12496                              <1> 	; INPUT ->
 12497                              <1> 	;	EBX = Virtual address (for current process, [u.uno])
 12498                              <1> 	;
 12499                              <1> 	; OUTPUT ->
 12500                              <1> 	;	EAX = [swpq_count]
 12501                              <1> 	;	      (after the PTE has been added)
 12502                              <1> 	;	EAX = 0 -> Swap queue is full, (1024 entries)
 12503                              <1> 	;	      the pte could not be added.
 12504                              <1> 	;
 12505                              <1> 	; Modified Registers -> EAX
 12506                              <1> 	;
 12507 000036C5 53                  <1> 	push	ebx
 12508 000036C6 6681E300F0          <1>         and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
 12509 000036CB 8A1D[5FB10000]      <1> 	mov	bl, [u.uno] ; current process number
 12510 000036D1 E853FFFFFF          <1> 	call	swap_queue_shift ; drop from the queue if
 12511                              <1> 				 ; it is already in the queue
 12512                              <1> 		; Then add it to the tail of the queue
 12513 000036D6 0FB705[C5BD0000]    <1> 	movzx	eax, word [swpq_count]
 12514 000036DD 663D0004            <1> 	cmp	ax, 1024
 12515 000036E1 7205                <1> 	jb	short atsq_1
 12516 000036E3 6629C0              <1> 	sub	ax, ax
 12517 000036E6 5B                  <1> 	pop	ebx
 12518 000036E7 C3                  <1> 	retn
 12519                              <1> atsq_1:
 12520 000036E8 56                  <1> 	push	esi
 12521 000036E9 BE00E00800          <1> 	mov	esi, swap_queue
 12522 000036EE 6621C0              <1> 	and	ax, ax
 12523 000036F1 740A                <1> 	jz	short atsq_2
 12524 000036F3 66C1E002            <1> 	shl	ax, 2	; convert to offset
 12525 000036F7 01C6                <1> 	add	esi, eax
 12526 000036F9 66C1E802            <1> 	shr	ax, 2
 12527                              <1> atsq_2:
 12528 000036FD 6640                <1> 	inc	ax
 12529 000036FF 891E                <1> 	mov	[esi], ebx ; Virtual address + [u.uno] combination
 12530 00003701 66A3[C5BD0000]      <1> 	mov	[swpq_count], ax
 12531 00003707 5E                  <1> 	pop	esi
 12532 00003708 5B                  <1> 	pop	ebx
 12533 00003709 C3                  <1> 	retn
 12534                              <1> 
 12535                              <1> unlink_swap_block:
 12536                              <1> 	; 15/09/2015
 12537                              <1> 	; 30/04/2015
 12538                              <1> 	; 18/04/2015
 12539                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12540                              <1> 	;
 12541                              <1> 	; INPUT -> 
 12542                              <1> 	;	EAX = swap disk/file offset address
 12543                              <1> 	;	      (bit 1 to bit 31)
 12544                              <1> 	; OUTPUT ->
 12545                              <1> 	;	[swpd_free] is increased
 12546                              <1> 	;	(corresponding SWAP DISK ALLOC. TABLE bit is SET)
 12547                              <1> 	;
 12548                              <1> 	; Modified Registers -> EAX
 12549                              <1> 	;
 12550 0000370A 53                  <1> 	push	ebx
 12551 0000370B 52                  <1> 	push	edx
 12552                              <1> 	;
 12553 0000370C C1E804              <1> 	shr	eax, SECTOR_SHIFT+1  ;3+1 ; shift sector address to 
 12554                              <1> 				     ; 3 bits right
 12555                              <1> 				     ; to get swap block/page number
 12556 0000370F 89C2                <1> 	mov	edx, eax
 12557                              <1> 	; 15/09/2015
 12558 00003711 C1EA03              <1> 	shr	edx, 3		     ; to get offset to S.A.T.
 12559                              <1> 				     ; (1 allocation bit = 1 page)
 12560                              <1> 				     ; (1 allocation bytes = 8 pages)
 12561 00003714 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
 12562                              <1> 				     ; (to get 32 bit position)			
 12563                              <1> 	;
 12564 00003717 BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table address
 12565 0000371C 01D3                <1> 	add	ebx, edx
 12566 0000371E 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
 12567                              <1> 				     ; (allocation bit position)	 
 12568 00003721 3B05[D3BD0000]      <1> 	cmp 	eax, [swpd_next]     ; is the new free block addr. lower
 12569                              <1> 				     ; than the address in 'swpd_next' ?
 12570                              <1> 				     ; (next/first free block value)		
 12571 00003727 7305                <1> 	jnb	short uswpbl_1	     ; no	
 12572 00003729 A3[D3BD0000]        <1> 	mov	[swpd_next], eax     ; yes	
 12573                              <1> uswpbl_1:
 12574 0000372E 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate block
 12575                              <1> 				     ; set relevant bit to 1.
 12576                              <1> 				     ; set CF to the previous bit value	
 12577 00003731 F5                  <1> 	cmc			     ; complement carry flag	
 12578 00003732 7206                <1> 	jc	short uswpbl_2	     ; do not increase swfd_free count
 12579                              <1> 				     ; if the block is already deallocated
 12580                              <1> 				     ; before.	
 12581 00003734 FF05[CFBD0000]      <1>         inc     dword [swpd_free]
 12582                              <1> uswpbl_2:
 12583 0000373A 5A                  <1> 	pop	edx
 12584 0000373B 5B                  <1> 	pop	ebx
 12585 0000373C C3                  <1> 	retn
 12586                              <1> 
 12587                              <1> link_swap_block:
 12588                              <1> 	; 01/07/2015
 12589                              <1> 	; 18/04/2015
 12590                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
 12591                              <1> 	;
 12592                              <1> 	; INPUT -> none
 12593                              <1> 	;
 12594                              <1> 	; OUTPUT ->
 12595                              <1> 	;	EAX = OFFSET ADDRESS OF THE ALLOCATED BLOCK (4096 bytes)
 12596                              <1> 	;	      in sectors (corresponding 
 12597                              <1> 	;	      SWAP DISK ALLOCATION TABLE bit is RESET)
 12598                              <1> 	;
 12599                              <1> 	;	CF = 1 and EAX = 0 
 12600                              <1> 	; 		   if there is not a free block to be allocated	
 12601                              <1> 	;
 12602                              <1> 	; Modified Registers -> none (except EAX)
 12603                              <1> 	;
 12604                              <1> 
 12605                              <1> 	;mov	eax, [swpd_free]
 12606                              <1> 	;and	eax, eax
 12607                              <1> 	;jz	short out_of_swpspc
 12608                              <1> 	;
 12609 0000373D 53                  <1> 	push	ebx
 12610 0000373E 51                  <1> 	push	ecx
 12611                              <1> 	;
 12612 0000373F BB00000D00          <1> 	mov	ebx, swap_alloc_table ; Swap Allocation Table offset
 12613 00003744 89D9                <1> 	mov	ecx, ebx
 12614 00003746 031D[D3BD0000]      <1> 	add	ebx, [swpd_next] ; Free block searching starts from here
 12615                              <1> 				 ; next_free_swap_block >> 5
 12616 0000374C 030D[D7BD0000]      <1> 	add	ecx, [swpd_last] ; Free block searching ends here
 12617                              <1> 				 ; (total_swap_blocks - 1) >> 5
 12618                              <1> lswbl_scan:
 12619 00003752 39CB                <1> 	cmp	ebx, ecx
 12620 00003754 770A                <1> 	ja	short lswbl_notfound
 12621                              <1> 	;
 12622 00003756 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
 12623                              <1> 			   ; Clears ZF if a bit is found set (1) and 
 12624                              <1> 			   ; loads the destination with an index to
 12625                              <1> 			   ; first set bit. (0 -> 31) 
 12626                              <1> 			   ; Sets ZF to 1 if no bits are found set.
 12627                              <1> 	; 01/07/2015
 12628 00003759 751C                <1> 	jnz	short lswbl_found ; ZF = 0 -> a free block has been found
 12629                              <1> 			 ;
 12630                              <1> 			 ; NOTE:  a Swap Disk Allocation Table bit 
 12631                              <1> 			 ;	  with value of 1 means 
 12632                              <1> 			 ;	  the corresponding page is free 
 12633                              <1> 			 ;	  (Retro UNIX 386 v1 feaure only!)
 12634 0000375B 83C304              <1> 	add	ebx, 4
 12635                              <1> 			 ; We return back for searching next page block
 12636                              <1> 			 ; NOTE: [swpd_free] is not ZERO; so, 
 12637                              <1> 			 ;	 we always will find at least 1 free block here.
 12638 0000375E EBF2                <1> 	jmp    	short lswbl_scan
 12639                              <1> 	;
 12640                              <1> lswbl_notfound:	
 12641 00003760 81E900000D00        <1> 	sub	ecx, swap_alloc_table
 12642 00003766 890D[D3BD0000]      <1> 	mov	[swpd_next], ecx ; next/first free page = last page 
 12643                              <1> 				 ; (unlink_swap_block procedure will change it)
 12644 0000376C 31C0                <1> 	xor	eax, eax
 12645 0000376E A3[CFBD0000]        <1> 	mov	[swpd_free], eax
 12646 00003773 F9                  <1> 	stc
 12647                              <1> lswbl_ok:
 12648 00003774 59                  <1> 	pop	ecx
 12649 00003775 5B                  <1> 	pop	ebx
 12650 00003776 C3                  <1> 	retn
 12651                              <1> 	;
 12652                              <1> ;out_of_swpspc:
 12653                              <1> ;	stc
 12654                              <1> ;	retn
 12655                              <1> 
 12656                              <1> lswbl_found:
 12657 00003777 89D9                <1> 	mov	ecx, ebx
 12658 00003779 81E900000D00        <1> 	sub	ecx, swap_alloc_table
 12659 0000377F 890D[D3BD0000]      <1> 	mov	[swpd_next], ecx ; Set first free block searching start
 12660                              <1> 				 ; address/offset (to the next)
 12661 00003785 FF0D[CFBD0000]      <1>         dec     dword [swpd_free] ; 1 block has been allocated (X = X-1) 
 12662                              <1> 	;
 12663 0000378B 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
 12664                              <1> 				 ; is copied into the Carry Flag and then cleared
 12665                              <1> 				 ; in the destination.
 12666                              <1> 				 ;
 12667                              <1> 				 ; Reset the bit which is corresponding to the 
 12668                              <1> 				 ; (just) allocated block.
 12669 0000378E C1E105              <1> 	shl	ecx, 5		 ; (block offset * 32) + block index
 12670 00003791 01C8                <1> 	add	eax, ecx	 ; = block number
 12671 00003793 C1E003              <1> 	shl	eax, SECTOR_SHIFT ; 3, sector (offset) address of the block
 12672                              <1> 				 ; 1 block =  8 sectors
 12673                              <1> 	;
 12674                              <1> 	; EAX = offset address of swap disk/file sector (beginning of the block)
 12675                              <1> 	;
 12676                              <1> 	; NOTE: The relevant page table entry will be updated
 12677                              <1> 	;       according to this EAX value...
 12678                              <1> 	;
 12679 00003796 EBDC                <1> 	jmp	short lswbl_ok
 12680                              <1> 
 12681                              <1> logical_disk_read:
 12682                              <1> 	; 20/07/2015
 12683                              <1> 	; 09/03/2015 (temporary code here)
 12684                              <1> 	;
 12685                              <1> 	; INPUT ->
 12686                              <1> 	; 	ESI = Logical disk description table address
 12687                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
 12688                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
 12689                              <1> 	; 	ECX = Sector count
 12690                              <1> 	;
 12691                              <1> 	;
 12692 00003798 C3                  <1> 	retn
 12693                              <1> 
 12694                              <1> logical_disk_write:
 12695                              <1> 	; 20/07/2015
 12696                              <1> 	; 09/03/2015 (temporary code here)
 12697                              <1> 	;
 12698                              <1> 	; INPUT ->
 12699                              <1> 	; 	ESI = Logical disk description table address
 12700                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
 12701                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
 12702                              <1> 	; 	ECX = Sector count
 12703                              <1> 	;
 12704 00003799 C3                  <1> 	retn
 12705                              <1> 
 12706                              <1> get_physical_addr:
 12707                              <1> 	; 18/10/2015
 12708                              <1> 	; 29/07/2015
 12709                              <1> 	; 20/07/2015
 12710                              <1> 	; 04/06/2015
 12711                              <1> 	; 20/05/2015
 12712                              <1> 	; 28/04/2015
 12713                              <1> 	; 18/04/2015
 12714                              <1> 	; Get physical address
 12715                              <1> 	;     (allocates a new page for user if it is not present)
 12716                              <1> 	;	
 12717                              <1> 	; (This subroutine is needed for mapping user's virtual 
 12718                              <1> 	; (buffer) address to physical address (of the buffer).)
 12719                              <1> 	; ('sys write', 'sys read' system calls...)
 12720                              <1> 	;
 12721                              <1> 	; INPUT ->
 12722                              <1> 	;	EBX = virtual address
 12723                              <1> 	;	u.pgdir = page directory (physical) address
 12724                              <1> 	;
 12725                              <1> 	; OUTPUT ->
 12726                              <1> 	;	EAX = physical address 
 12727                              <1> 	;	EBX = linear address	
 12728                              <1> 	;	EDX = physical address of the page frame
 12729                              <1> 	;	      (with attribute bits)
 12730                              <1> 	;	ECX = byte count within the page frame
 12731                              <1> 	;
 12732                              <1> 	; Modified Registers -> EAX, EBX, ECX, EDX
 12733                              <1> 	;
 12734 0000379A 81C300004000        <1> 	add	ebx, CORE ; 18/10/2015
 12735                              <1> 	;
 12736 000037A0 A1[69B10000]        <1> 	mov	eax, [u.pgdir]
 12737 000037A5 E878FAFFFF          <1> 	call	get_pte
 12738                              <1> 		; EDX = Page table entry address (if CF=0)
 12739                              <1> 	        ;       Page directory entry address (if CF=1)
 12740                              <1> 		;       (Bit 0 value is 0 if PT is not present)
 12741                              <1> 		; EAX = Page table entry value (page address)
 12742                              <1> 		;	CF = 1 -> PDE not present or invalid ? 
 12743 000037AA 731C                <1> 	jnc	short gpa_1
 12744                              <1> 	;
 12745 000037AC E856F9FFFF          <1> 	call	allocate_page
 12746 000037B1 725B                <1> 	jc	short gpa_im_err  ; 'insufficient memory' error
 12747                              <1> gpa_0:
 12748 000037B3 E8C9F9FFFF          <1> 	call 	clear_page
 12749                              <1> 	; EAX = Physical (base) address of the allocated (new) page
 12750 000037B8 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
 12751                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
 12752                              <1> 			   ; (user, writable, present page)	
 12753 000037BA 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
 12754 000037BC A1[69B10000]        <1> 	mov	eax, [u.pgdir]	
 12755 000037C1 E85CFAFFFF          <1> 	call	get_pte
 12756 000037C6 7246                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
 12757                              <1> gpa_1:
 12758                              <1> 	; EAX = PTE value, EDX = PTE address
 12759 000037C8 A801                <1> 	test 	al, PTE_A_PRESENT
 12760 000037CA 751A                <1> 	jnz	short gpa_3
 12761 000037CC 09C0                <1> 	or	eax, eax
 12762 000037CE 7430                <1> 	jz	short gpa_4  ; Allocate a new page
 12763                              <1> 	; 20/07/2015
 12764 000037D0 55                  <1> 	push	ebp
 12765 000037D1 89DD                <1> 	mov	ebp, ebx ; virtual (linear) address
 12766                              <1> 	; reload swapped page
 12767 000037D3 E83C000000          <1> 	call	reload_page ; 28/04/2015
 12768 000037D8 5D                  <1> 	pop	ebp
 12769 000037D9 7224                <1> 	jc	short gpa_retn
 12770                              <1> gpa_2:
 12771                              <1> 	; 20/07/2015
 12772                              <1> 	; 20/05/2015
 12773                              <1> 	; add this page to swap queue
 12774 000037DB 50                  <1> 	push	eax 
 12775                              <1> 	; EBX = virtual address
 12776 000037DC E8E3FEFFFF          <1> 	call 	add_to_swap_queue
 12777 000037E1 58                  <1> 	pop	eax
 12778                              <1> 		; PTE address in EDX
 12779                              <1> 		; virtual address in EBX
 12780                              <1> 	; EAX = memory page address
 12781 000037E2 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_USER + PTE_A_WRITE
 12782                              <1> 				  ; present flag, bit 0 = 1
 12783                              <1> 				  ; user flag, bit 2 = 1	
 12784                              <1> 				  ; writable flag, bit 1 = 1
 12785 000037E4 8902                <1> 	mov	[edx], eax  ; Update PTE value
 12786                              <1> gpa_3:
 12787                              <1> 	; 18/10/2015
 12788 000037E6 89D9                <1> 	mov	ecx, ebx
 12789 000037E8 81E1FF0F0000        <1> 	and	ecx, PAGE_OFF
 12790 000037EE 89C2                <1> 	mov 	edx, eax
 12791 000037F0 662500F0            <1> 	and	ax, PTE_A_CLEAR
 12792 000037F4 01C8                <1> 	add	eax, ecx
 12793 000037F6 F7D9                <1> 	neg	ecx ; 1 -> -1 (0FFFFFFFFh), 4095 (0FFFh) -> -4095
 12794 000037F8 81C100100000        <1> 	add	ecx, PAGE_SIZE
 12795 000037FE F8                  <1> 	clc
 12796                              <1> gpa_retn:
 12797 000037FF C3                  <1> 	retn	
 12798                              <1> gpa_4:	
 12799 00003800 E802F9FFFF          <1> 	call	allocate_page
 12800 00003805 7207                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
 12801 00003807 E875F9FFFF          <1> 	call	clear_page
 12802 0000380C EBCD                <1> 	jmp	short gpa_2
 12803                              <1> 
 12804                              <1> gpa_im_err:	
 12805 0000380E B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
 12806                              <1> 				  ; Major error = 0 (No protection fault)	
 12807 00003813 C3                  <1> 	retn
 12808                              <1> 
 12809                              <1> reload_page:
 12810                              <1> 	; 20/07/2015
 12811                              <1> 	; 28/04/2015 (Retro UNIX 386 v1 - beginning)
 12812                              <1> 	;
 12813                              <1> 	; Reload (Restore) swapped page at memory
 12814                              <1> 	;
 12815                              <1> 	; INPUT -> 
 12816                              <1> 	;	EBP = Virtual (linear) memory address
 12817                              <1> 	;	EAX = PTE value (swap disk sector address)
 12818                              <1> 	;	(Swap disk sector address = bit 1 to bit 31 of EAX)	
 12819                              <1> 	; OUTPUT ->
 12820                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF RELOADED PAGE
 12821                              <1> 	;
 12822                              <1> 	;	CF = 1 and EAX = error code
 12823                              <1> 	;
 12824                              <1> 	; Modified Registers -> none (except EAX)
 12825                              <1> 	;
 12826 00003814 D1E8                <1> 	shr	eax, 1   ; Convert PTE value to swap disk address 
 12827 00003816 53                  <1> 	push	ebx      ;
 12828 00003817 89C3                <1> 	mov	ebx, eax ; Swap disk (offset) address	
 12829 00003819 E8E9F8FFFF          <1> 	call	allocate_page
 12830 0000381E 720C                <1> 	jc	short rlp_im_err
 12831 00003820 93                  <1> 	xchg 	eax, ebx	
 12832                              <1> 	; EBX = Physical memory (page) address
 12833                              <1> 	; EAX = Swap disk (offset) address
 12834                              <1> 	; EBP = Virtual (linear) memory address
 12835 00003821 E81AFDFFFF          <1> 	call	swap_in
 12836 00003826 720B                <1> 	jc	short rlp_swp_err  ; (swap disk/file read error)
 12837 00003828 89D8                <1> 	mov	eax, ebx	
 12838                              <1> rlp_retn:
 12839 0000382A 5B                  <1> 	pop	ebx
 12840 0000382B C3                  <1> 	retn
 12841                              <1> 	
 12842                              <1> rlp_im_err:	
 12843 0000382C B801000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
 12844                              <1> 				  ; Major error = 0 (No protection fault)	
 12845 00003831 EBF7                <1> 	jmp	short rlp_retn
 12846                              <1> 
 12847                              <1> rlp_swp_err:
 12848 00003833 B804000000          <1> 	mov 	eax, SWP_DISK_READ_ERR ; Swap disk read error !
 12849 00003838 EBF0                <1> 	jmp	short rlp_retn
 12850                              <1> 
 12851                              <1> 
 12852                              <1> copy_page_dir:
 12853                              <1> 	; 19/09/2015
 12854                              <1> 	; temporary - 07/09/2015
 12855                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
 12856                              <1> 	;
 12857                              <1> 	; INPUT -> 
 12858                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
 12859                              <1> 	;		    page directory.
 12860                              <1> 	; OUTPUT ->
 12861                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
 12862                              <1> 	;	       page directory.
 12863                              <1> 	;	(New page directory with new page table entries.)
 12864                              <1> 	;	(New page tables with read only copies of the parent's
 12865                              <1> 	;	pages.)
 12866                              <1> 	;	EAX = 0 -> Error (CF = 1)
 12867                              <1> 	;
 12868                              <1> 	; Modified Registers -> none (except EAX)
 12869                              <1> 	;
 12870 0000383A E8C8F8FFFF          <1> 	call	allocate_page
 12871 0000383F 723E                <1> 	jc	short cpd_err
 12872                              <1> 	;
 12873 00003841 55                  <1> 	push	ebp ; 20/07/2015
 12874 00003842 56                  <1> 	push	esi
 12875 00003843 57                  <1> 	push	edi
 12876 00003844 53                  <1> 	push	ebx
 12877 00003845 51                  <1> 	push	ecx
 12878 00003846 8B35[69B10000]      <1> 	mov	esi, [u.pgdir]
 12879 0000384C 89C7                <1> 	mov	edi, eax
 12880 0000384E 50                  <1> 	push	eax ; save child's page directory address
 12881                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
 12882                              <1> 	; (use same system space for all user page tables) 
 12883 0000384F A5                  <1> 	movsd
 12884 00003850 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
 12885 00003855 B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
 12886                              <1> cpd_0:	
 12887 0000385A AD                  <1> 	lodsd
 12888                              <1> 	;or	eax, eax
 12889                              <1>         ;jnz     short cpd_1
 12890 0000385B A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
 12891 0000385D 7508                <1> 	jnz	short cpd_1
 12892                              <1>  	; (virtual address at the end of the page table)	
 12893 0000385F 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
 12894 00003865 EB0F                <1> 	jmp	short cpd_2
 12895                              <1> cpd_1:	
 12896 00003867 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
 12897 0000386B 89C3                <1> 	mov	ebx, eax
 12898                              <1> 	; EBX = Parent's page table address
 12899 0000386D E81F000000          <1> 	call	copy_page_table
 12900 00003872 720C                <1> 	jc	short cpd_p_err
 12901                              <1> 	; EAX = Child's page table address
 12902 00003874 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
 12903                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
 12904                              <1> 			 ; (present, writable, user)
 12905                              <1> cpd_2:
 12906 00003876 AB                  <1> 	stosd
 12907 00003877 E2E1                <1> 	loop	cpd_0
 12908                              <1> 	;
 12909 00003879 58                  <1> 	pop	eax  ; restore child's page directory address
 12910                              <1> cpd_3:
 12911 0000387A 59                  <1> 	pop	ecx
 12912 0000387B 5B                  <1> 	pop	ebx
 12913 0000387C 5F                  <1> 	pop	edi
 12914 0000387D 5E                  <1> 	pop	esi
 12915 0000387E 5D                  <1> 	pop	ebp
 12916                              <1> cpd_err:
 12917 0000387F C3                  <1> 	retn
 12918                              <1> cpd_p_err:
 12919                              <1> 	; release the allocated pages missing (recover free space)
 12920 00003880 58                  <1> 	pop	eax  ; the new page directory address (physical)
 12921 00003881 8B1D[69B10000]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
 12922 00003887 E8B4F9FFFF          <1> 	call 	deallocate_page_dir
 12923 0000388C 29C0                <1> 	sub	eax, eax ; 0
 12924 0000388E F9                  <1> 	stc
 12925 0000388F EBE9                <1> 	jmp	short cpd_3	
 12926                              <1> 
 12927                              <1> copy_page_table:
 12928                              <1> 	; 19/09/2015
 12929                              <1> 	; temporary - 07/09/2015
 12930                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
 12931                              <1> 	;
 12932                              <1> 	; INPUT -> 
 12933                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
 12934                              <1> 	;	EBP = page table entry index (from 'copy_page_dir')
 12935                              <1> 	; OUTPUT ->
 12936                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
 12937                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
 12938                              <1> 	;	CF = 1 -> error 
 12939                              <1> 	;
 12940                              <1> 	; Modified Registers -> EBP (except EAX)
 12941                              <1> 	;
 12942 00003891 E871F8FFFF          <1> 	call	allocate_page
 12943 00003896 725A                <1> 	jc	short cpt_err
 12944                              <1> 	;
 12945 00003898 50                  <1> 	push	eax ; *
 12946                              <1> 	;push 	ebx
 12947 00003899 56                  <1> 	push	esi
 12948 0000389A 57                  <1> 	push	edi
 12949 0000389B 52                  <1> 	push	edx
 12950 0000389C 51                  <1> 	push	ecx
 12951                              <1> 	;
 12952 0000389D 89DE                <1> 	mov	esi, ebx
 12953 0000389F 89C7                <1> 	mov	edi, eax
 12954 000038A1 89C2                <1> 	mov	edx, eax
 12955 000038A3 81C200100000        <1> 	add	edx, PAGE_SIZE 	
 12956                              <1> cpt_0:
 12957 000038A9 AD                  <1> 	lodsd
 12958 000038AA A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
 12959 000038AC 750B                <1> 	jnz	short cpt_1
 12960 000038AE 21C0                <1> 	and	eax, eax
 12961 000038B0 7430                <1> 	jz	short cpt_2
 12962                              <1> 	; ebp = virtual (linear) address of the memory page
 12963 000038B2 E85DFFFFFF          <1> 	call	reload_page ; 28/04/2015
 12964 000038B7 7234                <1> 	jc	short cpt_p_err
 12965                              <1> cpt_1:
 12966 000038B9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
 12967 000038BD 89C1                <1> 	mov	ecx, eax
 12968                              <1> 	; Allocate a new page for the child process
 12969 000038BF E843F8FFFF          <1> 	call	allocate_page
 12970 000038C4 7227                <1> 	jc	short cpt_p_err
 12971 000038C6 57                  <1> 	push	edi
 12972 000038C7 56                  <1> 	push	esi
 12973 000038C8 89CE                <1> 	mov	esi, ecx
 12974 000038CA 89C7                <1> 	mov	edi, eax
 12975 000038CC B900040000          <1> 	mov	ecx, PAGE_SIZE/4
 12976 000038D1 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
 12977 000038D3 5E                  <1> 	pop	esi
 12978 000038D4 5F                  <1> 	pop	edi
 12979                              <1> 	; 
 12980 000038D5 53                  <1> 	push	ebx
 12981 000038D6 50                  <1> 	push	eax
 12982 000038D7 89EB                <1> 	mov	ebx, ebp
 12983                              <1> 	; ebx = virtual address of the memory page
 12984 000038D9 E8E6FDFFFF          <1> 	call	add_to_swap_queue
 12985 000038DE 58                  <1> 	pop	eax
 12986 000038DF 5B                  <1> 	pop	ebx
 12987                              <1> 	;
 12988                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
 12989 000038E0 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
 12990                              <1> cpt_2:
 12991 000038E2 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
 12992                              <1> 	;
 12993 000038E3 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
 12994                              <1> 	;
 12995 000038E9 39D7                <1> 	cmp	edi, edx
 12996 000038EB 72BC                <1> 	jb	short cpt_0
 12997                              <1> cpt_p_err:
 12998 000038ED 59                  <1> 	pop	ecx
 12999 000038EE 5A                  <1> 	pop	edx
 13000 000038EF 5F                  <1> 	pop	edi
 13001 000038F0 5E                  <1> 	pop	esi
 13002                              <1> 	;pop	ebx
 13003 000038F1 58                  <1> 	pop	eax ; *
 13004                              <1> cpt_err:
 13005 000038F2 C3                  <1> 	retn
 13006                              <1> 
 13007                              <1> 
 13008                              <1> ; /// End Of MEMORY MANAGEMENT FUNCTIONS ///
 13009                              <1> 
 13010                              <1> ;; Data:
 13011                              <1> 
 13012                              <1> ; 09/03/2015
 13013                              <1> ;swpq_count: dw 0 ; count of pages on the swap que
 13014                              <1> ;swp_drv:    dd 0 ; logical drive description table address of the swap drive/disk
 13015                              <1> ;swpd_size:  dd 0 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
 13016                              <1> ;swpd_free:  dd 0 ; free page blocks (4096 bytes) on swap disk/drive (logical)
 13017                              <1> ;swpd_next:  dd 0 ; next free page block
 13018                              <1> ;swpd_last:  dd 0 ; last swap page block		 		
 13019                                  %include 'timer.s'   ; 17/01/2015
 13020                              <1> ; ****************************************************************************
 13021                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - timer.s
 13022                              <1> ; ----------------------------------------------------------------------------
 13023                              <1> ; Last Update: 29/01/2016
 13024                              <1> ; ----------------------------------------------------------------------------
 13025                              <1> ; Beginning: 17/01/2016
 13026                              <1> ; ----------------------------------------------------------------------------
 13027                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13028                              <1> ; ----------------------------------------------------------------------------
 13029                              <1> ; Turkish Rational DOS
 13030                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 13031                              <1> ;
 13032                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 13033                              <1> ;
 13034                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
 13035                              <1> ; ****************************************************************************
 13036                              <1> 
 13037                              <1> ; TRDOS 386  (TRDOS v2.0) Kernel - TIMER & REAL TIME CLOCK (BIOS) FUNCTIONS
 13038                              <1> 
 13039                              <1> ; IBM PC-AT BIOS Source Code ('BIOS2.ASM')
 13040                              <1> ; TITLE BIOS2 ---- 06/10/85 BIOS INTERRUPT ROUTINES
 13041                              <1> 
 13042                              <1> ;
 13043                              <1> ; ///////// TIMER (& REAL TIME CLOCK) FUNCTIONS ///////////////
 13044                              <1> 
 13045                              <1> int1Ah:
 13046                              <1> 	; 29/01/2016
 13047                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13048 000038F3 9C                  <1> 	pushfd
 13049 000038F4 0E                  <1> 	push 	cs
 13050 000038F5 E801000000          <1> 	call 	TIME_OF_DAY_1
 13051 000038FA C3                  <1> 	retn
 13052                              <1> 
 13053                              <1> ;--- INT  1A H -- (TIME OF DAY) -------------------------------------------------
 13054                              <1> ;       THIS BIOS ROUTINE ALLOWS THE CLOCKS TO BE SET OR READ			:
 13055                              <1> ;										:
 13056                              <1> ; PARAMETERS:									:
 13057                              <1> ;     (AH) = 00H  READ THE CURRENT SETTING AND RETURN WITH,			:
 13058                              <1> ;                      (CX) = HIGH PORTION OF COUNT				:
 13059                              <1> ;                      (DX) = LOW PORTION OF COUNT				:
 13060                              <1> ;                      (AL) = 0 TIMER HAS NOT PASSED 24 HOURS SINCE LAST READ	:
 13061                              <1> ;                             1 IF ON ANOTHER DAY. (RESET TO ZERO AFTER READ)	:
 13062                              <1> ;										:
 13063                              <1> ;     (AH) = 01H  SET THE CURRENT CLOCK USING,					:
 13064                              <1> ;		     (CX) = HIGH PORTION OF COUNT				:
 13065                              <1> ;		     (DX) = LOW PORTION OF COUNT.				:
 13066                              <1> ;										:
 13067                              <1> ;               NOTE: COUNTS OCCUR AT THE RATE OF 1193180/65536 COUNTS/SECOND	:
 13068                              <1> ;                            (OR ABOUT 18.2 PER SECOND -- SEE EQUATES)		:
 13069                              <1> ;										:
 13070                              <1> ;     (AH) = 02H  READ THE REAL TIME CLOCK AND RETURN WITH,			:
 13071                              <1> ;                      (CH) = HOURS IN BCD (00-23)				:
 13072                              <1> ;                      (CL) = MINUTES IN BCD (00-59)				:
 13073                              <1> ;                      (DH) = SECONDS IN BCD (00-59)				:
 13074                              <1> ;                      (DL) = DAYLIGHT SAVINGS ENABLE (00-01)			:
 13075                              <1> ;										:
 13076                              <1> ;     (AH) = 03H  SET THE REAL TIME CLOCK USING,				:
 13077                              <1> ;                     (CH) = HOURS IN BCD (00-23)				:
 13078                              <1> ;                     (CL) = MINUTES IN BCD (00-59)				:
 13079                              <1> ;                     (DH) = SECONDS IN BCD (00-59)				:
 13080                              <1> ;                     (DL) = 01 IF DAYLIGHT SAVINGS ENABLE OPTION, ELSE 00.	:
 13081                              <1> ;										:
 13082                              <1> ;             NOTE: (DL) = 00 IF DAYLIGHT SAVINGS TIME ENABLE IS NOT ENABLED.	:
 13083                              <1> ;                   (DL) = 01 ENABLES TWO SPECIAL UPDATES THE LAST SUNDAY IN	:
 13084                              <1> ;	           APRIL   (1:59:59 --> 3:00:00 AM) AND THE LAST SUNDAY IN	:
 13085                              <1> ;                   OCTOBER (1:59:59 --> 1:00:00 AM) THE FIRST TIME.		:
 13086                              <1> ;										:
 13087                              <1> ;     (AH) = 04H  READ THE DATE FROM THE REAL TIME CLOCK AND RETURN WITH,	:
 13088                              <1> ;                      (CH) = CENTURY IN BCD (19 OR 20)				:
 13089                              <1> ;                      (CL) = YEAR IN BCD (00-99)				:
 13090                              <1> ;                      (DH) = MONTH IN BCD (01-12)				:
 13091                              <1> ;                      (DL) = DAY IN BCD (01-31).				:
 13092                              <1> ;										:
 13093                              <1> ;     (AH) = 05H  SET THE DATE INTO THE REAL TIME CLOCK USING,			:
 13094                              <1> ;                     (CH) = CENTURY IN BCD (19 OR 20)				:
 13095                              <1> ;                     (CL) = YEAR IN BCD (00-99)				:
 13096                              <1> ;                     (DH) = MONTH IN BCD (01-12)				:
 13097                              <1> ;                     (DL) = DAY IN BCD (01-31).				:
 13098                              <1> ;										:
 13099                              <1> ;     (AH) = 06H  SET THE ALARM TO INTERRUPT AT SPECIFIED TIME,			:
 13100                              <1> ;                     (CH) = HOURS IN BCD (00-23 (OR FFH))			:
 13101                              <1> ;                     (CL) = MINUTES IN BCD (00-59 (OR FFH))			:
 13102                              <1> ;                     (DH) = SECONDS IN BCD (00-59 (OR FFH))			:
 13103                              <1> ;										:
 13104                              <1> ;     (AH) = 07H  RESET THE ALARM INTERRUPT FUNCTION.				:
 13105                              <1> ;										:
 13106                              <1> ; NOTES: FOR ALL RETURNS CY= 0 FOR SUCCESSFUL OPERATION.			:
 13107                              <1> ;        FOR (AH)= 2, 4, 6 - CARRY FLAG SET IF REAL TIME CLOCK NOT OPERATING.	:
 13108                              <1> ;        FOR (AH)= 6 - CARRY FLAG SET IF ALARM ALREADY ENABLED. 		:
 13109                              <1> ;        FOR THE ALARM FUNCTION (AH = 6) THE USER MUST SUPPLY A ROUTINE AND	:
 13110                              <1> ;         INTERCEPT THE CORRECT ADDRESS IN THE VECTOR TABLE FOR INTERRUPT 4AH.	:
 13111                              <1> ;         USE 0FFH FOR ANY "DO NOT CARE" POSITION FOR INTERVAL INTERRUPTS.	:
 13112                              <1> ;        INTERRUPTS ARE DISABLED DURING DATA MODIFICATION. 			:
 13113                              <1> ;        AH & AL ARE RETURNED MODIFIED AND NOT DEFINED EXCEPT WHERE INDICATED.	:
 13114                              <1> ;--------------------------------------------------------------------------------
 13115                              <1> 
 13116                              <1> ; 29/01/2016
 13117                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13118                              <1> 
 13119                              <1> TIME_OF_DAY_1:
 13120 000038FB FB                  <1> 	sti				; INTERRUPTS BACK ON
 13121 000038FC 80FC08              <1> 	cmp	ah, (RTC_TBE-RTC_TB)/4	; CHECK IF COMMAND IN VALID RANGE (0-7)
 13122 000038FF F5                  <1> 	cmc				; COMPLEMENT CARRY FOR ERROR EXIT
 13123 00003900 721A                <1> 	jc	short TIME_9		; EXIT WITH CARRY = 1 IF NOT VALID
 13124                              <1> 
 13125 00003902 1E                  <1> 	push	ds
 13126 00003903 56                  <1> 	push	esi
 13127 00003904 66BE1000            <1> 	mov	si, KDATA		; kernel data segment
 13128 00003908 8EDE                <1> 	mov	ds, si
 13129 0000390A C0E402              <1> 	shl	ah, 2			; convert function to dword offset
 13130 0000390D 0FB6F4              <1> 	movzx	esi, ah			; PLACE INTO ADDRESSING REGISTER
 13131 00003910 FA                  <1> 	cli				; NO INTERRUPTS DURING TIME FUNCTIONS
 13132 00003911 FF96[1F390000]      <1> 	call	[esi+RTC_TB]		; VECTOR TO FUNCTION REQUESTED WITH CY=0
 13133                              <1> 					; RETURN WITH CARRY FLAG SET FOR RESULT
 13134 00003917 FB                  <1> 	sti				; INTERRUPTS BACK ON
 13135 00003918 B400                <1> 	mov	ah, 0			; CLEAR (AH) TO ZERO
 13136 0000391A 5E                  <1> 	pop	esi			; RECOVER USERS REGISTER
 13137 0000391B 1F                  <1> 	pop	ds			; RECOVER USERS SEGMENT SELECTOR
 13138                              <1> TIME_9:					; RETURN WITH CY= 0 IF NO ERROR
 13139 0000391C CA0400              <1> 	retf	4
 13140                              <1> 					; ROUTINE VECTOR TABLE (AH)=
 13141                              <1> RTC_TB:
 13142 0000391F [3F390000]          <1> 	dd	RTC_00			; 0 = READ CURRENT CLOCK COUNT
 13143 00003923 [52390000]          <1> 	dd	RTC_10			; 1 = SET CLOCK COUNT
 13144 00003927 [60390000]          <1> 	dd	RTC_20			; 2 = READ THE REAL TIME CLOCK TIME
 13145 0000392B [8F390000]          <1> 	dd	RTC_30			; 3 = SET REAL TIME CLOCK TIME
 13146 0000392F [D1390000]          <1> 	dd	RTC_40			; 4 = READ THE REAL TIME CLOCK DATE
 13147 00003933 [FE390000]          <1> 	dd	RTC_50			; 5 = SET REAL TIME CLOCK DATE
 13148 00003937 [4B3A0000]          <1> 	dd	RTC_60			; 6 = SET THE REAL TIME CLOCK ALARM
 13149 0000393B [9E3A0000]          <1> 	dd	RTC_70			; 7 = RESET ALARM
 13150                              <1> 
 13151                              <1> RTC_TBE	equ	$
 13152                              <1> 
 13153                              <1> RTC_00:				; READ TIME COUNT
 13154 0000393F A0[D0A20000]        <1> 	mov	al, [TIMER_OFL]		; GET THE OVERFLOW FLAG
 13155 00003944 C605[D0A20000]00    <1> 	mov	byte [TIMER_OFL], 0	; AND THEN RESET THE OVERFLOW FLAG
 13156 0000394B 8B0D[CCA20000]      <1>         mov     ecx, [TIMER_LH]         ; GET COUNT OF TIME
 13157 00003951 C3                  <1> 	retn
 13158                              <1> 
 13159                              <1> RTC_10:				; SET TIME COUNT
 13160 00003952 890D[CCA20000]      <1>         mov     [TIMER_LH], ecx         ; SET TIME COUNT
 13161 00003958 C605[D0A20000]00    <1> 	mov	byte [TIMER_OFL], 0	; RESET OVERFLOW FLAG
 13162 0000395F C3                  <1> 	retn				; RETURN WITH NO CARRY
 13163                              <1> 
 13164                              <1> RTC_20:				; GET RTC TIME
 13165 00003960 E8EB010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13166 00003965 7227                <1> 	jc	short RTC_29		; EXIT IF ERROR (CY= 1)
 13167                              <1> 
 13168 00003967 B000                <1> 	mov	al, CMOS_SECONDS	; SET ADDRESS OF SECONDS
 13169 00003969 E8FD010000          <1> 	call	CMOS_READ		; GET SECONDS
 13170 0000396E 88C6                <1> 	mov	dh, al			; SAVE
 13171 00003970 B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13172 00003972 E8F4010000          <1> 	call	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
 13173 00003977 2401                <1> 	and	al, 00000001b		; MASK FOR VALID DSE BIT
 13174 00003979 88C2                <1> 	mov	dl, al			; SET [DL] TO ZERO FOR NO DSE BIT
 13175 0000397B B002                <1> 	mov	al, CMOS_MINUTES	; SET ADDRESS OF MINUTES
 13176 0000397D E8E9010000          <1> 	call	CMOS_READ		; GET MINUTES
 13177 00003982 88C1                <1> 	mov	cl, al			; SAVE
 13178 00003984 B004                <1>         mov     al, CMOS_HOURS          ; SET ADDRESS OF HOURS
 13179 00003986 E8E0010000          <1> 	call	CMOS_READ		; GET HOURS
 13180 0000398B 88C5                <1> 	mov	ch, al			; SAVE
 13181 0000398D F8                  <1> 	clc				; SET CY= 0
 13182                              <1> RTC_29:
 13183 0000398E C3                  <1> 	retn				; RETURN WITH RESULT IN CARRY FLAG
 13184                              <1> 
 13185                              <1> RTC_30:				; SET RTC TIME
 13186 0000398F E8BC010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13187 00003994 7305                <1> 	jnc	short RTC_35		; GO AROUND IF CLOCK OPERATING
 13188 00003996 E817010000          <1> 	call	RTC_STA			; ELSE TRY INITIALIZING CLOCK
 13189                              <1> RTC_35:
 13190 0000399B 88F4                <1> 	mov	ah, dh			; GET TIME BYTE - SECONDS
 13191 0000399D B000                <1> 	mov	al, CMOS_SECONDS	; ADDRESS SECONDS
 13192 0000399F E8DF010000          <1> 	call	CMOS_WRITE		; UPDATE SECONDS
 13193 000039A4 88CC                <1> 	mov	ah, cl			; GET TIME BYTE - MINUTES
 13194 000039A6 B002                <1> 	mov	al, CMOS_MINUTES	; ADDRESS MINUTES
 13195 000039A8 E8D6010000          <1> 	call	CMOS_WRITE		; UPDATE MINUTES
 13196 000039AD 88EC                <1> 	mov	ah, ch			; GET TIME BYTE - HOURS
 13197 000039AF B004                <1> 	mov	al, CMOS_HOURS		; ADDRESS HOURS
 13198 000039B1 E8CD010000          <1> 	call	CMOS_WRITE		; UPDATE ADDRESS
 13199                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13200                              <1> 	;mov	ah, al
 13201 000039B6 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13202 000039BA E8AC010000          <1> 	call	CMOS_READ		; READ CURRENT TIME
 13203 000039BF 2462                <1> 	and	al, 01100010b		; MASK FOR VALID BIT POSITIONS
 13204 000039C1 0C02                <1> 	or	al, 00000010b		; TURN ON 24 HOUR MODE
 13205 000039C3 80E201              <1> 	and	dl, 00000001b		; USE ONLY THE DSE BIT
 13206 000039C6 08D0                <1> 	or	al, dl			; GET DAY LIGHT SAVINGS TIME BIT (OSE)
 13207 000039C8 86E0                <1> 	xchg	ah, al			; PLACE IN WORK REGISTER AND GET ADDRESS
 13208 000039CA E8B4010000          <1> 	call	CMOS_WRITE		; SET NEW ALARM SITS
 13209 000039CF F8                  <1> 	clc				; SET CY= 0
 13210 000039D0 C3                  <1> 	retn				; RETURN WITH CY= 0
 13211                              <1> 
 13212                              <1> RTC_40:				; GET RTC DATE
 13213 000039D1 E87A010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13214 000039D6 7225                <1> 	jc	short RTC_49		; EXIT IF ERROR (CY= 1)
 13215                              <1> 
 13216 000039D8 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH
 13217 000039DA E88C010000          <1> 	call	CMOS_READ		; READ DAY OF MONTH
 13218 000039DF 88C2                <1> 	mov	dl, al			; SAVE
 13219 000039E1 B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH
 13220 000039E3 E883010000          <1> 	call	CMOS_READ		; READ MONTH
 13221 000039E8 88C6                <1> 	mov	dh, al			; SAVE
 13222 000039EA B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR
 13223 000039EC E87A010000          <1> 	call	CMOS_READ		; READ YEAR
 13224 000039F1 88C1                <1> 	mov	cl, al			; SAVE
 13225 000039F3 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY LOCATION
 13226 000039F5 E871010000          <1> 	call	CMOS_READ		; GET CENTURY BYTE
 13227 000039FA 88C5                <1> 	mov	ch, al			; SAVE
 13228 000039FC F8                  <1> 	clc				; SET CY=0
 13229                              <1> RTC_49:
 13230 000039FD C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAG
 13231                              <1> 
 13232                              <1> RTC_50:				; SET RTC DATE
 13233 000039FE E84D010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13234 00003A03 7305                <1> 	jnc	short RTC_55		; GO AROUND IF NO ERROR
 13235 00003A05 E8A8000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
 13236                              <1> RTC_55:
 13237 00003A0A 66B80600            <1> 	mov	ax, CMOS_DAY_WEEK	; ADDRESS OF DAY OF WEEK BYTE
 13238 00003A0E E870010000          <1> 	call	CMOS_WRITE		; LOAD ZEROS TO DAY OF WEEK
 13239 00003A13 88D4                <1> 	mov	ah, dl			; GET DAY OF MONTH BYTE
 13240 00003A15 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH BYTE
 13241 00003A17 E867010000          <1> 	call	CMOS_WRITE		; WRITE OF DAY OF MONTH REGISTER
 13242 00003A1C 88F4                <1> 	mov	ah, dh			; GET MONTH
 13243 00003A1E B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH BYTE
 13244 00003A20 E85E010000          <1> 	call	CMOS_WRITE		; WRITE MONTH REGISTER
 13245 00003A25 88CC                <1> 	mov	ah, cl			; GET YEAR BYTE
 13246 00003A27 B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR REGISTER
 13247 00003A29 E855010000          <1> 	call	CMOS_WRITE		; WRITE YEAR REGISTER
 13248 00003A2E 88EC                <1> 	mov	ah, ch			; GET CENTURY BYTE
 13249 00003A30 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY BYTE
 13250 00003A32 E84C010000          <1> 	call	CMOS_WRITE		; WRITE CENTURY LOCATION
 13251                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13252                              <1> 	;mov	ah, al
 13253 00003A37 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13254 00003A3B E82B010000          <1> 	call	CMOS_READ		; READ WIRRENT SETTINGS
 13255 00003A40 247F                <1> 	and	al, 07Fh		; CLEAR 'SET BIT'
 13256 00003A42 86E0                <1> 	xchg	ah, al			; MOVE TO WORK REGISTER
 13257 00003A44 E83A010000          <1> 	call	CMOS_WRITE		; AND START CLOCK UPDATING
 13258 00003A49 F8                  <1> 	clc				; SET CY= 0
 13259 00003A4A C3                  <1> 	retn				; RETURN CY=0
 13260                              <1> 
 13261                              <1> RTC_60:				; SET RTC ALARM
 13262 00003A4B B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM
 13263 00003A4D E819010000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
 13264 00003A52 A820                <1> 	test	al, 20h			; CHECK FOR ALARM ALREADY ENABLED
 13265 00003A54 F9                  <1> 	stc				; SET CARRY IN CASE OF ERROR
 13266 00003A55 7542                <1> 	jnz	short RTC_69		; ERROR EXIT IF ALARM SET
 13267 00003A57 E8F4000000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
 13268 00003A5C 7305                <1> 	jnc	short RTC_65		; SKIP INITIALIZATION IF NO ERROR
 13269 00003A5E E84F000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
 13270                              <1> RTC_65:	
 13271 00003A63 88F4                <1> 	mov	ah, dh			; GET SECONDS BYTE
 13272 00003A65 B001                <1> 	mov	al, CMOS_SEC_ALARM	; ADDRESS THE SECONDS ALARM REGISTER
 13273 00003A67 E817010000          <1> 	call	CMOS_WRITE		; INSERT SECONDS
 13274 00003A6C 88CC                <1> 	mov	ah, cl			; GET MINUTES PARAMETER
 13275 00003A6E B003                <1> 	mov	al, CMOS_MIN_ALARM	; ADDRESS MINUTES ALARM REGISTER
 13276 00003A70 E80E010000          <1> 	call	CMOS_WRITE		; INSERT MINUTES
 13277 00003A75 88EC                <1> 	mov	ah, ch			; GET HOURS PARAMETER
 13278 00003A77 B005                <1> 	mov	al, CMOS_HR_ALARM	; ADDRESS HOUR ALARM REGISTER
 13279 00003A79 E805010000          <1> 	call	CMOS_WRITE		; INSERT HOURS
 13280 00003A7E E4A1                <1> 	in	al, INTB01		; READ SECOND INTERRUPT MASK REGISTER
 13281 00003A80 24FE                <1> 	and	al, 0FEh		; ENABLE ALARM TIMER BIT (CY= 0)
 13282 00003A82 E6A1                <1> 	out	INTB01, al		; WRITE UPDATED MASK
 13283                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13284                              <1> 	;mov	ah, al
 13285 00003A84 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
 13286 00003A88 E8DE000000          <1> 	call	CMOS_READ		; READ CURRENT ALARM REGISTER
 13287 00003A8D 247F                <1> 	and	al, 07Fh		; ENSURE SET BIT TURNED OFF
 13288 00003A8F 0C20                <1> 	or	al, 20h			; TURN ON ALARM ENABLE
 13289 00003A91 86E0                <1> 	xchg	ah, al			; MOVE MASK TO OUTPUT REGISTER
 13290 00003A93 E8EB000000          <1> 	call	CMOS_WRITE		; WRITE NEW ALARM MASK
 13291 00003A98 F8                  <1> 	clc				; SET CY= 0
 13292                              <1> RTC_69:
 13293 00003A99 66B80000            <1> 	mov	ax, 0			; CLEAR AX REGISTER
 13294 00003A9D C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAC
 13295                              <1> 
 13296                              <1> RTC_70:				; RESET ALARM
 13297                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
 13298                              <1> 	;mov	ah, al
 13299 00003A9E 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257	; ADDRESS ALARM REGISTER (TO BOTH AH,AL)
 13300 00003AA2 E8C4000000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
 13301 00003AA7 2457                <1> 	and	al, 57h			; TURN OFF ALARM ENABLE
 13302 00003AA9 86E0                <1> 	xchg	ah, al			; SAVE DATA AND RECOVER ADDRESS
 13303 00003AAB E8D3000000          <1> 	call	CMOS_WRITE		; RESTORE NEW VALUE
 13304 00003AB0 F8                  <1> 	clc				; SET CY= 0
 13305 00003AB1 C3                  <1> 	retn				; RETURN WITH NO CARRY
 13306                              <1> 
 13307                              <1> RTC_STA:			; INITIALIZE REAL TIME CLOCK
 13308                              <1> 	;mov	al, CMOS_REG_A		; ADDRESS REGISTER A AND LOAD DATA MASK		
 13309                              <1> 	;mov	ah, 26h
 13310 00003AB2 66B80A26            <1> 	mov	ax, (26h*100h)+CMOS_REG_A
 13311 00003AB6 E8C8000000          <1> 	call	CMOS_WRITE		; INITIALIZE STATUS REGISTER A
 13312                              <1> 	;mov	al, CMOS_REG_B		; SET "SET BIT" FOR CLOCK INITIALIZATION	
 13313                              <1> 	;mov	ah, 82h
 13314 00003ABB 66B80B82            <1> 	mov	ax, (82h*100h)+CMOS_REG_B
 13315 00003ABF E8BF000000          <1> 	call	CMOS_WRITE		; AND 24 HOUR MODE TO REGISTER B
 13316 00003AC4 B00C                <1> 	mov	al, CMOS_REG_C		; ADDRESS REGISTER C
 13317 00003AC6 E8A0000000          <1> 	call	CMOS_READ		; READ REGISTER C TO INITIALIZE
 13318 00003ACB B00D                <1> 	mov	al, CMOS_REG_D		; ADDRESS REGISTER D
 13319 00003ACD E899000000          <1> 	call	CMOS_READ		; READ REGISTER D TO INITIALIZE
 13320 00003AD2 C3                  <1> 	retn
 13321                              <1> 
 13322                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13323                              <1> 
 13324                              <1> ;--- HARDWARE INT  70 H -- ( IRQ LEVEL  8) --------------------------------------
 13325                              <1> ; ALARM INTERRUPT HANDLER (RTC)							:
 13326                              <1> ;       THIS ROUTINE HANDLES THE PERIODIC AND ALARM INTERRUPTS FROM THE CMOS	:
 13327                              <1> ;       TIMER. INPUT FREQUENCY IS 1.024 KHZ OR APPROXIMATELY 1024 INTERRUPTS	:
 13328                              <1> ;       EVERY SECOND FOR THE PERIODIC INTERRUPT. FOR THE ALARM FUNCTION,	:
 13329                              <1> ;       THE INTERRUPT WILL OCCUR AT THE DESIGNATED TIME.			:
 13330                              <1> ;										:
 13331                              <1> ;       INTERRUPTS ARE ENABLED WHEN THE EVENT OR ALARM FUNCTION IS ACTIVATED.	:
 13332                              <1> ;       FOR THE EVENT INTERRUPT, THE HANDLER WILL DECREMENT THE WAIT COUNTER	:
 13333                              <1> ;       AND WHEN IT EXPIRES WILL SET THE DESIGNATED LOCATION TO 80H. FOR	:
 13334                              <1> ;       THE ALARM INTERRUPT. THE USER MUST PROVIDE A ROUTINE TO INTERCEPT	:
 13335                              <1> ;       THE CORRECT ADDRESS FROM THE VECTOR TABLE INVOKED BY INTERRUPT 4AH	:
 13336                              <1> ;       PRIOR TO SETTING THE REAL TIME CLOCK ALARM (INT 1AH, AH= 06H).		:
 13337                              <1> ;--------------------------------------------------------------------------------
 13338                              <1> 
 13339                              <1> RTC_INT:			; ALARM INTERRUPT
 13340 00003AD3 1E                  <1> 	push	ds			; LEAVE INTERRUPTS DISABLED
 13341 00003AD4 50                  <1> 	push	eax			; SAVE REGISTERS
 13342 00003AD5 57                  <1> 	push	edi
 13343                              <1> RTC_I_1:				; CHECK FOR SECOND INTERRUPT
 13344 00003AD6 66B88C8B            <1> 	mov	ax, 256*(CMOS_REG_B+NMI)+CMOS_REG_C+NMI ; ALARM AND STATUS
 13345 00003ADA E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM FLAG MASK ADDRESS
 13346 00003ADC 90                  <1> 	nop				; I/O DELAY
 13347 00003ADD EB00                <1> 	jmp	short $+2
 13348 00003ADF E471                <1> 	in	al, CMOS_DATA		; READ AND RESET INTERRUPT REQUEST FLAGS
 13349 00003AE1 A860                <1> 	test	al, 01100000b		; CHECK FOR EITHER INTERRUPT PENDING
 13350 00003AE3 745D                <1> 	jz	short	RTC_I_9		; EXIT IF NOT A VALID RTC INTERRUPT
 13351                              <1> 
 13352 00003AE5 86E0                <1> 	xchg	ah, al			; SAVE FLAGS AND GET ENABLE ADDRESS
 13353 00003AE7 E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM ENABLE MASK ADDRESS
 13354 00003AE9 90                  <1> 	nop				; I/O DELAY
 13355 00003AEA EB00                <1> 	jmp	short $+2	
 13356 00003AEC E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ALARM ENABLE MASK
 13357 00003AEE 20E0                <1> 	and	al, ah			; ALLOW ONLY SOURCES THAT ARE ENABLED
 13358 00003AF0 A840                <1> 	test	al, 01000000b		; CHECK FOR PERIODIC INTERRUPT
 13359 00003AF2 743B                <1> 	jz	short RTC_I_5		; SKIP IF NOT A PERIODIC INTERRUPT
 13360                              <1> 
 13361                              <1> ;-----	DECREMENT WAIT COUNT BY INTERRUPT INTERVAL
 13362                              <1> 
 13363 00003AF4 66BF1000            <1> 	mov	di, KDATA		; kernel data segment
 13364 00003AF8 8EDF                <1> 	mov	ds, di
 13365                              <1> 	
 13366 00003AFA 812D[C6A20000]D003- <1> 	sub	dword [RTC_LH], 976	; DECREMENT COUNT BY 1/1024
 13367 00003B02 0000                <1>
 13368 00003B04 7329                <1> 	jnc	short RTC_I_5		; SKIP TILL 32 BIT WORD LESS THAN ZERO
 13369                              <1> 
 13370                              <1> ;-----	TURN OFF PERIODIC INTERRUPT ENABLE
 13371                              <1> 
 13372 00003B06 6650                <1> 	push	ax			; SAVE INTERRUPT FLAG MASK
 13373 00003B08 66B88B8B            <1> 	mov	ax, 257*(CMOS_REG_B+NMI) ; INTERRUPT ENABLE REGISTER
 13374 00003B0C E670                <1> 	out	CMOS_PORT, al		; WRITE ADDRESS TO CMOS CLOCK
 13375 00003B0E 90                  <1> 	nop				; I/O DELAY
 13376 00003B0F EB00                <1> 	jmp	short $+2
 13377 00003B11 E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ENABLES
 13378 00003B13 24BF                <1> 	and	al, 0BFh		; TURN OFF PIE
 13379 00003B15 86C4                <1> 	xchg	al, ah			; GET CMOS ADDRESS AND SAVE VALUE
 13380 00003B17 E670                <1> 	out	CMOS_PORT, al		; ADDRESS REGISTER B
 13381 00003B19 86C4                <1> 	xchg	al, ah			; GET NEW INTERRUPT ENABLE MASK
 13382 00003B1B E671                <1> 	out	CMOS_DATA, al		; SET MASK IN INTERRUPT ENABLE REGISTER
 13383 00003B1D C605[CAA20000]00    <1> 	mov	byte [RTC_WAIT_FLAG], 0	; SET FUNCTION ACTIVE FLAG OFF
 13384 00003B24 8B3D[CBA20000]      <1> 	mov	edi, [USER_FLAG]	; SET UP (DS:DI) TO POINT TO USER FLAG
 13385 00003B2A C60780              <1> 	mov	byte [edi], 80h		; TURN ON USERS FLAG
 13386 00003B2D 6658                <1> 	pop	ax			; GET INTERRUPT SOURCE BACK
 13387                              <1> RTC_I_5:
 13388 00003B2F A820                <1> 	test	al, 00100000b		; TEST FOR ALARM INTERRUPT
 13389 00003B31 740D                <1> 	jz	short RTC_I_7		; SKIP USER INTERRUPT CALL IF NOT ALARM
 13390                              <1> 
 13391 00003B33 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
 13392 00003B35 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
 13393 00003B37 FB                  <1> 	sti				; INTERRUPTS BACK ON NOW
 13394 00003B38 52                  <1> 	push	edx
 13395 00003B39 E8DC560000          <1> 	call	INT4Ah			; TRANSFER TO USER ROUTINE
 13396 00003B3E 5A                  <1> 	pop	edx
 13397 00003B3F FA                  <1> 	cli				; BLOCK INTERRUPT FOR RETRY
 13398                              <1> RTC_I_7:				; RESTART ROUTINE TO HANDLE DELAYED
 13399 00003B40 EB94                <1> 	jmp	short RTC_I_1		;  ENTRY AND SECOND EVENT BEFORE DONE
 13400                              <1> 
 13401                              <1> RTC_I_9:				; EXIT - NO PENDING INTERRUPTS
 13402 00003B42 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
 13403 00003B44 E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
 13404 00003B46 B020                <1> 	mov	al, EOI			; END OF INTERRUPT MASK TO 8259 - 2
 13405 00003B48 E6A0                <1> 	out	INTB00, al		; TO 8259 - 2
 13406 00003B4A E620                <1> 	out	INTA00,	al		; TO 8259 - 1
 13407 00003B4C 5F                  <1> 	pop	edi			; RESTORE REGISTERS
 13408 00003B4D 58                  <1> 	pop	eax
 13409 00003B4E 1F                  <1> 	pop	ds
 13410 00003B4F CF                  <1> 	iret				; END OF INTERRUPT
 13411                              <1> 
 13412                              <1> 
 13413                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
 13414                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (bios2.asm)
 13415                              <1> UPD_IPR:				; WAIT TILL UPDATE NOT IN PROGRESS
 13416 00003B50 51                  <1> 	push	ecx
 13417 00003B51 B9FFFF0000          <1> 	mov	ecx, 65535		; SET TIMEOUT LOOP COUNT (= 800)
 13418                              <1> 		; mov cx, 800	
 13419                              <1> UPD_10:
 13420 00003B56 B00A                <1> 	mov	al, CMOS_REG_A		; ADDRESS STATUS REGISTER A
 13421 00003B58 FA                  <1> 	cli				; NO TIMER INTERRUPTS DURING UPDATES
 13422 00003B59 E80D000000          <1> 	call	CMOS_READ		; READ UPDATE IN PROCESS FLAG
 13423 00003B5E A880                <1> 	test	al, 80h			; IF UIP BIT IS ON ( CANNOT READ TIME )
 13424 00003B60 7406                <1> 	jz	short UPD_90		; EXIT WITH CY= 0 IF CAN READ CLOCK NOW
 13425 00003B62 FB                  <1> 	sti				; ALLOW INTERRUPTS WHILE WAITING
 13426 00003B63 E2F1                <1> 	loop	UPD_10			; LOOP TILL READY OR TIMEOUT
 13427 00003B65 31C0                <1> 	xor	eax, eax		; CLEAR RESULTS IF ERROR
 13428                              <1> 		; xor ax, ax
 13429 00003B67 F9                  <1> 	stc				; SET CARRY FOR ERROR
 13430                              <1> UPD_90:
 13431 00003B68 59                  <1> 	pop	ecx			; RESTORE CALLERS REGISTER
 13432 00003B69 FA                  <1> 	cli				; INTERRUPTS OFF DURING SET
 13433 00003B6A C3                  <1> 	retn				; RETURN WITH CY FLAG SET
 13434                              <1> 
 13435                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
 13436                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (test4.asm)
 13437                              <1> 
 13438                              <1> ;--- CMOS_READ -----------------------------------------------------------------
 13439                              <1> ;		READ BYTE FROM CMOS_SYSTEM CLOCK CONFIGURATION TABLE	       :
 13440                              <1> ;									       :
 13441                              <1> ; INPUT: (AL)=	CMOS_TABLE ADDRESS TO BE READ				       :
 13442                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
 13443                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
 13444                              <1> ;									       :
 13445                              <1> ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL). IF BIT 7 OF (AL) WAS   :
 13446                              <1> ;		ON THEN NMI LEFT DISABLED, DURING THE CMOS READ BOTH NMI AND   :
 13447                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
 13448                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
 13449                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
 13450                              <1> ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
 13451                              <1> ;-------------------------------------------------------------------------------
 13452                              <1> 
 13453                              <1> CMOS_READ:
 13454 00003B6B 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
 13455 00003B6C D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
 13456 00003B6E F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
 13457 00003B6F D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
 13458 00003B71 FA                  <1> 	cli				; DISABLE INTERRUPTS
 13459 00003B72 E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
 13460 00003B74 90                  <1> 	nop				; I/O DELAY
 13461 00003B75 E471                <1> 	in	al, CMOS_DATA		; READ THE REQUESTED CMOS LOCATION
 13462 00003B77 6650                <1> 	push	ax			; SAVE (AH) REGISTER VALUE AND CMOS BYTE
 13463                              <1> 	; 15/03/2015 ; IBM PC/XT Model 286 BIOS source code 
 13464                              <1> 		     ; ----- 10/06/85 (test4.asm)
 13465 00003B79 B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2 ; GET ADDRESS OF DEFAULT LOCATION
 13466                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
 13467 00003B7B D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
 13468 00003B7D E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
 13469 00003B7F 6658                <1> 	pop	ax			; RESTORE (AH) AND (AL), CMOS BYTE
 13470 00003B81 9D                  <1> 	popf	
 13471 00003B82 C3                  <1> 	retn				; RETURN WITH FLAGS RESTORED
 13472                              <1> 
 13473                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 13474                              <1> 
 13475                              <1> ;--- CMOS_WRITE ----------------------------------------------------------------
 13476                              <1> ;	WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE		       :
 13477                              <1> ;									       :
 13478                              <1> ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
 13479                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
 13480                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
 13481                              <1> ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
 13482                              <1> ;									       :
 13483                              <1> ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
 13484                              <1> ;		IF BIT 7 OF (AL) IS ON, DURING THE CMOS UPDATE BOTH NMI AND    :
 13485                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
 13486                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
 13487                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
 13488                              <1> ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
 13489                              <1> ;-------------------------------------------------------------------------------
 13490                              <1> 
 13491                              <1> CMOS_WRITE:				; WRITE (AH) TO LOCATION (AL)
 13492 00003B83 9C                  <1> 	pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
 13493 00003B84 6650                <1> 	push	ax			; SAVE WORK REGISTER VALUES
 13494 00003B86 D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
 13495 00003B88 F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
 13496 00003B89 D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
 13497 00003B8B FA                  <1> 	cli				; DISABLE INTERRUPTS
 13498 00003B8C E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
 13499 00003B8E 88E0                <1> 	mov	al, ah			; GET THE DATA BYTE TO WRITE
 13500 00003B90 E671                <1> 	out	CMOS_DATA, al		; PLACE IN REQUESTED CMOS LOCATION
 13501 00003B92 B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2	; GET ADDRESS OF DEFAULT LOCATION
 13502                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
 13503 00003B94 D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
 13504 00003B96 E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
 13505 00003B98 90                  <1> 	nop				; I/O DELAY
 13506 00003B99 E471                <1> 	in	al, CMOS_DATA		; OPEN STANDBY LATCH
 13507 00003B9B 6658                <1> 	pop	ax			; RESTORE WORK REGISTERS
 13508 00003B9D 9D                  <1> 	popf
 13509 00003B9E C3                  <1> 	retn
 13510                              <1> 
 13511                              <1> ; /// End Of TIMER FUNCTIONS ///
 13512                                  %include 'sysdefs.s' ; 24/01/2015
 13513                              <1> ; ****************************************************************************
 13514                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYSTEM DEFINITIONS : sysdefs.s
 13515                              <1> ; ----------------------------------------------------------------------------
 13516                              <1> ; Last Update: 24/01/2016
 13517                              <1> ; ----------------------------------------------------------------------------
 13518                              <1> ; Beginning: 24/01/2016
 13519                              <1> ; ----------------------------------------------------------------------------
 13520                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13521                              <1> ; ----------------------------------------------------------------------------
 13522                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 13523                              <1> ; sysdefs.inc (14/11/2015)
 13524                              <1> ; ****************************************************************************
 13525                              <1> 
 13526                              <1> ; Retro UNIX 386 v1 Kernel - SYSDEFS.INC
 13527                              <1> ; Last Modification: 14/11/2015
 13528                              <1> ;
 13529                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
 13530                              <1> ; (Modified from 
 13531                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
 13532                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
 13533                              <1> ; 	UNIX.ASM (MASM 6.11) --> SYSDEFS.INC (NASM 2.11)
 13534                              <1> ; ----------------------------------------------------------------------------
 13535                              <1> ;
 13536                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
 13537                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
 13538                              <1> ; <Bell Laboratories (17/3/1972)>
 13539                              <1> ; <Preliminary Release of UNIX Implementation Document>
 13540                              <1> ;
 13541                              <1> ; ****************************************************************************
 13542                              <1> 
 13543                              <1> nproc 	equ	16  ; number of processes
 13544                              <1> nfiles 	equ	50
 13545                              <1> ntty	equ     8   ; 8+1 -> 8 (10/05/2013)
 13546                              <1> nbuf	equ	4   ; 6 ;; 21/08/2015 - 'namei' buffer problem when nbuf > 4 	
 13547                              <1> 		; NOTE: If fd0 super block buffer addres is beyond of the 1st
 13548                              <1> 		; 32K, DMA r/w routine or someting else causes a jump to 
 13549                              <1> 		; kernel panic routine (in 'alloc' routine, in u5.s)
 13550                              <1> 		; because of invalid buffer content (r/w error). 
 13551                              <1> 		; When all buffers are set before the end of the 1st 32k,
 13552                              <1> 		; there is no problem!? (14/11/2015) 
 13553                              <1> 
 13554                              <1> ;csgmnt	equ	2000h	; 26/05/2013 (segment of process 1)
 13555                              <1> ;core	equ 	0  	    ; 19/04/2013	
 13556                              <1> ;ecore	equ	32768 - 64  ; 04/06/2013 (24/05/2013)
 13557                              <1> 	; (if total size of argument list and arguments is 128 bytes)
 13558                              <1> 	; maximum executable file size = 32768-(64+40+128-6) = 32530 bytes
 13559                              <1> 	; maximum stack size = 40 bytes (+6 bytes for 'IRET' at 32570)	
 13560                              <1> 	; initial value of user's stack pointer = 32768-64-128-2 = 32574
 13561                              <1> 	; 	(sp=32768-args_space-2 at the beginning of execution)
 13562                              <1> 	; argument list offset = 32768-64-128 = 32576 (if it is 128 bytes)
 13563                              <1> 	; 'u' structure offset (for the '/core' dump file) = 32704
 13564                              <1> 	; '/core' dump file size = 32768 bytes
 13565                              <1>  
 13566                              <1> ; 08/03/2014 
 13567                              <1> ;sdsegmnt equ	6C0h  ; 256*16 bytes (swap data segment size for 16 processes)		 	 
 13568                              <1> ; 19/04/2013 Retro UNIX 8086 v1 feaure only !
 13569                              <1> ;;sdsegmnt equ 	740h  ; swap data segment (for user structures and registers)
 13570                              <1> 
 13571                              <1> ; 30/08/2013
 13572                              <1> time_count equ 4 ; 10 --> 4 01/02/2014
 13573                              <1> 
 13574                              <1> ; 05/02/2014
 13575                              <1> ; process status
 13576                              <1> ;SFREE 	equ 0
 13577                              <1> ;SRUN	equ 1
 13578                              <1> ;SWAIT	equ 2
 13579                              <1> ;SZOMB	equ 3
 13580                              <1> ;SSLEEP	equ 4 ; Retro UNIX 8086 V1 extension (for sleep and wakeup)
 13581                              <1> 
 13582                              <1> ; 09/03/2015
 13583                              <1> userdata equ 80000h ; user structure data address for current user ; temporary
 13584                              <1> swap_queue equ 90000h - 2000h ; swap queue address ; temporary
 13585                              <1> swap_alloc_table equ 0D0000h  ;  swap allocation table address ; temporary
 13586                              <1> 
 13587                              <1> ; 17/09/2015
 13588                              <1> ESPACE equ 48 ; [u.usp] (at 'sysent') - [u.sp] value for error return
 13589                              <1> 
 13590                              <1> ; 21/09/2015 (36) 
 13591                              <1> ; 01/07/2015 (35)
 13592                              <1> ; 14/07/2013 (0-34)
 13593                              <1> ; UNIX v1 system calls
 13594                              <1> _rele 	equ 0
 13595                              <1> _exit 	equ 1
 13596                              <1> _fork 	equ 2
 13597                              <1> _read 	equ 3
 13598                              <1> _write	equ 4
 13599                              <1> _open	equ 5
 13600                              <1> _close 	equ 6
 13601                              <1> _wait 	equ 7
 13602                              <1> _creat 	equ 8
 13603                              <1> _link 	equ 9
 13604                              <1> _unlink	equ 10
 13605                              <1> _exec	equ 11
 13606                              <1> _chdir	equ 12
 13607                              <1> _time 	equ 13
 13608                              <1> _mkdir 	equ 14
 13609                              <1> _chmod	equ 15
 13610                              <1> _chown	equ 16
 13611                              <1> _break	equ 17
 13612                              <1> _stat	equ 18
 13613                              <1> _seek	equ 19
 13614                              <1> _tell 	equ 20
 13615                              <1> _mount	equ 21
 13616                              <1> _umount	equ 22
 13617                              <1> _setuid	equ 23
 13618                              <1> _getuid	equ 24
 13619                              <1> _stime	equ 25
 13620                              <1> _quit	equ 26	
 13621                              <1> _intr	equ 27
 13622                              <1> _fstat	equ 28
 13623                              <1> _emt 	equ 29
 13624                              <1> _mdate 	equ 30
 13625                              <1> _stty 	equ 31
 13626                              <1> _gtty	equ 32
 13627                              <1> _ilgins	equ 33
 13628                              <1> _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
 13629                              <1> _msg	equ 35 ; Retro UNIX 386 v1 feature only !
 13630                              <1> _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
 13631                              <1> 
 13632                              <1> %macro sys 1-4
 13633                              <1>     ; 13/04/2015
 13634                              <1>     ; Retro UNIX 386 v1 system call.		
 13635                              <1>     mov eax, %1
 13636                              <1>     %if %0 >= 2   
 13637                              <1>         mov ebx, %2
 13638                              <1>         %if %0 >= 3    
 13639                              <1>             mov ecx, %3
 13640                              <1>             %if %0 = 4
 13641                              <1>                mov edx, %4   
 13642                              <1>             %endif
 13643                              <1>         %endif
 13644                              <1>     %endif
 13645                              <1>     int 30h	   
 13646                              <1> %endmacro
 13647                              <1> 
 13648                              <1> ; 13/05/2015 - ERROR CODES
 13649                              <1> ERR_FILE_NOT_OPEN  equ 10 ; 'file not open !' error
 13650                              <1> ERR_FILE_ACCESS    equ 11 ; 'permission denied !' error
 13651                              <1> ; 14/05/2015
 13652                              <1> ERR_DIR_ACCESS     equ 11 ; 'permission denied !' error
 13653                              <1> ERR_FILE_NOT_FOUND equ 12 ; 'file not found !' error
 13654                              <1> ERR_TOO_MANY_FILES equ 13 ; 'too many open files !' error
 13655                              <1> ERR_DIR_EXISTS     equ 14 ; 'directory already exists !' error 	
 13656                              <1> ; 16/05/2015		
 13657                              <1> ERR_DRV_NOT_RDY    equ 15 ; 'drive not ready !' error
 13658                              <1> ; 18/05/2015
 13659                              <1> ERR_DEV_NOT_RDY    equ 15 ; 'device not ready !' error
 13660                              <1> ERR_DEV_ACCESS     equ 11 ; 'permission denied !' error 
 13661                              <1> ERR_DEV_NOT_OPEN   equ 10 ; 'device not open !' error	
 13662                              <1> ; 07/06/2015
 13663                              <1> ERR_FILE_EOF	   equ 16 ; 'end of file !' error
 13664                              <1> ERR_DEV_VOL_SIZE   equ 16 ; 'out of volume' error
 13665                              <1> ; 09/06/2015
 13666                              <1> ERR_DRV_READ	   equ 17 ; 'disk read error !'
 13667                              <1> ERR_DRV_WRITE	   equ 18 ; 'disk write error !'
 13668                              <1> ; 16/06/2015
 13669                              <1> ERR_NOT_DIR	   equ 19 ; 'not a (valid) directory !' error
 13670                              <1> ERR_FILE_SIZE	   equ 20 ; 'file size error !'	
 13671                              <1> ; 22/06/2015
 13672                              <1> ERR_NOT_SUPERUSER  equ 11 ; 'permission denied !' error
 13673                              <1> ERR_NOT_OWNER      equ 11 ; 'permission denied !' error
 13674                              <1> ERR_NOT_FILE       equ 11 ; 'permission denied !' error	
 13675                              <1> ; 23/06/2015
 13676                              <1> ERR_FILE_EXISTS    equ 14 ; 'file already exists !' error
 13677                              <1> ERR_DRV_NOT_SAME   equ 21 ; 'not same drive !' error
 13678                              <1> ERR_DIR_NOT_FOUND  equ 12 ; 'directory not found !' error
 13679                              <1> ERR_NOT_EXECUTABLE equ 22 ; 'not executable file !' error
 13680                              <1> ; 27/06/2015
 13681                              <1> ERR_INV_PARAMETER  equ 23 ; 'invalid parameter !' error
 13682                              <1> ERR_INV_DEV_NAME   equ 24 ; 'invalid device name !' error
 13683                              <1> ; 29/06/2015
 13684                              <1> ERR_TIME_OUT	   equ 25 ; 'time out !' error			
 13685                              <1> ERR_DEV_NOT_RESP   equ 25 ; 'device not responding !' error	
 13686                              <1> 
 13687                              <1> ; 26/08/2015
 13688                              <1> ; 24/07/2015
 13689                              <1> ; 24/06/2015
 13690                              <1> MAX_ARG_LEN	   equ 256 ; max. length of sys exec arguments
 13691                              <1> ; 01/07/2015
 13692                              <1> MAX_MSG_LEN	   equ 255 ; max. msg length for 'sysmsg'
 13693                              <1> ;	 					 		
 13694                                  %include 'trdosk0.s' ; 04/01/2016 
 13695                              <1> ; ****************************************************************************
 13696                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DEFINITIONS : trdosk0.s
 13697                              <1> ; ----------------------------------------------------------------------------
 13698                              <1> ; Last Update: 29/02/2016
 13699                              <1> ; ----------------------------------------------------------------------------
 13700                              <1> ; Beginning: 04/01/2016
 13701                              <1> ; ----------------------------------------------------------------------------
 13702                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13703                              <1> ; ----------------------------------------------------------------------------
 13704                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 13705                              <1> ; TRDOS2.ASM (09/11/2011)
 13706                              <1> ; ****************************************************************************
 13707                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
 13708                              <1> ;
 13709                              <1> ; Masterboot / Partition Table at Beginning+1BEh
 13710                              <1> ptBootable       equ 0
 13711                              <1> ptBeginHead      equ 1
 13712                              <1> ptBeginSector    equ 2
 13713                              <1> ptBeginCylinder  equ 3
 13714                              <1> ptFileSystemID   equ 4
 13715                              <1> ptEndHead        equ 5
 13716                              <1> ptEndSector      equ 6
 13717                              <1> ptEndCylinder    equ 7
 13718                              <1> ptStartSector    equ 8
 13719                              <1> ptSectors        equ 12
 13720                              <1> 
 13721                              <1> ; Boot Sector Parameters at 7C00h
 13722                              <1> DataArea1     equ -4
 13723                              <1> DataArea2     equ -2
 13724                              <1> BootStart     equ 0h
 13725                              <1> OemName       equ 03h
 13726                              <1> BytesPerSec   equ 0Bh
 13727                              <1> SecPerClust   equ 0Dh
 13728                              <1> ResSectors    equ 0Eh
 13729                              <1> FATs          equ 10h
 13730                              <1> RootDirEnts   equ 11h
 13731                              <1> Sectors       equ 13h
 13732                              <1> Media         equ 15h
 13733                              <1> FATSecs       equ 16h
 13734                              <1> SecPerTrack   equ 18h
 13735                              <1> Heads         equ 1Ah 
 13736                              <1> Hidden1       equ 1Ch
 13737                              <1> Hidden2       equ 1Eh
 13738                              <1> HugeSec1      equ 20h
 13739                              <1> HugeSec2      equ 22h
 13740                              <1> DriveNumber   equ 24h
 13741                              <1> Reserved1     equ 25h
 13742                              <1> bootsignature equ 26h                 
 13743                              <1> VolumeID      equ 27h
 13744                              <1> VolumeLabel   equ 2Bh
 13745                              <1> FileSysType   equ 36h          
 13746                              <1> Reserved2     equ 3Eh                           ; Starting cluster of P2000
 13747                              <1> 
 13748                              <1> ; FAT32 BPB Structure
 13749                              <1> FAT32_FAT_Size equ 36
 13750                              <1> FAT32_RootFClust equ 44
 13751                              <1> FAT32_FSInfoSec equ 48
 13752                              <1> FAT32_DrvNum equ 64
 13753                              <1> FAT32_BootSig equ 66
 13754                              <1> FAT32_VolID equ 67
 13755                              <1> FAT32_VolLab equ 71
 13756                              <1> FAT32_FilSysType equ 82
 13757                              <1> 
 13758                              <1> ; BIOS Disk Parameters
 13759                              <1> DPDiskNumber  equ 0h
 13760                              <1> DPDType       equ 1h
 13761                              <1> DPReturn      equ 2h
 13762                              <1> DPHeads       equ 3h
 13763                              <1> DPCylinders   equ 4h
 13764                              <1> DPSecPerTrack equ 6h
 13765                              <1> DPDisks       equ 7h
 13766                              <1> DPTableOff    equ 8h
 13767                              <1> DPTableSeg    equ 0Ah
 13768                              <1> DPNumOfSecs   equ 0Ch
 13769                              <1> 
 13770                              <1> ; BIOS INT 13h Extensions (LBA extensions)
 13771                              <1> ; Just After DP Data (DPDiskNumber+)
 13772                              <1> DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
 13773                              <1> DAP_Reserved1 equ 11h   ; Reserved Byte 
 13774                              <1> DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
 13775                              <1> DAP_Reserved2 equ 13h   ; Reserved Byte
 13776                              <1> DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
 13777                              <1> DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
 13778                              <1>                         ; C1= Selected Cylinder Number
 13779                              <1>                         ; H0= Number Of Heads (Maximum Head Number + 1)
 13780                              <1>                         ; H1= Selected Head Number
 13781                              <1>                         ; S0= Maximum Sector Number
 13782                              <1>                         ; S1= Selected Sector Number
 13783                              <1>                         ; QUAD WORD
 13784                              <1> ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
 13785                              <1>                              ; QUAD WORD (Also, value in 0h must be 18h) 
 13786                              <1>                              ; TR-DOS will not use 64 bit Flat Address
 13787                              <1> 
 13788                              <1> ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
 13789                              <1> ; Just After DP Data (DPDiskNumber+)
 13790                              <1> GetDParams_48h equ 20h ; Word. Data Length, must be 26 (1Ah) for short data.
 13791                              <1> GDP_48h_InfoFlag equ 22h ; Word
 13792                              <1> ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
 13793                              <1> GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
 13794                              <1> GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
 13795                              <1> GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
 13796                              <1> GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
 13797                              <1> GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
 13798                              <1> 
 13799                              <1> ; TR-DOS Standalone Program Extensions to the DiskParams Block
 13800                              <1> ; Just After DP Data (DPDiskNumber+)
 13801                              <1> TRDP_CurrentSector equ 3Ah  ; DX:AX (LBA)
 13802                              <1> TRDP_SectorCount equ 3Eh    ; CX (or Counter)
 13803                              <1> 
 13804                              <1> 
 13805                              <1> ; DOS Logical Disks
 13806                              <1> LD_Name equ 0
 13807                              <1> LD_DiskType equ 1
 13808                              <1> LD_PhyDrvNo equ 2
 13809                              <1> LD_FATType equ 3
 13810                              <1> LD_FSType equ 4
 13811                              <1> LD_LBAYes equ 5
 13812                              <1> LD_BPB equ 6
 13813                              <1> LD_FATBegin equ 96
 13814                              <1> LD_ROOTBegin equ 100
 13815                              <1> LD_DATABegin equ 104
 13816                              <1> LD_StartSector equ 108
 13817                              <1> LD_TotalSectors equ 112
 13818                              <1> LD_FreeSectors equ 116
 13819                              <1> LD_Clusters equ 120
 13820                              <1> LD_PartitionEntry equ 124
 13821                              <1> LD_DParamEntry equ 125
 13822                              <1> LD_MediaChanged equ 126
 13823                              <1> LD_CDirLevel equ 127
 13824                              <1> LD_CurrentDirectory equ 128
 13825                              <1> 
 13826                              <1> ; Singlix FS Extensions to DOS Logical Disks
 13827                              <1> ; 03/01/2010 (LD_BPB compatibility for CHS r/w)
 13828                              <1> 
 13829                              <1> LD_FS_Name equ 0
 13830                              <1> LD_FS_DiskType equ 1
 13831                              <1> LD_FS_PhyDrvNo equ 2
 13832                              <1> LD_FS_FATType equ 3
 13833                              <1> LD_FS_FSType equ 4
 13834                              <1> LD_FS_LBAYes equ 5
 13835                              <1> LD_FS_BPB equ 6
 13836                              <1> LD_FS_MediaAttrib equ 6
 13837                              <1> LD_FS_VersionMajor equ 7
 13838                              <1> LD_FS_RootDirD equ 8
 13839                              <1> LD_FS_MATLocation equ 12
 13840                              <1> LD_FS_Reserved1 equ 16 ;1 reserved byte
 13841                              <1> LD_FS_BytesPerSec equ 17 ; LD_BPB + 0Bh
 13842                              <1> LD_FS_Reserved2 equ 19 ;2 reserved byte
 13843                              <1> LD_FS_DATLocation equ 20
 13844                              <1> LD_FS_DATSectors equ 24
 13845                              <1> LD_FS_Reserved3 equ 28 ;3 reserved word
 13846                              <1> LD_FS_SecPerTrack equ 30 ; LD_BPB + 18h
 13847                              <1> LD_FS_NumHeads equ 32    ; LD_BPB + 1Ah
 13848                              <1> LD_FS_UnDelDirD equ 34
 13849                              <1> LD_FS_Reserved4 equ 38 ;4 reserved word
 13850                              <1> LD_FS_VolumeSerial equ 40
 13851                              <1> LD_FS_VolumeName equ 44
 13852                              <1> LD_FS_BeginSector equ 108
 13853                              <1> LD_FS_VolumeSize equ 112
 13854                              <1> LD_FS_FreeSectors equ 116
 13855                              <1> LD_FS_FirstFreeSector equ 120
 13856                              <1> LD_FS_PartitionEntry equ 124
 13857                              <1> LD_FS_DParamEntry equ 125
 13858                              <1> LD_FS_MediaChanged equ 126
 13859                              <1> LD_FS_CDirLevel equ 127
 13860                              <1> LD_FS_CDIR_Converted equ 128
 13861                              <1> 
 13862                              <1> ; Valid FAT Types
 13863                              <1> FS_FAT12 equ 1
 13864                              <1> FS_FAT16_CHS equ 2
 13865                              <1> FS_FAT32_CHS equ 3
 13866                              <1> FS_FAT16_LBA equ 4
 13867                              <1> FS_FAT32_LBA equ 5
 13868                              <1> 
 13869                              <1> ; Cursor Location
 13870                              <1> CCCpointer equ  0450h   ; BIOS data, current cursor column
 13871                              <1> ; FAT Clusters EOC sign
 13872                              <1> FAT12EOC equ 0FFFh
 13873                              <1> FAT16EOC equ 0FFFFh
 13874                              <1> ;FAT32EOC equ 0FFFFFFFh ; It is not direct usable for 8086 code
 13875                              <1> ; BAD Cluster
 13876                              <1> FAT12BADC equ 0FF7h
 13877                              <1> FAT16BADC equ 0FFF7h
 13878                              <1> ;FAT32BADC equ 0FFFFFF7h ; It is not direct usable for 8086 code
 13879                              <1> ; MS-DOS FAT16 FS (Maximum Possible) Last Cluster Number= 0FFF6h 
 13880                              <1> 
 13881                              <1> ; TRFS
 13882                              <1> 
 13883                              <1> bs_FS_JmpBoot equ 0 ; jmp short bsBootCode
 13884                              <1>                 ; db 0EBh, db 3Fh, db 90h
 13885                              <1> bs_FS_Identifier equ 3  ; db 'FS', db 0
 13886                              <1> bs_FS_BytesPerSec equ 6 ; dw 512
 13887                              <1> bs_FS_MediaAttrib equ 8 ; db 3
 13888                              <1> bs_FS_PartitionID equ 9 ; db 0A1h
 13889                              <1> bs_FS_VersionMaj equ 10 ; db 01h
 13890                              <1> bs_FS_VersionMin equ 11 ; db 0
 13891                              <1> bs_FS_BeginSector equ 12   ; dd 0 
 13892                              <1> bs_FS_VolumeSize equ 16 ; dd 2880
 13893                              <1> bs_FS_StartupFD equ 20 ; dd 0
 13894                              <1> bs_FS_MATLocation equ 24 ; dd 1
 13895                              <1> bs_FS_RootDirD equ 28 ; dd 8
 13896                              <1> bs_FS_SystemConfFD equ 32 ; dd 0
 13897                              <1> bs_FS_SwapFD equ 36 ; dd 0
 13898                              <1> bs_FS_UnDelDirD equ 40 ; dd 0
 13899                              <1> bs_FS_DriveNumber equ 44 ; db 0
 13900                              <1> bs_FS_LBA_Ready equ 45 ; db 0
 13901                              <1> bs_FS_MagicWord equ 46 
 13902                              <1> bs_FS_SecPerTrack equ 46 ; db 0A1h
 13903                              <1> bs_FS_Heads equ 47 ; db 01h 
 13904                              <1> bs_FS_OperationSys equ 48 ; db "TR-SINGLIX v1.0b"
 13905                              <1> bs_FS_Terminator equ 64 ; db 0
 13906                              <1> bs_FS_BootCode equ 65 
 13907                              <1> 
 13908                              <1> FS_MAT_DATLocation equ 12
 13909                              <1> FS_MAT_DATScount equ 16
 13910                              <1> FS_MAT_FreeSectors equ 20
 13911                              <1> FS_MAT_FirstFreeSector equ 24
 13912                              <1> FS_RDT_VolumeSerialNo equ 28
 13913                              <1> FS_RDT_VolumeName equ 64
 13914                              <1> 
 13915                              <1> ; FAT12 + FAT16 + FAT32
 13916                              <1> BS_JmpBoot equ 0
 13917                              <1> BS_OEMName equ 3
 13918                              <1> BPB_BytsPerSec equ 11
 13919                              <1> BPB_SecPerClust equ 13
 13920                              <1> BPB_RsvdSecCnt equ 14
 13921                              <1> BPB_NumFATs equ 16
 13922                              <1> BPB_RootEntCnt equ 17
 13923                              <1> BPB_TotalSec16 equ 19
 13924                              <1> BPB_Media equ 21
 13925                              <1> BPB_FATSz16 equ 22
 13926                              <1> BPB_SecPerTrk equ 24
 13927                              <1> BPB_NumHeads equ 26
 13928                              <1> BPB_HiddSec equ 28
 13929                              <1> BPB_TotalSec32 equ 32
 13930                              <1> 
 13931                              <1> ; FAT12 and FAT16 only
 13932                              <1> BS_DrvNum equ 36
 13933                              <1> BS_Reserved1 equ 37
 13934                              <1> BS_BootSig equ 38
 13935                              <1> BS_VolID equ 39
 13936                              <1> BS_VolLab equ 43
 13937                              <1> BS_FilSysType equ 54 ; 8 bytes
 13938                              <1> BS_BootCode equ 62
 13939                              <1> 
 13940                              <1> ; FAT32 only
 13941                              <1> BPB_FATSz32 equ 36 ; FAT32, 4 bytes
 13942                              <1> BPB_ExtFlags equ 40 ; FAT32, 2 bytes
 13943                              <1> BPB_FSVer equ 42 ; FAT32, 2 bytes
 13944                              <1> BPB_RootClus equ 44 ; FAT32, 4 bytes
 13945                              <1> BPB_FSInfo equ 48 ; FAT 32, 2 bytes 
 13946                              <1> BPB_BkBootSec equ 50 ; FAT32, 2 bytes
 13947                              <1> BPB_Reserved equ 52 ; FAT32, 12 bytes
 13948                              <1> BS_FAT32_DrvNum equ 64 ; FAT32, 1 byte
 13949                              <1> BS_FAT32_Reserved1 equ 65 ; FAT32, 1 byte
 13950                              <1> BS_FAT32_BootSig equ 66 ; FAT32, 1 byte
 13951                              <1> BS_FAT32_VolID equ 67 ; FAT32, 4 bytes
 13952                              <1> BS_FAT32_VolLab equ 71 ; FAT32, 11 bytes
 13953                              <1> BS_FAT32_FilSysType equ 82 ; FAT32, 8 bytes
 13954                              <1> BS_FAT32_BootCode equ 90
 13955                              <1> 
 13956                              <1> ; 29/02/2016
 13957                              <1> ;(FAT32 Free Cluster Count & First Free Cluster values)
 13958                              <1> ;[BPB_Reserved] = Free Cluster Count (offset 52)
 13959                              <1> ;[BPB_Reserved+4] = First Free Cluster (offset 56)
 13960                              <1> 
 13961                              <1> BS_Validation equ 510
 13962                              <1> 
 13963                              <1> ; 15/02/2016
 13964                              <1> ; FILE.ASM - 09/10/2011
 13965                              <1> ; Directory Entry Structure
 13966                              <1> ; 29/10/2009 (According to Microsoft FAT32 File System Specification)
 13967                              <1> DirEntry_Name equ 0
 13968                              <1> DirEntry_Attr equ 11
 13969                              <1> DirEntry_NTRes equ 12
 13970                              <1> DirEntry_CrtTimeTenth equ 13
 13971                              <1> DirEntry_CrtTime equ 14
 13972                              <1> DirEntry_CrtDate equ 16
 13973                              <1> DirEntry_LastAccDate equ 18
 13974                              <1> DirEntry_FstClusHI equ 20
 13975                              <1> DirEntry_WrtTime equ 22
 13976                              <1> DirEntry_WrtDate equ 24
 13977                              <1> DirEntry_FstClusLO equ 26
 13978                              <1> DirEntry_FileSize equ 28
 13979                                  %include 'trdosk1.s' ; 04/01/2016 
 13980                              <1> ; ****************************************************************************
 13981                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - SYS INIT : trdosk1.s
 13982                              <1> ; ----------------------------------------------------------------------------
 13983                              <1> ; Last Update: 30/01/2016
 13984                              <1> ; ----------------------------------------------------------------------------
 13985                              <1> ; Beginning: 04/01/2016
 13986                              <1> ; ----------------------------------------------------------------------------
 13987                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 13988                              <1> ; ----------------------------------------------------------------------------
 13989                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 13990                              <1> ; TRDOS2.ASM (09/11/2011)
 13991                              <1> ; ****************************************************************************
 13992                              <1> ; TRDOS2.ASM (c) 2004-2011 Erdogan TAN [ 17/01/2004 ] Last Update: 09/11/2011
 13993                              <1> ;
 13994                              <1> 
 13995                              <1> sys_init:
 13996                              <1> 	; 24/01/2016
 13997                              <1> 	; 06/01/2016
 13998                              <1> 	; 04/01/2016
 13999                              <1> 
 14000 00003B9F B83F3A2F00          <1> 	mov	eax, '?:/'
 14001 00003BA4 A3[0FA30000]        <1> 	mov	[Current_Dir_Drv], eax
 14002                              <1> 
 14003                              <1> 	; Logical DRV INIT (only for hard disks)
 14004 00003BA9 E854010000          <1> 	call 	ldrv_init  ; trdosk2.s
 14005                              <1> 	
 14006                              <1> 	; When floppy_drv_init call is disabled
 14007                              <1> 	; media changed sign is needed
 14008                              <1> 	; for proper drive initialization
 14009                              <1>         
 14010 00003BAE BE00010900          <1> 	mov 	esi, Logical_DOSDisks
 14011 00003BB3 B001                <1> 	mov 	al, 1 ; Initialization sign (invalid_fd_parameter)
 14012 00003BB5 83C67E              <1> 	add 	esi, LD_MediaChanged ; Media Change Status = 1 (init needed)
 14013 00003BB8 8806                <1> 	mov 	[esi], al ; A:
 14014 00003BBA 81C600010000        <1> 	add 	esi, 100h 
 14015 00003BC0 8806                <1> 	mov 	[esi], al ; B: 
 14016                              <1>            
 14017                              <1> _current_drive_bootdisk:
 14018 00003BC2 8A15[1A9D0000]      <1> 	mov 	dl, [boot_drv] ; physical drive number
 14019 00003BC8 80FAFF              <1> 	cmp 	dl, 0FFh
 14020 00003BCB 740A                <1> 	je 	short _last_dos_diskno_check
 14021                              <1> _boot_drive_check:
 14022 00003BCD 80FA80              <1> 	cmp 	dl, 80h
 14023 00003BD0 7218                <1> 	jb 	short _current_drive_a
 14024 00003BD2 80EA7E              <1> 	sub 	dl, 7Eh ; C = 2 , D = 3
 14025 00003BD5 EB13                <1> 	jmp 	short _current_drive_a 
 14026                              <1> 
 14027                              <1> _last_dos_diskno_check:
 14028 00003BD7 8A15[40940000]      <1> 	mov 	dl, [Last_DOS_DiskNo]
 14029 00003BDD 80FA02              <1> 	cmp 	dl, 2
 14030 00003BE0 7706                <1> 	ja 	short _current_drive_c
 14031 00003BE2 7406                <1> 	je 	short _current_drive_a
 14032 00003BE4 30D2                <1> 	xor 	dl, dl ; A:
 14033 00003BE6 EB02                <1> 	jmp 	short _current_drive_a
 14034                              <1> 
 14035                              <1> _current_drive_c:
 14036 00003BE8 B202                <1> 	mov 	dl, 2 ; C:
 14037                              <1> 
 14038                              <1> _current_drive_a:
 14039 00003BEA 8815[1B9D0000]      <1> 	mov	[drv], dl
 14040 00003BF0 BE[42940000]        <1>         mov     esi, msg_CRLF_temp
 14041 00003BF5 E840000000          <1> 	call 	print_msg
 14042                              <1> 
 14043 00003BFA 8A15[1B9D0000]      <1> 	mov	dl, [drv]
 14044 00003C00 E839090000          <1> 	call 	change_current_drive
 14045 00003C05 730C                <1> 	jnc 	short _start_mainprog
 14046                              <1> 
 14047                              <1> _drv_not_ready_error: 
 14048 00003C07 BE[06970000]        <1> 	mov 	esi, msgl_drv_not_ready
 14049 00003C0C E829000000          <1> 	call 	print_msg
 14050 00003C11 EB05                <1> 	jmp 	short _end_of_mainprog
 14051                              <1> 
 14052                              <1> _start_mainprog:
 14053 00003C13 E8620A0000          <1>         call    dos_prompt
 14054                              <1>               
 14055                              <1> _end_of_mainprog:
 14056 00003C18 BE[42940000]        <1>         mov     esi, msg_CRLF_temp
 14057 00003C1D E818000000          <1> 	call 	print_msg
 14058 00003C22 BE[48940000]        <1> 	mov 	esi, mainprog_Version
 14059 00003C27 E80E000000          <1> 	call 	print_msg
 14060                              <1> 	; 24/01/2016
 14061 00003C2C 28E4                <1> 	sub	ah, ah
 14062 00003C2E E8B4CFFFFF          <1> 	call	int16h ; call getch
 14063 00003C33 E971D4FFFF          <1> 	jmp	cpu_reset
 14064                              <1> 
 14065 00003C38 EBFE                <1> infinitiveloop: jmp short infinitiveloop
 14066                              <1> 
 14067                              <1> 
 14068                              <1> print_msg:
 14069                              <1> 	; 04/01/2016
 14070                              <1> 	; 01/07/2015
 14071                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14072                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
 14073                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
 14074                              <1> 	;
 14075 00003C3A AC                  <1> 	lodsb
 14076                              <1> pmsg1:
 14077 00003C3B 56                  <1> 	push 	esi
 14078 00003C3C 0FB61D[78A20000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; 04/01/2016 (ptty)
 14079 00003C43 B407                <1> 	mov	ah, 07h ; Black background, light gray forecolor
 14080 00003C45 E86CDBFFFF          <1> 	call 	WRITE_TTY
 14081 00003C4A 5E                  <1> 	pop	esi
 14082 00003C4B AC                  <1> 	lodsb
 14083 00003C4C 20C0                <1> 	and 	al, al
 14084 00003C4E 75EB                <1> 	jnz 	short pmsg1
 14085 00003C50 C3                  <1> 	retn
 14086                              <1> 
 14087                              <1> clear_screen:
 14088                              <1> 	; 30/01/2016
 14089                              <1> 	; 24/01/2016
 14090                              <1> 	; 04/01/2016
 14091 00003C51 0FB61D[78A20000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; video page number (0 to 7)
 14092 00003C58 8AA3[909C0000]      <1> 	mov 	ah, [ebx+vmode] ; default = 03h (80x25 text)
 14093 00003C5E 80FC04              <1> 	cmp	ah, 4
 14094 00003C61 7205                <1> 	jb	short cls1
 14095 00003C63 80FC07              <1> 	cmp	ah, 7
 14096 00003C66 7524                <1> 	jne	short vga_clear
 14097                              <1> cls1:
 14098 00003C68 3A25[769C0000]      <1> 	cmp	ah, [CRT_MODE] ; current video mode ? 
 14099                              <1> 	;je	short cls2 ; yes (current video mode = 3)
 14100                              <1> 	;;call	set_mode_3 ; set video mode to 3 (& clear screen)
 14101                              <1> 	;;retn
 14102                              <1> 	;jmp	set_mode_3
 14103 00003C6E 0F8554D8FFFF        <1> 	jne	set_mode_3
 14104                              <1> cls2:
 14105 00003C74 B407                <1> 	mov	ah, 07h ; attribute to be used on blanked line
 14106 00003C76 28C0                <1> 	sub 	al, al ; 0 =  entire window
 14107 00003C78 6631C9              <1> 	xor 	cx, cx
 14108 00003C7B 66BA4F18            <1> 	mov 	dx, 184Fh
 14109 00003C7F E888D9FFFF          <1> 	call	_scroll_up ; 24/01/2016
 14110                              <1> 	;
 14111                              <1> 	;mov	bl, [ACTIVE_PAGE] ; video page number (0 to 7)
 14112 00003C84 6631D2              <1> 	xor 	dx, dx
 14113 00003C87 E8BEDBFFFF          <1> 	call	_set_cpos ; 24/01/2016 
 14114                              <1> 	;retn
 14115                              <1> vga_clear:
 14116 00003C8C C3                  <1> 	retn	
 14117                              <1> 
 14118                              <1> panic:
 14119                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14120                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
 14121 00003C8D BE[299F0000]        <1> 	mov 	esi, panic_msg
 14122 00003C92 E8A3FFFFFF          <1> 	call 	print_msg
 14123                              <1> key_to_reboot:
 14124                              <1>         ; 24/01/2016
 14125 00003C97 28E4                <1>         sub     ah, ah
 14126 00003C99 E849CFFFFF          <1>         call    int16h ; call   getch
 14127                              <1>         ; wait for a character from the current tty
 14128                              <1> 	;
 14129 00003C9E B00A                <1> 	mov	al, 0Ah
 14130 00003CA0 8A1D[78A20000]      <1> 	mov	bl, [ptty] ; [ACTIVE_PAGE]
 14131 00003CA6 B407                <1> 	mov	ah, 07h ; Black background, 
 14132                              <1> 			; light gray forecolor
 14133 00003CA8 E809DBFFFF          <1> 	call 	WRITE_TTY
 14134 00003CAD E9F7D3FFFF          <1> 	jmp	cpu_reset 
 14135                              <1> 
 14136                              <1> ctrlbrk:
 14137                              <1> 	; 12/11/2015
 14138                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
 14139                              <1> 	; 06/12/2013 (Retro UNIX 8086 v1)
 14140                              <1> 	;
 14141                              <1> 	; INT 1Bh (control+break) handler		
 14142                              <1> 	;
 14143                              <1>       	; Retro Unix 8086 v1 feature only!
 14144                              <1>       	;
 14145 00003CB2 66833D[54B10000]00  <1> 	cmp 	word [u.intr], 0
 14146 00003CBA 7645                <1> 	jna 	short cbrk4
 14147                              <1> cbrk0:
 14148                              <1> 	; 12/11/2015
 14149                              <1> 	; 06/12/2013
 14150 00003CBC 66833D[56B10000]00  <1> 	cmp 	word [u.quit], 0
 14151 00003CC4 743B                <1> 	jz	short cbrk4
 14152                              <1> 	;
 14153                              <1> 	; 20/09/2013	
 14154 00003CC6 6650                <1> 	push 	ax
 14155 00003CC8 A0[78A20000]        <1> 	mov	al, [ptty]
 14156                              <1> 	;
 14157                              <1> 	; 12/11/2015
 14158                              <1> 	;
 14159                              <1> 	; ctrl+break (EOT, CTRL+D) from serial port
 14160                              <1> 	; or ctrl+break from console (pseudo) tty
 14161                              <1> 	; (!redirection!)
 14162                              <1> 	;
 14163 00003CCD 3C08                <1> 	cmp	al, 8 ; serial port tty nums > 7
 14164 00003CCF 7211                <1>         jb      short cbrk1 ; console (pseudo) tty
 14165                              <1> 	;	
 14166                              <1> 	; Serial port interrupt handler sets [ptty]
 14167                              <1> 	; to the port's tty number (as temporary).
 14168                              <1> 	;
 14169                              <1> 	; If active process is using a stdin or 
 14170                              <1> 	; stdout redirection (by the shell),
 14171                              <1>         ; console tty keyboard must be available
 14172                              <1> 	; to terminate running process,
 14173                              <1> 	; in order to prevent a deadlock. 
 14174                              <1> 	;
 14175 00003CD1 52                  <1> 	push	edx
 14176 00003CD2 0FB615[5FB10000]    <1> 	movzx	edx, byte [u.uno]
 14177 00003CD9 3A82[63AE0000]      <1> 	cmp     al, [edx+p.ttyc-1] ; console tty (rw)
 14178 00003CDF 5A                  <1> 	pop	edx
 14179 00003CE0 7412                <1> 	je	short cbrk2
 14180                              <1> cbrk1:
 14181 00003CE2 FEC0                <1> 	inc 	al  ; [u.ttyp] : 1 based tty number
 14182                              <1> 	; 06/12/2013
 14183 00003CE4 3A05[40B10000]      <1> 	cmp	al, [u.ttyp] ; recent open tty (r)
 14184 00003CEA 7408                <1> 	je	short cbrk2	
 14185 00003CEC 3A05[41B10000]      <1>         cmp     al, [u.ttyp+1] ; recent open tty (w)
 14186 00003CF2 750B                <1> 	jne	short cbrk3	
 14187                              <1> cbrk2:
 14188                              <1> 	;; 06/12/2013
 14189                              <1> 	;mov	ax, [u.quit]
 14190                              <1> 	;and	ax, ax
 14191                              <1> 	;jz	short cbrk3
 14192                              <1> 	;
 14193 00003CF4 6631C0              <1> 	xor	ax, ax ; 0
 14194 00003CF7 6648                <1> 	dec	ax
 14195                              <1> 	; 0FFFFh = 'ctrl+brk' keystroke
 14196 00003CF9 66A3[56B10000]      <1> 	mov	[u.quit], ax
 14197                              <1> cbrk3:
 14198 00003CFF 6658                <1> 	pop	ax
 14199                              <1> cbrk4:
 14200 00003D01 C3                  <1> 	retn
 14201                                  %include 'trdosk2.s' ; 04/01/2016
 14202                              <1> ; ****************************************************************************
 14203                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DRV INIT : trdosk2.s
 14204                              <1> ; ----------------------------------------------------------------------------
 14205                              <1> ; Last Update: 29/02/2016
 14206                              <1> ; ----------------------------------------------------------------------------
 14207                              <1> ; Beginning: 04/01/2016
 14208                              <1> ; ----------------------------------------------------------------------------
 14209                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 14210                              <1> ; ----------------------------------------------------------------------------
 14211                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 14212                              <1> ; TRDOS2.ASM (09/11/2011)
 14213                              <1> ; ****************************************************************************
 14214                              <1> ; DRV_INIT.ASM (c) 2009-2011 Erdogan TAN  [26/09/2009] Last Update: 07/08/2011
 14215                              <1> ;
 14216                              <1> 
 14217                              <1> ldrv_init: ; Logical Drive Initialization
 14218                              <1> 	; 12/02/2016
 14219                              <1> 	; 06/01/2016
 14220                              <1> 	;  	('diskinit.inc', 'diskio.inc' integration)
 14221                              <1> 	; 04/01/2016 (TRDOS 386 = TRDOS v2.0)
 14222                              <1> 	; 07/08/2011
 14223                              <1> 	; 20/09/2009
 14224                              <1> 	; 2005
 14225 00003D02 0FB60D[E8A20000]    <1> 	movzx	ecx, byte [HF_NUM] ; number of fixed disks
 14226 00003D09 80F901              <1> 	cmp	cl, 1
 14227 00003D0C 7301                <1> 	jnb	short load_hd_partition_tables
 14228                              <1> 	; No hard disks
 14229 00003D0E C3                  <1> 	retn
 14230                              <1> load_hd_partition_tables:
 14231 00003D0F 8B35[ECA20000]      <1> 	mov	esi, [HDPM_TBL_VEC] ; primary master disk FDPT
 14232 00003D15 BF[0EA70000]        <1> 	mov 	edi, PTable_hd0
 14233 00003D1A B280                <1> 	mov 	dl, 80h
 14234                              <1> load_next_hd_partition_table:
 14235 00003D1C 51                  <1> 	push	ecx
 14236 00003D1D 57                  <1> 	push	edi
 14237 00003D1E 56                  <1> 	push	esi ; FDPT (+ DPTE) address
 14238 00003D1F 8A4614              <1> 	mov	al, [esi+20] ; DPTE offset 4
 14239 00003D22 2440                <1> 	and	al, 40h ;  LBA bit (bit 6)
 14240                              <1> 	;shr	al, 6
 14241 00003D24 A2[0EA90000]        <1> 	mov 	[HD_LBA_yes], al
 14242 00003D29 E81C040000          <1> 	call	load_masterboot
 14243 00003D2E 7275                <1> 	jc	short pass_pt_this_hard_disk
 14244                              <1> 
 14245 00003D30 BE[CCA60000]        <1> 	mov	esi, PartitionTable
 14246 00003D35 89F3                <1> 	mov	ebx, esi
 14247                              <1> 	;mov	ecx, 16
 14248 00003D37 B110                <1> 	mov	cl, 16
 14249 00003D39 F3A5                <1> 	rep 	movsd
 14250 00003D3B 89DE                <1> 	mov 	esi, ebx 
 14251 00003D3D C605[1D9D0000]04    <1> 	mov 	byte [hdc], 4 ; 4 - partition index
 14252                              <1> loc_validate_hdp_partition:
 14253 00003D44 807E0400            <1> 	cmp 	byte [esi+ptFileSystemID], 0
 14254 00003D48 7641                <1> 	jna	short loc_validate_next_hdp_partition2
 14255 00003D4A 56                  <1> 	push	esi ; Masterboot partition table offset
 14256 00003D4B 52                  <1> 	push	edx ; dl = Physical drive number 
 14257 00003D4C FE05[0FA90000]      <1> 	inc	byte [PP_Counter]
 14258 00003D52 31FF                <1>         xor	edi, edi ; 0  
 14259                              <1> 	; Input -> ESI = PartitionTable offset
 14260                              <1> 	; DL = Hard disk drive number 
 14261                              <1> 	; EDI = 0 -> Primary Partition
 14262                              <1> 	; EDI > 0 -> Extended Partition's Start Sector   
 14263 00003D54 E879010000          <1> 	call 	validate_hd_fat_partition
 14264 00003D59 730A                <1> 	jnc 	short loc_set_valid_hdp_partition_entry
 14265                              <1> 	;pop	edx
 14266                              <1> 	;push	edx
 14267 00003D5B 8B1424              <1> 	mov	edx, [esp] 
 14268 00003D5E E8C5020000          <1> 	call	validate_hd_fs_partition
 14269 00003D63 7224                <1> 	jc	short loc_validate_next_hdp_partition1
 14270                              <1> loc_set_valid_hdp_partition_entry:
 14271 00003D65 8A0D[40940000]      <1> 	mov 	cl, [Last_DOS_DiskNo] 
 14272 00003D6B 80C141              <1> 	add 	cl, 'A'
 14273                              <1> 	; ESI = Logical dos drive description table address
 14274 00003D6E 880E                <1> 	mov	[esi+LD_Name], cl
 14275 00003D70 8A6602              <1> 	mov	ah, [esi+LD_PhyDrvNo]
 14276 00003D73 88E0                <1> 	mov	al, ah ; Physical drive number
 14277 00003D75 2C80                <1> 	sub	al, 80h
 14278 00003D77 C0E002              <1> 	shl	al, 2
 14279 00003D7A 0404                <1> 	add	al, 4 ; 0 Based
 14280 00003D7C 2A05[1D9D0000]      <1> 	sub	al, [hdc] ; 4 - partition index
 14281                              <1> 	; AL = Partition entry/index, 0 based
 14282                              <1> 	;  0 -> hd 0, Partition Table offset = 0
 14283                              <1> 	; 15 -> hd 3, Partition Table offset = 3
 14284                              <1> 	;mov	[esi+LD_PartitionEntry], al 
 14285 00003D82 80EC7E              <1> 	sub 	ah, 7Eh
 14286                              <1> 	; AH = Physical drive index, zero based
 14287                              <1> 	;  0 for drive A:, 2 for drive C:
 14288                              <1> 	;mov 	[esi+LD_DParamEntry], ah 
 14289 00003D85 6689467C            <1> 	mov 	[esi+LD_PartitionEntry], ax
 14290                              <1> loc_validate_next_hdp_partition1:
 14291 00003D89 5A                  <1> 	pop 	edx ; dl = Physical drive number 
 14292 00003D8A 5E                  <1> 	pop	esi ; Masterboot partition table offset
 14293                              <1> loc_validate_next_hdp_partition2:
 14294                              <1> 	; ESI = PartitionTable offset
 14295                              <1> 	; DL = Hard/Fixed disk drive number
 14296 00003D8B FE0D[1D9D0000]      <1> 	dec	byte [hdc] ; 4 - partition index
 14297 00003D91 7412                <1> 	jz	short pass_pt_this_hard_disk
 14298 00003D93 83C610              <1> 	add	esi, 16 ; 10h
 14299 00003D96 EBAC                <1> 	jmp	short loc_validate_hdp_partition
 14300                              <1> loc_next_hd_partition_table:
 14301 00003D98 FEC2                <1> 	inc	dl
 14302 00003D9A 83C620              <1> 	add	esi, 32 ; next FDPT address
 14303 00003D9D 83C740              <1> 	add	edi, 64 ; next partition table destination
 14304 00003DA0 E977FFFFFF          <1>         jmp     load_next_hd_partition_table
 14305                              <1> pass_pt_this_hard_disk:
 14306 00003DA5 5E                  <1> 	pop	esi ; FDPT (+ DPTE) address
 14307 00003DA6 5F                  <1> 	pop	edi ; Ptable_hd?
 14308 00003DA7 59                  <1> 	pop	ecx
 14309 00003DA8 E2EE                <1> 	loop	loc_next_hd_partition_table
 14310 00003DAA 803D[0FA90000]01    <1> 	cmp	byte [PP_Counter], 1
 14311 00003DB1 7301                <1> 	jnb	short load_extended_dos_partitions
 14312                              <1> 	; Empty partition table
 14313 00003DB3 C3                  <1> 	retn 
 14314                              <1> load_extended_dos_partitions:
 14315 00003DB4 BE[0EA70000]        <1> 	mov	esi, PTable_hd0
 14316 00003DB9 BF[0EA80000]        <1> 	mov	edi, PTable_ep0
 14317 00003DBE C605[1D9D0000]80    <1> 	mov	byte [hdc], 80h
 14318                              <1> next_hd_extd_partition:
 14319 00003DC5 56                  <1> 	push	esi ; PTable_hd? offset
 14320 00003DC6 57                  <1> 	push	edi ; PTable_ep?
 14321                              <1> 	;mov	ecx, 4
 14322 00003DC7 B104                <1> 	mov	cl, 4
 14323 00003DC9 8A15[1D9D0000]      <1> 	mov	dl, byte [hdc]
 14324                              <1> hd_check_fs_id_05h:
 14325 00003DCF 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
 14326 00003DD2 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
 14327 00003DD4 7404                <1> 	je	short loc_set_ep_start_sector
 14328 00003DD6 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
 14329 00003DD8 7546                <1> 	jne	short continue_to_check_ep
 14330                              <1> loc_set_ep_start_sector:
 14331 00003DDA FE05[10A90000]      <1> 	inc	byte [EP_Counter]
 14332 00003DE0 88D4                <1> 	mov	ah, dl ; byte [hdc]
 14333 00003DE2 86E0                <1> 	xchg	ah, al ; al = Drv Number, ah = Partition Identifier
 14334 00003DE4 50                  <1> 	push	eax 
 14335 00003DE5 30E4                <1> 	xor	ah, ah  
 14336 00003DE7 2C80                <1> 	sub	al, 80h
 14337 00003DE9 50                  <1> 	push	eax
 14338 00003DEA C0E002              <1> 	shl	al, 2 ; al = al * 4
 14339 00003DED 0FB6D8              <1> 	movzx	ebx, al
 14340 00003DF0 81C3[11A90000]      <1> 	add	ebx, EP_StartSector
 14341 00003DF6 8B4608              <1> 	mov	eax, [esi+ptStartSector]
 14342                              <1>         ; EAX = Extended partition's start sector
 14343 00003DF9 8903                <1>         mov	[ebx], eax
 14344 00003DFB 58                  <1> 	pop	eax ; AL = Drv number - 80h, AH = 0 
 14345 00003DFC 5A                  <1> 	pop	edx ; DL = Drv number, DH = Partition ID
 14346 00003DFD BB[0EA50000]        <1> 	mov	ebx, MasterBootBuff
 14347 00003E02 803D[0EA90000]01    <1> 	cmp	byte [HD_LBA_yes], 1 ; LBA ready = Yes
 14348 00003E09 7240                <1> 	jb	short loc_hd_load_ep_05h
 14349 00003E0B 80FE05              <1> 	cmp	dh, 05h
 14350 00003E0E 743B                <1> 	je	short loc_hd_load_ep_05h
 14351                              <1> loc_hd_load_ep_0Fh:
 14352                              <1> 	; 04/01/2016
 14353 00003E10 51                  <1> 	push	ecx
 14354 00003E11 8B4E08              <1> 	mov	ecx, [esi+ptStartSector] ; sector number
 14355                              <1> 	;mov	ebx, MasterBootBuff ; buffer address
 14356                              <1> 	; LBA read/write (with private LBA function) 
 14357                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 14358                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 14359 00003E14 B41B                <1> 	mov	ah, 1Bh ; LBA read
 14360 00003E16 B001                <1> 	mov	al, 1 ; sector count
 14361 00003E18 E8AEEAFFFF          <1> 	call	int13h
 14362 00003E1D 59                  <1> 	pop	ecx
 14363 00003E1E 733F                <1> 	jnc	short loc_hd_move_ep_table
 14364                              <1> continue_to_check_ep:
 14365 00003E20 83C610              <1> 	add	esi, 16
 14366 00003E23 E2AA                <1> 	loop	hd_check_fs_id_05h
 14367                              <1> continue_check_ep_next_disk:
 14368 00003E25 5F                  <1> 	pop	edi ; PTable_ep?
 14369 00003E26 5E                  <1> 	pop	esi ; PTable_hd?
 14370 00003E27 A0[E8A20000]        <1> 	mov	al, [HF_NUM] ; number of hard disks
 14371 00003E2C 047F                <1> 	add	al, 7Fh
 14372 00003E2E 3805[1D9D0000]      <1> 	cmp	[hdc], al
 14373 00003E34 0F8392000000        <1> 	jnb	loc_validating_hd_partitions_ok
 14374 00003E3A 83C640              <1> 	add	esi, 64
 14375 00003E3D 83C740              <1> 	add	edi, 64
 14376 00003E40 FE05[1D9D0000]      <1> 	inc	byte [hdc]
 14377 00003E46 E97AFFFFFF          <1> 	jmp	next_hd_extd_partition
 14378                              <1> loc_hd_load_ep_05h:
 14379 00003E4B 51                  <1> 	push	ecx 
 14380 00003E4C 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 14381 00003E4F 668B4E02            <1>         mov     cx, word [esi+ptBeginSector]
 14382 00003E53 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14383                              <1> 	;mov	ebx, MasterBootBuff
 14384 00003E57 E86FEAFFFF          <1> 	call	int13h
 14385 00003E5C 59                  <1> 	pop	ecx  
 14386 00003E5D 72C1                <1> 	jc	short continue_to_check_ep
 14387                              <1> loc_hd_move_ep_table:
 14388                              <1>         ;pop	edi
 14389                              <1> 	;push	edi  ; PTable_ep?
 14390 00003E5F 8B3C24              <1> 	mov	edi, [esp]        
 14391 00003E62 BE[CCA60000]        <1>         mov	esi, PartitionTable ; Extended
 14392 00003E67 89F3                <1> 	mov	ebx, esi
 14393                              <1> 	;mov	ecx, 16
 14394 00003E69 B110                <1> 	mov	cl, 16
 14395 00003E6B F3A5                <1>        	rep	movsd
 14396 00003E6D 89DE                <1> 	mov	esi, ebx 
 14397                              <1> loc_set_hde_sub_partition_count:
 14398 00003E6F C605[0FA90000]04    <1> 	mov	byte [PP_Counter], 4
 14399                              <1> loc_validate_hde_partition:
 14400 00003E76 807E0400            <1> 	cmp	byte [esi+ptFileSystemID], 0
 14401 00003E7A 763F                <1> 	jna	short loc_validate_next_hde_partition2
 14402 00003E7C 56                  <1> 	push	esi ; Extended partition table offset
 14403 00003E7D 8A15[1D9D0000]      <1> 	mov	dl, byte [hdc]
 14404 00003E83 0FB6C2              <1> 	movzx	eax, dl
 14405 00003E86 2C80                <1> 	sub	al, 80h
 14406 00003E88 C0E002              <1> 	shl	al, 2
 14407                              <1> 	; 06/01/2016 
 14408                              <1> 	; (TRDOS v1.0 had a bug here, in 'DRV_INIT.ASM')
 14409                              <1> 	; BUGFIX *
 14410                              <1> 	;mov	ecx, eax
 14411 00003E8B 88C1                <1> 	mov	cl, al
 14412 00003E8D 80C104              <1> 	add	cl, 4
 14413 00003E90 2A0D[0FA90000]      <1> 	sub	cl, [PP_Counter] ; 4 to 1
 14414                              <1> 	; CL = Partition entry/index, 0 based
 14415                              <1>         ;  0 -> hd 0, Partition Table offset = 0
 14416                              <1>         ; 15 -> hd 3, Partition Table offset = 3
 14417 00003E96 88D5                <1>       	mov	ch, dl   
 14418 00003E98 80ED7E              <1> 	sub	ch, 7Eh ;
 14419                              <1> 	; CH = Physical drive index, zero based
 14420                              <1> 	;  0 for drive A:, 2 for drive C:	
 14421                              <1> 	; BUGFIX *
 14422 00003E9B 51                  <1> 	push	ecx ; *
 14423 00003E9C BF[11A90000]        <1> 	mov	edi, EP_StartSector
 14424 00003EA1 01C7                <1> 	add	edi, eax
 14425                              <1> 	; Input -> ESI = PartitionTable offset
 14426                              <1> 	; DL = Hard disk drive number   
 14427                              <1> 	; EDI = Extended partition start sector pointer
 14428 00003EA3 E82A000000          <1> 	call	validate_hd_fat_partition
 14429 00003EA8 59                  <1> 	pop	ecx ; *
 14430 00003EA9 720F                <1> 	jc	short loc_validate_next_hde_partition1
 14431                              <1> loc_set_valid_hde_partition_entry:
 14432                              <1> 	; 06/01/2016 (TRDOS v2.0)
 14433                              <1> 	; BUGFIX *
 14434                              <1> 	;mov	[esi+LD_PartitionEntry], cl 
 14435                              <1> 	;mov	[esi+LD_DParamEntry], ch 
 14436 00003EAB 66894E7C            <1> 	mov	[esi+LD_PartitionEntry], cx 
 14437                              <1> 	;
 14438 00003EAF 8A0D[40940000]      <1> 	mov	cl, [Last_DOS_DiskNo] 
 14439 00003EB5 80C141              <1> 	add	cl, 'A'
 14440 00003EB8 880E                <1> 	mov	[esi+LD_Name], cl
 14441                              <1> loc_validate_next_hde_partition1:
 14442 00003EBA 5E                  <1> 	pop	esi ; Extended partition table offset
 14443                              <1> loc_validate_next_hde_partition2:
 14444                              <1> 	; ESI = Extended partition table offset
 14445                              <1> 	; DL = Hard disk drive number
 14446 00003EBB FE0D[0FA90000]      <1> 	dec	byte [PP_Counter]
 14447 00003EC1 0F845EFFFFFF        <1> 	jz	continue_check_ep_next_disk
 14448 00003EC7 83C610              <1> 	add 	esi, 16 ; 10h
 14449 00003ECA EBAA                <1> 	jmp	short loc_validate_hde_partition
 14450                              <1> loc_validating_hd_partitions_ok:
 14451 00003ECC A0[40940000]        <1> 	mov	al, [Last_DOS_DiskNo]
 14452                              <1> loc_drv_init_retn:
 14453 00003ED1 C3                  <1> 	retn
 14454                              <1> 
 14455                              <1> validate_hd_fat_partition:
 14456                              <1> 	; 12/02/2016
 14457                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
 14458                              <1> 	; 07/08/2011
 14459                              <1> 	; 23/07/2011
 14460                              <1> 	; Input
 14461                              <1> 	;   DL = Hard/Fixed Disk Drive Number
 14462                              <1> 	;   ESI = PartitionTable offset
 14463                              <1> 	;   EDI = Extend. Part. Start Sector Pointer
 14464                              <1> 	;   EDI = 0 -> Primary Partition 
 14465                              <1> 	;   byte [Last_DOS_DiskNo]
 14466                              <1>  	; Output
 14467                              <1> 	;  cf=0 -> Validated
 14468                              <1> 	;   ESI = Logical dos drv desc. table
 14469                              <1> 	;   EBX = FAT boot sector buffer
 14470                              <1> 	;   byte [Last_DOS_DiskNo]
 14471                              <1> 	;  cf=1 -> Not a valid FAT partition
 14472                              <1> 	; EAX, EDX, ECX, EDI -> changed 
 14473                              <1> 	
 14474                              <1> 	;mov 	esi, PartitionTable
 14475 00003ED2 8A6604              <1> 	mov 	ah, [esi+ptFileSystemID]
 14476 00003ED5 80FC06              <1> 	cmp 	ah, 06h ; FAT16 CHS partition
 14477                              <1> 	; 12/02/2016
 14478                              <1> 	;jb	short loc_not_a_valid_fat_partition2
 14479 00003ED8 7305                <1>  	jnb	short vhdp_FAT16_32
 14480                              <1> 	;
 14481 00003EDA 80FC04              <1> 	cmp	ah, 04h ; FAT16 CHS partition (< 32MB)		
 14482 00003EDD 7519                <1> 	jne	short loc_not_a_valid_fat_partition1
 14483                              <1> vhdp_FAT16_32:
 14484 00003EDF B002                <1> 	mov	al, 2
 14485 00003EE1 7417                <1> 	je	short loc_set_valid_hd_partition_params
 14486 00003EE3 80FC0E              <1> 	cmp	ah, 0Eh ; FAT16 LBA partition
 14487 00003EE6 7710                <1> 	ja	short loc_not_a_valid_fat_partition1
 14488 00003EE8 7410                <1> 	je	short loc_set_valid_hd_partition_params
 14489                              <1> 
 14490 00003EEA FEC0                <1> 	inc	al ; 3
 14491 00003EEC 80FC0B              <1> 	cmp	ah, 0Bh ; FAT32 CHS partition 
 14492 00003EEF 7409                <1> 	je	short loc_set_valid_hd_partition_params
 14493 00003EF1 7206                <1> 	jb	short loc_not_a_valid_fat_partition2
 14494 00003EF3 80FC0C              <1> 	cmp	ah, 0Ch ; FAT32 LBA partition
 14495 00003EF6 7402                <1> 	je	short loc_set_valid_hd_partition_params
 14496                              <1> loc_not_a_valid_fat_partition1:
 14497 00003EF8 F9                  <1> 	stc
 14498                              <1> loc_not_a_valid_fat_partition2:
 14499 00003EF9 C3                  <1> 	retn
 14500                              <1> 
 14501                              <1> loc_set_valid_hd_partition_params:
 14502 00003EFA FE05[40940000]      <1> 	inc 	byte [Last_DOS_DiskNo] ; > 1
 14503                              <1> 	;
 14504 00003F00 31DB                <1> 	xor	ebx, ebx
 14505 00003F02 8A3D[40940000]      <1> 	mov	bh, [Last_DOS_DiskNo] ; * 256	
 14506 00003F08 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 14507                              <1> 	;
 14508 00003F0E C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
 14509 00003F12 885302              <1> 	mov	byte [ebx+LD_PhyDrvNo], dl
 14510                              <1> 	;mov	byte [ebx+LD_FATType], al ; 2 or 3
 14511                              <1> 	;mov	byte [ebx+LD_FSType], ah ; 06h, 0Eh, 0Bh, 0Ch
 14512 00003F15 66894303            <1> 	mov	word [ebx+LD_FATType], ax
 14513                              <1> 	;
 14514 00003F19 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
 14515 00003F1C 09FF                <1> 	or	edi, edi 
 14516 00003F1E 7402                <1> 	jz	short pass_hd_FAT_ep_start_sector_adding
 14517                              <1> loc_add_hd_FAT_ep_start_sector:
 14518 00003F20 030F                <1> 	add	ecx, [edi]
 14519                              <1> pass_hd_FAT_ep_start_sector_adding:
 14520 00003F22 894B6C              <1> 	mov	[ebx+LD_StartSector], ecx
 14521                              <1> loc_hd_FAT_logical_drv_init:
 14522 00003F25 89DD                <1> 	mov	ebp, ebx
 14523                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
 14524 00003F27 A0[0EA90000]        <1> 	mov	al, [HD_LBA_yes] ; 07/01/2016
 14525 00003F2C 884305              <1> 	mov	[ebx+LD_LBAYes], al
 14526 00003F2F BB[21A90000]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
 14527 00003F34 08C0                <1> 	or	al, al
 14528 00003F36 740C                <1> 	jz	short loc_hd_FAT_drv_init_load_bs_chs
 14529                              <1> loc_hd_FAT_drv_init_load_bs_lba:
 14530                              <1> 	; DL = Physical drive number
 14531                              <1>    	;mov	ecx, [esi+ptStartSector] ; sector number
 14532                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
 14533                              <1> 	; LBA read/write (with private LBA function) 
 14534                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 14535                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 14536 00003F38 B41B                <1> 	mov	ah, 1Bh ; LBA read
 14537 00003F3A B001                <1> 	mov	al, 1 ; sector count
 14538 00003F3C E88AE9FFFF          <1> 	call	int13h
 14539 00003F41 7313                <1> 	jnc	short loc_hd_drv_FAT_boot_validation
 14540                              <1> loc_not_a_valid_fat_partition3:
 14541 00003F43 C3                  <1> 	retn
 14542                              <1> loc_hd_FAT_drv_init_load_bs_chs:
 14543 00003F44 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 14544 00003F47 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
 14545 00003F4B 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14546                              <1> 	;mov	ebx, DOSBootSectorBuff
 14547 00003F4F E877E9FFFF          <1> 	call	int13h
 14548 00003F54 72ED                <1> 	jc	short loc_not_a_valid_fat_partition3
 14549                              <1> loc_hd_drv_FAT_boot_validation:
 14550                              <1> 	;mov	esi, DOSBootSectorBuff
 14551 00003F56 89DE                <1> 	mov	esi, ebx
 14552 00003F58 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 14553 00003F61 751A                <1> 	jne	short loc_not_a_valid_fat_partition4
 14554 00003F63 807E15F8            <1> 	cmp	byte [esi+BPB_Media], 0F8h
 14555 00003F67 7514                <1> 	jne	short loc_not_a_valid_fat_partition4
 14556 00003F69 66837E1600          <1> 	cmp	word [esi+BPB_FATSz16], 0
 14557 00003F6E 770F                <1> 	ja	short loc_hd_FAT16_BPB
 14558 00003F70 807E4229            <1> 	cmp	byte [esi+BS_FAT32_BootSig], 29h
 14559 00003F74 7507                <1> 	jne	short loc_not_a_valid_fat_partition4
 14560                              <1> loc_hd_FAT32_BPB:
 14561 00003F76 B92D000000          <1> 	mov	ecx, 45
 14562 00003F7B EB0D                <1> 	jmp	short loc_hd_move_FAT_BPB
 14563                              <1> 	;
 14564                              <1> loc_not_a_valid_fat_partition4:
 14565 00003F7D F9                  <1> 	stc
 14566 00003F7E C3                  <1> 	retn
 14567                              <1> 	;
 14568                              <1> loc_hd_FAT16_BPB:
 14569 00003F7F 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
 14570 00003F83 75F8                <1> 	jne	short loc_not_a_valid_fat_partition4
 14571 00003F85 B920000000          <1> 	mov	ecx, 32
 14572                              <1> loc_hd_move_FAT_BPB:
 14573 00003F8A 89EF                <1> 	mov 	edi, ebp
 14574                              <1> 	;mov	esi, ebx ; Boot sector
 14575 00003F8C 57                  <1> 	push	edi
 14576 00003F8D 83C706              <1> 	add	edi, LD_BPB
 14577 00003F90 F366A5              <1> 	rep	movsw 
 14578 00003F93 5E                  <1> 	pop	esi
 14579 00003F94 0FB74614            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RsvdSecCnt]
 14580 00003F98 03466C              <1> 	add	eax, [esi+LD_StartSector]
 14581 00003F9B 894660              <1> 	mov	[esi+LD_FATBegin], eax
 14582 00003F9E 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
 14583 00003FA2 7224                <1> 	jb	short loc_set_FAT16_RootDirLoc
 14584                              <1> loc_set_FAT32_RootDirLoc:
 14585 00003FA4 8B462A              <1> 	mov	eax, [esi+LD_BPB+BPB_FATSz32]
 14586 00003FA7 0FB65E16            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_NumFATs]
 14587 00003FAB F7E3                <1> 	mul	ebx
 14588 00003FAD 034660              <1> 	add	eax, [esi+LD_FATBegin]
 14589                              <1> loc_set_FAT32_data_begin:
 14590 00003FB0 894668              <1> 	mov	[esi+LD_DATABegin], eax
 14591 00003FB3 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 14592                              <1> 	; If Root Directory Cluster <> 2 then
 14593                              <1> 	; change the beginning sector value 
 14594                              <1> 	; of the root dir by adding sector offset.
 14595 00003FB6 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
 14596 00003FB9 83E802              <1> 	sub	eax, 2
 14597 00003FBC 7442                <1> 	jz	short short loc_set_32bit_FAT_total_sectors  
 14598                              <1> 	;movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
 14599 00003FBE 8A5E13              <1> 	mov	bl, byte [esi+LD_BPB+BPB_SecPerClust] 
 14600 00003FC1 F7E3                <1> 	mul	ebx
 14601 00003FC3 014664              <1> 	add	[esi+LD_ROOTBegin], eax
 14602 00003FC6 EB38                <1> 	jmp	short loc_set_32bit_FAT_total_sectors
 14603                              <1> 	;
 14604                              <1> loc_set_FAT16_RootDirLoc:
 14605 00003FC8 0FB64616            <1> 	movzx	eax, byte [esi+LD_BPB+BPB_NumFATs]
 14606 00003FCC 0FB7561C            <1> 	movzx	edx, word [esi+LD_BPB+BPB_FATSz16]
 14607 00003FD0 F7E2                <1> 	mul	edx
 14608 00003FD2 034660              <1> 	add	eax, [esi+LD_FATBegin]  
 14609 00003FD5 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 14610                              <1> loc_set_FAT16_data_begin:
 14611 00003FD8 894668              <1> 	mov	[esi+LD_DATABegin], eax 
 14612 00003FDB B820000000          <1> 	mov	eax, 20h  ; Size of a directory entry
 14613                              <1> 	;movzx	edx, word [esi+LD_BPB+BPB_RootEntCnt]
 14614 00003FE0 668B5617            <1>         mov     dx, [esi+LD_BPB+BPB_RootEntCnt]
 14615 00003FE4 F7E2                <1>         mul	edx
 14616                              <1> 	;mov	ecx, 511
 14617 00003FE6 66B9FF01            <1> 	mov	cx, 511
 14618 00003FEA 01C8                <1> 	add	eax, ecx
 14619 00003FEC 41                  <1> 	inc	ecx ; 512
 14620 00003FED F7F1                <1> 	div	ecx
 14621 00003FEF 014668              <1> 	add	[esi+LD_DATABegin], eax
 14622 00003FF2 0FB74619            <1> 	movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
 14623 00003FF6 6685C0              <1> 	test	ax, ax
 14624 00003FF9 7405                <1> 	jz	short loc_set_32bit_FAT_total_sectors
 14625                              <1> loc_set_16bit_FAT_total_sectors:
 14626 00003FFB 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 14627 00003FFE EB06                <1> 	jmp	short loc_set_hd_FAT_cluster_count
 14628                              <1> loc_set_32bit_FAT_total_sectors:
 14629 00004000 8B4626              <1> 	mov	eax, [esi+LD_BPB+BPB_TotalSec32]
 14630 00004003 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 14631                              <1> loc_set_hd_FAT_cluster_count:
 14632 00004006 8B5668              <1> 	mov	edx, [esi+LD_DATABegin]
 14633 00004009 2B566C              <1> 	sub	edx, [esi+LD_StartSector]
 14634 0000400C 29D0                <1> 	sub	eax, edx
 14635 0000400E 31D2                <1> 	xor	edx, edx ; 0
 14636 00004010 0FB64E13            <1>         movzx   ecx, byte [esi+LD_BPB+BPB_SecPerClust]
 14637 00004014 F7F1                <1>         div	ecx 
 14638 00004016 894678              <1> 	mov	[esi+LD_Clusters], eax
 14639                              <1> 	; Maximum Valid Cluster Number= EAX +1
 14640                              <1> 	; with 2 reserved clusters= EAX +2
 14641                              <1> loc_set_hd_FAT_fs_free_sectors:
 14642                              <1> 	;mov	dword [esi+LD_FreeSectors], 0
 14643 00004019 E859010000          <1> 	call	get_free_FAT_sectors
 14644 0000401E 7207                <1> 	jc	short loc_validate_hd_FAT_partition_retn
 14645 00004020 894674              <1> 	mov	[esi+LD_FreeSectors], eax
 14646 00004023 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6  ; Volume Name Reset
 14647                              <1> 	;mov	cl, [Last_DOS_DiskNo] 
 14648                              <1> 	;add	cl, 'A'
 14649                              <1> 	;mov	[esi+LD_FS_Name], cl
 14650                              <1> 
 14651                              <1> loc_validate_hd_FAT_partition_retn:         
 14652 00004027 C3                  <1> 	retn
 14653                              <1> 
 14654                              <1> validate_hd_fs_partition:
 14655                              <1> 	; 13/02/2016
 14656                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 14657                              <1> 	; 29/01/2011
 14658                              <1> 	; 23/07/2011
 14659                              <1> 	; Input
 14660                              <1> 	;   DL = Hard/Fixed Disk Drive Number
 14661                              <1> 	;   ESI = PartitionTable offset
 14662                              <1> 	;   byte [Last_DOS_DiskNo]
 14663                              <1> 	; Output
 14664                              <1> 	;  cf=0 -> Validated
 14665                              <1> 	;   ESI = Logical dos drv desc. table
 14666                              <1> 	;   EBX = Singlix FS boot sector buffer
 14667                              <1> 	;   byte [Last_DOS_DiskNo]
 14668                              <1> 	;  cf=1 -> Not a valid 'Singlix FS' partition
 14669                              <1> 	; EAX, EDX, ECX, EDI -> changed 
 14670                              <1> 
 14671                              <1> 	;mov	esi, PartitionTable
 14672 00004028 8A6604              <1> 	mov	ah, [esi+ptFileSystemID]
 14673 0000402B 80FCA1              <1> 	cmp	ah, 0A1h ; SINGLIX FS1 (trfs1) partition
 14674 0000402E 7549                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 14675                              <1> loc_set_valid_hd_fs_partition_params:
 14676 00004030 FE05[40940000]      <1> 	inc	byte [Last_DOS_DiskNo] ; > 1
 14677 00004036 30C0                <1> 	xor	al, al ; mov al, 0
 14678                              <1> 	;mov	[drv], dl
 14679 00004038 29DB                <1> 	sub	ebx, ebx ; 0
 14680 0000403A 8A3D[40940000]      <1> 	mov	bh, [Last_DOS_DiskNo] 
 14681 00004040 81C300010900        <1> 	add	ebx, Logical_DOSDisks
 14682 00004046 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
 14683 0000404A 885302              <1> 	mov	[ebx+LD_PhyDrvNo], dl
 14684                              <1> 	;mov	[ebx+LD_FATType], al ; 0
 14685                              <1> 	;mov	[ebx+LD_FSType], ah
 14686 0000404D 66894303            <1> 	mov	[ebx+LD_FATType], ax
 14687                              <1> 	;mov	eax, [esi+ptStartSector]
 14688                              <1> 	;mov	[ebx+LD_StartSector], eax
 14689                              <1> loc_hd_fs_logical_drv_init:
 14690 00004051 89DD                <1> 	mov	ebp, ebx ; 10/01/2016
 14691                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
 14692 00004053 A0[0EA90000]        <1> 	mov	al, [HD_LBA_yes] ; 10/01/2016
 14693 00004058 884305              <1> 	mov	[ebx+LD_LBAYes], al
 14694 0000405B 89DE                <1> 	mov	esi, ebx
 14695 0000405D BB[21A90000]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer addressh
 14696 00004062 08C0                <1> 	or	al, al
 14697 00004064 7515                <1> 	jnz	short loc_hd_fs_drv_init_load_bs_lba
 14698                              <1> loc_hd_fs_drv_init_load_bs_chs:
 14699 00004066 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
 14700 00004069 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
 14701 0000406D 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14702                              <1> 	;mov	ebx, DOSBootSectorBuff
 14703 00004071 E855E8FFFF          <1> 	call	int13h
 14704 00004076 7311                <1> 	jnc	short loc_hd_drv_fs_boot_validation
 14705                              <1> loc_validate_hd_fs_partition_err_retn:
 14706 00004078 C3                  <1> 	retn
 14707                              <1> loc_validate_hd_fs_partition_stc_retn:
 14708 00004079 F9                  <1> 	stc
 14709 0000407A C3                  <1> 	retn
 14710                              <1> loc_hd_fs_drv_init_load_bs_lba:
 14711                              <1> 	; DL = Physical drive number
 14712                              <1> 	;mov	esi, ebx
 14713 0000407B 8B4E08              <1>    	mov	ecx, [esi+ptStartSector] ; sector number
 14714                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
 14715                              <1> 	; LBA read/write (with private LBA function) 
 14716                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 14717                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 14718 0000407E B41B                <1> 	mov	ah, 1Bh ; LBA read
 14719 00004080 B001                <1> 	mov	al, 1 ; sector count
 14720 00004082 E844E8FFFF          <1> 	call	int13h
 14721 00004087 72EF                <1> 	jc	short loc_validate_hd_fs_partition_err_retn
 14722                              <1> loc_hd_drv_fs_boot_validation:
 14723                              <1> 	;mov	esi, DOSBootSectorBuff
 14724 00004089 89DE                <1> 	mov	esi, ebx ; Boot sector buffer
 14725 0000408B 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 14726 00004094 75E3                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 14727                              <1>         ;
 14728                              <1> 	;Singlix FS Extensions to TR-DOS (7/6/2009) 
 14729 00004096 66817E035346        <1> 	cmp	word [esi+bs_FS_Identifier], 'SF'
 14730 0000409C 75DB                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 14731                              <1>         ;'A1h' check is not necessary
 14732                              <1> 	;  if 'FS' check is passed as OK/Yes.
 14733 0000409E 807E09A1            <1> 	cmp	byte [esi+bs_FS_PartitionID], 0A1h
 14734 000040A2 75D5                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
 14735                              <1> 	;
 14736 000040A4 89EF                <1> 	mov	edi, ebp ; 10/01/2016
 14737                              <1> 	;
 14738 000040A6 8A462D              <1> 	mov	al, byte [esi+bs_FS_LBA_Ready]
 14739 000040A9 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
 14740                              <1> 	;
 14741                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
 14742 000040AC 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
 14743 000040AF 884706              <1> 	mov	byte [edi+LD_FS_MediaAttrib], al
 14744                              <1> 	;
 14745 000040B2 8A460A              <1> 	mov	al, [esi+bs_FS_VersionMaj]
 14746 000040B5 884707              <1> 	mov	[edi+LD_FS_VersionMajor], al
 14747                              <1> 	;
 14748 000040B8 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
 14749 000040BC 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
 14750 000040C0 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
 14751 000040C3 6698                <1> 	cbw
 14752 000040C5 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
 14753 000040C9 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
 14754                              <1> 	;cbw
 14755 000040CC 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
 14756                              <1> 	;
 14757 000040D0 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
 14758 000040D3 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
 14759 000040D6 8B5618              <1> 	mov	edx, [esi+bs_FS_MATLocation]
 14760 000040D9 89570C              <1> 	mov	[edi+LD_FS_MATLocation], edx
 14761 000040DC 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
 14762 000040DF 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
 14763 000040E2 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
 14764 000040E5 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
 14765 000040E8 8B4710              <1> 	mov	eax, [edi+bs_FS_VolumeSize]
 14766 000040EB 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
 14767                              <1> 	;
 14768 000040EE 89D0                <1> 	mov	eax, edx ; [edi+LD_FS_MATLocation]
 14769 000040F0 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
 14770 000040F3 89FE                <1> 	mov	esi, edi
 14771                              <1> mread_hd_fs_MAT_sector:
 14772                              <1>        ;mov	ebx, DOSBootSectorBuff
 14773 000040F5 B901000000          <1> 	mov	ecx, 1
 14774 000040FA E808500000          <1> 	call	disk_read
 14775 000040FF 7248                <1> 	jc	short loc_validate_hd_fs_partition_retn
 14776                              <1> 	; EDI will not be changed
 14777 00004101 89DE                <1> 	mov	esi, ebx
 14778                              <1> use_hdfs_mat_sector_params:
 14779 00004103 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
 14780 00004106 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
 14781 00004109 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
 14782 0000410C 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
 14783 0000410F 8B4614              <1> 	mov	eax, [esi+FS_MAT_FreeSectors]
 14784 00004112 894774              <1>         mov     [edi+LD_FS_FreeSectors], eax
 14785 00004115 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
 14786 00004118 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
 14787 0000411B 8B4708              <1> 	mov	eax, [edi+LD_FS_RootDirD]
 14788 0000411E 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
 14789 00004121 89FE                <1> 	mov	esi, edi   
 14790                              <1> read_hd_fs_RDT_sector:
 14791 00004123 BB[21A90000]        <1> 	mov	ebx, DOSBootSectorBuff
 14792                              <1> 	;mov	ecx, 1
 14793 00004128 B101                <1> 	mov	cl, 1
 14794 0000412A E8D84F0000          <1> 	call	disk_read
 14795 0000412F 7218                <1> 	jc	short loc_validate_hd_fs_partition_retn
 14796                              <1> 	; EDI will not be changed
 14797 00004131 89DE                <1> 	mov	esi, ebx
 14798                              <1> use_hdfs_RDT_sector_params:
 14799 00004133 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
 14800 00004136 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
 14801 00004139 57                  <1> 	push	edi
 14802                              <1> 	;mov	ecx, 16
 14803 0000413A B110                <1> 	mov	cl, 16
 14804 0000413C 83C640              <1> 	add	esi, FS_RDT_VolumeName
 14805 0000413F 83C72C              <1> 	add	edi, LD_FS_VolumeName
 14806 00004142 F3A5                <1> 	rep	movsd ; 64 bytes
 14807 00004144 5E                  <1> 	pop	esi
 14808                              <1> 		; Volume Name Reset
 14809 00004145 C6467E06            <1>         mov     byte [esi+LD_FS_MediaChanged], 6
 14810                              <1> 	;
 14811                              <1>         ;mov	cl, [Last_DOS_DiskNo] 
 14812                              <1> 	;add	cl, 'A'
 14813                              <1> 	;mov	[esi+LD_FS_Name], cl
 14814                              <1> 
 14815                              <1> loc_validate_hd_fs_partition_retn:
 14816 00004149 C3                  <1> 	retn
 14817                              <1> 
 14818                              <1> load_masterboot:
 14819                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 14820                              <1> 	; 2005 - 2011
 14821                              <1> 	; input -> DL = drive number
 14822 0000414A B40D                <1> 	mov	ah, 0Dh ; Alternate disk reset
 14823 0000414C E87AE7FFFF          <1> 	call	int13h
 14824 00004151 7301                <1> 	jnc	short pass_reset_error
 14825                              <1> harddisk_error:
 14826 00004153 C3                  <1>   	retn
 14827                              <1> pass_reset_error:
 14828 00004154 BB[0EA50000]        <1> 	mov	ebx, MasterBootBuff
 14829 00004159 66B80102            <1> 	mov	ax, 0201h
 14830 0000415D 66B90100            <1> 	mov	cx, 1
 14831 00004161 30F6                <1> 	xor	dh, dh
 14832 00004163 E863E7FFFF          <1>  	call	int13h
 14833 00004168 72E9                <1> 	jc	short harddisk_error
 14834                              <1> 	;
 14835 0000416A 66813D[0CA70000]55- <1> 	cmp	word [MBIDCode], 0AA55h
 14836 00004172 AA                  <1>
 14837 00004173 7401                <1> 	je	short load_masterboot_ok
 14838 00004175 F9                  <1> 	stc
 14839                              <1> load_masterboot_ok:
 14840 00004176 C3                  <1> 	retn
 14841                              <1> 
 14842                              <1> get_free_FAT_sectors:
 14843                              <1> 	; 29/02/2016
 14844                              <1> 	; 13/02/2016
 14845                              <1> 	; 04/02/2016
 14846                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
 14847                              <1> 	; 11/07/2010
 14848                              <1> 	; 21/06/2009
 14849                              <1> 	; INPUT: ESI = Logical DOS Drive Description Table address
 14850                              <1> 	; OUTPUT: STC => Error
 14851                              <1>         ;	cf = 0 and EAX = Free FAT sectors
 14852                              <1> 	; Also, related parameters and FAT buffer will be reset and updated
 14853                              <1> 
 14854 00004177 31C0                <1> 	xor	eax, eax
 14855                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Reset
 14856                              <1> 	
 14857 00004179 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
 14858 0000417D 7650                <1> 	jna	short loc_gfc_get_fat_free_clusters
 14859                              <1> 
 14860                              <1> 	; 29/02/2016
 14861 0000417F 48                  <1> 	dec	eax ; 0FFFFFFFFh
 14862 00004180 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count (reset)
 14863 00004183 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster (reset)
 14864 00004186 40                  <1> 	inc	eax ; 0
 14865                              <1> 	;
 14866 00004187 668B4636            <1> 	mov	ax, [esi+LD_BPB+BPB_FSInfo]
 14867 0000418B 03466C              <1> 	add	eax, [esi+LD_StartSector]
 14868                              <1> 
 14869 0000418E BB[21A90000]        <1> 	mov	ebx, DOSBootSectorBuff
 14870 00004193 B901000000          <1> 	mov	ecx, 1
 14871 00004198 E86A4F0000          <1>  	call	disk_read
 14872 0000419D 7301                <1> 	jnc	short loc_gfc_check_fsinfo_signs
 14873                              <1> retn_gfc_get_fsinfo_sec:
 14874 0000419F C3                  <1> 	retn
 14875                              <1> 
 14876                              <1> loc_gfc_check_fsinfo_signs:
 14877 000041A0 BB[21A90000]        <1> 	mov 	ebx, DOSBootSectorBuff ; 13/02/2016
 14878 000041A5 813B52526141        <1>         cmp     dword [ebx], 41615252h
 14879 000041AB 7520                <1> 	jne	short retn_gfc_get_fsinfo_stc
 14880                              <1> 	;add	ebx, 484
 14881                              <1> 	;cmp	dword [ebx], 61417272h
 14882 000041AD 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 14883 000041B6 61                  <1>
 14884 000041B7 7514                <1> 	jne	short retn_gfc_get_fsinfo_stc
 14885                              <1> 	;add	ebx, 4
 14886                              <1> 	;mov	eax, [ebx]
 14887 000041B9 8B83E8010000        <1> 	mov	eax, [ebx+488]
 14888                              <1> 	; 29/02/2016
 14889 000041BF 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
 14890 000041C2 8B93EC010000        <1> 	mov	edx,  [ebx+492] 
 14891 000041C8 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster
 14892                              <1> 	;
 14893 000041CB EB12                <1> 	jmp	short retn_from_get_free_fat32_clusters
 14894                              <1> 
 14895                              <1> retn_gfc_get_fsinfo_stc:
 14896 000041CD F9                  <1> 	stc
 14897 000041CE C3                  <1> 	retn
 14898                              <1> 
 14899                              <1> loc_gfc_get_fat_free_clusters:
 14900                              <1> 	;mov	eax, 2
 14901 000041CF B002                <1> 	mov	al, 2
 14902                              <1> 	;mov	[FAT_CurrentCluster], eax
 14903                              <1> loc_gfc_loop_get_next_cluster:
 14904 000041D1 E85C2F0000          <1> 	call	get_next_cluster
 14905 000041D6 730E                <1> 	jnc	short loc_gfc_free_fat_clusters_cont
 14906 000041D8 21C0                <1> 	and	eax, eax
 14907 000041DA 7411                <1> 	jz	short loc_gfc_pass_inc_free_cluster_count
 14908                              <1>  
 14909                              <1> retn_from_get_free_fat_clusters:
 14910 000041DC 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors] ; Free clusters !
 14911                              <1> retn_from_get_free_fat32_clusters:
 14912 000041DF 0FB65E13            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
 14913 000041E3 F7E3                <1>       	mul	ebx
 14914                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Free sectors
 14915                              <1> retn_get_free_sectors_calc:
 14916 000041E5 C3                  <1> 	retn
 14917                              <1> 
 14918                              <1> loc_gfc_free_fat_clusters_cont:
 14919 000041E6 09C0                <1> 	or	eax, eax
 14920 000041E8 7503                <1> 	jnz	short loc_gfc_pass_inc_free_cluster_count
 14921 000041EA FF4674              <1> 	inc	dword [esi+LD_FreeSectors] ; Free clusters !
 14922                              <1>    
 14923                              <1> loc_gfc_pass_inc_free_cluster_count:
 14924                              <1> 	;mov	eax, [FAT_CurrentCluster]
 14925 000041ED 89C8                <1> 	mov	eax, ecx ; [FAT_CurrentCluster]
 14926 000041EF 3B4678              <1> 	cmp	eax, [esi+LD_Clusters]
 14927 000041F2 77E8                <1> 	ja	short retn_from_get_free_fat_clusters
 14928 000041F4 40                  <1> 	inc	eax
 14929                              <1> 	;mov	[FAT_CurrentCluster], eax
 14930 000041F5 EBDA                <1> 	jmp	short loc_gfc_loop_get_next_cluster
 14931                              <1> 
 14932                              <1> floppy_drv_init:
 14933                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 14934                              <1> 	; 24/07/2011
 14935                              <1> 	; 04/07/2009
 14936                              <1> 	; INPUT ->
 14937                              <1> 	;	DL = Drive number (0,1)
 14938                              <1> 	; OUTPUT ->
 14939                              <1> 	;	BL = drive name
 14940                              <1> 	;	BH = drive number
 14941                              <1> 	;	ESI = Logical DOS drv description table
 14942                              <1> 	;	EAX = Volume serial number
 14943                              <1>  
 14944 000041F7 BE[1E9D0000]        <1> 	mov	esi, fd0_type ; 10/01/2016
 14945 000041FC BF00010900          <1> 	mov	edi, Logical_DOSDisks
 14946 00004201 08D2                <1> 	or	dl, dl
 14947 00004203 7407                <1> 	jz	short loc_drv_init_fd0_fd1
 14948 00004205 81C700010000        <1> 	add	edi, 100h
 14949 0000420B 46                  <1> 	inc	esi ; fd1_type ; 10/01/2016
 14950                              <1> loc_drv_init_fd0_fd1:
 14951 0000420C C6477E00            <1> 	mov	byte [edi+LD_MediaChanged], 0
 14952 00004210 803E01              <1> 	cmp	byte [esi], 1 ; type (>0 if it is existing) 
 14953                              <1> 		; 4 = 1.44 MB, 80 track, 3 1/2"
 14954 00004213 7221                <1> 	jb	short read_fd_boot_sector_retn
 14955 00004215 885702              <1> 	mov	[edi+LD_PhyDrvNo], dl
 14956                              <1> read_fd_boot_sector:
 14957 00004218 30F6                <1> 	xor	dh, dh
 14958 0000421A B904000000          <1> 	mov	ecx, 4 ; Retry Count
 14959                              <1> read_fd_boot_sector_again:
 14960 0000421F 51                  <1> 	push 	ecx
 14961                              <1> 	;mov	cx, 1
 14962 00004220 B101                <1> 	mov	cl, 1
 14963 00004222 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
 14964 00004226 BB[21A90000]        <1> 	mov	ebx, DOSBootSectorBuff
 14965 0000422B E89BE6FFFF          <1> 	call	int13h
 14966 00004230 59                  <1> 	pop	ecx
 14967 00004231 7304                <1> 	jnc	short use_fd_boot_sector_params
 14968 00004233 E2EA                <1> 	loop	read_fd_boot_sector_again
 14969                              <1> 
 14970                              <1> read_fd_boot_sector_stc_retn:
 14971 00004235 F9                  <1> 	stc
 14972                              <1> read_fd_boot_sector_retn:
 14973 00004236 C3                  <1> 	retn
 14974                              <1> 
 14975                              <1> use_fd_boot_sector_params:
 14976                              <1> 	;mov	esi, DOSBootSectorBuff
 14977 00004237 89DE                <1> 	mov	esi, ebx
 14978 00004239 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
 14979 00004242 75F1                <1> 	jne	short read_fd_boot_sector_stc_retn
 14980 00004244 66817E035346        <1>         cmp     word [esi+bs_FS_Identifier], 'SF'
 14981 0000424A 0F85A2000000        <1>         jne     use_fd_fatfs_boot_sector_params
 14982                              <1> 	;
 14983 00004250 8A462D              <1> 	mov	al, [esi+bs_FS_LBA_Ready]
 14984 00004253 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
 14985                              <1> 	;
 14986                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
 14987 00004256 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
 14988 00004259 884706              <1> 	mov	[edi+LD_FS_MediaAttrib], al
 14989                              <1> 	;
 14990 0000425C 8A460A              <1>         mov	al, [esi+bs_FS_VersionMaj]
 14991 0000425F 884707              <1> 	mov	byte [edi+LD_FS_VersionMajor], al
 14992 00004262 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
 14993 00004266 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
 14994 0000426A 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
 14995 0000426D 6698                <1> 	cbw
 14996 0000426F 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
 14997 00004273 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
 14998                              <1> 	;cbw
 14999 00004276 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
 15000                              <1> 	;
 15001 0000427A 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
 15002 0000427D 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
 15003 00004280 8B4618              <1> 	mov	eax, [esi+bs_FS_MATLocation]
 15004 00004283 89470C              <1> 	mov	[edi+LD_FS_MATLocation], eax
 15005 00004286 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
 15006 00004289 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
 15007 0000428C 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
 15008 0000428F 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
 15009 00004292 8B4610              <1> 	mov	eax, [esi+bs_FS_VolumeSize]
 15010 00004295 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
 15011                              <1> 	;		
 15012 00004298 89FE                <1> 	mov	esi, edi
 15013 0000429A 8B460C              <1>  	mov	eax, [esi+LD_FS_MATLocation]
 15014                              <1> 	;add	eax, [edi+LD_FS_BeginSector]
 15015                              <1> read_fd_MAT_sector_again:
 15016                              <1> 	;mov	ebx, DOSBootSectorBuff
 15017                              <1> 	;mov	ecx, 1
 15018 0000429D B101                <1> 	mov	cl, 1
 15019 0000429F E8694E0000          <1> 	call	chs_read
 15020 000042A4 89DE                <1> 	mov	esi, ebx
 15021 000042A6 7301                <1> 	jnc	short use_fdfs_mat_sector_params
 15022                              <1> 	;jmp	short read_fd_boot_sector_retn
 15023 000042A8 C3                  <1> 	retn
 15024                              <1> use_fdfs_mat_sector_params:
 15025 000042A9 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
 15026 000042AC 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
 15027 000042AF 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
 15028 000042B2 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
 15029 000042B5 8B4714              <1> 	mov	eax, [edi+FS_MAT_FreeSectors]
 15030 000042B8 894774              <1> 	mov	[edi+LD_FS_FreeSectors], eax
 15031 000042BB 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
 15032 000042BE 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
 15033                              <1> 	;
 15034 000042C1 89FE                <1> 	mov	esi, edi
 15035 000042C3 8B4608              <1>  	mov	eax, [esi+LD_FS_RootDirD]
 15036                              <1> read_fd_RDT_sector_again:
 15037                              <1> 	;mov	ebx, DOSBootSectorBuff
 15038                              <1> 	;mov	cx, 1
 15039 000042C6 B101                <1> 	mov	cl, 1
 15040 000042C8 E8404E0000          <1> 	call	chs_read
 15041 000042CD 89DE                <1> 	mov	esi, ebx
 15042 000042CF 7220                <1> 	jc	short read_fd_RDT_sector_retn
 15043                              <1> use_fdfs_RDT_sector_params:
 15044 000042D1 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
 15045 000042D4 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
 15046 000042D7 57                  <1> 	push	edi
 15047                              <1> 	;mov	ecx, 16
 15048 000042D8 B110                <1> 	mov	cl, 16	
 15049 000042DA 83C640              <1> 	add	esi, FS_RDT_VolumeName
 15050 000042DD 83C72C              <1> 	add	edi, LD_FS_VolumeName
 15051 000042E0 F3A5                <1> 	rep	movsd ; 64 bytes
 15052 000042E2 5E                  <1> 	pop	esi
 15053 000042E3 C6460300            <1> 	mov	byte [esi+LD_FATType], 0
 15054 000042E7 C64604A1            <1> 	mov	byte [esi+LD_FSType], 0A1h  
 15055 000042EB E9AA000000          <1>         jmp     loc_cont_use_fd_boot_sector_params
 15056                              <1> 
 15057                              <1> read_fd_RDT_sector_stc_retn:
 15058 000042F0 F9                  <1> 	stc
 15059                              <1> read_fd_RDT_sector_retn:
 15060 000042F1 C3                  <1> 	retn
 15061                              <1> 
 15062                              <1> use_fd_fatfs_boot_sector_params:
 15063 000042F2 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
 15064 000042F6 75F8                <1> 	jne	short read_fd_RDT_sector_stc_retn
 15065 000042F8 807E15F0            <1> 	cmp	byte [esi+BPB_Media], 0F0h
 15066 000042FC 72F3                <1> 	jb	short read_fd_RDT_sector_retn
 15067 000042FE 57                  <1> 	push	edi
 15068 000042FF 83C706              <1> 	add	edi, LD_BPB
 15069                              <1> 	;mov	ecx, 16
 15070 00004302 B110                <1> 	mov	cl, 16
 15071 00004304 F3A5                <1> 	rep	movsd ; 64 bytes 
 15072 00004306 5E                  <1> 	pop	esi
 15073 00004307 31C0                <1> 	xor	eax, eax
 15074 00004309 89466C              <1> 	mov	[esi+LD_StartSector], eax ; 0
 15075 0000430C 668B461C            <1> 	mov	ax, [esi+LD_BPB+BPB_FATSz16]
 15076 00004310 8A4E16              <1> 	mov	cl, [esi+LD_BPB+BPB_NumFATs] 
 15077 00004313 F7E1                <1>   	mul	ecx
 15078                              <1> 	; edx = 0 !
 15079 00004315 668B5614            <1> 	mov	dx, [esi+LD_BPB+BPB_RsvdSecCnt]
 15080 00004319 66895660            <1> 	mov	[esi+LD_FATBegin], dx
 15081                              <1> 	;add	eax, edx
 15082 0000431D 6601D0              <1> 	add	ax, dx
 15083 00004320 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
 15084 00004323 894668              <1> 	mov	[esi+LD_DATABegin], eax 
 15085 00004326 668B5617            <1> 	mov	dx, [esi+LD_BPB+BPB_RootEntCnt]
 15086                              <1> 	;shl	edx, 5 ; * 32 (Size of a directory entry)
 15087 0000432A 66C1E205            <1> 	shl	dx, 5
 15088                              <1> 	;add	edx, 511
 15089 0000432E 6681C2FF01          <1> 	add	dx, 511
 15090                              <1> 	;shr	edx, 9 ; edx = ((edx*32)+511) / 512
 15091 00004333 66C1EA09            <1> 	shr	dx, 9
 15092 00004337 015668              <1> 	add 	[esi+LD_DATABegin], edx
 15093                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
 15094 0000433A 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
 15095 0000433E 894670              <1> 	mov	[esi+LD_TotalSectors], eax
 15096 00004341 2B4668              <1> 	sub	eax, [esi+LD_DATABegin]
 15097                              <1>   	;movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust]
 15098 00004344 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]  
 15099 00004347 80F901              <1> 	cmp	cl, 1
 15100 0000434A 7605                <1> 	jna	short save_fd_fatfs_cluster_count
 15101                              <1> 	;sub	edx, edx
 15102 0000434C 6629D2              <1> 	sub	dx, dx ; 0
 15103 0000434F F7F1                <1> 	div	ecx
 15104                              <1> save_fd_fatfs_cluster_count:
 15105 00004351 894678              <1> 	mov	[esi+LD_Clusters], eax
 15106                              <1> 
 15107                              <1>       ; Maximum Valid Cluster Number = EAX +1
 15108                              <1>       ; with 2 reserved clusters= EAX +2
 15109                              <1>  
 15110                              <1> reset_FAT_buffer_decriptors:
 15111 00004354 29C0                <1> 	sub	eax, eax ; 0  
 15112 00004356 A2[25AB0000]        <1> 	mov	[FAT_BuffValidData], al ; 0
 15113 0000435B A2[26AB0000]        <1> 	mov	[FAT_BuffDrvName], al ; 0
 15114 00004360 A3[29AB0000]        <1> 	mov	[FAT_BuffSector], eax ; 0
 15115                              <1> 
 15116                              <1> read_fd_FAT_sectors:
 15117 00004365 BB001C0900          <1>   	mov	ebx, FAT_Buffer
 15118 0000436A 668B4614            <1> 	mov	ax, [esi+LD_BPB+BPB_RsvdSecCnt]
 15119                              <1> 	;mov	ecx, 3
 15120 0000436E B103                <1> 	mov	cl, 3 ; 3 sectors
 15121 00004370 E8984D0000          <1> 	call	chs_read
 15122 00004375 7240                <1> 	jc	short read_fd_FAT_sectors_retn
 15123                              <1> use_fd_FAT_sectors:
 15124 00004377 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo]
 15125 0000437A 0441                <1> 	add	al, 'A' 
 15126 0000437C A2[26AB0000]        <1> 	mov	[FAT_BuffDrvName], al 
 15127 00004381 C605[25AB0000]01    <1>  	mov	byte [FAT_BuffValidData], 1
 15128 00004388 E82B000000          <1> 	call	fd_init_calculate_free_clusters
 15129 0000438D 7228                <1> 	jc	short read_fd_FAT_sectors_retn
 15130                              <1>   
 15131                              <1> loc_use_fd_boot_sector_params_FAT:
 15132 0000438F C6460301            <1> 	mov	byte [esi+LD_FATType], 1 ; FAT 12
 15133 00004393 C6460401            <1> 	mov	byte [esi+LD_FSType], 1
 15134 00004397 8B462D              <1>         mov     eax, [esi+LD_BPB+VolumeID]
 15135                              <1> loc_cont_use_fd_boot_sector_params:
 15136 0000439A 8A7E02              <1> 	mov	bh, [esi+LD_PhyDrvNo]
 15137 0000439D 887E7D              <1> 	mov	[esi+LD_DParamEntry], bh
 15138 000043A0 88FB                <1> 	mov	bl, bh
 15139 000043A2 80C341              <1> 	add	bl, 'A'
 15140 000043A5 881E                <1> 	mov	byte [esi+LD_Name], bl
 15141 000043A7 C6460101            <1> 	mov	byte [esi+LD_DiskType], 1
 15142 000043AB C6460500            <1> 	mov	byte [esi+LD_LBAYes], 0
 15143 000043AF C6467C00            <1> 	mov	byte [esi+LD_PartitionEntry], 0
 15144 000043B3 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6 ; Volume Name Reset
 15145                              <1> 
 15146                              <1> read_fd_FAT_sectors_retn:
 15147 000043B7 C3                  <1> 	retn   
 15148                              <1> 
 15149                              <1> fd_init_calculate_free_clusters:
 15150                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15151                              <1> 	; 04/07/2009
 15152                              <1> 	; INPUT ->
 15153                              <1> 	;     ESI = Logical DOS drive description table address
 15154                              <1> 	; OUTPUT ->
 15155                              <1> 	;    [ESI+LD_FreeSectors] will be set
 15156                              <1> 	
 15157 000043B8 29C0                <1> 	sub	eax, eax
 15158 000043BA 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; 0
 15159 000043BD B002                <1> 	mov	al, 2 ; eax = 2
 15160                              <1> 
 15161                              <1> fd_init_loop_get_next_cluster:
 15162 000043BF E830000000          <1> 	call	fd_init_get_next_cluster
 15163 000043C4 722D                <1> 	jc	short fd_init_calculate_free_clusters_retn
 15164                              <1> 
 15165                              <1> fd_init_free_fat_clusters:
 15166                              <1> 	;cmp 	eax, 0
 15167                              <1> 	;ja	short fd_init_pass_inc_free_cluster_count
 15168                              <1> 	;and	eax, eax
 15169                              <1> 	;jnz	short fd_init_pass_inc_free_cluster_count
 15170 000043C6 6621C0              <1> 	and	ax, ax
 15171 000043C9 7504                <1> 	jnz	short fd_init_pass_inc_free_cluster_count
 15172                              <1> 	;inc	dword [esi+LD_FreeSectors]
 15173 000043CB 66FF4674            <1>         inc	word [esi+LD_FreeSectors]
 15174                              <1>     
 15175                              <1> fd_init_pass_inc_free_cluster_count:
 15176                              <1>   	;mov	eax, [FAT_CurrentCluster]
 15177 000043CF 66A1[21AB0000]      <1> 	mov	ax, [FAT_CurrentCluster]
 15178                              <1> 	;cmp	eax, [esi+LD_Clusters]
 15179 000043D5 663B4678            <1> 	cmp	ax, [esi+LD_Clusters]
 15180 000043D9 7704                <1> 	ja	short short retn_from_fd_init_calculate_free_clusters
 15181                              <1> 	;inc	eax
 15182 000043DB 6640                <1> 	inc	ax
 15183 000043DD EBE0                <1> 	jmp	short fd_init_loop_get_next_cluster
 15184                              <1> 
 15185                              <1> retn_from_fd_init_calculate_free_clusters:
 15186 000043DF 8A4613              <1>   	mov	al, [esi+LD_BPB+BPB_SecPerClust]
 15187 000043E2 3C01                <1>   	cmp	al, 1
 15188 000043E4 760D                <1> 	jna	short fd_init_calculate_free_clusters_retn
 15189                              <1> 	;movzx	eax, al
 15190 000043E6 6698                <1> 	cbw
 15191                              <1> 	;mov	ecx, [esi+LD_FreeSectors]
 15192 000043E8 668B4E74            <1> 	mov	cx, [esi+LD_FreeSectors] ; Count of free clusters
 15193                              <1>   	;mul	ecx
 15194 000043EC 66F7E1              <1> 	mul	cx
 15195                              <1> 	;mov	[esi+LD_FreeSectors], eax
 15196 000043EF 66894674            <1> 	mov	[esi+LD_FreeSectors], ax
 15197                              <1> fd_init_calculate_free_clusters_retn:
 15198 000043F3 C3                  <1> 	retn
 15199                              <1> 
 15200                              <1> fd_init_get_next_cluster:
 15201                              <1> 	; 04/02/2016
 15202                              <1> 	; 02/02/2016
 15203                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15204                              <1> 	; 04/07/2009
 15205                              <1> 	; INPUT ->
 15206                              <1> 	;    EAX = Current cluster
 15207                              <1> 	;    ESI = Logical DOS drive description table address
 15208                              <1> 	;    EDX = 0
 15209                              <1> 	; OUTPUT ->
 15210                              <1> 	;    EAX = Next cluster
 15211                              <1> 
 15212 000043F4 A3[21AB0000]        <1> 	mov	[FAT_CurrentCluster], eax
 15213                              <1> fd_init_get_next_cluster_readnext:
 15214 000043F9 29D2                <1> 	sub	edx, edx ; 0
 15215 000043FB BB00040000          <1>   	mov	ebx, 1024 ; 400h
 15216 00004400 F7F3                <1>   	div	ebx
 15217                              <1>   	; EAX = Count of 3 FAT sectors
 15218                              <1>   	; EDX = Buffer entry index
 15219 00004402 89C1                <1> 	mov	ecx, eax
 15220                              <1> 	;mov	eax, 3
 15221 00004404 B003                <1> 	mov	al, 3
 15222 00004406 F7E2                <1> 	mul	edx ; Multiply by 3
 15223 00004408 66D1E8              <1> 	shr	ax, 1 ; Divide by 2
 15224 0000440B 89C3                <1> 	mov	ebx, eax ; Buffer byte offset
 15225 0000440D 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 15226 00004413 89C8                <1> 	mov	eax, ecx
 15227                              <1> 	;mov	edx, 3
 15228 00004415 66BA0300            <1> 	mov	dx, 3
 15229 00004419 F7E2                <1> 	mul	edx 
 15230                              <1>   	; EAX = FAT Beginning Sector
 15231                              <1> 	; EDX = 0
 15232 0000441B 8A0E                <1> 	mov	cl, [esi+LD_Name]
 15233                              <1> 	;cmp	byte [FAT_BuffValidData], 0
 15234                              <1> 	;jna	short fd_init_load_FAT_sectors0
 15235 0000441D 3A0D[26AB0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 15236 00004423 751E                <1> 	jne	short fd_init_load_FAT_sectors0
 15237 00004425 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 15238 0000442B 751C                <1> 	jne	short fd_init_load_FAT_sectors1
 15239                              <1> 	;mov	eax, [FAT_CurrentCluster]
 15240 0000442D A0[21AB0000]        <1> 	mov	al, [FAT_CurrentCluster]
 15241                              <1> 	;shr	eax, 1
 15242 00004432 D0E8                <1> 	shr	al, 1
 15243 00004434 668B03              <1> 	mov	ax, [ebx]
 15244 00004437 7306                <1>   	jnc	short fd_init_gnc_even
 15245 00004439 66C1E804            <1> 	shr	ax, 4
 15246                              <1> fd_init_gnc_clc_retn:
 15247 0000443D F8                  <1> 	clc
 15248 0000443E C3                  <1> 	retn
 15249                              <1> 
 15250                              <1> fd_init_gnc_even:
 15251 0000443F 80E40F              <1> 	and	ah, 0Fh
 15252 00004442 C3                  <1> 	retn
 15253                              <1> 
 15254                              <1> fd_init_load_FAT_sectors0:
 15255 00004443 880D[26AB0000]      <1> 	mov 	[FAT_BuffDrvName], cl
 15256                              <1> fd_init_load_FAT_sectors1:
 15257 00004449 C605[25AB0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 15258 00004450 A3[29AB0000]        <1> 	mov	[FAT_BuffSector], eax
 15259 00004455 034660              <1> 	add	eax, [esi+LD_FATBegin]
 15260 00004458 BB001C0900          <1>  	mov	ebx, FAT_Buffer
 15261                              <1> 	;movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
 15262 0000445D 668B4E1C            <1> 	mov	cx, [esi+LD_BPB+BPB_FATSz16]
 15263 00004461 662B0D[29AB0000]    <1> 	sub	cx, [FAT_BuffSector]
 15264                              <1>         ;cmp	ecx, 3
 15265 00004468 6683F903            <1> 	cmp	cx, 3
 15266 0000446C 7605                <1> 	jna	short fdinit_pass_fix_sector_count_3
 15267                              <1> 	;mov	ecx, 3
 15268 0000446E B903000000          <1> 	mov	ecx, 3
 15269                              <1> fdinit_pass_fix_sector_count_3:  
 15270 00004473 E8954C0000          <1> 	call	chs_read
 15271 00004478 730D                <1> 	jnc	short fd_init_FAT_sectors_no_load_error
 15272 0000447A C605[25AB0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 15273                              <1> 		; Drv not ready or read Error !
 15274 00004481 B80F000000          <1> 	mov	eax, ERR_DRV_NOT_RDY ; 15
 15275                              <1> 	;xor	edx, edx
 15276 00004486 C3                  <1> 	retn
 15277                              <1> 
 15278                              <1> fd_init_FAT_sectors_no_load_error:
 15279 00004487 C605[25AB0000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 15280 0000448E A1[21AB0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 15281 00004493 E961FFFFFF          <1>         jmp     fd_init_get_next_cluster_readnext
 15282                              <1> 
 15283                              <1> get_FAT_volume_name:
 15284                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15285                              <1> 	; 12/09/2009
 15286                              <1> 	; INPUT ->
 15287                              <1> 	;	BH = Logical DOS drive number (0,1,2,3,4 ...)
 15288                              <1> 	;       BL = 0
 15289                              <1> 	; OUTPUT ->
 15290                              <1> 	;	CF = 0 -> ESI = Volume name address
 15291                              <1> 	; 	CF = 1 -> Root volume name not found
 15292                              <1> 
 15293                              <1> 	;mov 	ah, 0FFh
 15294                              <1> 	;mov 	al, [Last_Dos_DiskNo]
 15295                              <1> 	;cmp 	al, bh
 15296                              <1> 	;jb     short loc_gfvn_dir_load_err
 15297                              <1> 
 15298 00004498 89DE                <1> 	mov	esi, ebx
 15299 0000449A 81E600FF0000        <1> 	and	esi, 0FF00h ; esi = bh
 15300 000044A0 81C600010900        <1> 	add	esi, Logical_DOSDisks
 15301 000044A6 8A06                <1> 	mov     al, [esi+LD_Name]
 15302 000044A8 8A6603              <1> 	mov     ah, [esi+LD_FATType]
 15303 000044AB 80FC01              <1> 	cmp     ah, 1
 15304 000044AE 7210                <1> 	jb    	short loc_gfvn_dir_load_err
 15305 000044B0 3C41                <1> 	cmp 	al, 'A'
 15306 000044B2 720C                <1> 	jb      short loc_gfvn_dir_load_err
 15307 000044B4 80FC02              <1> 	cmp 	ah, 2 
 15308 000044B7 7708                <1> 	ja      short get_FAT32_root_cluster
 15309                              <1> 	
 15310 000044B9 E8CA2D0000          <1> 	call    load_FAT_root_directory
 15311 000044BE 730B                <1> 	jnc     short loc_get_volume_name
 15312                              <1> 
 15313                              <1> loc_gfvn_dir_load_err:
 15314 000044C0 C3                  <1> 	retn
 15315                              <1> 
 15316                              <1> get_FAT32_root_cluster:
 15317 000044C1 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
 15318 000044C4 E84A2E0000          <1> 	call    load_FAT_sub_directory
 15319 000044C9 7224                <1> 	jc	short loc_get_volume_name_retn
 15320                              <1> 
 15321                              <1> loc_get_volume_name:
 15322 000044CB BE00000800          <1>         mov     esi, Directory_Buffer
 15323 000044D0 6631C9              <1> 	xor	cx, cx ; 0
 15324                              <1> check_root_volume_name:
 15325 000044D3 8A06                <1> 	mov	al, [esi]
 15326 000044D5 08C0                <1> 	or      al, al
 15327 000044D7 7416                <1> 	jz      short loc_get_volume_name_retn
 15328 000044D9 807E0B08            <1> 	cmp     byte [esi+0Bh], 08h
 15329 000044DD 7410                <1> 	je      short loc_get_volume_name_retn
 15330 000044DF 663B0D[3BAB0000]    <1> 	cmp     cx, [DirBuff_LastEntry]
 15331 000044E6 7308                <1> 	jnb     short pass_check_root_volume_name
 15332 000044E8 6641                <1> 	inc     cx
 15333 000044EA 83C620              <1> 	add     esi, 32
 15334 000044ED EBE4                <1> 	jmp     short check_root_volume_name
 15335                              <1> 
 15336                              <1> loc_get_volume_name_retn:
 15337 000044EF C3                  <1> 	retn
 15338                              <1>     
 15339                              <1> pass_check_root_volume_name:
 15340 000044F0 803D[37AB0000]03    <1> 	cmp	byte [DirBuff_FATType], 3
 15341 000044F7 7230                <1> 	jb	short loc_get_volume_name_retn_xor
 15342                              <1> 
 15343 000044F9 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 15344 000044FE BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15345 00004503 31C0                <1> 	xor	eax, eax
 15346 00004505 8A25[36AB0000]      <1> 	mov	ah, [DirBuff_DRV]
 15347 0000450B 80EC41              <1> 	sub	ah, 'A' 
 15348 0000450E 01C6                <1> 	add	esi, eax
 15349 00004510 A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 15350 00004515 E8182C0000          <1> 	call	get_next_cluster
 15351 0000451A 7305                <1> 	jnc 	short loc_gfvn_load_FAT32_dir_cluster
 15352                              <1>   	
 15353 0000451C 83F801              <1> 	cmp     eax, 1
 15354 0000451F F5                  <1> 	cmc
 15355 00004520 C3                  <1> 	retn
 15356                              <1>   
 15357                              <1> loc_gfvn_load_FAT32_dir_cluster:
 15358 00004521 E8ED2D0000          <1> 	call	load_FAT_sub_directory
 15359 00004526 73A3                <1> 	jnc	short loc_get_volume_name
 15360 00004528 C3                  <1> 	retn
 15361                              <1> 
 15362                              <1> loc_get_volume_name_retn_xor:
 15363 00004529 31C0                <1> 	xor 	eax, eax
 15364 0000452B C3                  <1> 	retn
 15365                              <1> 
 15366                              <1> get_media_change_status:
 15367                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
 15368                              <1> 	; 09/09/2009
 15369                              <1> 	; INPUT:
 15370                              <1> 	;     DL = Drive number (physical)
 15371                              <1> 	; OUTPUT: clc & AH = 6 media changed
 15372                              <1> 	;     clc & AH = 0 media not changed         
 15373                              <1> 	;     stc -> Drive not ready or an error 
 15374                              <1>   
 15375 0000452C B416                <1> 	mov	ah, 16h
 15376 0000452E E898E3FFFF          <1>   	call	int13h
 15377 00004533 80FC06              <1> 	cmp	ah, 06h
 15378 00004536 7405                <1> 	je	short loc_gmc_status_retn
 15379 00004538 08E4                <1> 	or	ah, ah
 15380 0000453A 7401                <1> 	jz	short loc_gmc_status_retn
 15381                              <1> loc_gmc_status_stc_retn:    
 15382 0000453C F9                  <1> 	stc
 15383                              <1> loc_gmc_status_retn:
 15384 0000453D C3                  <1> 	retn
 15385                                  %include 'trdosk3.s' ; 06/01/2016
 15386                              <1> ; ****************************************************************************
 15387                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk3.s
 15388                              <1> ; ----------------------------------------------------------------------------
 15389                              <1> ; Last Update: 29/02/2016
 15390                              <1> ; ----------------------------------------------------------------------------
 15391                              <1> ; Beginning: 06/01/2016
 15392                              <1> ; ----------------------------------------------------------------------------
 15393                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 15394                              <1> ; ----------------------------------------------------------------------------
 15395                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 15396                              <1> ; MAINPROG.ASM (09/11/2011)
 15397                              <1> ; ****************************************************************************
 15398                              <1> ; MAINPROG.ASM [ TRDOS KERNEL - COMMAND EXECUTER SECTION - MAIN PROGRAM ]
 15399                              <1> ; (c) 2004-2011  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/11/2011
 15400                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ] Last Update: 09/11/2011
 15401                              <1> ; DIR.ASM [ DIRECTORY FUNCTIONS ] Last Update: 09/10/2011
 15402                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
 15403                              <1> 
 15404                              <1> change_current_drive:
 15405                              <1> 	; 02/02/2016
 15406                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
 15407                              <1> 	; 18/08/2011
 15408                              <1> 	; 09/09/2009
 15409                              <1> 	; INPUT:
 15410                              <1> 	;   DL = Logical DOS Drive Number
 15411                              <1> 	; OUTPUT:
 15412                              <1> 	;  cf=1 -> Not successful
 15413                              <1> 	;   EAX = Error code
 15414                              <1> 	;  cf=0 ->
 15415                              <1> 	;   EAX = 0 (successful)
 15416                              <1> 
 15417 0000453E 31DB                <1> 	xor	ebx, ebx
 15418 00004540 88D7                <1> 	mov	bh, dl
 15419                              <1> 
 15420                              <1> 	;cmp	dl, 1
 15421                              <1> 	;jna	short loc_ccdrv_initial_media_change_check
 15422                              <1> 	;cmp	bh, [Last_Dos_DiskNo]
 15423                              <1> 	;ja	short loc_ccdrv_drive_not_ready_err
 15424                              <1> 
 15425                              <1> loc_ccdrv_initial_media_change_check:
 15426 00004542 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15427 00004547 01DE                <1> 	add	esi, ebx
 15428                              <1> loc_ccdrv_dos_drive_name_check:
 15429 00004549 80FA02              <1> 	cmp	dl, 2
 15430 0000454C 720F                <1> 	jb	short loc_ccdrv_dos_drive_name_check_ok
 15431                              <1> 
 15432 0000454E 8A06                <1> 	mov	al, [esi+LD_Name]
 15433 00004550 2C41                <1> 	sub	al, 'A'
 15434 00004552 38D0                <1> 	cmp	al, dl
 15435 00004554 7407                <1> 	je	short loc_ccdrv_dos_drive_name_check_ok
 15436                              <1> 
 15437                              <1> loc_ccdrv_drive_not_ready_err:
 15438 00004556 B815000000          <1> 	mov	eax, 15h ; Drive not ready
 15439                              <1> loc_change_current_drive_stc_retn:
 15440 0000455B F9                  <1> 	stc
 15441 0000455C C3                  <1> 	retn  
 15442                              <1> 
 15443                              <1> loc_ccdrv_dos_drive_name_check_ok:
 15444 0000455D 8A667E              <1> 	mov	ah, [esi+LD_MediaChanged]
 15445 00004560 80FC06              <1> 	cmp	ah, 6  ; VOLUME NAME CHECK/MOVE SIGN
 15446 00004563 7450                <1> 	je	short loc_ccdrv_get_FAT_volume_name_0
 15447                              <1> 
 15448 00004565 80FA01              <1> 	cmp	dl, 1
 15449 00004568 7778                <1> 	ja	short loc_gmcs_init_drv_hd
 15450                              <1> 
 15451                              <1> loc_gmcs_init_drv_fd:
 15452 0000456A 08E4                <1> 	or	ah, ah 
 15453                              <1> 	; AH = 1 is initialization sign (invalid_fd_parameter)
 15454 0000456C 7517                <1> 	jnz	short loc_ccdrv_call_fd_init
 15455                              <1> 
 15456 0000456E E8B9FFFFFF          <1> 	call	get_media_change_status
 15457 00004573 72E1                <1> 	jc	short loc_ccdrv_drive_not_ready_err
 15458                              <1> 
 15459 00004575 20E4                <1> 	and	ah, ah
 15460 00004577 7471                <1> 	jz	short loc_change_current_drv3
 15461                              <1> 
 15462 00004579 80F406              <1> 	xor	ah, 6
 15463 0000457C 75D8                <1> 	jnz	short loc_ccdrv_drive_not_ready_err
 15464                              <1> 
 15465                              <1> loc_ccdrv_call_fd_init_check_vol_id:
 15466 0000457E E82D0A0000          <1> 	call	get_volume_serial_number
 15467 00004583 7308                <1> 	jnc	short loc_ccdrv_check_vol_serial
 15468                              <1> 
 15469                              <1> loc_ccdrv_call_fd_init:
 15470 00004585 E86DFCFFFF          <1> 	call	floppy_drv_init
 15471 0000458A 7315                <1> 	jnc	short loc_reset_drv_fd_current_dir
 15472                              <1> 
 15473                              <1> loc_ccdrv_fdinit_fail_retn:
 15474 0000458C C3                  <1> 	retn
 15475                              <1> 
 15476                              <1> loc_ccdrv_check_vol_serial:
 15477 0000458D A3[04A30000]        <1> 	mov	[Current_VolSerial], eax
 15478                              <1> 	;mov	dl, bh
 15479 00004592 E860FCFFFF          <1> 	call	floppy_drv_init
 15480 00004597 72F3                <1> 	jc	short loc_ccdrv_fdinit_fail_retn
 15481                              <1> 
 15482 00004599 3B05[04A30000]      <1> 	cmp	eax, [Current_VolSerial]
 15483 0000459F 7445                <1> 	je	short loc_change_current_drv2
 15484                              <1> 
 15485                              <1> loc_reset_drv_fd_current_dir:
 15486 000045A1 31C0                <1> 	xor	eax, eax              
 15487 000045A3 88467F              <1>         mov	[esi+LD_CDirLevel], al
 15488 000045A6 89F7                <1> 	mov	edi, esi
 15489 000045A8 81C780000000        <1> 	add	edi, LD_CurrentDirectory
 15490 000045AE B920000000          <1> 	mov	ecx, 32
 15491 000045B3 F3AB                <1> 	rep	stosd   
 15492                              <1>  
 15493                              <1> loc_ccdrv_get_FAT_volume_name_0:
 15494 000045B5 8A4603              <1> 	mov	al, [esi+LD_FATType]
 15495 000045B8 08C0                <1> 	or	al, al
 15496 000045BA 742A                <1> 	jz	short loc_change_current_drv2
 15497                              <1> 
 15498 000045BC 56                  <1> 	push	esi 
 15499 000045BD 3C02                <1> 	cmp	al, 2
 15500 000045BF 7705                <1> 	ja	short loc_ccdrv_get_FAT32_vol_name
 15501                              <1>              
 15502                              <1> loc_ccdrv_get_FAT2_16_vol_name:
 15503 000045C1 83C631              <1> 	add	esi, LD_BPB + VolumeLabel
 15504 000045C4 EB03                <1> 	jmp	short loc_ccdrv_get_FAT_volume_name_1
 15505                              <1> 
 15506                              <1> loc_ccdrv_get_FAT32_vol_name:
 15507 000045C6 83C64D              <1> 	add	esi, LD_BPB + FAT32_VolLab
 15508                              <1> loc_ccdrv_get_FAT_volume_name_1:
 15509 000045C9 53                  <1> 	push	ebx
 15510 000045CA 56                  <1> 	push	esi
 15511 000045CB E8C8FEFFFF          <1> 	call	get_FAT_volume_name
 15512 000045D0 5F                  <1> 	pop	edi
 15513 000045D1 5B                  <1> 	pop	ebx
 15514                              <1> 	; BL = 0
 15515 000045D2 720B                <1> 	jc	short loc_change_current_drv1
 15516 000045D4 20C0                <1> 	and	al, al
 15517 000045D6 7407                <1> 	jz	short loc_change_current_drv1
 15518                              <1> 
 15519                              <1> loc_ccdrv_move_FAT_volume_name:
 15520 000045D8 B90B000000          <1> 	mov	ecx, 11
 15521 000045DD F3A4                <1> 	rep	movsb
 15522                              <1> 
 15523                              <1> loc_change_current_drv1:
 15524 000045DF 5E                  <1> 	pop	esi
 15525 000045E0 EB04                <1> 	jmp	short loc_change_current_drv2
 15526                              <1> 
 15527                              <1> loc_gmcs_init_drv_hd:
 15528 000045E2 08E4                <1> 	or	ah, ah
 15529 000045E4 7404                <1> 	jz	short loc_change_current_drv3
 15530                              <1> 	; BL = 0, BH = Logical DOS drive number
 15531                              <1> loc_change_current_drv2:
 15532 000045E6 C6467E00            <1> 	mov	byte [esi+LD_MediaChanged], 0
 15533                              <1> loc_change_current_drv3:
 15534 000045EA 883D[0EA30000]      <1> 	mov	[Current_Drv], bh
 15535                              <1> 
 15536                              <1> 	;call	restore_current_directory
 15537                              <1> 	;retn
 15538                              <1> 
 15539                              <1> restore_current_directory:
 15540                              <1> 	; 11/02/2016
 15541                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
 15542                              <1> 	; 25/01/2010
 15543                              <1> 	; 12/10/2009
 15544                              <1> 	;
 15545                              <1> 	; INPUT:
 15546                              <1> 	;   ESI = Logical DOS Drive Description Table
 15547                              <1> 	;
 15548                              <1> 	; OUTPUT:
 15549                              <1> 	;   ESI = Logical DOS Drive Description Table
 15550                              <1> 	;   EDI = offset Current_Dir_Drv 
 15551                              <1> 
 15552 000045F0 8A4603              <1> 	mov	al, [esi+LD_FATType]
 15553 000045F3 A2[0DA30000]        <1> 	mov	[Current_FATType], al
 15554                              <1> 
 15555 000045F8 8A26                <1> 	mov	ah, [esi+LD_Name] 
 15556 000045FA 8825[0FA30000]      <1> 	mov	[Current_Dir_Drv], ah
 15557                              <1> 
 15558 00004600 20C0                <1> 	and	al, al
 15559 00004602 741D                <1> 	jz	short loc_restore_FS_current_directory
 15560                              <1> 
 15561                              <1> loc_restore_FAT_current_directory:
 15562 00004604 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
 15563 00004607 8825[0CA30000]      <1> 	mov	[Current_Dir_Level], ah
 15564 0000460D 08E4                <1> 	or	ah, ah
 15565 0000460F 7416                <1>         jz	short loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster
 15566                              <1> 
 15567 00004611 0FB6D4              <1> 	movzx	edx, ah
 15568 00004614 C0E204              <1> 	shl	dl, 4 ; * 16
 15569 00004617 01F2                <1>         add	edx, esi
 15570 00004619 8B828C000000        <1> 	mov	eax, [edx+LD_CurrentDirectory+12]
 15571 0000461F EB2C                <1> 	jmp	short loc_ccdrv_reset_cdir_FAT_fcluster
 15572                              <1> 
 15573                              <1> loc_restore_FS_current_directory:
 15574 00004621 E8282D0000          <1> 	call	load_current_FS_directory 
 15575 00004626 C3                  <1> 	retn 
 15576                              <1> 
 15577                              <1> loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster:
 15578 00004627 3C03                <1> 	cmp	al, 3
 15579 00004629 7205                <1> 	jb	short loc_ccdrv_reset_cdir_FAT_12_16_fcluster
 15580                              <1> loc_ccdrv_reset_cdir_FAT32_fcluster:
 15581 0000462B 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
 15582 0000462E EB04                <1> 	jmp	short loc_ccdrv_check_rootdir_sign
 15583                              <1> loc_ccdrv_reset_cdir_FAT_12_16_fcluster:   
 15584 00004630 30C0                <1> 	xor	al, al  ; xor eax, eax
 15585 00004632 31D2                <1> 	xor	edx, edx
 15586                              <1> loc_ccdrv_check_rootdir_sign:
 15587 00004634 80BE8000000000      <1> 	cmp	byte [esi+LD_CurrentDirectory], 0
 15588 0000463B 7510                <1> 	jne	short loc_ccdrv_reset_cdir_FAT_fcluster
 15589                              <1> loc_ccdrv_set_rootdir_FAT_fcluster:
 15590 0000463D 89868C000000        <1>         mov     [esi+LD_CurrentDirectory+12], eax
 15591 00004643 C78680000000524F4F- <1> 	mov	dword [esi+LD_CurrentDirectory], 'ROOT'
 15592 0000464C 54                  <1>
 15593                              <1> 
 15594                              <1> loc_ccdrv_reset_cdir_FAT_fcluster:
 15595 0000464D A3[08A30000]        <1> 	mov	[Current_Dir_FCluster], eax
 15596                              <1> 
 15597 00004652 BF[6FAB0000]        <1> 	mov	edi, PATH_Array
 15598 00004657 89F2                <1> 	mov	edx, esi
 15599 00004659 81C680000000        <1> 	add	esi, LD_CurrentDirectory
 15600 0000465F B920000000          <1> 	mov	ecx, 32
 15601 00004664 F3A5                <1> 	rep	movsd
 15602                              <1> 
 15603 00004666 E8EF1B0000          <1> 	call	change_prompt_dir_string
 15604                              <1>                
 15605 0000466B 89D6                <1> 	mov	esi, edx
 15606                              <1>                
 15607 0000466D 29C0                <1>         sub	eax, eax
 15608                              <1>        ;sub	edx, edx
 15609 0000466F BF[0FA30000]        <1> 	mov	edi, Current_Dir_Drv
 15610                              <1> 
 15611 00004674 A2[41940000]        <1> 	mov	[Restore_CDIR], al ; 0
 15612 00004679 C3                  <1> 	retn
 15613                              <1> 
 15614                              <1> dos_prompt:
 15615                              <1> 	; 30/01/2016
 15616                              <1> 	; 29/01/2016
 15617                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
 15618                              <1> 	; 15/09/2011
 15619                              <1> 	; 13/09/2009
 15620                              <1> 	; 2004-2005
 15621                              <1> 
 15622                              <1> loc_TRDOS_prompt:
 15623 0000467A BF[0EA40000]        <1> 	mov	edi, TextBuffer
 15624 0000467F C6075B              <1> 	mov	byte [edi], "["
 15625 00004682 47                  <1> 	inc	edi
 15626 00004683 BE[94940000]        <1> 	mov	esi, TRDOSPromptLabel
 15627                              <1> get_next_prompt_label_char:
 15628 00004688 803E20              <1> 	cmp	byte [esi], 20h
 15629 0000468B 7203                <1> 	jb	short pass_prompt_label
 15630 0000468D A4                  <1> 	movsb
 15631 0000468E EBF8                <1> 	jmp	short get_next_prompt_label_char
 15632                              <1> pass_prompt_label:
 15633 00004690 C6075D              <1> 	mov	byte [edi], "]"
 15634 00004693 47                  <1> 	inc	edi
 15635 00004694 C60720              <1> 	mov	byte [edi], 20h
 15636 00004697 47                  <1> 	inc	edi
 15637 00004698 BE[0FA30000]        <1> 	mov	esi, Current_Dir_Drv
 15638 0000469D 66A5                <1> 	movsw
 15639 0000469F A4                  <1> 	movsb 
 15640                              <1> loc_prompt_current_directory:
 15641 000046A0 803E20              <1> 	cmp	byte [esi], 20h
 15642 000046A3 7203                <1> 	jb	short pass_prompt_current_directory
 15643 000046A5 A4                  <1> 	movsb
 15644 000046A6 EBF8                <1> 	jmp	short loc_prompt_current_directory  
 15645                              <1> pass_prompt_current_directory:
 15646 000046A8 C6073E              <1> 	mov	byte [edi], '>'
 15647 000046AB 47                  <1> 	inc	edi
 15648 000046AC C60700              <1> 	mov	byte [edi], 0  
 15649 000046AF BE[0EA40000]        <1> 	mov	esi, TextBuffer
 15650 000046B4 E881F5FFFF          <1> 	call	print_msg
 15651                              <1>         
 15652                              <1> 	;sub	bl, bl ; video page = 0
 15653                              <1> 	;call	get_cpos ; get cursor position
 15654 000046B9 668B15[68A20000]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
 15655 000046C0 8815[6EA30000]      <1> 	mov	[CursorColumn], dl
 15656                              <1> 
 15657                              <1> 	; 30/01/2016 (to show cursor on the row, again)
 15658                              <1> 	; (Initial color attributes of video page 0 is 0)
 15659                              <1> 	; (see: 'StartPMP' in trdos386.s)
 15660                              <1> 	; 
 15661                              <1> 	;mov	edi, 0B8000h ; start of video page 0
 15662                              <1> 	;movzx	ecx, dl ; column	 
 15663                              <1> 	;mov	al, 80
 15664                              <1> 	;mul	dh
 15665                              <1> 	;add	ax, cx
 15666                              <1> 	;shl	ax, 1 ; character + attribute
 15667                              <1> 	;add	di, ax ; (2*80*row) + (2*column)
 15668                              <1> 	;neg	cl
 15669                              <1> 	;add	cl, 80
 15670                              <1> 	;mov	ax, 700h ;  ah = 7 (color attribute)
 15671                              <1> 	;rep	stosw	
 15672                              <1> 
 15673                              <1> loc_rw_char:
 15674 000046C6 E899000000          <1> 	call	rw_char
 15675                              <1> loc_move_command:
 15676 000046CB BE[BEA30000]        <1> 	mov	esi, CommandBuffer
 15677 000046D0 89F7                <1> 	mov	edi, esi
 15678 000046D2 31C9                <1> 	xor	ecx, ecx
 15679                              <1> first_command_char:
 15680 000046D4 AC                  <1> 	lodsb
 15681 000046D5 3C20                <1> 	cmp	al, 20h
 15682 000046D7 772E                <1> 	ja	short pass_space_control
 15683 000046D9 7241                <1> 	jb	short loc_move_cmd_arguments_ok
 15684 000046DB 81FE[0DA40000]      <1> 	cmp	esi, CommandBuffer + 79
 15685 000046E1 72F1                <1> 	jb	short first_command_char
 15686 000046E3 EB37                <1> 	jmp	short loc_move_cmd_arguments_ok
 15687                              <1> 
 15688                              <1> next_command_char:
 15689 000046E5 AC                  <1> 	lodsb
 15690 000046E6 3C20                <1> 	cmp	al, 20h
 15691 000046E8 771D                <1> 	ja	short pass_space_control
 15692 000046EA 7230                <1> 	jb	short loc_move_cmd_arguments_ok
 15693                              <1> 
 15694                              <1> loc_1st_cmd_arg: ; 30/01/2016
 15695 000046EC AC                  <1> 	lodsb
 15696 000046ED 3C20                <1> 	cmp	al, 20h
 15697 000046EF 74FB                <1> 	je	short loc_1st_cmd_arg
 15698 000046F1 7229                <1> 	jb	short loc_move_cmd_arguments_ok
 15699                              <1> 	
 15700 000046F3 C60700              <1>         mov     byte [edi], 0
 15701 000046F6 47                  <1> 	inc	edi
 15702                              <1> 
 15703                              <1> loc_move_cmd_arguments:
 15704 000046F7 AA                  <1> 	stosb
 15705 000046F8 81FE[0DA40000]      <1> 	cmp	esi, CommandBuffer + 79
 15706 000046FE 731C                <1> 	jnb	short loc_move_cmd_arguments_ok
 15707 00004700 AC                  <1>         lodsb
 15708 00004701 3C20                <1> 	cmp	al, 20h
 15709 00004703 73F2                <1> 	jnb	short loc_move_cmd_arguments
 15710 00004705 EB15                <1> 	jmp	short loc_move_cmd_arguments_ok
 15711                              <1> 
 15712                              <1> pass_space_control:
 15713 00004707 3C61                <1> 	cmp	al, 61h
 15714 00004709 7206                <1> 	jb	short pass_capitalize
 15715 0000470B 3C7A                <1> 	cmp	al, 7Ah
 15716 0000470D 7702                <1> 	ja	short pass_capitalize
 15717 0000470F 24DF                <1> 	and	al, 0DFh
 15718                              <1> pass_capitalize:
 15719 00004711 AA                  <1> 	stosb   
 15720 00004712 FEC1                <1> 	inc     cl
 15721 00004714 81FE[0DA40000]      <1>         cmp     esi, CommandBuffer + 79
 15722 0000471A 72C9                <1> 	jb      short next_command_char 
 15723                              <1> 
 15724                              <1> loc_move_cmd_arguments_ok:
 15725 0000471C C60700              <1>         mov     byte [edi], 0
 15726                              <1>        
 15727                              <1> call_command_intepreter:
 15728 0000471F E8C7080000          <1> 	call    command_interpreter
 15729                              <1> 
 15730 00004724 B950000000          <1>         mov	ecx, 80
 15731                              <1> 	;mov	cx, 80
 15732 00004729 BF[BEA30000]        <1> 	mov	edi, CommandBuffer
 15733 0000472E 30C0                <1> 	xor	al, al
 15734 00004730 F3AA                <1> 	rep	stosb
 15735                              <1> 	;cmp	byte [Program_Exit], 0
 15736                              <1> 	;ja	short loc_terminate_trdos
 15737                              <1>         
 15738                              <1> 	; 16/01/2016
 15739 00004732 803D[769C0000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80*25 color
 15740 00004739 741D                <1> 	je	short pass_set_txt_mode
 15741                              <1> 
 15742 0000473B E8B9CDFFFF          <1> 	call	set_txt_mode ; set vide mode to 03h
 15743                              <1> 
 15744                              <1> loc_check_active_page:
 15745 00004740 30C0                <1> 	xor	al, al
 15746 00004742 3805[78A20000]      <1> 	cmp	[ACTIVE_PAGE], al ; 0
 15747 00004748 0F842CFFFFFF        <1>         je      loc_TRDOS_prompt 
 15748                              <1> 	; AL = 0 = video page 0
 15749 0000474E E840CEFFFF          <1> 	call	set_active_page
 15750 00004753 E922FFFFFF          <1>         jmp     loc_TRDOS_prompt ; infinitive loop
 15751                              <1> 
 15752                              <1> pass_set_txt_mode: 
 15753 00004758 BE[269F0000]        <1> 	mov	esi, nextline
 15754 0000475D E8D8F4FFFF          <1> 	call	print_msg
 15755 00004762 EBDC                <1> 	jmp     short loc_check_active_page
 15756                              <1> 
 15757                              <1> rw_char:
 15758                              <1> 	; 30/01/2016
 15759                              <1> 	; 29/01/2016
 15760                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
 15761                              <1> 	; 2004-2005
 15762                              <1> 	
 15763                              <1> 	; DH = cursor row, DL = cursor column
 15764                              <1> 	; BL = 0 = video page number (active page)
 15765                              <1> 
 15766                              <1> readnextchar:
 15767 00004764 30E4                <1> 	xor     ah, ah
 15768 00004766 E87CC4FFFF          <1> 	call	int16h
 15769 0000476B 20C0                <1> 	and	al, al
 15770 0000476D 7439                <1> 	jz	short loc_arrow    
 15771 0000476F 3CE0                <1> 	cmp	al, 0E0h          
 15772 00004771 7435                <1> 	je	short loc_arrow
 15773 00004773 3C08                <1> 	cmp	al, 08h             
 15774 00004775 7549                <1> 	jne	short char_return
 15775                              <1> loc_back:
 15776 00004777 3A15[6EA30000]      <1> 	cmp	dl, [CursorColumn]
 15777 0000477D 76E5                <1> 	jna     short readnextchar
 15778                              <1> prev_column:
 15779 0000477F FECA                <1> 	dec	dl
 15780                              <1> set_cursor_pos:
 15781 00004781 6652                <1> 	push	dx
 15782 00004783 30DB                <1> 	xor	bl, bl ; 0 = video page 0
 15783                              <1> 	; DH = Row, DL = Column
 15784 00004785 E8C0D0FFFF          <1> 	call	_set_cpos ; 17/01/2016
 15785 0000478A 665A                <1>         pop	dx
 15786 0000478C 0FB6DA              <1> 	movzx	ebx, dl
 15787 0000478F 2A1D[6EA30000]      <1> 	sub	bl, [CursorColumn] 
 15788 00004795 B407                <1> 	mov	ah, 7 ; color attribute
 15789 00004797 B020                <1> 	mov	al, 20h
 15790 00004799 8883[BEA30000]      <1> 	mov	[CommandBuffer+ebx], al
 15791 0000479F 28DB                <1> 	sub	bl, bl ; video page 0
 15792                              <1> 	;mov	cx, 1
 15793 000047A1 E8DFCFFFFF          <1> 	call	_write_c_current ; 17/01/2016
 15794                              <1> 	;mov	dx, [CURSOR_POSN]
 15795 000047A6 EBBC                <1> 	jmp	short readnextchar
 15796                              <1> loc_arrow:    
 15797 000047A8 80FC4B              <1> 	cmp	ah, 4Bh
 15798 000047AB 74CA                <1> 	je	short loc_back
 15799 000047AD 80FC53              <1> 	cmp	ah, 53h
 15800 000047B0 74C5                <1> 	je      short loc_back
 15801 000047B2 80FC4D              <1> 	cmp	ah, 4Dh
 15802 000047B5 75AD                <1> 	jne	short readnextchar
 15803 000047B7 80FA4F              <1> 	cmp	dl, 79
 15804 000047BA 73A8                <1> 	jnb	short readnextchar
 15805 000047BC FEC2                <1> 	inc	dl
 15806 000047BE EBC1                <1> 	jmp	short set_cursor_pos
 15807                              <1> char_return:
 15808 000047C0 0FB6DA              <1> 	movzx	ebx, dl
 15809 000047C3 2A1D[6EA30000]      <1> 	sub	bl, [CursorColumn] 
 15810 000047C9 3C20                <1> 	cmp	al, 20h
 15811 000047CB 7220                <1> 	jb	short loc_escape
 15812 000047CD 8883[BEA30000]      <1> 	mov	[CommandBuffer+ebx], al
 15813 000047D3 28DB                <1> 	sub	bl, bl ; 0
 15814 000047D5 80FA4F              <1> 	cmp	dl, 79
 15815 000047D8 738A                <1> 	jnb	short readnextchar
 15816 000047DA B407                <1> 	mov	ah, 7 ; color attribute
 15817 000047DC E8D5CFFFFF          <1> 	call	WRITE_TTY
 15818 000047E1 668B15[68A20000]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
 15819 000047E8 E977FFFFFF          <1>         jmp     readnextchar
 15820                              <1> loc_escape:
 15821 000047ED 3C1B                <1> 	cmp	al, 1Bh
 15822 000047EF 741A                <1> 	je	short rw_char_retn
 15823                              <1> 	;
 15824 000047F1 3C0D                <1> 	cmp	al, 0Dh ; CR
 15825 000047F3 0F856BFFFFFF        <1>         jne     readnextchar
 15826 000047F9 30DB                <1> 	xor	bl, bl ; 0
 15827 000047FB B407                <1> 	mov	ah, 7 ; attribute/color
 15828 000047FD E8B4CFFFFF          <1> 	call	WRITE_TTY
 15829 00004802 B407                <1> 	mov	ah, 7 ; attribute/color
 15830 00004804 B00A                <1> 	mov	al, 0Ah ; LF
 15831 00004806 E8ABCFFFFF          <1> 	call	WRITE_TTY
 15832                              <1> rw_char_retn:
 15833 0000480B C3                  <1> 	retn
 15834                              <1> 
 15835                              <1> show_date:
 15836                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 15837                              <1>         ; 2004-2005
 15838                              <1> 
 15839                              <1> 	;mov	ah, 04h
 15840                              <1> 	;call	int1Ah
 15841 0000480C E8C0F1FFFF          <1> 	call	RTC_40	; GET RTC DATE
 15842                              <1> 
 15843 00004811 88D0                <1> 	mov	al, dl
 15844 00004813 E8C6C3FFFF          <1>   	call	bcd_to_ascii
 15845 00004818 66A3[89950000]      <1> 	mov	[Day], ax
 15846                              <1> 
 15847 0000481E 88F0                <1> 	mov	al, dh
 15848 00004820 E8B9C3FFFF          <1>   	call	bcd_to_ascii
 15849 00004825 66A3[8C950000]      <1> 	mov	[Month], ax
 15850                              <1> 
 15851 0000482B 88E8                <1> 	mov	al, ch
 15852 0000482D E8ACC3FFFF          <1>   	call	bcd_to_ascii
 15853 00004832 66A3[8F950000]      <1> 	mov	[Century], ax
 15854                              <1> 
 15855 00004838 88C8                <1> 	mov	al, cl
 15856 0000483A E89FC3FFFF          <1>   	call	bcd_to_ascii
 15857 0000483F 66A3[91950000]      <1> 	mov	word [Year], ax
 15858                              <1> 
 15859 00004845 BE[79950000]        <1> 	mov	esi, Msg_Show_Date
 15860 0000484A E8EBF3FFFF          <1> 	call	print_msg
 15861                              <1> 
 15862 0000484F C3                  <1> 	retn
 15863                              <1> 
 15864                              <1> set_date:
 15865                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 15866                              <1>         ; 2004-2005
 15867                              <1> 
 15868 00004850 BE[5D950000]        <1> 	mov	esi, Msg_Enter_Date
 15869 00004855 E8E0F3FFFF          <1> 	call	print_msg
 15870                              <1> 
 15871                              <1> loc_enter_day_1:
 15872 0000485A 30E4                <1> 	xor     ah, ah
 15873 0000485C E886C3FFFF          <1> 	call	int16h
 15874                              <1> 	; AL = ASCII Code of the Character
 15875 00004861 3C0D                <1> 	cmp	al, 13
 15876 00004863 0F84B7010000        <1> 	je	loc_set_date_retn
 15877 00004869 3C1B                <1> 	cmp	al, 27
 15878 0000486B 0F84AF010000        <1> 	je	loc_set_date_retn
 15879 00004871 A2[89950000]        <1> 	mov	[Day], al
 15880 00004876 3C30                <1> 	cmp	al, '0'
 15881 00004878 0F82AD010000        <1> 	jb	loc_set_date_stc_0
 15882 0000487E 3C33                <1> 	cmp	al, '3'
 15883 00004880 0F87A5010000        <1> 	ja	loc_set_date_stc_0
 15884                              <1> 	;sub	bl, bl ; 0
 15885 00004886 B407                <1> 	mov	ah, 7 ; attribute/color
 15886 00004888 E829CFFFFF          <1> 	call	WRITE_TTY
 15887                              <1> loc_enter_day_2:
 15888 0000488D 30E4                <1> 	xor     ah, ah
 15889 0000488F E853C3FFFF          <1> 	call	int16h
 15890                              <1> 	; AL = ASCII Code of the Character
 15891 00004894 3C1B                <1> 	cmp	al, 27
 15892 00004896 0F8484010000        <1>         je      loc_set_date_retn
 15893 0000489C A2[8A950000]        <1> 	mov	[Day+1], al
 15894 000048A1 3C30                <1> 	cmp	al, '0'
 15895 000048A3 0F828C010000        <1>         jb      loc_set_date_stc_1
 15896 000048A9 3C39                <1> 	cmp	al, '9'
 15897 000048AB 0F8784010000        <1>         ja      loc_set_date_stc_1
 15898 000048B1 803D[89950000]33    <1> 	cmp	byte [Day], '3'
 15899 000048B8 7208                <1> 	jb	short pass_set_day_31
 15900 000048BA 3C31                <1> 	cmp	al, '1'
 15901 000048BC 0F8773010000        <1>         ja      loc_set_date_stc_1
 15902                              <1> pass_set_day_31:
 15903                              <1> 	;sub	bl, bl ; 0
 15904 000048C2 B407                <1> 	mov	ah, 7 ; attribute/color
 15905 000048C4 E8EDCEFFFF          <1> 	call	WRITE_TTY
 15906                              <1> loc_enter_separator_1:
 15907 000048C9 28E4                <1> 	sub     ah, ah ; 0
 15908 000048CB E817C3FFFF          <1> 	call	int16h
 15909                              <1> 	; AL = ASCII Code of the Character
 15910 000048D0 3C1B                <1> 	cmp	al, 27
 15911 000048D2 0F8448010000        <1>         je      loc_set_date_retn
 15912 000048D8 3C2D                <1> 	cmp	al, '-'
 15913 000048DA 7408                <1> 	je	short pass_set_date_separator_1
 15914 000048DC 3C2F                <1> 	cmp	al, '/'
 15915 000048DE 0F856C010000        <1>         jne     loc_set_date_stc_2
 15916                              <1> pass_set_date_separator_1:
 15917                              <1> 	;xor	bl, bl ; 0
 15918 000048E4 B407                <1> 	mov	ah, 7 ; attribute/color
 15919 000048E6 E8CBCEFFFF          <1> 	call	WRITE_TTY
 15920                              <1> loc_enter_month_1:
 15921 000048EB 30E4                <1> 	xor     ah, ah ; 0
 15922 000048ED E8F5C2FFFF          <1> 	call	int16h
 15923                              <1> 	; AL = ASCII Code of the Character
 15924 000048F2 3C1B                <1> 	cmp	al, 27
 15925 000048F4 0F8426010000        <1>         je      loc_set_date_retn
 15926 000048FA A2[8C950000]        <1> 	mov	[Month], al
 15927 000048FF 3C30                <1> 	cmp	al, '0'
 15928 00004901 0F8264010000        <1>         jb      loc_set_date_stc_3
 15929 00004907 3C31                <1> 	cmp	al, '1'
 15930 00004909 0F875C010000        <1>         ja      loc_set_date_stc_3
 15931                              <1> 	;sub	bl, bl
 15932 0000490F B407                <1> 	mov	ah, 7 ; attribute/color
 15933 00004911 E8A0CEFFFF          <1> 	call	WRITE_TTY
 15934                              <1> loc_enter_month_2:
 15935 00004916 30E4                <1> 	xor     ah, ah
 15936 00004918 E8CAC2FFFF          <1> 	call	int16h
 15937                              <1> 	; AL = ASCII Code of the Character
 15938 0000491D 3C1B                <1> 	cmp	al, 27
 15939 0000491F 0F84FB000000        <1>         je      loc_set_date_retn
 15940 00004925 A2[8D950000]        <1> 	mov	[Month+1], al
 15941 0000492A 3C30                <1> 	cmp	al, '0'
 15942 0000492C 0F8254010000        <1>         jb      loc_set_date_stc_4
 15943 00004932 3C39                <1> 	cmp	al, '9'
 15944 00004934 0F874C010000        <1>         ja      loc_set_date_stc_4
 15945 0000493A 803D[8C950000]31    <1> 	cmp	byte [Month], '1'
 15946 00004941 7208                <1> 	jb	short pass_set_month_12
 15947 00004943 3C32                <1> 	cmp	al, '2'
 15948 00004945 0F873B010000        <1>         ja      loc_set_date_stc_4
 15949                              <1> pass_set_month_12:
 15950                              <1> 	;sub	bl, bl
 15951 0000494B B407                <1> 	mov	ah, 7 ; attribute/color
 15952 0000494D E864CEFFFF          <1> 	call	WRITE_TTY
 15953                              <1> loc_enter_separator_2:
 15954 00004952 28E4                <1> 	sub     ah, ah
 15955 00004954 E88EC2FFFF          <1> 	call	int16h
 15956                              <1> 	; AL = ASCII Code of the Character
 15957 00004959 3C1B                <1> 	cmp	al, 27
 15958 0000495B 0F84BF000000        <1>         je      loc_set_date_retn
 15959 00004961 3C2D                <1> 	cmp	al, '-'
 15960 00004963 7408                <1> 	je	short pass_set_date_separator_2
 15961 00004965 3C2F                <1> 	cmp	al, '/'
 15962 00004967 0F8534010000        <1>         jne     loc_set_date_stc_5
 15963                              <1> pass_set_date_separator_2:
 15964                              <1> 	;xor	bl, bl
 15965 0000496D B407                <1> 	mov	ah, 7 ; attribute/color
 15966 0000496F E842CEFFFF          <1> 	call	WRITE_TTY
 15967                              <1> loc_enter_year_1:
 15968 00004974 30E4                <1> 	xor    ah, ah
 15969 00004976 E86CC2FFFF          <1> 	call	int16h
 15970                              <1> 	; AL = ASCII Code of the Character
 15971 0000497B 3C1B                <1> 	cmp	al, 27
 15972 0000497D 0F849D000000        <1>         je      loc_set_date_retn
 15973 00004983 A2[91950000]        <1> 	mov	[Year], al
 15974 00004988 3C30                <1> 	cmp	al, '0'
 15975 0000498A 0F822C010000        <1>         jb      loc_set_date_stc_6
 15976 00004990 3C39                <1> 	cmp	al, '9'
 15977 00004992 0F8724010000        <1>         ja      loc_set_date_stc_6
 15978                              <1> 	;sub	bl, bl
 15979 00004998 B407                <1> 	mov	ah, 7 ; attribute/color
 15980 0000499A E817CEFFFF          <1> 	call	WRITE_TTY
 15981                              <1> loc_enter_year_2:
 15982 0000499F 30E4                <1> 	xor	ah, ah
 15983 000049A1 E841C2FFFF          <1> 	call	int16h
 15984                              <1> 	; AL = ASCII Code of the Character
 15985 000049A6 3C1B                <1> 	cmp	al, 27
 15986 000049A8 7476                <1> 	je	short loc_set_date_retn
 15987 000049AA A2[92950000]        <1> 	mov	byte [Year+1], al
 15988 000049AF 3C30                <1> 	cmp	al, '0'
 15989 000049B1 0F8220010000        <1>         jb      loc_set_date_stc_7
 15990 000049B7 3C39                <1> 	cmp	al, '9'
 15991 000049B9 0F8718010000        <1>         ja      loc_set_date_stc_7
 15992                              <1> 	;sub	bl, bl
 15993 000049BF B407                <1> 	mov	ah, 7 ; attribute/color
 15994 000049C1 E8F0CDFFFF          <1> 	call	WRITE_TTY
 15995                              <1> loc_set_date_get_lchar_again:
 15996 000049C6 28E4                <1> 	sub	ah, ah ; 0
 15997 000049C8 E81AC2FFFF          <1> 	call	int16h
 15998                              <1> 	; AL = ASCII Code of the Character
 15999 000049CD 3C0D                <1> 	cmp	al, 13 ; ENTER key
 16000 000049CF 7412                <1> 	je	short loc_set_date_progress
 16001 000049D1 3C1B                <1> 	cmp	al, 27 ; ESC key
 16002 000049D3 744B                <1> 	je	short loc_set_date_retn
 16003                              <1> 	;
 16004 000049D5 E82A010000          <1> 	call	check_for_backspace
 16005 000049DA 75EA                <1> 	jne	short loc_set_date_get_lchar_again
 16006                              <1> 
 16007                              <1> loc_set_date_bs_8:
 16008 000049DC E811010000          <1> 	call	write_backspace
 16009 000049E1 EBBC                <1> 	jmp	short loc_enter_year_2
 16010                              <1> 
 16011                              <1> loc_set_date_progress:
 16012                              <1> 	; Get Current Date
 16013                              <1> 	;mov	ah, 04h
 16014                              <1> 	;call	int1Ah
 16015 000049E3 E8E9EFFFFF          <1> 	call	RTC_40	; GET RTC DATE
 16016                              <1> 	; CH = century (in BCD)
 16017                              <1> 
 16018 000049E8 66A1[91950000]      <1> 	mov	ax, [Year]
 16019 000049EE 662D3030            <1> 	sub	ax, '00'
 16020 000049F2 C0E004              <1> 	shl	al, 4 ; * 16
 16021 000049F5 88C1                <1> 	mov	cl, al
 16022 000049F7 00E1                <1> 	add	cl, ah
 16023 000049F9 66A1[8C950000]      <1> 	mov	ax, [Month]
 16024 000049FF 662D3030            <1> 	sub	ax, '00'
 16025 00004A03 C0E004              <1> 	shl	al, 4 ; * 16
 16026 00004A06 88C6                <1> 	mov	dh, al
 16027 00004A08 00E6                <1> 	add	dh, ah
 16028 00004A0A 66A1[89950000]      <1> 	mov	ax, [Day]
 16029 00004A10 662D3030            <1> 	sub	ax, '00'
 16030 00004A14 C0E004              <1> 	shl	al, 4 ; * 16
 16031 00004A17 88C2                <1> 	mov	dl, al
 16032 00004A19 00E2                <1> 	add	dl, ah
 16033                              <1> 
 16034                              <1> 	;mov	ah, 05h
 16035                              <1> 	;call	int1Ah
 16036 00004A1B E8DEEFFFFF          <1> 	call	RTC_50	; SET RTC DATE
 16037                              <1> 
 16038                              <1> loc_set_date_retn:
 16039 00004A20 BE[269F0000]        <1> 	mov	esi, nextline
 16040 00004A25 E810F2FFFF          <1> 	call	print_msg
 16041 00004A2A C3                  <1> 	retn
 16042                              <1> 
 16043                              <1> loc_set_date_stc_0:
 16044                              <1> 	;xor	bl, bl ; video page 0
 16045 00004A2B E864CEFFFF          <1> 	call	beeper ; BEEP !
 16046 00004A30 E925FEFFFF          <1>         jmp     loc_enter_day_1
 16047                              <1> loc_set_date_stc_1:
 16048 00004A35 E8CA000000          <1> 	call	check_for_backspace
 16049 00004A3A 740A                <1> 	je	short loc_set_date_bs_1
 16050                              <1> 	;xor	bl, bl ; video page 0
 16051 00004A3C E853CEFFFF          <1> 	call	beeper ; BEEP !
 16052 00004A41 E947FEFFFF          <1>         jmp     loc_enter_day_2
 16053                              <1> loc_set_date_bs_1:
 16054 00004A46 E8A7000000          <1> 	call	write_backspace
 16055 00004A4B E90AFEFFFF          <1>         jmp     loc_enter_day_1
 16056                              <1> loc_set_date_stc_2:
 16057 00004A50 E8AF000000          <1> 	call	check_for_backspace
 16058 00004A55 740A                <1> 	je	short loc_set_date_bs_2
 16059                              <1> 	;xor	bl, bl ; video page 0
 16060 00004A57 E838CEFFFF          <1> 	call	beeper ; BEEP !
 16061 00004A5C E968FEFFFF          <1>         jmp     loc_enter_separator_1
 16062                              <1> loc_set_date_bs_2:
 16063 00004A61 E88C000000          <1> 	call	write_backspace
 16064 00004A66 E922FEFFFF          <1>         jmp     loc_enter_day_2
 16065                              <1> loc_set_date_stc_3:
 16066 00004A6B E894000000          <1> 	call	check_for_backspace	
 16067 00004A70 740A                <1> 	je short loc_set_date_bs_3
 16068                              <1> 	;xor	bl, bl ; video page 0
 16069 00004A72 E81DCEFFFF          <1> 	call	beeper ; BEEP !
 16070 00004A77 E96FFEFFFF          <1>         jmp     loc_enter_month_1
 16071                              <1> loc_set_date_bs_3:
 16072 00004A7C E871000000          <1> 	call	write_backspace
 16073 00004A81 E943FEFFFF          <1>         jmp     loc_enter_separator_1
 16074                              <1> loc_set_date_stc_4:
 16075 00004A86 E879000000          <1> 	call	check_for_backspace	
 16076 00004A8B 740A                <1> 	je	short loc_set_date_bs_4
 16077                              <1> 	;xor	bl, bl ; video page 0
 16078 00004A8D E802CEFFFF          <1> 	call	beeper ; BEEP !
 16079 00004A92 E97FFEFFFF          <1>         jmp     loc_enter_month_2
 16080                              <1> loc_set_date_bs_4:
 16081 00004A97 E856000000          <1> 	call	write_backspace
 16082 00004A9C E94AFEFFFF          <1>         jmp     loc_enter_month_1
 16083                              <1> loc_set_date_stc_5:
 16084 00004AA1 E85E000000          <1> 	call	check_for_backspace
 16085 00004AA6 740A                <1> 	je	short loc_set_date_bs_5
 16086                              <1> 	;xor	bl, bl ; video page 0
 16087 00004AA8 E8E7CDFFFF          <1> 	call	beeper ; BEEP !
 16088 00004AAD E9A0FEFFFF          <1>         jmp     loc_enter_separator_2
 16089                              <1> loc_set_date_bs_5:
 16090 00004AB2 E83B000000          <1> 	call	write_backspace
 16091 00004AB7 E95AFEFFFF          <1>         jmp     loc_enter_month_2
 16092                              <1> loc_set_date_stc_6:
 16093 00004ABC E843000000          <1> 	call	check_for_backspace
 16094 00004AC1 740A                <1>         je      short  loc_set_date_bs_6
 16095                              <1> 	;xor	bl, bl ; video page 0
 16096 00004AC3 E8CCCDFFFF          <1> 	call	beeper ; BEEP !
 16097 00004AC8 E9A7FEFFFF          <1>         jmp     loc_enter_year_1
 16098                              <1> loc_set_date_bs_6:
 16099 00004ACD E820000000          <1> 	call	write_backspace
 16100 00004AD2 E97BFEFFFF          <1>         jmp     loc_enter_separator_2
 16101                              <1> loc_set_date_stc_7:
 16102 00004AD7 E828000000          <1> 	call	check_for_backspace
 16103 00004ADC 740A                <1> 	je	short loc_set_date_bs_7
 16104                              <1> 	;xor	bl, bl ; video page 0
 16105 00004ADE E8B1CDFFFF          <1> 	call	beeper ; BEEP !
 16106 00004AE3 E9B7FEFFFF          <1>         jmp     loc_enter_year_2
 16107                              <1> loc_set_date_bs_7:
 16108 00004AE8 E805000000          <1> 	call	write_backspace
 16109 00004AED E982FEFFFF          <1>         jmp     loc_enter_year_1
 16110                              <1> 
 16111                              <1> write_backspace:
 16112                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16113 00004AF2 B008                <1> 	mov	al, 08h ; BACKSPACE
 16114                              <1> 	;xor	bl, bl
 16115 00004AF4 B407                <1> 	mov	ah, 7 ; attribute/color
 16116 00004AF6 E8BBCCFFFF          <1> 	call	WRITE_TTY
 16117 00004AFB B020                <1> 	mov	al, 20h ; BLANK/SPACE char 
 16118                              <1> 	;xor	bl, bl
 16119 00004AFD B407                <1> 	mov	ah, 7 ; attribute/color
 16120                              <1> 	;call	_write_c_current
 16121                              <1> 	;retn
 16122 00004AFF E981CCFFFF          <1> 	jmp	_write_c_current
 16123                              <1> 
 16124                              <1> check_for_backspace:
 16125                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16126 00004B04 663D080E            <1> 	cmp	ax, 0E08h
 16127 00004B08 7410                <1> 	je	short cfbs_retn
 16128 00004B0A 663DE04B            <1> 	cmp	ax, 4BE0h
 16129 00004B0E 740A                <1> 	je	short cfbs_retn
 16130 00004B10 663D004B            <1> 	cmp	ax, 4B00h
 16131 00004B14 7404                <1> 	je	short cfbs_retn
 16132 00004B16 663DE053            <1> 	cmp	ax, 53E0h
 16133                              <1> cfbs_retn:
 16134 00004B1A C3                  <1> 	retn
 16135                              <1> 
 16136                              <1> show_time:
 16137                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16138                              <1>         ; 2004-2005
 16139                              <1> 
 16140                              <1> 	;mov	ah, 02h
 16141                              <1> 	;call	int1Ah
 16142 00004B1B E840EEFFFF          <1> 	call	RTC_20	; GET RTC TIME
 16143                              <1> 	
 16144 00004B20 88E8                <1> 	mov	al, ch
 16145 00004B22 E8B7C0FFFF          <1> 	call	bcd_to_ascii
 16146 00004B27 66A3[B7950000]      <1> 	mov	[Hour], ax
 16147                              <1> 
 16148 00004B2D 88C8                <1> 	mov	al, cl
 16149 00004B2F E8AAC0FFFF          <1> 	call	bcd_to_ascii
 16150 00004B34 66A3[BA950000]      <1> 	mov	[Minute], ax
 16151                              <1> 
 16152 00004B3A 88F0                <1> 	mov	al, dh
 16153 00004B3C E89DC0FFFF          <1> 	call	bcd_to_ascii
 16154 00004B41 66A3[BD950000]      <1> 	mov	[Second], ax
 16155                              <1> 
 16156 00004B47 BE[A7950000]        <1> 	mov	esi, Msg_Show_Time
 16157 00004B4C E8E9F0FFFF          <1> 	call	print_msg
 16158 00004B51 C3                  <1> 	retn
 16159                              <1> 
 16160                              <1> set_time:
 16161                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16162                              <1>         ; 2004-2005
 16163                              <1> 
 16164 00004B52 BE[96950000]        <1> 	mov 	esi, Msg_Enter_Time
 16165 00004B57 E8DEF0FFFF          <1> 	call	print_msg
 16166                              <1> 
 16167                              <1> loc_enter_hour_1:
 16168 00004B5C 30E4                <1> 	xor     ah, ah
 16169 00004B5E E884C0FFFF          <1> 	call	int16h
 16170                              <1> 	; AL = ASCII Code of the Character
 16171 00004B63 3C0D                <1> 	cmp	al, 13 ; ENTER key
 16172 00004B65 0F84AE010000        <1>         je      loc_set_time_retn
 16173 00004B6B 3C1B                <1> 	cmp	al, 27 ; ESC key
 16174 00004B6D 0F84A6010000        <1>         je      loc_set_time_retn
 16175 00004B73 A2[B7950000]        <1> 	mov	[Hour], al
 16176 00004B78 3C30                <1> 	cmp	al, '0'
 16177 00004B7A 0F82A4010000        <1>         jb      loc_set_time_stc_0
 16178 00004B80 3C32                <1> 	cmp	al, '2'
 16179 00004B82 0F879C010000        <1>         ja      loc_set_time_stc_0
 16180                              <1> 	;sub	bl, bl ; 0
 16181 00004B88 B407                <1> 	mov	ah, 7 ; attribute/color
 16182 00004B8A E827CCFFFF          <1> 	call	WRITE_TTY
 16183                              <1> loc_enter_hour_2:
 16184 00004B8F 30E4                <1> 	xor     ah, ah
 16185 00004B91 E851C0FFFF          <1> 	call	int16h
 16186                              <1> 	; AL = ASCII Code of the Character
 16187 00004B96 3C1B                <1> 	cmp	al, 27
 16188 00004B98 0F847B010000        <1>         je      loc_set_time_retn
 16189 00004B9E A2[B8950000]        <1> 	mov	[Hour+1], al
 16190 00004BA3 3C30                <1> 	cmp	al, '0'
 16191 00004BA5 0F8283010000        <1>         jb      loc_set_time_stc_1
 16192 00004BAB 3C39                <1> 	cmp	al, '9'
 16193 00004BAD 0F877B010000        <1> 	ja	loc_set_time_stc_1
 16194 00004BB3 803D[B7950000]32    <1>         cmp     byte [Hour], '2'
 16195 00004BBA 7208                <1> 	jb	short pass_set_time_24
 16196 00004BBC 3C34                <1> 	cmp	al, '4'
 16197 00004BBE 0F876A010000        <1>         ja      loc_set_time_stc_1
 16198                              <1> pass_set_time_24:
 16199                              <1> 	;sub	bl, bl ; 0
 16200 00004BC4 B407                <1> 	mov	ah, 7 ; attribute/color
 16201 00004BC6 E8EBCBFFFF          <1> 	call	WRITE_TTY
 16202                              <1> loc_enter_time_separator_1:
 16203 00004BCB 28E4                <1> 	sub    ah, ah ; 0
 16204 00004BCD E815C0FFFF          <1> 	call	int16h
 16205                              <1> 	; AL = ASCII Code of the Character
 16206 00004BD2 3C1B                <1> 	cmp	al, 27
 16207 00004BD4 0F843F010000        <1>         je      loc_set_time_retn
 16208 00004BDA 3C3A                <1> 	cmp	al, ':'
 16209 00004BDC 0F8567010000        <1>         jne     loc_set_time_stc_2
 16210                              <1> 	;xor	bl, bl
 16211 00004BE2 B407                <1> 	mov	ah, 7 ; attribute/color
 16212 00004BE4 E8CDCBFFFF          <1> 	call	WRITE_TTY
 16213                              <1> loc_enter_minute_1:
 16214 00004BE9 30E4                <1> 	xor     ah, ah
 16215 00004BEB E8F7BFFFFF          <1> 	call	int16h
 16216                              <1> 	; AL = ASCII Code of the Character
 16217 00004BF0 3C1B                <1> 	cmp	al, 27
 16218 00004BF2 0F8421010000        <1>         je      loc_set_time_retn
 16219 00004BF8 A2[BA950000]        <1> 	mov	[Minute], al
 16220 00004BFD 3C30                <1> 	cmp	al, '0'
 16221 00004BFF 0F825F010000        <1>         jb      loc_set_time_stc_3
 16222 00004C05 3C35                <1> 	cmp	al, '5'
 16223 00004C07 0F8757010000        <1>         ja      loc_set_time_stc_3
 16224                              <1> 	;sub	bl, bl
 16225 00004C0D B407                <1> 	mov	ah, 7 ; attribute/color
 16226 00004C0F E8A2CBFFFF          <1> 	call	WRITE_TTY
 16227                              <1> loc_enter_minute_2:
 16228 00004C14 30E4                <1> 	xor     ah, ah
 16229 00004C16 E8CCBFFFFF          <1> 	call	int16h
 16230                              <1> 	; AL = ASCII Code of the Character
 16231 00004C1B 3C1B                <1> 	cmp	al, 27
 16232 00004C1D 0F84F6000000        <1>         je      loc_set_time_retn
 16233 00004C23 A2[BB950000]        <1> 	mov	[Minute+1], al
 16234 00004C28 3C30                <1> 	cmp	al, '0'
 16235 00004C2A 0F824F010000        <1>         jb      loc_set_time_stc_4
 16236 00004C30 3C39                <1> 	cmp	al, '9'
 16237 00004C32 0F8747010000        <1>         ja      loc_set_time_stc_4
 16238                              <1> 	;sub	bl, bl
 16239 00004C38 B407                <1> 	mov	ah, 7 ; attribute/color
 16240 00004C3A E877CBFFFF          <1> 	call	WRITE_TTY
 16241                              <1> loc_enter_time_separator_2:
 16242 00004C3F 66C705[BD950000]30- <1> 	mov	word [Second], 3030h
 16243 00004C47 30                  <1>
 16244 00004C48 28E4                <1> 	sub     ah, ah
 16245 00004C4A E898BFFFFF          <1> 	call	int16h
 16246                              <1> 	; AL = ASCII Code of the Character
 16247 00004C4F 3C0D                <1> 	cmp	al, 13
 16248 00004C51 0F8485000000        <1>         je      loc_set_time_progress
 16249 00004C57 3C1B                <1> 	cmp	al, 27
 16250 00004C59 0F84BA000000        <1>         je      loc_set_time_retn
 16251 00004C5F 3C3A                <1> 	cmp	al, ':'
 16252 00004C61 0F8533010000        <1>         jne     loc_set_time_stc_5
 16253                              <1> 	;xor	bl, bl
 16254 00004C67 B407                <1> 	mov	ah, 7 ; attribute/color
 16255 00004C69 E848CBFFFF          <1> 	call	WRITE_TTY
 16256                              <1> loc_enter_second_1:
 16257 00004C6E 30E4                <1> 	xor     ah, ah
 16258 00004C70 E872BFFFFF          <1> 	call	int16h
 16259                              <1> 	; AL = ASCII Code of the Character
 16260 00004C75 3C0D                <1> 	cmp	al, 13
 16261 00004C77 7463                <1> 	je	short loc_set_time_progress
 16262 00004C79 3C1B                <1> 	cmp	al, 27
 16263 00004C7B 0F8498000000        <1>         je      loc_set_time_retn
 16264 00004C81 A2[BD950000]        <1> 	mov	[Second], al
 16265 00004C86 3C30                <1> 	cmp	al, '0'
 16266 00004C88 0F8227010000        <1>         jb      loc_set_time_stc_6
 16267 00004C8E 3C35                <1> 	cmp	al, '5'
 16268 00004C90 0F871F010000        <1>         ja      loc_set_time_stc_6
 16269                              <1> 	;sub	bl, bl
 16270 00004C96 B407                <1> 	mov	ah, 7 ; attribute/color
 16271 00004C98 E819CBFFFF          <1> 	call	WRITE_TTY
 16272                              <1> loc_enter_second_2:
 16273 00004C9D 30E4                <1> 	xor     ah, ah
 16274 00004C9F E843BFFFFF          <1> 	call	int16h
 16275                              <1> 	; AL = ASCII Code of the Character
 16276 00004CA4 3C1B                <1> 	cmp	al, 27
 16277 00004CA6 7471                <1> 	je	short loc_set_time_retn
 16278 00004CA8 3C30                <1> 	cmp	al, '0'
 16279 00004CAA 0F8229010000        <1>         jb      loc_set_time_stc_7
 16280 00004CB0 3C39                <1> 	cmp	al, '9'
 16281 00004CB2 0F8721010000        <1>         ja      loc_set_time_stc_7
 16282                              <1> 	;sub	bl, bl
 16283 00004CB8 B407                <1> 	mov	ah, 7 ; attribute/color
 16284 00004CBA E8F7CAFFFF          <1> 	call	WRITE_TTY
 16285                              <1> loc_set_time_get_lchar_again:
 16286 00004CBF 28E4                <1> 	sub	ah, ah ; 0
 16287 00004CC1 E821BFFFFF          <1> 	call	int16h
 16288                              <1> 	; AL = ASCII Code of the Character
 16289 00004CC6 3C0D                <1> 	cmp	al, 13
 16290 00004CC8 7412                <1> 	je	short loc_set_time_progress
 16291 00004CCA 3C1B                <1> 	cmp	al, 27
 16292 00004CCC 744B                <1> 	je	short loc_set_time_retn
 16293                              <1> 	;
 16294 00004CCE E831FEFFFF          <1> 	call	check_for_backspace
 16295 00004CD3 75EA                <1> 	jne	short loc_set_time_get_lchar_again
 16296                              <1> 
 16297                              <1> loc_set_time_bs_8:
 16298 00004CD5 E818FEFFFF          <1> 	call	write_backspace
 16299 00004CDA EBC1                <1> 	jmp	short loc_enter_second_2
 16300                              <1> 
 16301                              <1> loc_set_time_progress:
 16302                              <1> 	; Get Current Time
 16303                              <1> 	;mov 	ah, 02h
 16304                              <1> 	;call	int1Ah
 16305 00004CDC E87FECFFFF          <1> 	call	RTC_20	; GET RTC TIME
 16306                              <1> 	;DL = Daylight Savings Enable option (0-1)	
 16307                              <1> 
 16308 00004CE1 66A1[B7950000]      <1> 	mov	ax, [Hour]
 16309 00004CE7 662D3030            <1> 	sub	ax, '00'
 16310 00004CEB C0E004              <1> 	shl	al, 4 ; * 16
 16311 00004CEE 88C5                <1> 	mov	ch, al
 16312 00004CF0 00E5                <1> 	add	ch, ah
 16313 00004CF2 66A1[BA950000]      <1> 	mov	ax, [Minute]
 16314 00004CF8 662D3030            <1> 	sub	ax, '00'
 16315 00004CFC C0E004              <1> 	shl	al, 4 ; * 16
 16316 00004CFF 88C1                <1> 	mov	cl, al
 16317 00004D01 00E1                <1> 	add	cl, ah
 16318 00004D03 66A1[BD950000]      <1> 	mov	ax, [Second]
 16319 00004D09 662D3030            <1> 	sub	ax, '00'
 16320 00004D0D C0E004              <1> 	shl	al, 4 ; * 16
 16321 00004D10 88C6                <1> 	mov	dh, al
 16322 00004D12 00E6                <1> 	add	dh, ah
 16323                              <1> 	
 16324                              <1> 	;mov	ah, 03h
 16325                              <1> 	;call	int1Ah
 16326 00004D14 E876ECFFFF          <1> 	call	RTC_30	; SET RTC TIME
 16327                              <1> 
 16328                              <1> loc_set_time_retn:
 16329 00004D19 BE[269F0000]        <1> 	mov 	esi, nextline
 16330 00004D1E E817EFFFFF          <1> 	call	print_msg
 16331 00004D23 C3                  <1> 	retn
 16332                              <1> 
 16333                              <1> loc_set_time_stc_0:
 16334                              <1> 	;xor	bl, bl ; video page 0
 16335 00004D24 E86BCBFFFF          <1> 	call	beeper ; BEEP !
 16336 00004D29 E92EFEFFFF          <1>         jmp     loc_enter_hour_1
 16337                              <1> loc_set_time_stc_1:
 16338 00004D2E E8D1FDFFFF          <1> 	call	check_for_backspace
 16339 00004D33 740A                <1> 	je	short loc_set_time_bs_1
 16340                              <1> 	;xor	bl, bl ; video page 0
 16341 00004D35 E85ACBFFFF          <1> 	call	beeper ; BEEP !
 16342 00004D3A E950FEFFFF          <1>         jmp     loc_enter_hour_2
 16343                              <1> loc_set_time_bs_1:
 16344 00004D3F E8AEFDFFFF          <1> 	call	write_backspace
 16345 00004D44 E913FEFFFF          <1>         jmp     loc_enter_hour_1
 16346                              <1> loc_set_time_stc_2:
 16347 00004D49 E8B6FDFFFF          <1> 	call	check_for_backspace
 16348 00004D4E 740A                <1> 	je	short loc_set_time_bs_2
 16349                              <1> 	;xor	bl, bl ; video page 0
 16350 00004D50 E83FCBFFFF          <1> 	call	beeper ; BEEP !
 16351 00004D55 E971FEFFFF          <1>         jmp     loc_enter_time_separator_1
 16352                              <1> loc_set_time_bs_2:
 16353 00004D5A E893FDFFFF          <1> 	call	write_backspace
 16354 00004D5F E92BFEFFFF          <1>         jmp     loc_enter_hour_2
 16355                              <1> loc_set_time_stc_3:
 16356 00004D64 E89BFDFFFF          <1> 	call	check_for_backspace
 16357 00004D69 740A                <1> 	je	short loc_set_time_bs_3
 16358                              <1> 	;xor	bl, bl ; video page 0
 16359 00004D6B E824CBFFFF          <1> 	call	beeper ; BEEP !6
 16360 00004D70 E974FEFFFF          <1>         jmp     loc_enter_minute_1
 16361                              <1> loc_set_time_bs_3:
 16362 00004D75 E878FDFFFF          <1> 	call	write_backspace
 16363 00004D7A E94CFEFFFF          <1>         jmp     loc_enter_time_separator_1
 16364                              <1> loc_set_time_stc_4:
 16365 00004D7F E880FDFFFF          <1> 	call	check_for_backspace
 16366 00004D84 740A                <1> 	je	short loc_set_time_bs_4
 16367                              <1> 	;xor	bl, bl ; video page 0
 16368 00004D86 E809CBFFFF          <1> 	call	beeper ; BEEP !
 16369 00004D8B E984FEFFFF          <1>         jmp     loc_enter_minute_2
 16370                              <1> loc_set_time_bs_4:
 16371 00004D90 E85DFDFFFF          <1> 	call	write_backspace
 16372 00004D95 E94FFEFFFF          <1>         jmp     loc_enter_minute_1
 16373                              <1> loc_set_time_stc_5:
 16374 00004D9A E865FDFFFF          <1> 	call	check_for_backspace
 16375 00004D9F 740A                <1> 	je	short loc_set_time_bs_5
 16376                              <1> 	;xor	bl, bl ; video page 0
 16377 00004DA1 E8EECAFFFF          <1> 	call	beeper ; BEEP !
 16378 00004DA6 E994FEFFFF          <1>         jmp     loc_enter_time_separator_2
 16379                              <1> loc_set_time_bs_5:
 16380 00004DAB E842FDFFFF          <1> 	call	write_backspace
 16381 00004DB0 E95FFEFFFF          <1>         jmp     loc_enter_minute_2
 16382                              <1> loc_set_time_stc_6:
 16383 00004DB5 E84AFDFFFF          <1> 	call	check_for_backspace
 16384 00004DBA 7413                <1> 	je	short loc_set_time_bs_6
 16385                              <1> 	;xor	bl, bl ; video page 0
 16386 00004DBC E8D3CAFFFF          <1> 	call	beeper ; BEEP !
 16387 00004DC1 66C705[BD950000]30- <1> 	mov	word [Second], 3030h
 16388 00004DC9 30                  <1>
 16389 00004DCA E99FFEFFFF          <1>         jmp     loc_enter_second_1
 16390                              <1> loc_set_time_bs_6:
 16391 00004DCF E81EFDFFFF          <1> 	call	write_backspace
 16392 00004DD4 E966FEFFFF          <1>         jmp     loc_enter_time_separator_2
 16393                              <1> loc_set_time_stc_7:
 16394 00004DD9 E826FDFFFF          <1> 	call	check_for_backspace
 16395 00004DDE 740A                <1> 	je	short loc_set_time_bs_7
 16396                              <1> 	;xor	bl, bl ; video page 0
 16397 00004DE0 E8AFCAFFFF          <1> 	call	beeper ; BEEP !
 16398 00004DE5 E9B3FEFFFF          <1>         jmp     loc_enter_second_2
 16399                              <1> loc_set_time_bs_7:
 16400 00004DEA E803FDFFFF          <1> 	call	write_backspace
 16401 00004DEF E97AFEFFFF          <1>         jmp     loc_enter_second_1
 16402                              <1> 
 16403                              <1> print_volume_info:
 16404                              <1> 	; 08/02/2016
 16405                              <1> 	; 06/02/2016
 16406                              <1> 	; 04/02/2016
 16407                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
 16408                              <1> 	; 25/10/2009
 16409                              <1> 	;
 16410                              <1> 	; "Volume Serial No: "
 16411                              <1>  	;
 16412                              <1> 	; INPUT  : AL = DOS Drive Number
 16413                              <1> 	; OUTPUT : AH = FS Type
 16414                              <1> 	;          AL = DOS Drive Name
 16415                              <1> 	; CF = 0 -> OK
 16416                              <1> 	; CF = 1 -> Drive not ready 
 16417                              <1> 
 16418 00004DF4 88C4                <1> 	mov	ah, al
 16419 00004DF6 28C0                <1> 	sub	al, al
 16420 00004DF8 0FB7F0              <1> 	movzx	esi, ax	
 16421 00004DFB 81C600010900        <1> 	add	esi, Logical_DOSDisks
 16422 00004E01 8A06                <1> 	mov	al, [esi]
 16423 00004E03 3C41                <1> 	cmp	al, 'A'  
 16424 00004E05 7304                <1> 	jnb	short loc_pvi_set_vol_name
 16425 00004E07 8A6604              <1> 	mov	ah, [esi+LD_FSType]
 16426 00004E0A C3                  <1> 	retn
 16427                              <1> 
 16428                              <1> loc_pvi_set_vol_name:
 16429 00004E0B A2[F1950000]        <1> 	mov	[Vol_Drv_Name], al
 16430 00004E10 56                  <1> 	push	esi
 16431 00004E11 E844010000          <1> 	call	move_volume_name_and_serial_no ;;;
 16432 00004E16 7302                <1> 	jnc	short loc_pvi_mvn_ok
 16433 00004E18 5E                  <1> 	pop	esi
 16434 00004E19 C3                  <1> 	retn
 16435                              <1> 
 16436                              <1> loc_pvi_mvn_ok:
 16437 00004E1A 8B3424              <1> 	mov	esi, [esp]
 16438 00004E1D 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 16439 00004E21 7509                <1> 	jne	short loc_pvi_fat_vol_size
 16440 00004E23 8B4670              <1> 	mov	eax, [esi+LD_FS_VolumeSize]
 16441 00004E26 0FB75E11            <1> 	movzx	ebx, word [esi+LD_FS_BytesPerSec]
 16442 00004E2A EB07                <1> 	jmp	short loc_vol_size_mul32
 16443                              <1> loc_pvi_fat_vol_size:
 16444 00004E2C 8B4670              <1> 	mov	eax, [esi+LD_TotalSectors]
 16445 00004E2F 0FB75E11            <1> 	movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
 16446                              <1> loc_vol_size_mul32:
 16447 00004E33 F7E3                <1> 	mul	ebx
 16448 00004E35 09D2                <1> 	or	edx, edx
 16449 00004E37 7507                <1> 	jnz	short loc_vol_size_in_kbytes
 16450                              <1> loc_vol_size_in_bytes:
 16451 00004E39 B9[CF950000]        <1> 	mov	ecx, VolSize_Bytes
 16452 00004E3E EB0D                <1> 	jmp	short loc_write_vol_size_str
 16453                              <1> loc_vol_size_in_kbytes:
 16454 00004E40 66BB0004            <1> 	mov	bx, 1024
 16455 00004E44 F7F3                <1> 	div	ebx
 16456 00004E46 B9[C2950000]        <1> 	mov 	ecx, VolSize_KiloBytes
 16457 00004E4B 31D2                <1> 	xor	edx, edx ; 0
 16458                              <1> loc_write_vol_size_str:
 16459 00004E4D 890D[47AB0000]      <1> 	mov	[VolSize_Unit1], ecx
 16460                              <1> 	; 
 16461 00004E53 BF[5DAB0000]        <1> 	mov	edi, Vol_Tot_Sec_Str_End
 16462                              <1>         ;mov	byte [edi], 0
 16463 00004E58 B90A000000          <1> 	mov	ecx, 10
 16464                              <1> loc_write_vol_size_chr:
 16465 00004E5D F7F1                <1> 	div	ecx
 16466 00004E5F 80C230              <1> 	add	dl, '0'
 16467 00004E62 4F                  <1> 	dec	edi	
 16468 00004E63 8817                <1> 	mov	[edi], dl
 16469 00004E65 85C0                <1> 	test	eax, eax
 16470 00004E67 7404                <1> 	jz	short loc_write_vol_size_str_ok
 16471 00004E69 28D2                <1> 	sub	dl, dl ; 0
 16472 00004E6B EBF0                <1> 	jmp	short loc_write_vol_size_chr
 16473                              <1> 
 16474                              <1> loc_write_vol_size_str_ok:
 16475 00004E6D 893D[4FAB0000]      <1> 	mov	[Vol_Tot_Sec_Str_Start], edi
 16476                              <1> 	;
 16477 00004E73 BF[DA950000]        <1> 	mov	edi, Vol_FS_Name
 16478 00004E78 8A4E03              <1> 	mov	cl, [esi+LD_FATType]
 16479 00004E7B 20C9                <1> 	and	cl, cl ; 0 ?
 16480 00004E7D 7515                <1> 	jnz	short loc_write_vol_FAT_str_1
 16481 00004E7F 66C7075452          <1> 	mov	word [edi], 'TR'
 16482 00004E84 C7470420465331      <1> 	mov	dword [edi+4], ' FS1'
 16483                              <1> 	;movzx	ebx, word [esi+LD_FS_BytesPerSec]
 16484 00004E8B 668B5E11            <1> 	mov	bx, [esi+LD_FS_BytesPerSec]
 16485 00004E8F 8B4674              <1> 	mov	eax, [esi+LD_FS_FreeSectors]
 16486 00004E92 EB22                <1> 	jmp	short loc_vol_freespace_mul32
 16487                              <1> 
 16488                              <1> loc_write_vol_FAT_str_1:
 16489 00004E94 66B83332            <1> 	mov	ax, '32' ; FAT32
 16490 00004E98 80F902              <1> 	cmp	cl, 2 ; [esi+LD_FATType]
 16491 00004E9B 7708                <1> 	ja	short loc_write_vol_FAT_str_2
 16492 00004E9D 66B83132            <1> 	mov	ax, '12' ; FAT12
 16493 00004EA1 7202                <1> 	jb	short loc_write_vol_FAT_str_2
 16494 00004EA3 B436                <1> 	mov	ah, '6'  ; FAT16
 16495                              <1> loc_write_vol_FAT_str_2:
 16496 00004EA5 C70746415420        <1> 	mov	dword [edi], 'FAT '
 16497 00004EAB 66894704            <1> 	mov	word [edi+4], ax
 16498                              <1> 	;
 16499                              <1> 	;movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
 16500 00004EAF 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec]
 16501 00004EB3 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
 16502                              <1> 
 16503                              <1> loc_vol_freespace_mul32:
 16504 00004EB6 F7E3                <1> 	mul	ebx
 16505 00004EB8 09D2                <1> 	or	edx, edx
 16506 00004EBA 7507                <1> 	jnz	short loc_vol_fspace_in_kbytes
 16507                              <1> loc_vol_fspace_in_bytes:
 16508 00004EBC B9[CF950000]        <1> 	mov	ecx, VolSize_Bytes
 16509 00004EC1 EB0D                <1> 	jmp	short loc_write_vol_fspace_str
 16510                              <1> loc_vol_fspace_in_kbytes:
 16511 00004EC3 66BB0004            <1> 	mov	bx, 1024
 16512 00004EC7 F7F3                <1> 	div	ebx
 16513 00004EC9 B9[C2950000]        <1> 	mov 	ecx, VolSize_KiloBytes
 16514 00004ECE 31D2                <1> 	xor	edx, edx ; 0
 16515                              <1> loc_write_vol_fspace_str:
 16516 00004ED0 890D[4BAB0000]      <1> 	mov	[VolSize_Unit2], ecx
 16517                              <1> 	;	
 16518 00004ED6 BF[6DAB0000]        <1> 	mov	edi, Vol_Free_Sectors_Str_End
 16519                              <1>         ;mov	byte [edi], 0
 16520 00004EDB B90A000000          <1> 	mov	ecx, 10
 16521                              <1> loc_write_vol_fspace_chr:
 16522 00004EE0 F7F1                <1> 	div	ecx
 16523 00004EE2 80C230              <1> 	add	dl, '0'
 16524 00004EE5 4F                  <1> 	dec	edi	
 16525 00004EE6 8817                <1> 	mov	[edi], dl
 16526 00004EE8 85C0                <1> 	test	eax, eax
 16527 00004EEA 7404                <1> 	jz	short loc_write_vol_fspace_str_ok
 16528 00004EEC 28D2                <1> 	sub	dl, dl ; 0
 16529 00004EEE EBF0                <1> 	jmp	short loc_write_vol_fspace_chr
 16530                              <1> 
 16531                              <1> loc_write_vol_fspace_str_ok:
 16532 00004EF0 893D[5FAB0000]      <1> 	mov	[Vol_Free_Sectors_Str_Start], edi
 16533                              <1> 	;
 16534 00004EF6 BE[D8950000]        <1> 	mov	esi, Volume_in_drive
 16535 00004EFB E83AEDFFFF          <1> 	call	print_msg
 16536 00004F00 BE[18960000]        <1> 	mov	esi, Vol_Name
 16537 00004F05 E830EDFFFF          <1> 	call	print_msg
 16538 00004F0A BE[269F0000]        <1> 	mov	esi, nextline
 16539 00004F0F E826EDFFFF          <1> 	call	print_msg
 16540                              <1> 	;
 16541 00004F14 BE[79960000]        <1> 	mov	esi, Vol_Total_Sector_Header
 16542 00004F19 E81CEDFFFF          <1> 	call	print_msg
 16543 00004F1E 8B35[4FAB0000]      <1> 	mov	esi, [Vol_Tot_Sec_Str_Start]
 16544 00004F24 E811EDFFFF          <1> 	call	print_msg
 16545 00004F29 8B35[47AB0000]      <1> 	mov	esi, [VolSize_Unit1]
 16546 00004F2F E806EDFFFF          <1> 	call	print_msg
 16547                              <1> 	;
 16548 00004F34 BE[8A960000]        <1> 	mov	esi, Vol_Free_Sectors_Header
 16549 00004F39 E8FCECFFFF          <1> 	call	print_msg
 16550 00004F3E 8B35[5FAB0000]      <1> 	mov	esi, [Vol_Free_Sectors_Str_Start]
 16551 00004F44 E8F1ECFFFF          <1> 	call	print_msg
 16552 00004F49 8B35[4BAB0000]      <1> 	mov	esi, [VolSize_Unit2]
 16553 00004F4F E8E6ECFFFF          <1> 	call	print_msg
 16554                              <1> 	;
 16555 00004F54 5E                  <1> 	pop	esi
 16556                              <1> 	
 16557                              <1> 	;mov	ah, [esi+LD_FSType]
 16558                              <1> 	;mov	al, [esi+LD_FATType]
 16559 00004F55 668B4603            <1> 	mov	ax, [esi+LD_FATType]
 16560                              <1> 
 16561 00004F59 C3                  <1> 	retn
 16562                              <1> 
 16563                              <1> move_volume_name_and_serial_no:
 16564                              <1> 	; 08/02/2016  (TRDOS 386 = TRDOS v2.0)
 16565                              <1> 	; this routine will be called by
 16566                              <1> 	; "print_volume_info" and "print_directory"
 16567                              <1> 	; INPUT ->
 16568                              <1> 	;	ESI = Logical DOS drv descripton table address
 16569                              <1> 	; OUTPUT ->
 16570                              <1> 	;	*Volume name will be moved to text area
 16571                              <1> 	;	*Volume serial number will be converted to
 16572                              <1> 	;	 text and will be moved to text area
 16573                              <1> 	;   cf = 1 -> invalid/unknown dos drive
 16574                              <1> 	;   cf = 0 -> ecx = 0
 16575                              <1> 	;
 16576                              <1> 	; (eax, edx, ecx, esi, edi will be changed)
 16577                              <1> 
 16578 00004F5A BF[18960000]        <1> 	mov 	edi, Vol_Name
 16579                              <1> 
 16580                              <1> 	;mov	ah, [esi+LD_FSType]
 16581                              <1> 	;mov	al, [esi+LD_FATType]
 16582 00004F5F 668B4603            <1> 	mov	ax, [esi+LD_FATType]
 16583 00004F63 80FCA1              <1> 	cmp	ah, 0A1h
 16584 00004F66 7418                <1> 	je	short mvn_2
 16585 00004F68 08E4                <1> 	or	ah, ah
 16586 00004F6A 7404                <1> 	jz	short mvn_0
 16587 00004F6C 08C0                <1> 	or	al, al
 16588 00004F6E 7504                <1> 	jnz	short mvn_1
 16589                              <1> mvn_0:
 16590 00004F70 8A06                <1> 	mov	al, [esi]
 16591 00004F72 F9                  <1> 	stc
 16592 00004F73 C3                  <1> 	retn
 16593                              <1> mvn_1:
 16594 00004F74 3C02                <1> 	cmp	al, 2
 16595 00004F76 7717                <1> 	ja	short mvn_3 
 16596                              <1> 	;or	al, al
 16597                              <1> 	;jz	short mvn_2
 16598 00004F78 8B462D              <1> 	mov	eax, [esi+LD_BPB+VolumeID]
 16599 00004F7B 83C631              <1> 	add	esi, LD_BPB+VolumeLabel
 16600 00004F7E EB15                <1> 	jmp	short mvn_4
 16601                              <1> mvn_2:
 16602 00004F80 8B4628              <1> 	mov	eax, [esi+LD_FS_VolumeSerial]
 16603 00004F83 83C62C              <1> 	add	esi, LD_FS_VolumeName
 16604 00004F86 B910000000          <1> 	mov	ecx, 16
 16605 00004F8B F3A5                <1> 	rep	movsd
 16606 00004F8D EB10                <1> 	jmp	short mvn_5
 16607                              <1> mvn_3:
 16608 00004F8F 8B4649              <1> 	mov	eax, [esi+LD_BPB+FAT32_VolID]
 16609 00004F92 83C64D              <1> 	add	esi, LD_BPB+FAT32_VolLab
 16610                              <1> mvn_4:
 16611 00004F95 B90B000000          <1> 	mov	ecx, 11
 16612 00004F9A F3A4                <1> 	rep	movsb
 16613 00004F9C C60700              <1> 	mov	byte [edi], 0
 16614                              <1> mvn_5:
 16615                              <1> 	;mov	[Current_VolSerial], eax  
 16616 00004F9F E842CAFFFF          <1> 	call	dwordtohex
 16617 00004FA4 8915[6D960000]      <1> 	mov	[Vol_Serial1], edx
 16618 00004FAA A3[72960000]        <1> 	mov	[Vol_Serial2], eax
 16619                              <1> 	; ecx = 0
 16620 00004FAF C3                  <1> 	retn
 16621                              <1> 
 16622                              <1> get_volume_serial_number:
 16623                              <1> 	; 19/01/2016 (TRDOS 386 = TRDOS v2.0)
 16624                              <1> 	; 08/08/2010
 16625                              <1> 	;
 16626                              <1> 	; INPUT -> DL = Logical DOS Drive number
 16627                              <1> 	; OUTPUT -> EAX = Volume serial number
 16628                              <1> 	;          BL= FAT Type	    
 16629                              <1> 	;          BH = Logical DOS drv Number (DL input)
 16630                              <1> 	; cf = 1 -> Drive not ready
 16631                              <1> 
 16632 00004FB0 31DB                <1> 	xor	ebx, ebx
 16633 00004FB2 88D7                <1> 	mov	bh, dl
 16634 00004FB4 3815[40940000]      <1> 	cmp	[Last_DOS_DiskNo], dl
 16635 00004FBA 7304                <1> 	jnb	short loc_gvsn_start
 16636                              <1> loc_gvsn_stc_retn:
 16637 00004FBC 31C0                <1> 	xor	eax, eax
 16638 00004FBE F9                  <1> 	stc 
 16639 00004FBF C3                  <1>         retn 
 16640                              <1> loc_gvsn_start:
 16641 00004FC0 56                  <1> 	push	esi
 16642 00004FC1 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 16643 00004FC6 01DE                <1> 	add	esi, ebx
 16644 00004FC8 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
 16645 00004FCB 20DB                <1> 	and	bl, bl
 16646 00004FCD 740F                <1> 	jz	short loc_gvsn_fs
 16647 00004FCF 80FB02              <1> 	cmp	bl, 2
 16648 00004FD2 7705                <1> 	ja	short loc_gvsn_fat32
 16649                              <1> loc_gvsn_fat:
 16650 00004FD4 83C62D              <1> 	add	esi, LD_BPB + VolumeID
 16651 00004FD7 EB0E                <1> 	jmp	short loc_gvsn_return
 16652                              <1> loc_gvsn_fat32: 
 16653 00004FD9 83C649              <1> 	add	esi, LD_BPB + FAT32_VolID
 16654 00004FDC EB09                <1> 	jmp	short loc_gvsn_return 
 16655                              <1> loc_gvsn_fs:
 16656 00004FDE 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 16657 00004FE2 75D8                <1> 	jne	short loc_gvsn_stc_retn 
 16658 00004FE4 83C628              <1> 	add	esi, LD_FS_VolumeSerial
 16659                              <1> loc_gvsn_return:
 16660 00004FE7 8B06                <1> 	mov	eax, [esi]
 16661 00004FE9 5E                  <1> 	pop	esi
 16662 00004FEA C3                  <1> 	retn
 16663                              <1> 
 16664                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ]
 16665                              <1> ; 09/11/2011
 16666                              <1> ; 29/01/2005
 16667                              <1> 
 16668                              <1> command_interpreter:
 16669                              <1> 	; 04/02/2016
 16670                              <1> 	; 03/02/2016
 16671                              <1> 	; 30/01/2016
 16672                              <1> 	; 29/01/2016 (TRDOS 386 = TRDOS 2.0)
 16673                              <1> 	; 15/09/2011         
 16674                              <1> 	; 29/01/2005
 16675                              <1>         
 16676                              <1> 	; Input: ecx = command word length (CL)
 16677                              <1> 	;	 CommandBuffer = Command string offset
 16678                              <1>  
 16679 00004FEB C605[00AC0000]00    <1> 	mov	byte [Program_Exit],0
 16680 00004FF2 80F904              <1> 	cmp	cl, 4
 16681 00004FF5 0F87BA020000        <1>         ja      c_6
 16682 00004FFB 0F8216010000        <1>         jb      c_2
 16683                              <1> c_4:
 16684                              <1> 
 16685                              <1> cmp_cmd_exit:
 16686 00005001 BF[AE940000]        <1> 	mov	edi, Cmd_Exit
 16687 00005006 E8B1030000          <1> 	call	cmp_cmd	
 16688 0000500B 7208                <1> 	jc	short cmp_cmd_date
 16689                              <1> 
 16690 0000500D C605[00AC0000]01    <1>         mov     byte [Program_Exit], 1
 16691 00005014 C3                  <1>         retn
 16692                              <1> 
 16693                              <1> cmp_cmd_date:
 16694 00005015 B104                <1> 	mov	cl, 4
 16695 00005017 BF[CA940000]        <1> 	mov	edi, Cmd_Date
 16696 0000501C E89B030000          <1> 	call	cmp_cmd	
 16697 00005021 720B                <1>         jc	short cmp_cmd_time
 16698                              <1> 	
 16699 00005023 E8E4F7FFFF          <1> 	call	show_date
 16700 00005028 E823F8FFFF          <1> 	call	set_date
 16701 0000502D C3                  <1> 	retn
 16702                              <1> 
 16703                              <1> cmp_cmd_time:
 16704 0000502E B104                <1> 	mov	cl, 4
 16705 00005030 BF[CF940000]        <1> 	mov	edi, Cmd_Time
 16706 00005035 E882030000          <1>    	call	cmp_cmd	
 16707 0000503A 720B                <1> 	jc	short cmp_cmd_show
 16708                              <1> 
 16709 0000503C E8DAFAFFFF          <1> 	call	show_time
 16710 00005041 E80CFBFFFF          <1> 	call	set_time
 16711 00005046 C3                  <1> 	retn
 16712                              <1> 
 16713                              <1> cmp_cmd_show:
 16714 00005047 B104                <1> 	mov	cl, 4
 16715 00005049 BF[E0940000]        <1> 	mov	edi, Cmd_Show
 16716 0000504E E869030000          <1>    	call	cmp_cmd	
 16717 00005053 0F83D8090000        <1>         jnc     show_file
 16718                              <1> 
 16719                              <1> cmp_cmd_echo:
 16720 00005059 B104                <1> 	mov	cl, 4
 16721 0000505B BF[25950000]        <1> 	mov	edi, Cmd_Echo
 16722 00005060 E857030000          <1>    	call	cmp_cmd	
 16723 00005065 720A                <1> 	jc	short cmp_cmd_copy
 16724                              <1> 
 16725 00005067 803E20              <1> 	cmp	byte [esi], 20h
 16726 0000506A 0F83CAEBFFFF        <1> 	jnb	print_msg
 16727 00005070 C3                  <1> 	retn
 16728                              <1> 
 16729                              <1> cmp_cmd_copy:
 16730 00005071 B104                <1> 	mov	cl, 4
 16731 00005073 BF[03950000]        <1> 	mov	edi, Cmd_Copy
 16732 00005078 E83F030000          <1>    	call	cmp_cmd	
 16733 0000507D 0F83CB110000        <1> 	jnc	copy_file
 16734                              <1> 
 16735                              <1> cmp_cmd_move:
 16736 00005083 B104                <1> 	mov	cl, 4
 16737 00005085 BF[08950000]        <1> 	mov	edi, Cmd_Move
 16738 0000508A E82D030000          <1>    	call	cmp_cmd	
 16739 0000508F 0F83BA110000        <1> 	jnc	move_file
 16740                              <1> 
 16741                              <1> cmp_cmd_path:
 16742 00005095 B104                <1> 	mov	cl, 4
 16743 00005097 BF[0D950000]        <1> 	mov	edi, Cmd_Path
 16744 0000509C E81B030000          <1>    	call	cmp_cmd	
 16745 000050A1 0F83A9110000        <1> 	jnc	set_get_path
 16746                              <1> 
 16747                              <1> cmp_cmd_beep:
 16748 000050A7 B104                <1> 	mov	cl, 4
 16749 000050A9 BF[43950000]        <1> 	mov	edi, Cmd_Beep
 16750 000050AE E809030000          <1>    	call	cmp_cmd	
 16751 000050B3 0F83DBC7FFFF        <1> 	jnc	beeper
 16752                              <1> 
 16753                              <1> cmp_cmd_find:
 16754 000050B9 B104                <1> 	mov	cl, 4
 16755 000050BB BF[17950000]        <1> 	mov	edi, Cmd_Find
 16756 000050C0 E8F7020000          <1>    	call	cmp_cmd	
 16757 000050C5 0F82DE020000        <1>         jc      loc_cmd_failed
 16758                              <1> 
 16759                              <1> 	;call	find_and_list_files
 16760 000050CB E981110000          <1> 	jmp	find_and_list_files
 16761                              <1> 	;retn
 16762                              <1> 
 16763                              <1> c_1:
 16764 000050D0 AD                  <1> 	lodsd
 16765                              <1> cmp_cmd_help:
 16766 000050D1 3C3F                <1> 	cmp	al, '?'
 16767 000050D3 751D                <1>         jne     short cmp_cmd_remark
 16768                              <1> 
 16769 000050D5 BE[A0940000]        <1> 	mov	esi, Command_List
 16770                              <1> cmd_help_next_w:
 16771 000050DA E85BEBFFFF          <1> 	call	print_msg
 16772                              <1> 
 16773 000050DF 803E20              <1> 	cmp	byte [esi], 20h ; 0
 16774 000050E2 7232                <1> 	jb	short cmd_help_retn
 16775                              <1> 	
 16776 000050E4 56                  <1> 	push	esi
 16777 000050E5 BE[269F0000]        <1> 	mov	esi, nextline
 16778 000050EA E84BEBFFFF          <1> 	call	print_msg
 16779 000050EF 5E                  <1> 	pop	esi
 16780 000050F0 EBE8                <1> 	jmp	short cmd_help_next_w	
 16781                              <1> 
 16782                              <1> cmp_cmd_remark:
 16783 000050F2 3C2A                <1> 	cmp	al, '*'
 16784 000050F4 0F85AF020000        <1>         jne     loc_cmd_failed
 16785 000050FA 46                  <1> 	inc	esi
 16786 000050FB BF[70A30000]        <1> 	mov	edi, Remark
 16787 00005100 8A06                <1> 	mov	al, [esi]
 16788 00005102 3C20                <1> 	cmp	al, 20h
 16789 00005104 7707                <1> 	ja	short cmd_remark_write
 16790 00005106 89FE                <1> 	mov	esi, edi ; Remark
 16791 00005108 E92DEBFFFF          <1> 	jmp	print_msg
 16792                              <1> 
 16793                              <1> cmd_remark_write:
 16794 0000510D AA                  <1> 	stosb
 16795 0000510E AC                  <1> 	lodsb
 16796 0000510F 3C20                <1> 	cmp	al, 20h
 16797 00005111 73FA                <1> 	jnb	short cmd_remark_write
 16798 00005113 C60700              <1> 	mov	byte [edi], 0
 16799                              <1> 
 16800                              <1> cmd_help_retn:
 16801                              <1> cmd_remark_retn:
 16802                              <1> cd_retn:
 16803 00005116 C3                  <1> 	retn
 16804                              <1> 
 16805                              <1> c_2:
 16806 00005117 80F902              <1> 	cmp	cl, 2
 16807 0000511A 0F87B1000000        <1>         ja      c_3
 16808 00005120 BE[BEA30000]        <1> 	mov	esi, CommandBuffer
 16809 00005125 72A9                <1> 	jb	short c_1
 16810                              <1> 
 16811                              <1> cmp_cmd_cd:
 16812 00005127 66AD                <1> 	lodsw
 16813 00005129 663D4344            <1> 	cmp	ax, 'CD'
 16814 0000512D 7553                <1> 	jne	short cmp_cmd_drive
 16815 0000512F 46                  <1>         inc	esi
 16816                              <1> cd_0:
 16817 00005130 668B06              <1> 	mov	ax, [esi]	
 16818 00005133 3C20                <1> 	cmp	al, 20h
 16819 00005135 76DF                <1> 	jna	short cd_retn
 16820                              <1> 	; 10/02/2016
 16821 00005137 80FC3A              <1> 	cmp	ah, ':'
 16822 0000513A 7504                <1> 	jne	short cd_1
 16823 0000513C 46                  <1> 	inc	esi
 16824 0000513D 46                  <1> 	inc	esi
 16825 0000513E EB4B                <1> 	jmp	short cd_2
 16826                              <1> 
 16827                              <1> cd_1:	; change current directory
 16828                              <1> 	; 29/11/2009
 16829                              <1> 	; AH = CDh	; to separate 'CD' command from others
 16830                              <1> 			; for restoring current directory
 16831                              <1> 			; 0CDh sign is for saving cdir into 
 16832                              <1> 			; DOS drv description table cdir area
 16833                              <1> 	
 16834 00005140 B4CD                <1> 	mov	ah, 0CDh ; mov byte [CD_COMMAND], 0CDh 
 16835                              <1> 
 16836 00005142 E8F3110000          <1> 	call	change_current_directory
 16837 00005147 0F830D110000        <1>         jnc     change_prompt_dir_string
 16838                              <1> 
 16839                              <1> cd_error_messages:
 16840 0000514D 3C03                <1> 	cmp	al, 3
 16841 0000514F 740C                <1> 	je	short cd_path_not_found
 16842 00005151 3C15                <1> 	cmp	al, 15h 
 16843 00005153 745B                <1> 	je	short cd_drive_not_ready
 16844 00005155 3C18                <1> 	cmp	al, 18h ; Bad request structure length 
 16845 00005157 746C                <1> 	je	short cd_command_failed
 16846 00005159 3C1A                <1> 	cmp	al, 1Ah ; Unknown media type, non-DOS disk
 16847 0000515B 7468                <1>         je      short cd_command_failed
 16848                              <1> 
 16849                              <1> cd_path_not_found:
 16850 0000515D 6650                <1> 	push	ax	
 16851 0000515F BE[4C970000]        <1> 	mov	esi, Msg_Dir_Not_Found
 16852 00005164 E8D1EAFFFF          <1> 	call	print_msg
 16853 00005169 6658                <1> 	pop	ax
 16854 0000516B 3A25[0CA30000]      <1> 	cmp	ah, [Current_Dir_Level]
 16855 00005171 0F83E3100000        <1>         jnb     change_prompt_dir_string
 16856 00005177 8825[0CA30000]      <1> 	mov	[Current_Dir_Level], ah
 16857 0000517D E9D8100000          <1>         jmp     change_prompt_dir_string   
 16858                              <1> 
 16859                              <1> cmp_cmd_drive: ; change current drive
 16860                              <1> 	; C:, D:, E: etc.
 16861 00005182 80FC3A              <1> 	cmp	ah, ':'
 16862 00005185 0F851E020000        <1>         jne     loc_cmd_failed
 16863                              <1> 
 16864                              <1> cd_2:	; 'CD C:', 'CD D:' ...
 16865 0000518B 803E20              <1> 	cmp	byte [esi], 20h
 16866 0000518E 0F8715020000        <1>         ja      loc_cmd_failed
 16867                              <1> 
 16868 00005194 24DF                <1> 	and	al, 0DFh
 16869 00005196 2C41                <1> 	sub	al, 'A'
 16870 00005198 0F820B020000        <1>         jc      loc_cmd_failed
 16871                              <1> 
 16872 0000519E 3A05[40940000]      <1>         cmp     al, [Last_DOS_DiskNo]
 16873 000051A4 770A                <1>         ja	short cd_drive_not_ready
 16874                              <1> 	
 16875 000051A6 88C2                <1> 	mov	dl, al
 16876 000051A8 E891F3FFFF          <1> 	call 	change_current_drive
 16877 000051AD 7201                <1> 	jc	short cd_drive_not_ready	
 16878 000051AF C3                  <1> 	retn
 16879                              <1> 
 16880                              <1> cd_drive_not_ready:
 16881 000051B0 BE[09970000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 16882 000051B5 E880EAFFFF          <1> 	call	print_msg
 16883                              <1> 
 16884                              <1> cd_fail_drive_restart:
 16885 000051BA 8A15[0EA30000]      <1> 	mov	dl, [Current_Drv]
 16886                              <1> 	;call 	change_current_drive
 16887 000051C0 E979F3FFFF          <1>         jmp     change_current_drive
 16888                              <1> 	;retn
 16889                              <1> 
 16890                              <1> cd_command_failed:
 16891 000051C5 BE[EA960000]        <1> 	mov	esi, Msg_Bad_Command
 16892 000051CA E86BEAFFFF          <1> 	call	print_msg
 16893 000051CF EBE9                <1> 	jmp	short cd_fail_drive_restart
 16894                              <1> 
 16895                              <1> c_3:
 16896                              <1> cmp_cmd_dir:
 16897                              <1> 
 16898 000051D1 BF[A0940000]        <1> 	mov	edi, Cmd_Dir
 16899 000051D6 E8E1010000          <1> 	call	cmp_cmd	
 16900 000051DB 0F8380020000        <1> 	jnc	print_directory_list
 16901                              <1> 
 16902                              <1> cmp_cmd_cls:
 16903 000051E1 B103                <1> 	mov	cl, 3
 16904 000051E3 BF[DC940000]        <1> 	mov	edi, Cmd_Cls
 16905 000051E8 E8CF010000          <1> 	call	cmp_cmd	
 16906 000051ED 0F835EEAFFFF        <1>         jnc	clear_screen
 16907                              <1> 
 16908                              <1> cmp_cmd_ver:
 16909 000051F3 B103                <1> 	mov	cl, 3
 16910 000051F5 BF[AA940000]        <1> 	mov	edi, Cmd_Ver
 16911 000051FA E8BD010000          <1> 	call	cmp_cmd	
 16912 000051FF 720A                <1> 	jc	short cmp_cmd_mem
 16913                              <1> 
 16914 00005201 BE[48940000]        <1> 	mov	esi, mainprog_Version
 16915                              <1> 	;call	print_msg
 16916 00005206 E92FEAFFFF          <1> 	jmp	print_msg
 16917                              <1> 	;retn
 16918                              <1> 
 16919                              <1> cmp_cmd_mem:
 16920 0000520B B103                <1> 	mov	cl, 3
 16921 0000520D BF[12950000]        <1> 	mov	edi, Cmd_Mem
 16922 00005212 E8A5010000          <1> 	call	cmp_cmd	
 16923 00005217 0F8313C7FFFF        <1> 	jnc	memory_info
 16924                              <1> 
 16925                              <1> cmp_cmd_del:
 16926 0000521D B103                <1> 	mov	cl, 3
 16927 0000521F BF[E5940000]        <1> 	mov	edi, Cmd_Del
 16928 00005224 E893010000          <1> 	call	cmp_cmd	
 16929 00005229 0F83030F0000        <1>         jnc     delete_file
 16930                              <1> 
 16931                              <1> cmp_cmd_set:
 16932 0000522F B103                <1> 	mov	cl, 3
 16933 00005231 BF[D8940000]        <1> 	mov	edi, Cmd_Set
 16934 00005236 E881010000          <1> 	call	cmp_cmd	
 16935 0000523B 0F8311100000        <1>         jnc     set_get_env
 16936                              <1> 
 16937                              <1> cmp_cmd_run:
 16938 00005241 B103                <1> 	mov	cl, 3
 16939 00005243 BF[D4940000]        <1> 	mov	edi, Cmd_Run
 16940 00005248 E86F010000          <1> 	call	cmp_cmd	
 16941 0000524D 0F8256010000        <1>         jc      loc_cmd_failed
 16942                              <1> 
 16943 00005253 E8FB0F0000          <1> 	call	set_exec_arguments
 16944 00005258 0F824B010000        <1>         jc      loc_cmd_failed
 16945                              <1> 
 16946 0000525E E8F10F0000          <1> 	call	load_and_execute_file
 16947 00005263 0F826B010000        <1>         jc      loc_run_cmd_failed
 16948 00005269 C3                  <1> 	retn
 16949                              <1> 
 16950                              <1> c_5:
 16951                              <1> cmp_cmd_attrib:
 16952 0000526A BF[E9940000]        <1> 	mov	edi, Cmd_Attrib
 16953 0000526F E848010000          <1> 	call	cmp_cmd	
 16954 00005274 0F83DB0F0000        <1>         jnc     set_file_attributes
 16955                              <1> 
 16956                              <1> cmp_cmd_mkdir:
 16957 0000527A B105                <1> 	mov	cl, 5
 16958 0000527C BF[FD940000]        <1> 	mov	edi, Cmd_Mkdir
 16959 00005281 E836010000          <1> 	call	cmp_cmd	
 16960 00005286 0F83650A0000        <1>         jnc     make_directory
 16961                              <1> 
 16962                              <1> cmp_cmd_rmdir:
 16963 0000528C B105                <1> 	mov	cl, 5
 16964 0000528E BF[F7940000]        <1> 	mov	edi, Cmd_Rmdir
 16965 00005293 E824010000          <1> 	call	cmp_cmd	
 16966 00005298 0F83720B0000        <1>         jnc     delete_directory
 16967                              <1> 
 16968                              <1> cmp_cmd_chdir:
 16969 0000529E B105                <1> 	mov	cl, 5
 16970 000052A0 BF[3D950000]        <1> 	mov	edi, Cmd_Chdir
 16971 000052A5 E812010000          <1> 	call	cmp_cmd	
 16972 000052AA 0F82F9000000        <1> 	jc	loc_cmd_failed
 16973                              <1> 
 16974 000052B0 E97BFEFFFF          <1> 	jmp	cd_0
 16975                              <1> 
 16976                              <1> c_6:
 16977 000052B5 80F906              <1> 	cmp	cl, 6
 16978 000052B8 0F87C5000000        <1>         ja      c_8
 16979 000052BE 72AA                <1> 	jb	short c_5
 16980                              <1> cmp_cmd_prompt:
 16981 000052C0 BF[B3940000]        <1> 	mov	edi, Cmd_Prompt
 16982 000052C5 E8F2000000          <1> 	call	cmp_cmd	
 16983 000052CA 722E                <1>         jc	short cmp_cmd_volume
 16984                              <1> get_prompt_name_fchar:
 16985 000052CC AC                  <1> 	lodsb
 16986 000052CD 3C20                <1> 	cmp	al, 20h
 16987 000052CF 74FB                <1> 	je	short get_prompt_name_fchar
 16988 000052D1 7712                <1> 	ja	short loc_change_prompt_label
 16989 000052D3 BE[94940000]        <1> 	mov	esi, TRDOSPromptLabel
 16990 000052D8 C7065452444F        <1> 	mov	dword [esi], "TRDO"
 16991 000052DE 66C746045300        <1>        	mov	word [esi+4], "S" 
 16992                              <1> loc_cmd_prompt_return:
 16993 000052E4 C3                  <1> 	retn
 16994                              <1> loc_change_prompt_label:
 16995 000052E5 66B90B00            <1> 	mov	cx, 11
 16996 000052E9 BF[94940000]        <1> 	mov	edi, TRDOSPromptLabel
 16997                              <1> put_char_new_prompt_label:
 16998 000052EE AA                  <1> 	stosb
 16999 000052EF AC                  <1> 	lodsb
 17000 000052F0 3C20                <1> 	cmp	al, 20h
 17001 000052F2 7202                <1> 	jb	short pass_put_new_prompt_label
 17002 000052F4 E2F8                <1> 	loop	put_char_new_prompt_label
 17003                              <1> pass_put_new_prompt_label:
 17004 000052F6 C60700              <1> 	mov	byte [edi], 0
 17005 000052F9 C3                  <1> 	retn
 17006                              <1> 
 17007                              <1> cmp_cmd_volume:
 17008 000052FA B106                <1> 	mov	cl, 6
 17009 000052FC BF[BA940000]        <1> 	mov	edi, Cmd_Volume
 17010 00005301 E8B6000000          <1> 	call	cmp_cmd	
 17011 00005306 724D                <1>         jc	short cmp_cmd_rename
 17012                              <1> 
 17013                              <1> cmd_vol1:
 17014 00005308 AC                  <1> 	lodsb
 17015 00005309 3C20                <1> 	cmp	al, 20h
 17016 0000530B 7707                <1> 	ja	short cmd_vol2
 17017 0000530D A0[0EA30000]        <1> 	mov	al, [Current_Drv]
 17018 00005312 EB35                <1> 	jmp	short cmd_vol4
 17019                              <1> cmd_vol2:
 17020 00005314 3C41                <1> 	cmp	al, 'A'
 17021 00005316 0F828D000000        <1>         jb      loc_cmd_failed
 17022 0000531C 3C7A                <1> 	cmp	al, 'z'
 17023 0000531E 0F8785000000        <1>         ja      loc_cmd_failed
 17024 00005324 3C5A                <1> 	cmp	al, 'Z'
 17025 00005326 7606                <1> 	jna	short cmd_vol3
 17026 00005328 3C61                <1> 	cmp	al, 'a'
 17027 0000532A 727D                <1> 	jb	short loc_cmd_failed
 17028 0000532C 24DF                <1> 	and	al, 0DFh
 17029                              <1> cmd_vol3:
 17030 0000532E 8A26                <1> 	mov	ah, [esi]
 17031 00005330 80FC3A              <1> 	cmp	ah, ':'
 17032 00005333 7574                <1> 	jne	short loc_cmd_failed
 17033 00005335 2C41                <1> 	sub	al, 'A'
 17034 00005337 3A05[40940000]      <1>         cmp     al, [Last_DOS_DiskNo]
 17035 0000533D 760A                <1> 	jna	short cmd_vol4
 17036                              <1> 
 17037 0000533F BE[09970000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17038 00005344 E9F1E8FFFF          <1> 	jmp	print_msg
 17039                              <1> 	
 17040                              <1> cmd_vol4:
 17041 00005349 E8A6FAFFFF          <1> 	call	print_volume_info
 17042 0000534E 0F825CFEFFFF        <1>         jc      cd_drive_not_ready
 17043 00005354 C3                  <1> 	retn
 17044                              <1> 
 17045                              <1> cmp_cmd_rename:
 17046 00005355 B106                <1> 	mov	cl, 6
 17047 00005357 BF[F0940000]        <1> 	mov	edi, Cmd_Rename
 17048 0000535C E85B000000          <1> 	call	cmp_cmd	
 17049 00005361 0F83EF0E0000        <1>         jnc     rename_file
 17050                              <1> 
 17051                              <1> cmp_cmd_device:
 17052 00005367 B106                <1> 	mov	cl, 6
 17053 00005369 BF[2E950000]        <1> 	mov	edi, Cmd_Device
 17054 0000536E E849000000          <1> 	call	cmp_cmd	
 17055 00005373 7234                <1>         jc	short loc_cmd_failed
 17056                              <1> 
 17057 00005375 C3                  <1> 	retn
 17058                              <1> 
 17059                              <1> c_7:
 17060                              <1> cmp_cmd_devlist:
 17061 00005376 BF[35950000]        <1> 	mov	edi, Cmd_DevList
 17062 0000537B E83C000000          <1> 	call	cmp_cmd	
 17063 00005380 7227                <1>         jc	short loc_cmd_failed
 17064                              <1> 
 17065 00005382 C3                  <1> 	retn
 17066                              <1> 
 17067                              <1> c_8:
 17068 00005383 80F908              <1>         cmp	cl, 8
 17069 00005386 7721                <1> 	ja	short cmp_cmd_external
 17070 00005388 72EC                <1> 	jb	short c_7
 17071                              <1> 
 17072                              <1> cmp_cmd_longname:
 17073 0000538A BF[C1940000]        <1> 	mov	edi, Cmd_LongName
 17074 0000538F E828000000          <1> 	call	cmp_cmd	
 17075 00005394 0F8341060000        <1>         jnc     get_and_print_longname
 17076                              <1> 
 17077                              <1> cmp_cmd_readfile:
 17078 0000539A B108                <1> 	mov	cl, 8
 17079 0000539C BF[1C950000]        <1> 	mov	edi, Cmd_ReadFile
 17080 000053A1 E816000000          <1> 	call	cmp_cmd	
 17081 000053A6 7201                <1>         jc	short loc_cmd_failed
 17082                              <1> 
 17083                              <1> loc_cmd_return:
 17084 000053A8 C3                  <1> 	retn
 17085                              <1> 
 17086                              <1> cmp_cmd_external:
 17087                              <1> loc_cmd_failed:
 17088 000053A9 803D[BEA30000]20    <1> 	cmp	byte [CommandBuffer], 20h
 17089 000053B0 76F6                <1> 	jna	short loc_cmd_return
 17090 000053B2 BE[EA960000]        <1> 	mov	esi, Msg_Bad_Command
 17091                              <1> ;	call	print_msg
 17092                              <1> ;loc_cmd_return:
 17093                              <1> ;	retn
 17094 000053B7 E97EE8FFFF          <1> 	jmp	print_msg
 17095                              <1> 
 17096                              <1> cmp_cmd:
 17097                              <1> 	 ; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
 17098 000053BC BE[BEA30000]        <1>          mov  esi, CommandBuffer
 17099                              <1>          ; edi = internal command word (ASCIIZ)
 17100                              <1> 	 ; ecx = command length (<=8)
 17101                              <1> cmp_cmd_1:
 17102 000053C1 AC                  <1> 	lodsb
 17103 000053C2 AE                  <1> 	scasb
 17104 000053C3 750D                <1> 	jne	short cmp_cmd_3
 17105 000053C5 E2FA                <1> 	loop	cmp_cmd_1
 17106 000053C7 AC                  <1>  	lodsb
 17107 000053C8 3C20                <1> 	cmp	al, 20h
 17108 000053CA 7703                <1> 	ja	short cmp_cmd_2
 17109 000053CC 30C0                <1> 	xor	al, al
 17110                              <1> 	; ZF = 1 -> internal command word matches
 17111 000053CE C3                  <1> 	retn
 17112                              <1> cmp_cmd_2:
 17113                              <1> 	; ZF = 0 (CF = 0) -> external command word 	
 17114 000053CF 58                  <1> 	pop	eax ; no return to the caller from here 
 17115 000053D0 EBD7                <1> 	jmp	cmp_cmd_external	
 17116                              <1> cmp_cmd_3:
 17117 000053D2 F9                  <1> 	stc
 17118                              <1> 	; CF = 1 -> internal command word does not match
 17119 000053D3 C3                  <1> 	retn
 17120                              <1> 
 17121                              <1> loc_run_cmd_failed:
 17122                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17123                              <1> 	; 07/12/2009 (CMD_INTR.ASM)	
 17124                              <1> 	; 29/11/2009
 17125                              <1> 
 17126 000053D4 E855000000          <1> 	call	restore_cdir_after_cmd_fail
 17127                              <1> 
 17128                              <1> loc_run_cmd_failed_cmp_al:
 17129                              <1> 	; End of Restore_CDIR code (29/11/2009)
 17130                              <1> 
 17131 000053D9 3C01                <1> 	cmp	al, 1
 17132 000053DB 74CC                <1> 	je	loc_cmd_failed
 17133                              <1> loc_run_dir_not_found:
 17134 000053DD 3C03                <1> 	cmp	al, 3
 17135 000053DF 750A                <1> 	jne	short loc_run_file_notfound_msg
 17136                              <1> 	; Path not found (MS-DOS Error Code = 3)
 17137 000053E1 BE[4C970000]        <1> 	mov	esi, Msg_Dir_Not_Found
 17138 000053E6 E94FE8FFFF          <1> 	jmp	print_msg
 17139                              <1> 
 17140                              <1> loc_run_file_notfound_msg:
 17141 000053EB 3C02                <1> 	cmp	al, 2 ; File not found
 17142 000053ED 750A                <1> 	jne	short loc_run_file_drv_read_err
 17143                              <1> 
 17144                              <1> loc_print_file_notfound_msg: 
 17145 000053EF BE[63970000]        <1>         mov     esi, Msg_File_Not_Found
 17146                              <1> 	;call	proc_printmsg
 17147                              <1> 	;retn
 17148 000053F4 E941E8FFFF          <1> 	jmp	print_msg
 17149                              <1> 
 17150                              <1> loc_run_file_drv_read_err:
 17151                              <1> 	; 16/05/2010 -> Err: 1Eh (Read fault)
 17152 000053F9 3C1E                <1> 	cmp	al, 1Eh ; Drive not ready or read error
 17153 000053FB 7404                <1> 	je	short loc_run_file_print_drv_read_err
 17154                              <1> 	;
 17155 000053FD 3C15                <1> 	cmp	al, 15h ; Drive not ready (or read error)
 17156 000053FF 750A                <1> 	jne	short loc_run_file_toobig
 17157                              <1> 
 17158                              <1> loc_run_file_print_drv_read_err:
 17159 00005401 BE[09970000]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
 17160 00005406 E92FE8FFFF          <1> 	jmp	print_msg
 17161                              <1> 
 17162                              <1> loc_run_file_toobig:
 17163 0000540B 3C08                <1> 	cmp	al, 8 ; Not enough free memory to load&run file
 17164 0000540D 750A                <1> 	jne	short loc_run_misc_error
 17165 0000540F BE[AB970000]        <1> 	mov	esi, Msg_Insufficient_Memory
 17166 00005414 E921E8FFFF          <1> 	jmp	print_msg
 17167                              <1> 
 17168                              <1> loc_run_misc_error:
 17169 00005419 E888C5FFFF          <1> 	call	bytetohex ; 15/02/2016
 17170 0000541E 66A3[DF970000]      <1> 	mov	[Error_Code], ax
 17171                              <1> 	
 17172 00005424 BE[C2970000]        <1> 	mov	esi, Msg_Error_Code 
 17173 00005429 E90CE8FFFF          <1> 	jmp	print_msg
 17174                              <1> 
 17175                              <1> restore_cdir_after_cmd_fail:
 17176                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17177 0000542E 50                  <1> 	push	eax
 17178 0000542F 8A3D[6EAB0000]      <1> 	mov	bh, [RUN_CDRV] ; it is set at the beginning
 17179                              <1> 				; of the 'run' command.
 17180 00005435 3A3D[0EA30000]      <1> 	cmp	bh, [Current_Drv]
 17181 0000543B 7409                <1> 	je	short loc_run_restore_cdir
 17182 0000543D 88FA                <1> 	mov	dl, bh
 17183 0000543F E8FAF0FFFF          <1> 	call	change_current_drive 
 17184 00005444 EB19                <1> 	jmp	short loc_run_err_pass_restore_cdir
 17185                              <1> 
 17186                              <1> loc_run_restore_cdir:
 17187 00005446 803D[41940000]00    <1> 	cmp	byte [Restore_CDIR], 0
 17188 0000544D 7610                <1> 	jna	short loc_run_err_pass_restore_cdir
 17189 0000544F 30DB                <1> 	xor	bl, bl
 17190 00005451 0FB7F3              <1> 	movzx	esi, bx
 17191 00005454 81C600010900        <1> 	add	esi, Logical_DOSDisks
 17192 0000545A E891F1FFFF          <1> 	call	restore_current_directory
 17193                              <1> 
 17194                              <1> loc_run_err_pass_restore_cdir:
 17195 0000545F 58                  <1> 	pop	eax
 17196 00005460 C3                  <1> 	retn
 17197                              <1> 
 17198                              <1> print_directory_list:
 17199                              <1> 	; 10/02/2016
 17200                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17201                              <1> 	; 06/12/2009 ('cmp_cmd_dir')	
 17202                              <1> 	;
 17203 00005461 66C705[B0AC0000]00- <1> 	mov	word [AttributesMask], 0800h ; ..except volume names..
 17204 00005469 08                  <1>
 17205 0000546A A0[0EA30000]        <1> 	mov	al, [Current_Drv]
 17206 0000546F A2[6EAB0000]        <1> 	mov	[RUN_CDRV], al
 17207                              <1> get_dfname_fchar:
 17208 00005474 AC                  <1> 	lodsb
 17209 00005475 3C20                <1> 	cmp	al, 20h
 17210 00005477 74FB                <1> 	je	short get_dfname_fchar
 17211 00005479 0F82A4000000        <1>         jb      loc_print_dir_call_all
 17212 0000547F 3C2D                <1> 	cmp	al, '-'
 17213 00005481 7542                <1> 	jne	short loc_print_dir_call_flt
 17214                              <1> get_next_attr_char:
 17215 00005483 AC                  <1> 	lodsb
 17216 00005484 3C20                <1> 	cmp	al, 20h
 17217 00005486 74FB                <1> 	je	short get_next_attr_char
 17218 00005488 0F821BFFFFFF        <1>         jb      loc_cmd_failed
 17219 0000548E 24DF                <1> 	and	al, 0DFh
 17220 00005490 3C44                <1> 	cmp	al, 'D' ; directories only ?
 17221 00005492 7512                <1> 	jne	short pass_only_directories
 17222 00005494 AC                  <1> 	lodsb
 17223 00005495 3C20                <1> 	cmp	al, 20h
 17224 00005497 0F870CFFFFFF        <1>         ja      loc_cmd_failed
 17225 0000549D 800D[B0AC0000]10    <1> 	or	byte [AttributesMask], 10h ; ..directory..
 17226 000054A4 EB18                <1> 	jmp	short get_dfname_fchar_attr
 17227                              <1> pass_only_directories:
 17228 000054A6 3C46                <1> 	cmp	al, 'F'	; files only ?
 17229 000054A8 0F85B0000000        <1>         jne     check_attr_s
 17230 000054AE AC                  <1> 	lodsb
 17231 000054AF 3C20                <1> 	cmp	al, 20h
 17232 000054B1 0F87F2FEFFFF        <1>         ja      loc_cmd_failed
 17233 000054B7 800D[B1AC0000]10    <1> 	or	byte [AttributesMask+1], 10h ; ..except directories..
 17234                              <1> get_dfname_fchar_attr:
 17235 000054BE AC                  <1> 	lodsb
 17236 000054BF 3C20                <1> 	cmp	al, 20h
 17237 000054C1 74FB                <1> 	je	short get_dfname_fchar_attr
 17238 000054C3 725E                <1> 	jb	short loc_print_dir_call_all
 17239                              <1> 
 17240                              <1> loc_print_dir_call_flt:
 17241 000054C5 4E                  <1> 	dec	esi
 17242 000054C6 BF[B2AC0000]        <1> 	mov	edi, FindFile_Drv
 17243 000054CB E86E140000          <1> 	call	parse_path_name
 17244 000054D0 7308                <1>  	jnc	short loc_print_dir_change_drv_1
 17245 000054D2 3C01                <1> 	cmp	al, 1
 17246 000054D4 0F87FAFEFFFF        <1>         ja      loc_run_cmd_failed
 17247                              <1> 
 17248                              <1> loc_print_dir_change_drv_1:
 17249 000054DA 8A15[B2AC0000]      <1> 	mov	dl, [FindFile_Drv]
 17250                              <1> loc_print_dir_change_drv_2:
 17251 000054E0 3A15[6EAB0000]      <1> 	cmp	dl, [RUN_CDRV]
 17252 000054E6 740B                <1> 	je	short loc_print_dir_change_directory 
 17253 000054E8 E851F0FFFF          <1> 	call	change_current_drive
 17254 000054ED 0F82E1FEFFFF        <1>         jc      loc_run_cmd_failed
 17255                              <1> loc_print_dir_change_directory:
 17256 000054F3 803D[B3AC0000]20    <1> 	cmp	byte [FindFile_Directory], 20h ; 0 or 20h ?
 17257 000054FA 761D                <1> 	jna	short pass_print_dir_change_directory
 17258                              <1> 
 17259 000054FC FE05[41940000]      <1> 	inc	byte [Restore_CDIR]
 17260 00005502 BE[B3AC0000]        <1> 	mov	esi, FindFile_Directory
 17261 00005507 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 17262 00005509 E82C0E0000          <1> 	call	change_current_directory
 17263 0000550E 0F82C0FEFFFF        <1>         jc      loc_run_cmd_failed
 17264                              <1> 
 17265                              <1> loc_print_dir_change_prompt_dir_string:
 17266 00005514 E8410D0000          <1> 	call	change_prompt_dir_string
 17267                              <1> 
 17268                              <1> pass_print_dir_change_directory:
 17269 00005519 BE[F4AC0000]        <1> 	mov	esi, FindFile_Name
 17270 0000551E 803E20              <1> 	cmp	byte [esi], 20h ; ; 0 or 20h ?
 17271 00005521 7706                <1> 	ja	short loc_print_dir_call
 17272                              <1> 
 17273                              <1> loc_print_dir_call_all:
 17274 00005523 C7062A2E2A00        <1> 	mov	dword [esi], '*.*'
 17275                              <1> loc_print_dir_call:
 17276 00005529 E87E000000          <1> 	call	print_directory
 17277                              <1> 
 17278 0000552E 8A15[6EAB0000]      <1> 	mov	dl, [RUN_CDRV]  ; it is set at the beginning
 17279 00005534 3A15[0EA30000]      <1> 	cmp	dl, [Current_Drv]
 17280 0000553A 7406                <1> 	je	short loc_print_dir_call_restore_cdir_retn
 17281 0000553C E8FDEFFFFF          <1> 	call	change_current_drive 
 17282 00005541 C3                  <1> 	retn
 17283                              <1> 
 17284                              <1> loc_print_dir_call_restore_cdir_retn:
 17285 00005542 803D[41940000]00    <1> 	cmp	byte [Restore_CDIR], 0
 17286 00005549 7610                <1> 	jna	short pass_print_dir_call_restore_cdir_retn
 17287                              <1> 
 17288 0000554B BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17289 00005550 31C0                <1> 	xor	eax, eax
 17290 00005552 88D4                <1> 	mov	ah, dl
 17291 00005554 01C6                <1> 	add	esi, eax
 17292                              <1> 
 17293 00005556 E895F0FFFF          <1> 	call	restore_current_directory
 17294                              <1> 
 17295                              <1> pass_print_dir_call_restore_cdir_retn:
 17296 0000555B C3                  <1> 	retn
 17297                              <1> 
 17298                              <1> check_attr_s_cap:
 17299 0000555C 24DF                <1> 	and	al, 0DFh
 17300                              <1> check_attr_s:
 17301 0000555E 3C53                <1> 	cmp	al, 'S'
 17302 00005560 7514                <1> 	jne	short pass_attr_s
 17303 00005562 800D[B0AC0000]04    <1> 	or	byte [AttributesMask], 4 ; system
 17304 00005569 AC                  <1> 	lodsb
 17305 0000556A 3C20                <1> 	cmp	al, 20h
 17306 0000556C 0F844CFFFFFF        <1>         je      get_dfname_fchar_attr
 17307 00005572 72AF                <1> 	jb	short loc_print_dir_call_all
 17308 00005574 24DF                <1> 	and	al, 0DFh
 17309                              <1> pass_attr_s:
 17310 00005576 3C48                <1> 	cmp	al, 'H'
 17311 00005578 7514                <1> 	jne	short pass_attr_h
 17312 0000557A 800D[B0AC0000]02    <1> 	or	byte [AttributesMask], 2 ; hidden
 17313                              <1> pass_attr_shr:
 17314 00005581 AC                  <1> 	lodsb
 17315 00005582 3C20                <1> 	cmp	al, 20h
 17316 00005584 0F8434FFFFFF        <1>         je      get_dfname_fchar_attr
 17317 0000558A 7297                <1> 	jb	short loc_print_dir_call_all
 17318 0000558C EBCE                <1> 	jmp	short check_attr_s_cap
 17319                              <1> 
 17320                              <1> pass_attr_h:
 17321 0000558E 3C52                <1> 	cmp	al, 'R'
 17322 00005590 7509                <1> 	jne	short pass_attr_r
 17323 00005592 800D[B0AC0000]01    <1> 	or	byte [AttributesMask], 1 ; read only
 17324 00005599 EBE6                <1> 	jmp	short pass_attr_shr
 17325                              <1> 
 17326                              <1> pass_attr_r:
 17327 0000559B 3C41                <1> 	cmp	al, 'A'
 17328 0000559D 0F8506FEFFFF        <1>         jne     loc_cmd_failed
 17329 000055A3 800D[B0AC0000]20    <1> 	or	byte [AttributesMask], 20h ; archive
 17330 000055AA EBD5                <1> 	jmp	short pass_attr_shr
 17331                              <1> 
 17332                              <1> print_directory:
 17333                              <1> 	; 11/02/2016
 17334                              <1> 	; 10/02/2016
 17335                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17336                              <1> 	; 30/10/2010 ('proc_print_directory')	
 17337                              <1> 	; 19/09/2009
 17338                              <1> 	; 2005 
 17339                              <1> 	; INPUT ->
 17340                              <1> 	;	ESI = Asciiz File/Dir Name Address
 17341                              <1> 
 17342 000055AC 56                  <1> 	push	esi
 17343                              <1> 
 17344 000055AD 29C0                <1> 	sub	eax, eax
 17345                              <1> 
 17346 000055AF 66A3[3AAD0000]      <1> 	mov	word [Dir_Count], ax ; 0
 17347 000055B5 66A3[38AD0000]      <1> 	mov 	word [File_Count], ax ; 0
 17348 000055BB A3[3CAD0000]        <1> 	mov 	dword [Total_FSize], eax ; 0
 17349                              <1> 
 17350 000055C0 E88CE6FFFF          <1> 	call    clear_screen
 17351                              <1> 	
 17352 000055C5 31C9                <1> 	xor	ecx, ecx	
 17353 000055C7 8A2D[0EA30000]      <1> 	mov     ch, [Current_Drv] ; DirBuff_Drv - 'A'
 17354 000055CD A0[0FA30000]        <1> 	mov     al, [Current_Dir_Drv] 
 17355 000055D2 A2[07960000]        <1> 	mov     [Dir_Drive_Name], al
 17356 000055D7 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17357 000055DC 01CE                <1> 	add	esi, ecx
 17358                              <1> 
 17359 000055DE E877F9FFFF          <1> 	call	move_volume_name_and_serial_no
 17360 000055E3 7306                <1> 	jnc	short print_dir_strlen_check
 17361                              <1> 
 17362 000055E5 5E                  <1> 	pop	esi
 17363                              <1> 	;call	beeper
 17364                              <1> 	;retn
 17365 000055E6 E9A9C2FFFF          <1> 	jmp	beeper  ; beep ! and return
 17366                              <1> 
 17367                              <1> print_dir_strlen_check:
 17368 000055EB BE[11A30000]        <1> 	mov	esi, Current_Dir_Root
 17369 000055F0 BF[A4960000]        <1> 	mov	edi, Dir_Str_Root
 17370                              <1> 	
 17371                              <1> 	;xor	ecx, ecx
 17372 000055F5 8A0D[6DA30000]      <1>         mov     cl, [Current_Dir_StrLen]
 17373 000055FB FEC1                <1> 	inc	cl
 17374 000055FD 80F940              <1> 	cmp	cl, 64
 17375 00005600 760D                <1> 	jna	short pass_print_dir_strlen_shorting
 17376 00005602 46                  <1> 	inc	esi
 17377 00005603 01CE                <1> 	add	esi, ecx
 17378 00005605 83EE40              <1> 	sub	esi, 64 
 17379 00005608 47                  <1> 	inc	edi
 17380 00005609 B82E2E2E20          <1> 	mov	eax, '... ' 
 17381 0000560E AB                  <1> 	stosd
 17382                              <1>  
 17383                              <1> pass_print_dir_strlen_shorting:
 17384 0000560F F3A4                <1> 	rep	movsb
 17385                              <1> 
 17386 00005611 BE[FA950000]        <1> 	mov	esi, Dir_Drive_Str
 17387 00005616 E81FE6FFFF          <1> 	call	print_msg
 17388                              <1> 
 17389 0000561B BE[59960000]        <1> 	mov	esi, Vol_Serial_Header
 17390 00005620 E815E6FFFF          <1> 	call	print_msg
 17391                              <1> 
 17392 00005625 BE[99960000]        <1> 	mov	esi, Dir_Str_Header
 17393 0000562A E80BE6FFFF          <1> 	call	print_msg
 17394                              <1> 	
 17395 0000562F BE[249F0000]        <1> 	mov	esi, next2line
 17396 00005634 E801E6FFFF          <1> 	call	print_msg
 17397                              <1> 
 17398                              <1> loc_print_dir_first_file:
 17399 00005639 C605[4FAD0000]10    <1> 	mov	byte [PrintDir_RowCounter], 16
 17400 00005640 66A1[B0AC0000]      <1> 	mov	ax, [AttributesMask]
 17401 00005646 5E                  <1> 	pop	esi
 17402                              <1> 
 17403 00005647 E859020000          <1> 	call	find_first_file
 17404 0000564C 0F826F010000        <1>         jc      loc_dir_ok
 17405                              <1> 	 
 17406                              <1> loc_dfname_use_this:
 17407                              <1> 	; bl =	File Attributes (bh = Long Name Entry Length)
 17408 00005652 F6C310              <1> 	test	bl, 10h  ; Is it a directory?
 17409 00005655 741B                <1> 	jz	short loc_not_dir
 17410                              <1> 
 17411 00005657 66FF05[3AAD0000]    <1> 	inc	word [Dir_Count]
 17412 0000565E 89F2                <1> 	mov	edx, esi 	; FindFile_DirEntry address
 17413 00005660 BE[E6970000]        <1>  	mov	esi, Type_Dir	; '<DIR>     '
 17414 00005665 BF[FD970000]        <1> 	mov	edi, Dir_Or_FileSize
 17415                              <1> 	; move 10 bytes
 17416 0000566A A5                  <1> 	movsd
 17417 0000566B A5                  <1> 	movsd
 17418 0000566C 66A5                <1> 	movsw	    	
 17419 0000566E 89D6                <1> 	mov	esi, edx
 17420 00005670 EB36                <1> 	jmp     short loc_dir_attribute
 17421                              <1> 
 17422                              <1> loc_not_dir:
 17423 00005672 66FF05[38AD0000]    <1> 	inc	word [File_Count]
 17424 00005679 0105[3CAD0000]      <1> 	add	[Total_FSize], eax
 17425                              <1> 
 17426 0000567F B90A000000          <1> 	mov	ecx, 10  ; 32 bit divisor
 17427 00005684 89CF                <1> 	mov	edi, ecx
 17428 00005686 81C7[FD970000]      <1> 	add	edi, Dir_Or_FileSize
 17429                              <1> loc_dir_rdivide:
 17430 0000568C 29D2                <1> 	sub	edx, edx
 17431 0000568E F7F1                <1> 	div	ecx 	 ; remainder in dl (< 10)
 17432 00005690 80C230              <1> 	add     dl, '0'	 ; to make visible (ascii)
 17433 00005693 4F                  <1> 	dec	edi
 17434 00005694 8817                <1> 	mov     [edi], dl
 17435 00005696 21C0                <1> 	and	eax, eax
 17436 00005698 75F2                <1> 	jnz	short loc_dir_rdivide
 17437                              <1> 
 17438                              <1> loc_dir_fill_space:
 17439 0000569A 81FF[FD970000]      <1> 	cmp     edi, Dir_Or_FileSize
 17440 000056A0 7606                <1> 	jna     short loc_dir_attribute
 17441 000056A2 4F                  <1> 	dec     edi
 17442 000056A3 C60720              <1> 	mov     byte [edi], 20h
 17443 000056A6 EBF2                <1> 	jmp     short loc_dir_fill_space
 17444                              <1> 
 17445                              <1> loc_dir_attribute:
 17446 000056A8 C705[08980000]2020- <1> 	mov	dword [File_Attribute], 20202020h
 17447 000056B0 2020                <1>
 17448                              <1> 
 17449 000056B2 80FB20              <1> 	cmp	bl, 20h  ; Is it an archive file?
 17450 000056B5 7207                <1> 	jb	short loc_dir_pass_arch
 17451 000056B7 C605[0B980000]41    <1> 	mov	byte [File_Attribute+3], 'A'
 17452                              <1> 
 17453                              <1> loc_dir_pass_arch:
 17454 000056BE 80E307              <1> 	and	bl, 7
 17455 000056C1 7428                <1> 	jz	short loc_dir_file_name
 17456 000056C3 88DF                <1> 	mov	bh, bl
 17457 000056C5 80E303              <1> 	and	bl, 3
 17458 000056C8 38DF                <1> 	cmp	bh, bl
 17459 000056CA 7607                <1> 	jna	short loc_dir_pass_s
 17460 000056CC C605[08980000]53    <1> 	mov	byte [File_Attribute], 'S'
 17461                              <1> 
 17462                              <1> loc_dir_pass_s:
 17463 000056D3 80E302              <1> 	and     bl,2
 17464 000056D6 7407                <1> 	jz      short loc_dir_pass_h
 17465 000056D8 C605[09980000]48    <1> 	mov     byte [File_Attribute+1], 'H'
 17466                              <1> loc_dir_pass_h:
 17467 000056DF 80E701              <1> 	and     bh,1
 17468 000056E2 7407                <1> 	jz      short loc_dir_file_name
 17469 000056E4 C605[0A980000]52    <1> 	mov     byte [File_Attribute+2], 'R'
 17470                              <1> loc_dir_file_name:
 17471                              <1> 	;mov     bx, [esi+18h] ; Date
 17472                              <1> 	;mov     dx, [esi+16h] ; Time
 17473 000056EB 8B5E16              <1> 	mov	ebx, [esi+16h]
 17474 000056EE 89F1                <1> 	mov	ecx, esi ; FindFile_DirEntry address
 17475 000056F0 BF[F0970000]        <1> 	mov     edi, File_Name
 17476                              <1> 	; move 8 bytes
 17477 000056F5 A5                  <1> 	movsd
 17478 000056F6 A5                  <1> 	movsd
 17479 000056F7 C60720              <1> 	mov	byte [edi], 20h
 17480 000056FA 47                  <1> 	inc	edi
 17481                              <1> 	; move 3 bytes
 17482 000056FB 66A5                <1> 	movsw
 17483 000056FD A4                  <1> 	movsb
 17484 000056FE 89CE                <1> 	mov	esi, ecx
 17485                              <1> 
 17486                              <1> Dir_Time_start:
 17487                              <1> 	;mov	ax, dx		; Time
 17488 00005700 6689D8              <1> 	mov	ax, bx
 17489 00005703 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
 17490 00005707 6683E03F            <1> 	and	ax, 0000111111b	; Minute Mask
 17491 0000570B D40A                <1> 	aam			; Q([AL]/10)->AH
 17492                              <1> 				; R([AL]/10)->AL
 17493                              <1> 				; [AL]+[AH]= Minute as BCD
 17494 0000570D 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
 17495 00005711 86E0                <1> 	xchg	ah, al
 17496 00005713 66A3[1B980000]      <1> 	mov	[File_Minute], ax
 17497                              <1> 
 17498                              <1> 	;mov	al, dh
 17499 00005719 88F8                <1> 	mov	al, bh
 17500 0000571B C0E803              <1> 	shr	al, 3		; shift right 3 times
 17501 0000571E D40A                <1> 	aam			; [AL]+[AH]= Hours as BCD
 17502 00005720 660D3030            <1> 	or	ax, '00'
 17503 00005724 86E0                <1> 	xchg	ah, al
 17504 00005726 66A3[18980000]      <1> 	mov     [File_Hour], ax
 17505                              <1> 
 17506 0000572C C1EB10              <1> 	shr	ebx, 16		; BX = Date
 17507                              <1> 	
 17508                              <1> Dir_Date_start:
 17509 0000572F 6689D8              <1> 	mov	ax, bx		; Date
 17510 00005732 6683E01F            <1> 	and	ax, 00011111b	; Day Mask
 17511 00005736 D40A                <1> 	aam			; Q([AL]/10)->AH
 17512                              <1> 				; R([AL]/10)->AL
 17513                              <1> 				; [AL]+[AH]= Day as BCD
 17514 00005738 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
 17515 0000573C 86C4                <1> 	xchg	al, ah
 17516                              <1> 
 17517 0000573E 66A3[0D980000]      <1> 	mov	[File_Day], ax
 17518                              <1> 
 17519 00005744 6689D8              <1> 	mov	ax, bx
 17520 00005747 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
 17521 0000574B 6683E00F            <1> 	and	ax, 00001111b	; Month Mask
 17522 0000574F D40A                <1> 	aam
 17523 00005751 660D3030            <1> 	or	ax, '00'
 17524 00005755 86E0                <1> 	xchg	ah, al
 17525 00005757 66A3[10980000]      <1> 	mov	[File_Month], ax
 17526                              <1> 
 17527 0000575D 6689D8              <1> 	mov	ax, bx
 17528 00005760 66C1E809            <1> 	shr     ax, 9
 17529 00005764 6683E07F            <1> 	and	ax, 01111111b	; Result = Year - 1980
 17530 00005768 6605BC07            <1> 	add	ax, 1980
 17531                              <1> 
 17532 0000576C B10A                <1> 	mov	cl, 10
 17533 0000576E F6F1                <1> 	div	cl		; Q -> AL, R -> AH 
 17534 00005770 80CC30              <1> 	or	ah, '0'
 17535 00005773 8825[16980000]      <1> 	mov	[File_Year+3], ah
 17536 00005779 D40A                <1> 	aam
 17537 0000577B 86E0                <1> 	xchg	ah, al
 17538 0000577D 80CC30              <1> 	or	ah, '0'	  ; Convert to ASCII
 17539 00005780 8825[15980000]      <1> 	mov	[File_Year+2], ah
 17540 00005786 D40A                <1> 	aam
 17541 00005788 86C4                <1> 	xchg	al, ah
 17542 0000578A 660D3030            <1> 	or	ax, '00'
 17543 0000578E 66A3[13980000]      <1> 	mov	[File_Year], ax
 17544                              <1> 
 17545                              <1> loc_show_line:
 17546 00005794 56                  <1> 	push	esi
 17547 00005795 BE[F0970000]        <1> 	mov     esi, File_Name
 17548 0000579A E89BE4FFFF          <1> 	call	print_msg
 17549 0000579F BE[269F0000]        <1> 	mov	esi, nextline
 17550 000057A4 E891E4FFFF          <1> 	call	print_msg
 17551 000057A9 5E                  <1> 	pop	esi
 17552                              <1> 
 17553 000057AA FE0D[4FAD0000]      <1> 	dec	byte [PrintDir_RowCounter]
 17554 000057B0 0F84D4000000        <1>         jz      pause_dir_scroll
 17555                              <1> 
 17556                              <1> loc_next_entry:
 17557 000057B6 E899010000          <1> 	call	find_next_file
 17558 000057BB 0F8391FEFFFF        <1>         jnc     loc_dfname_use_this
 17559                              <1> 
 17560                              <1> loc_dir_ok:
 17561 000057C1 B90A000000          <1> 	mov     ecx, 10
 17562 000057C6 66A1[3AAD0000]      <1> 	mov	ax, [Dir_Count]
 17563 000057CC BF[31980000]        <1> 	mov	edi, Decimal_Dir_Count
 17564 000057D1 6639C8              <1> 	cmp	ax, cx ; 10
 17565 000057D4 7216                <1> 	jb	short pass_ddc
 17566 000057D6 47                  <1> 	inc	edi
 17567 000057D7 6683F864            <1> 	cmp	ax, 100
 17568 000057DB 720F                <1> 	jb	short pass_ddc
 17569 000057DD 47                  <1> 	inc	edi
 17570 000057DE 663DE803            <1> 	cmp	ax, 1000
 17571 000057E2 7208                <1> 	jb	short pass_ddc
 17572 000057E4 47                  <1> 	inc	edi
 17573 000057E5 663D1027            <1> 	cmp	ax, 10000
 17574 000057E9 7201                <1> 	jb	short pass_ddc
 17575 000057EB 47                  <1> 	inc	edi
 17576                              <1> pass_ddc:
 17577 000057EC 886F01              <1> 	mov     [edi+1], ch ; 0
 17578                              <1> loc_ddc_rediv:
 17579 000057EF 31D2                <1> 	xor     edx, edx
 17580 000057F1 66F7F1              <1> 	div     cx	; 10
 17581 000057F4 80C230              <1> 	add     dl, '0'
 17582 000057F7 8817                <1> 	mov     [edi], dl
 17583 000057F9 4F                  <1> 	dec     edi
 17584 000057FA 6609C0              <1> 	or	ax, ax
 17585 000057FD 75F0                <1> 	jnz	short loc_ddc_rediv
 17586                              <1> 
 17587 000057FF 66A1[38AD0000]      <1> 	mov     ax, [File_Count]
 17588 00005805 BF[20980000]        <1> 	mov     edi, Decimal_File_Count
 17589 0000580A 6639C8              <1> 	cmp     ax, cx ; 10
 17590 0000580D 7216                <1> 	jb      short pass_dfc
 17591 0000580F 47                  <1> 	inc     edi
 17592 00005810 6683F864            <1> 	cmp     ax, 100
 17593 00005814 720F                <1> 	jb      short pass_dfc
 17594 00005816 47                  <1> 	inc     edi
 17595 00005817 663DE803            <1> 	cmp     ax, 1000
 17596 0000581B 7208                <1> 	jb      short pass_dfc
 17597 0000581D 47                  <1> 	inc     edi
 17598 0000581E 663D1027            <1> 	cmp     ax, 10000
 17599 00005822 7201                <1> 	jb      short pass_dfc
 17600 00005824 47                  <1> 	inc     edi
 17601                              <1> pass_dfc:
 17602                              <1> 	;mov    cx, 10
 17603 00005825 886F01              <1> 	mov     [edi+1], ch ; 00
 17604                              <1> loc_dfc_rediv:
 17605                              <1> 	;xor	dx, dx
 17606 00005828 30D2                <1> 	xor	dl, dl
 17607 0000582A 66F7F1              <1> 	div	cx
 17608 0000582D 80C230              <1> 	add	dl, '0'
 17609 00005830 8817                <1> 	mov	[edi], dl
 17610 00005832 4F                  <1> 	dec	edi
 17611 00005833 6609C0              <1> 	or	ax, ax
 17612 00005836 75F0                <1> 	jnz	short loc_dfc_rediv
 17613                              <1> 
 17614 00005838 BF[4EAD0000]        <1> 	mov     edi, TFS_Dec_End
 17615                              <1>         ;mov    byte [edi], 0
 17616 0000583D A1[3CAD0000]        <1> 	mov     eax, [Total_FSize]
 17617                              <1> 	;mov    ecx, 10
 17618                              <1> rediv_tfs_hex:
 17619                              <1> 	;sub	edx, edx
 17620 00005842 28D2                <1> 	sub	dl, dl
 17621 00005844 F7F1                <1> 	div	ecx
 17622 00005846 80C230              <1> 	add	dl, '0'
 17623 00005849 4F                  <1> 	dec     edi
 17624 0000584A 8817                <1> 	mov     [edi], dl
 17625 0000584C 21C0                <1> 	and	eax, eax
 17626 0000584E 75F2                <1> 	jnz	short rediv_tfs_hex
 17627                              <1> 	
 17628 00005850 893D[40AD0000]      <1> 	mov	[TFS_Dec_Begin], edi
 17629 00005856 BE[1E980000]        <1> 	mov	esi, Decimal_File_Count_Header
 17630 0000585B E8DAE3FFFF          <1> 	call	print_msg
 17631 00005860 BE[26980000]        <1> 	mov	esi, str_files
 17632 00005865 E8D0E3FFFF          <1> 	call	print_msg
 17633 0000586A BE[37980000]        <1> 	mov	esi, str_dirs
 17634 0000586F E8C6E3FFFF          <1> 	call	print_msg
 17635 00005874 8B35[40AD0000]      <1> 	mov	esi, [TFS_Dec_Begin]
 17636 0000587A E8BBE3FFFF          <1> 	call	print_msg
 17637 0000587F BE[48980000]        <1> 	mov	esi, str_bytes
 17638 00005884 E8B1E3FFFF          <1> 	call	print_msg
 17639                              <1> 
 17640 00005889 C3                  <1> 	retn
 17641                              <1> 
 17642                              <1> pause_dir_scroll:
 17643 0000588A 28E4                <1> 	sub	ah, ah           
 17644 0000588C E856B3FFFF          <1> 	call	int16h
 17645 00005891 3C1B                <1> 	cmp	al, 1Bh
 17646 00005893 0F8428FFFFFF        <1>         je      loc_dir_ok
 17647 00005899 C605[4FAD0000]10    <1> 	mov	byte [PrintDir_RowCounter], 16 ; Reset counter
 17648 000058A0 E911FFFFFF          <1>         jmp     loc_next_entry
 17649                              <1> 
 17650                              <1> find_first_file:
 17651                              <1> 	; 11/02/2015
 17652                              <1> 	; 10/02/2016
 17653                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17654                              <1> 	; 09/10/2011
 17655                              <1> 	; 17/09/2009
 17656                              <1> 	; 2005
 17657                              <1> 	; INPUT ->
 17658                              <1> 	;	ESI = ASCIIZ File/Dir/Path Name Address
 17659                              <1> 	;	AL = Attributes AND mask (The AND result must be equal to AL)
 17660                              <1> 	;	      bit 0 = Read Only
 17661                              <1> 	;	      bir 1 = Hidden
 17662                              <1> 	;	      bit 2 = System
 17663                              <1> 	;	      bit 3 = Volume Label
 17664                              <1> 	;	      bit 4 = Directory
 17665                              <1> 	;	      bit 5 = Archive
 17666                              <1> 	;	      bit 6 = Reserved, must be 0
 17667                              <1> 	;	      bit 7 = Reserved, must be 0
 17668                              <1> 	;       AH = Attributes Negative AND mask (The AND result must be ZERO)
 17669                              <1> 	;
 17670                              <1> 	; OUTPUT ->
 17671                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
 17672                              <1> 	;	CF = 0 ->
 17673                              <1> 	;	     ESI = Directory Entry (FindFile_DirEntry) Location
 17674                              <1> 	;	     EDI = Directory Buffer Directory Entry Location
 17675                              <1> 	;	     EAX = File Size
 17676                              <1> 	;	      BL = Attributes of The File/Directory
 17677                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
 17678                              <1> 	;             DX > 0 : Ambiguous filename chars are used
 17679                              <1> 	;
 17680                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 17681                              <1> 
 17682 000058A5 66A3[02AD0000]      <1> 	mov	[FindFile_AttributesMask], ax
 17683 000058AB BF[04AD0000]        <1> 	mov	edi, FindFile_DirEntry ; TR-DOS Fullfilename formatted buffer
 17684 000058B0 31C0                <1> 	xor	eax, eax
 17685 000058B2 B90B000000          <1> 	mov	ecx, 11
 17686 000058B7 F3AB                <1> 	rep	stosd	; 44 bytes
 17687                              <1> 	;stosw		; +2 bytes 
 17688                              <1> 	    
 17689 000058B9 BF[F4AC0000]        <1> 	mov	edi, FindFile_Name ; FFF structure, offset 66
 17690 000058BE 39FE                <1> 	cmp	esi, edi
 17691 000058C0 7408                <1> 	je	short loc_fff_mfn_ok
 17692 000058C2 89FA                <1> 	mov	edx, edi 
 17693                              <1> 	 ; move 13 bytes
 17694 000058C4 A5                  <1> 	movsd
 17695 000058C5 A5                  <1> 	movsd
 17696 000058C6 A5                  <1> 	movsd
 17697 000058C7 AA                  <1> 	stosb
 17698 000058C8 89D6                <1> 	mov	esi, edx
 17699                              <1> loc_fff_mfn_ok:
 17700 000058CA BF[A3AC0000]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
 17701 000058CF E8AF0F0000          <1> 	call	convert_file_name
 17702 000058D4 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
 17703                              <1> 
 17704 000058D6 66A1[02AD0000]      <1> 	mov	ax, [FindFile_AttributesMask]
 17705                              <1> 	;xor	ecx, ecx
 17706 000058DC 30C9                <1> 	xor	cl, cl  
 17707 000058DE E8AB0C0000          <1> 	call	locate_current_dir_file
 17708 000058E3 726E                <1> 	jc	short loc_fff_retn
 17709                              <1> 	; EDI = Directory Entry
 17710                              <1> 	; EBX = Directory Buffer Entry Index/Number
 17711                              <1> 
 17712                              <1> loc_fff_fnf_ln_check:
 17713 000058E5 30ED                <1> 	xor	ch, ch 
 17714 000058E7 80F60F              <1> 	xor	dh, 0Fh
 17715 000058EA 7408                <1> 	jz	short loc_fff_longname_yes
 17716 000058EC 882D[01AD0000]      <1> 	mov	[FindFile_LongNameYes], ch ; 0
 17717 000058F2 EB0C                <1> 	jmp	short loc_fff_longname_no
 17718                              <1> 
 17719                              <1> loc_fff_longname_yes:
 17720                              <1> 	;inc	byte [FindFile_LongNameYes]
 17721 000058F4 8A0D[0EAC0000]      <1> 	mov	cl, [LFN_EntryLength]  
 17722 000058FA 880D[01AD0000]      <1> 	mov	[FindFile_LongNameEntryLength], cl ; FindFile_LongNameYes
 17723                              <1> 
 17724                              <1> loc_fff_longname_no:
 17725                              <1> 	;mov	bx, [DirBuff_CurrentEntry]
 17726 00005900 66891D[2CAD0000]    <1> 	mov	[FindFile_DirEntryNumber], bx
 17727 00005907 6689C2              <1> 	mov	dx, ax ; Ambigouos Filename chars used sign > 0
 17728                              <1> 
 17729 0000590A A0[0EA30000]        <1> 	mov	al, [Current_Drv]
 17730 0000590F A2[B2AC0000]        <1> 	mov	[FindFile_Drv], al 
 17731                              <1> 
 17732 00005914 A1[08A30000]        <1> 	mov	eax, [Current_Dir_FCluster]
 17733 00005919 A3[24AD0000]        <1> 	mov	[FindFile_DirFirstCluster], eax
 17734                              <1> 
 17735 0000591E A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 17736 00005923 A3[28AD0000]        <1> 	mov	[FindFile_DirCluster], eax
 17737                              <1> 
 17738 00005928 66FF05[2EAD0000]    <1> 	inc	word [FindFile_MatchCounter]
 17739                              <1> 
 17740 0000592F 89FB                <1> 	mov	ebx, edi
 17741 00005931 89FE                <1> 	mov	esi, edi
 17742 00005933 BF[04AD0000]        <1> 	mov	edi, FindFile_DirEntry
 17743 00005938 89F8                <1> 	mov	eax, edi
 17744 0000593A B108                <1> 	mov	cl, 8
 17745 0000593C F3A5                <1> 	rep	movsd
 17746 0000593E 89C6                <1> 	mov	esi, eax
 17747 00005940 89DF                <1> 	mov	edi, ebx
 17748                              <1> 
 17749 00005942 A1[20AD0000]        <1> 	mov	eax, [FindFile_DirEntry+28] ; File Size
 17750                              <1> 
 17751 00005947 8A1D[0FAD0000]      <1> 	mov	bl, [FindFile_DirEntry+11] ; File Attributes 
 17752 0000594D 8A3D[01AD0000]      <1> 	mov	bh, [FindFile_LongNameYes]
 17753                              <1> 
 17754                              <1> 	;mov	cx, [DirBuff_EntryCounter]
 17755                              <1> 	;mov	[FindFile_DirEntryNumber], cx
 17756                              <1> 	;mov	cx, [FindFile_DirEntryNumber]
 17757                              <1> 	; ecx = 0
 17758                              <1> 
 17759                              <1> loc_fff_retn:
 17760 00005953 C3                  <1> 	retn
 17761                              <1> 
 17762                              <1> find_next_file:
 17763                              <1> 	; 10/02/2016
 17764                              <1> 	; 08/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17765                              <1> 	; 06/02/2011
 17766                              <1> 	; 17/09/2009
 17767                              <1> 	; 2005
 17768                              <1> 	; INPUT ->
 17769                              <1> 	;	NONE, Find First File Parameters
 17770                              <1> 	; OUTPUT ->
 17771                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
 17772                              <1> 	;	CF = 0 -> 
 17773                              <1> 	;	    ESI = Directory Entry (FindFile_DirEntry) Location
 17774                              <1> 	;	    EDI = Directory Buffer Directory Entry Location
 17775                              <1> 	;	    EAX = File Size
 17776                              <1> 	;	      BL = Attributes of The File/Directory
 17777                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
 17778                              <1> 	;             DX > 0 : Ambiguous filename chars are used 
 17779                              <1> 	;
 17780                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 17781                              <1> 
 17782 00005954 66833D[2EAD0000]00  <1> 	cmp	word [FindFile_MatchCounter], 0
 17783 0000595C 7707                <1> 	ja	short loc_start_search_next_file
 17784                              <1> 
 17785                              <1> loc_fnf_stc_retn:
 17786 0000595E F9                  <1> 	stc
 17787                              <1> loc_fnf_ax12h_retn:
 17788 0000595F B812000000          <1> 	mov	eax, 12h ; 18, No More files
 17789                              <1> ;loc_fnf_retn:
 17790 00005964 C3                  <1> 	retn
 17791                              <1> 
 17792                              <1> loc_start_search_next_file:
 17793 00005965 668B1D[2CAD0000]    <1> 	mov	bx, [FindFile_DirEntryNumber]
 17794 0000596C 6643                <1> 	inc	bx
 17795 0000596E 663B1D[3BAB0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 17796 00005975 7719                <1> 	ja	short loc_cont_search_next_file
 17797                              <1> 
 17798                              <1> loc_fnf_search:
 17799 00005977 BE[A3AC0000]        <1> 	mov	esi, Dir_Entry_Name
 17800 0000597C 66A1[02AD0000]      <1> 	mov	ax, [FindFile_AttributesMask]
 17801 00005982 6631C9              <1> 	xor	cx, cx
 17802 00005985 E8060D0000          <1> 	call	find_directory_entry
 17803 0000598A 0F8355FFFFFF        <1>         jnc     loc_fff_fnf_ln_check
 17804                              <1> 
 17805                              <1> loc_cont_search_next_file:
 17806 00005990 31DB                <1> 	xor	ebx, ebx
 17807 00005992 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 17808 00005998 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17809 0000599D 01DE                <1> 	add	esi, ebx
 17810                              <1> 
 17811 0000599F 803D[0CA30000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 17812 000059A6 7608                <1> 	jna	short loc_fnf_check_FAT_type
 17813 000059A8 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 17814 000059AC 72B1                <1> 	jb	short loc_fnf_ax12h_retn
 17815 000059AE EB06                <1> 	jmp	short loc_fnf_check_next_cluster
 17816                              <1>  
 17817                              <1> loc_fnf_check_FAT_type:
 17818 000059B0 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
 17819 000059B4 72A9                <1> 	jb	short loc_fnf_ax12h_retn
 17820                              <1> 
 17821                              <1> loc_fnf_check_next_cluster:
 17822 000059B6 A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 17823 000059BB E872170000          <1> 	call	get_next_cluster
 17824 000059C0 7306                <1> 	jnc	short loc_fnf_load_next_dir_cluster
 17825 000059C2 09C0                <1> 	or	eax, eax
 17826 000059C4 7498                <1> 	jz	short loc_fnf_stc_retn
 17827                              <1> 	;mov	eax, 15h ;Drive not ready or read error
 17828 000059C6 F5                  <1>  	cmc	;stc
 17829                              <1> loc_fnf_retn:
 17830 000059C7 C3                  <1> 	retn
 17831                              <1> 
 17832                              <1> loc_fnf_load_next_dir_cluster:
 17833 000059C8 E846190000          <1> 	call	load_FAT_sub_directory
 17834 000059CD 72F8                <1> 	jc	short loc_fnf_retn
 17835 000059CF 6631DB              <1> 	xor	bx, bx
 17836 000059D2 66891D[2CAD0000]    <1> 	mov	[FindFile_DirEntryNumber], bx
 17837 000059D9 EB9C                <1> 	jmp	short loc_fnf_search
 17838                              <1> 
 17839                              <1> get_and_print_longname:
 17840                              <1> 	; 13/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17841                              <1> 	; 24/01/2010
 17842                              <1> 	; 17/10/2009 (CMD_INTR.ASM, 'cmp_cmd_longname')
 17843                              <1> get_longname_fchar:
 17844 000059DB 803E20              <1> 	cmp	byte [esi], 20h
 17845 000059DE 7701                <1> 	ja	short loc_find_longname
 17846                              <1> 	;jb	short loc_longname_retn
 17847                              <1> 	;inc	esi
 17848                              <1> 	;je	short get_longname_fchar
 17849                              <1> ;loc_longname_retn:
 17850 000059E0 C3                  <1> 	retn
 17851                              <1> loc_find_longname:
 17852 000059E1 E801100000          <1> 	call	find_longname
 17853 000059E6 7320                <1> 	jnc	short loc_print_longname
 17854                              <1>                
 17855 000059E8 08C0                <1> 	or	al, al
 17856 000059EA 7412                <1> 	jz	short loc_longname_not_found
 17857                              <1> 	  
 17858 000059EC 3C15                <1> 	cmp	al, 15h
 17859 000059EE 0F84BCF7FFFF        <1> 	je	cd_drive_not_ready
 17860                              <1> 
 17861                              <1> loc_ln_file_dir_not_found:
 17862 000059F4 BE[75970000]        <1> 	mov	esi, Msg_File_Directory_Not_Found
 17863                              <1> 	;call	print_msg	
 17864                              <1>         ;retn
 17865 000059F9 E93CE2FFFF          <1> 	jmp	print_msg
 17866                              <1> 
 17867                              <1> loc_longname_not_found:
 17868 000059FE BE[94970000]        <1>         mov     esi, Msg_LongName_Not_Found
 17869                              <1> 	;call	print_msg	
 17870                              <1>         ;retn
 17871 00005A03 E932E2FFFF          <1> 	jmp	print_msg
 17872                              <1> 
 17873                              <1> loc_print_longname:
 17874                              <1> 	;mov	esi, LongFileName
 17875 00005A08 BF[0EA40000]        <1> 	mov	edi, TextBuffer
 17876 00005A0D 57                  <1> 	push	edi 
 17877 00005A0E 3C00                <1> 	cmp	al, 0
 17878 00005A10 7708                <1> 	ja	short loc_print_longname_1
 17879                              <1> loc_print_FS_longname: ; Singlix FS (64 byte ASCIIZ file name)
 17880 00005A12 AC                  <1> 	lodsb
 17881 00005A13 AA                  <1> 	stosb  
 17882 00005A14 08C0                <1> 	or	al, al
 17883 00005A16 75FA                <1> 	jnz	short loc_print_FS_longname
 17884 00005A18 EB07                <1> 	jmp	short loc_print_longname_2
 17885                              <1> 	;
 17886                              <1> loc_print_longname_1: ; MS Windows long name (UNICODE chars)
 17887 00005A1A 66AD                <1> 	lodsw
 17888 00005A1C AA                  <1> 	stosb  
 17889 00005A1D 08C0                <1> 	or	al, al
 17890 00005A1F 75F9                <1> 	jnz	short loc_print_longname_1
 17891                              <1> 	;
 17892                              <1> loc_print_longname_2:               
 17893 00005A21 5E                  <1> 	pop	esi
 17894 00005A22 E813E2FFFF          <1> 	call	print_msg
 17895 00005A27 BE[269F0000]        <1>   	mov	esi, nextline
 17896                              <1> 	;call	print_msg
 17897                              <1> 	;retn
 17898 00005A2C E909E2FFFF          <1> 	jmp	print_msg	
 17899                              <1> 
 17900                              <1> show_file:
 17901                              <1> 	; 18/02/2016
 17902                              <1> 	; 17/02/2016
 17903                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 17904                              <1> 	; 13/09/2011 (CMD_INTR.ASM, 'cmp_cmd_show')
 17905                              <1> 	; 08/11/2009
 17906                              <1> 
 17907                              <1> loc_show_parse_path_name:
 17908 00005A31 BF[B2AC0000]        <1> 	mov	edi, FindFile_Drv
 17909 00005A36 E8030F0000          <1> 	call	parse_path_name
 17910 00005A3B 0F8268F9FFFF        <1> 	jc	loc_cmd_failed
 17911                              <1> 
 17912                              <1> loc_show_check_filename_exists:
 17913 00005A41 BE[F4AC0000]        <1> 	mov	esi, FindFile_Name
 17914 00005A46 803E20              <1> 	cmp	byte [esi], 20h
 17915 00005A49 0F865AF9FFFF        <1> 	jna	loc_cmd_failed
 17916                              <1> 
 17917                              <1> 	; 15/02/2016 (invalid file name check)
 17918 00005A4F E805020000          <1> 	call	check_filename 	
 17919 00005A54 730A                <1> 	jnc	short loc_show_change_drv
 17920                              <1> 
 17921 00005A56 BE[5E980000]        <1> 	mov	esi, Msg_invalid_name_chars
 17922 00005A5B E9DAE1FFFF          <1> 	jmp	print_msg
 17923                              <1>    
 17924                              <1> loc_show_change_drv:
 17925 00005A60 8A35[0EA30000]      <1> 	mov	dh, [Current_Drv]
 17926 00005A66 8835[6EAB0000]      <1> 	mov	[RUN_CDRV], dh
 17927 00005A6C 8A15[B2AC0000]      <1> 	mov	dl, [FindFile_Drv]
 17928 00005A72 38F2                <1> 	cmp	dl, dh
 17929 00005A74 740B                <1> 	je	short loc_show_change_directory
 17930 00005A76 E8C3EAFFFF          <1> 	call	change_current_drive
 17931                              <1> 	;jc	loc_file_rw_cmd_failed
 17932 00005A7B 0F8253F9FFFF        <1> 	jc	loc_run_cmd_failed
 17933                              <1> 
 17934                              <1> loc_show_change_directory:
 17935 00005A81 803D[B3AC0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 17936 00005A88 7618                <1> 	jna	short loc_findload_showfile
 17937                              <1> 
 17938 00005A8A FE05[41940000]      <1> 	inc	byte [Restore_CDIR]
 17939 00005A90 BE[B3AC0000]        <1> 	mov	esi, FindFile_Directory
 17940 00005A95 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 17941 00005A97 E89E080000          <1> 	call	change_current_directory
 17942                              <1> 	;jc	loc_file_rw_cmd_failed
 17943 00005A9C 0F8232F9FFFF        <1> 	jc	loc_run_cmd_failed
 17944                              <1> 
 17945                              <1> ;loc_show_change_prompt_dir_string:
 17946                              <1> 	;call	change_prompt_dir_string
 17947                              <1> 
 17948                              <1> loc_findload_showfile:
 17949                              <1> 	; 15/02/2016
 17950 00005AA2 BE[F4AC0000]        <1> 	mov	esi, FindFile_Name
 17951 00005AA7 BF[A3AC0000]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
 17952 00005AAC E8D20D0000          <1> 	call	convert_file_name
 17953 00005AB1 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
 17954                              <1> 
 17955 00005AB3 28C0                <1> 	sub	al, al	; Attrib AND mask = 0
 17956                              <1> 	; Directory attribute : 10h
 17957                              <1> 	; Volume name attribute: 8h
 17958 00005AB5 B418                <1> 	mov	ah, 00011000b ; 18h (Attrib NAND, AND --> zero mask)
 17959                              <1> 	;
 17960 00005AB7 6631C9              <1> 	xor	cx, cx  
 17961 00005ABA E8CF0A0000          <1> 	call	locate_current_dir_file
 17962                              <1> 	;jc	loc_file_rw_cmd_failed
 17963 00005ABF 0F820FF9FFFF        <1> 	jc	loc_run_cmd_failed
 17964                              <1> 
 17965                              <1> loc_show_load_file:
 17966                              <1> 	; EDI = Directory Entry
 17967 00005AC5 668B4714            <1> 	mov	ax, [edi+DirEntry_FstClusHI] ; First Cluster High Word
 17968 00005AC9 C1E010              <1> 	shl	eax, 16
 17969 00005ACC 668B471A            <1> 	mov	ax, [edi+DirEntry_FstClusLO] ; First Cluster Low Word
 17970 00005AD0 A3[58AD0000]        <1> 	mov	[Show_Cluster], eax
 17971 00005AD5 8B471C              <1> 	mov	eax, [edi+DirEntry_FileSize] ; File Size
 17972 00005AD8 21C0                <1> 	and	eax, eax ; Empty file !
 17973 00005ADA 0F8491000000        <1>         jz      end_of_show_file 
 17974 00005AE0 A3[5CAD0000]        <1> 	mov	[Show_FileSize], eax
 17975 00005AE5 31C0                <1> 	xor	eax, eax
 17976 00005AE7 A3[60AD0000]        <1> 	mov	[Show_FilePointer], eax ; 0
 17977 00005AEC 66A3[64AD0000]      <1> 	mov	[Show_ClusterPointer], ax ; 0
 17978 00005AF2 29DB                <1> 	sub	ebx, ebx
 17979 00005AF4 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 17980 00005AFA BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17981 00005AFF 01DE                <1> 	add	esi, ebx
 17982 00005B01 8935[54AD0000]      <1> 	mov	[Show_LDDDT], esi ; Logical DOS Drv Description Table addr
 17983                              <1> 
 17984 00005B07 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0	
 17985 00005B0B 7713                <1> 	ja	short loc_show_calculate_cluster_size
 17986                              <1> 	; Singlix FS
 17987                              <1> 	; First Cluster Number is FDT number (in compatibility buffer)
 17988 00005B0D 8B15[58AD0000]      <1> 	mov	edx, [Show_Cluster] ; Compatibility dir. buffer value (FDT)	
 17989 00005B13 8915[50AD0000]      <1> 	mov	[Show_FDT], edx
 17990 00005B19 31C0                <1> 	xor	eax, eax
 17991 00005B1B A3[58AD0000]        <1> 	mov	[Show_Cluster], eax ; Sector index  = 0
 17992                              <1> 				    ; (next time it will be 1)			
 17993                              <1> loc_show_calculate_cluster_size:
 17994 00005B20 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec] ; FAT 12-16-32 (512)
 17995                              <1> 	; BX = 512 = [esi+LD_FS_BytesPerSec] ; Singlix FS	
 17996 00005B24 8A4613              <1> 	mov	al, [esi+LD_BPB+BPB_SecPerClust] ; FAT 12-16-32 (<= 128)
 17997                              <1> 	; AL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 17998 00005B27 F7E3                <1> 	mul	ebx	
 17999                              <1> 
 18000                              <1> 	;cmp	eax, 65536 ; non-compatible (very big) cluster size
 18001                              <1> 	;ja	short end_of_show_file	
 18002 00005B29 66A3[66AD0000]      <1> 	mov	[Show_ClusterSize], ax
 18003                              <1> 
 18004                              <1> loc_start_show_file:
 18005 00005B2F BE[269F0000]        <1> 	mov	esi, nextline
 18006 00005B34 E801E1FFFF          <1> 	call	print_msg
 18007                              <1> 
 18008 00005B39 A1[58AD0000]        <1> 	mov	eax, [Show_Cluster]
 18009 00005B3E C605[68AD0000]17    <1> 	mov	byte [Show_RowCount], 23
 18010                              <1> 
 18011                              <1> 	; 17/02/2016
 18012 00005B45 8B35[54AD0000]      <1> 	mov	esi, [Show_LDDDT]
 18013                              <1> 
 18014                              <1> loc_show_next_cluster:
 18015                              <1> 	; 15/02/2016
 18016 00005B4B BB00000700          <1> 	mov	ebx, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
 18017                              <1> 	; ESI = Logical DOS drv description table address
 18018 00005B50 E8FC170000          <1> 	call	read_cluster
 18019                              <1> 	;jc	loc_file_rw_cmd_failed
 18020 00005B55 0F8279F8FFFF        <1> 	jc	loc_run_cmd_failed
 18021                              <1> 
 18022 00005B5B 31DB                <1> 	xor 	ebx, ebx
 18023                              <1> loc_show_next_byte:
 18024 00005B5D 803D[68AD0000]00    <1> 	cmp	byte [Show_RowCount], 0
 18025 00005B64 7521                <1> 	jne	short pass_show_wait_for_key
 18026 00005B66 30E4                <1> 	xor	ah, ah
 18027 00005B68 E87AB0FFFF          <1> 	call	int16h
 18028 00005B6D 3C1B                <1> 	cmp	al, 1Bh
 18029 00005B6F 750F                <1> 	jne	short pass_exit_show
 18030                              <1> end_of_show_file:
 18031                              <1> pass_show_file:
 18032 00005B71 BE[269F0000]        <1> 	mov	esi, nextline
 18033 00005B76 E8BFE0FFFF          <1> 	call	print_msg
 18034 00005B7B E949010000          <1> 	jmp	loc_file_rw_restore_retn
 18035                              <1> 
 18036                              <1> pass_exit_show:
 18037 00005B80 C605[68AD0000]14    <1> 	mov	byte [Show_RowCount], 20
 18038                              <1> pass_show_wait_for_key:
 18039 00005B87 81C300000700        <1> 	add	ebx, Cluster_Buffer
 18040 00005B8D 8A03                <1> 	mov	al, [ebx]
 18041 00005B8F 0FB61D[78A20000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18042 00005B96 3C0D                <1> 	cmp	al, 0Dh
 18043 00005B98 0F858A000000        <1>         jne     loc_show_check_tab_space
 18044 00005B9E FE0D[68AD0000]      <1> 	dec	byte [Show_RowCount]
 18045                              <1> pass_show_dec_rowcount:
 18046 00005BA4 B407                <1> 	mov	ah, 7 ; (light gray character color, black background)
 18047 00005BA6 E80BBCFFFF          <1> 	call	WRITE_TTY
 18048                              <1> loc_show_check_eof:
 18049 00005BAB FF05[60AD0000]      <1> 	inc	dword [Show_FilePointer]
 18050 00005BB1 A1[60AD0000]        <1> 	mov	eax, [Show_FilePointer]
 18051 00005BB6 3B05[5CAD0000]      <1> 	cmp	eax, [Show_FileSize]
 18052 00005BBC 73B3                <1> 	jnb	short end_of_show_file
 18053 00005BBE 66FF05[64AD0000]    <1> 	inc	word [Show_ClusterPointer]
 18054 00005BC5 0FB71D[64AD0000]    <1> 	movzx	ebx, word [Show_ClusterPointer]
 18055                              <1> 
 18056                              <1> 	; 17/02/2016
 18057                              <1> 	; (sector boundary -9 bits- check, 512 = 0)
 18058 00005BCC 66F7C3FF01          <1>         test    bx, 1FFh ;  1 to 511
 18059 00005BD1 758A                <1> 	jnz	short loc_show_next_byte
 18060                              <1> 
 18061                              <1> 	; 16/02/2016
 18062 00005BD3 8B35[54AD0000]      <1> 	mov	esi, [Show_LDDDT]
 18063                              <1> 	;
 18064 00005BD9 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 18065 00005BDD 7719                <1> 	ja	short loc_show_check_fat_cluster_size
 18066                              <1> 
 18067                              <1> 	; Singlix FS
 18068                              <1> 	; 1 sector, more... (cluster size = 1 sector)
 18069 00005BDF A1[58AD0000]        <1> 	mov	eax, [Show_Cluster]
 18070 00005BE4 40                  <1> 	inc	eax
 18071 00005BE5 A3[58AD0000]        <1> 	mov	[Show_Cluster], eax
 18072                              <1> 
 18073 00005BEA 6621DB              <1> 	and	bx, bx ; 65536 -> 0
 18074 00005BED 0F856AFFFFFF        <1>         jnz	loc_show_next_byte
 18075 00005BF3 E953FFFFFF          <1> 	jmp     loc_show_next_cluster
 18076                              <1> 	 
 18077                              <1> loc_show_check_fat_cluster_size:
 18078                              <1> 	; 17/02/2016
 18079 00005BF8 663B1D[66AD0000]    <1> 	cmp	bx, [Show_ClusterSize] ; cluster size in bytes
 18080 00005BFF 0F8258FFFFFF        <1>         jb	loc_show_next_byte
 18081 00005C05 66C705[64AD0000]00- <1> 	mov	word [Show_ClusterPointer], 0
 18082 00005C0D 00                  <1>
 18083                              <1> 
 18084 00005C0E A1[58AD0000]        <1> 	mov	eax, [Show_Cluster]
 18085                              <1> 	;mov	esi, [Show_LDDDT]
 18086                              <1> loc_show_get_next_cluster:
 18087 00005C13 E81A150000          <1> 	call	get_next_cluster
 18088                              <1> 	;jc	loc_file_rw_cmd_failed
 18089 00005C18 0F82B6F7FFFF        <1> 	jc	loc_run_cmd_failed
 18090                              <1> loc_show_update_ccluster:
 18091 00005C1E A3[58AD0000]        <1> 	mov	[Show_Cluster], eax			
 18092 00005C23 E923FFFFFF          <1>         jmp     loc_show_next_cluster
 18093                              <1> 
 18094                              <1> loc_show_check_tab_space:
 18095 00005C28 3C09                <1> 	cmp	al, 09h
 18096 00005C2A 0F8574FFFFFF        <1>         jne     pass_show_dec_rowcount
 18097                              <1> loc_show_put_tab_space:
 18098                              <1> 	;movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18099 00005C30 E847B9FFFF          <1> 	call	get_cpos
 18100                              <1> 	; dl = cursor column
 18101 00005C35 80E207              <1> 	and	dl, 7 ; 18/02/2016
 18102                              <1> loc_show_put_space_chars:
 18103                              <1> 	;mov	al, 20h ; space
 18104                              <1> 	;mov 	ah, 7	; color attribute
 18105 00005C38 66B82007            <1> 	mov	ax, 0720h ; 
 18106 00005C3C 0FB61D[78A20000]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; [ptty]
 18107 00005C43 6652                <1> 	push	dx
 18108 00005C45 E86CBBFFFF          <1> 	call	WRITE_TTY
 18109 00005C4A 665A                <1> 	pop	dx
 18110                              <1> 	; 18/02/2016
 18111 00005C4C 80FA07              <1> 	cmp	dl, 7
 18112 00005C4F 0F8356FFFFFF        <1> 	jnb	loc_show_check_eof
 18113 00005C55 FEC2                <1> 	inc	dl
 18114 00005C57 EBDF                <1> 	jmp	short loc_show_put_space_chars
 18115                              <1> 
 18116                              <1> check_filename:
 18117                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18118                              <1> 	; 07/08/2010 (FILE.ASM, 'proc_check_filename')
 18119                              <1> 	; 10/07/2010
 18120                              <1> 	; Derived from 'proc_check_filename'
 18121                              <1> 	; in the old TRDOS.ASM (09/02/2005).
 18122                              <1> 	;
 18123                              <1> 	; INPUT -> 
 18124                              <1> 	;	ESI = Dot File Name Location
 18125                              <1> 	; OUTPUT ->
 18126                              <1> 	;	cf = 1 -> error code in AL
 18127                              <1> 	;	     AL = 0Bh -> Invalid file name   
 18128                              <1> 	;	cf = 0 -> valid file name
 18129                              <1> 	; 
 18130                              <1> 	;(EAX, ECX, EDI will be changed)
 18131                              <1> 
 18132                              <1> check_invalid_filename_chars:
 18133                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18134                              <1> 	; 10/07/2010 (FILE.ASM, 'proc_check_invalid_filename_chars')
 18135                              <1> 	; 10/02/2010
 18136                              <1> 	; Derived from 'proc_check_invalid_filename_chars'
 18137                              <1> 	; in the old TRDOS.ASM (09/02/2005).
 18138                              <1> 	;
 18139                              <1> 	; INPUT -> 
 18140                              <1> 	;	ESI = ASCIIZ FileName
 18141                              <1> 	; OUTPUT ->
 18142                              <1> 	;	cf = 1 -> invalid
 18143                              <1> 	;	cf = 0 -> valid
 18144                              <1> 	; 
 18145                              <1> 	;(EAX, ECX, ESI, EDI will be changed)
 18146                              <1>   
 18147 00005C59 56                  <1> 	push	esi
 18148                              <1> 
 18149 00005C5A BF[49950000]        <1>         mov     edi, invalid_fname_chars
 18150 00005C5F AC                  <1> 	lodsb
 18151                              <1> check_filename_next_char:
 18152 00005C60 B914000000          <1> 	mov	ecx, sizeInvFnChars
 18153 00005C65 BF[49950000]        <1> 	mov	edi, invalid_fname_chars
 18154                              <1> loc_scan_invalid_filename_char:
 18155 00005C6A AE                  <1> 	scasb 
 18156 00005C6B 741F                <1> 	je	short loc_invalid_filename_stc 
 18157 00005C6D E2FB                <1> 	loop	loc_scan_invalid_filename_char
 18158 00005C6F AC                  <1> 	lodsb
 18159 00005C70 3C1F                <1> 	cmp	al, 1Fh  ; 20h and above 
 18160 00005C72 77EC                <1> 	ja	short check_filename_next_char
 18161                              <1> 
 18162                              <1> check_filename_dot:
 18163 00005C74 8B3424              <1> 	mov	esi, [esp]
 18164                              <1> 
 18165 00005C77 B421                <1> 	mov	ah, 21h
 18166 00005C79 B908000000          <1> 	mov	ecx, 8
 18167                              <1> loc_check_filename_next_char:
 18168 00005C7E AC                  <1> 	lodsb
 18169 00005C7F 3C2E                <1> 	cmp	al, 2Eh
 18170 00005C81 7511                <1> 	jne	short pass_check_fn_dot_check
 18171                              <1> loc_check_filename_ext_0:
 18172 00005C83 AC                  <1> 	lodsb
 18173 00005C84 38E0                <1> 	cmp	al, ah ; 21h
 18174 00005C86 7205                <1> 	jb	short loc_invalid_filename
 18175 00005C88 3C2E                <1> 	cmp	al, 2Eh
 18176 00005C8A 7519                <1> 	jne	short loc_check_filename_ext_1
 18177                              <1> 
 18178                              <1> loc_invalid_filename_stc:
 18179                              <1> loc_check_fn_stc_rtn:
 18180 00005C8C F9                  <1> 	stc
 18181                              <1> loc_invalid_filename:
 18182 00005C8D B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 18183                              <1> 	; Invalid file name chars
 18184                              <1> loc_check_fn_rtn:
 18185 00005C92 5E                  <1> 	pop	esi
 18186 00005C93 C3                  <1> 	retn
 18187                              <1> 
 18188                              <1> pass_check_fn_dot_check:
 18189 00005C94 38E0                <1> 	cmp	al, ah ; 21h
 18190 00005C96 7224                <1> 	jb	short loc_check_fn_clc_rtn
 18191 00005C98 E2E4                <1> 	loop	loc_check_filename_next_char
 18192 00005C9A AC                  <1> 	lodsb
 18193 00005C9B 38E0                <1> 	cmp	al, ah ; 21h
 18194 00005C9D 721D                <1> 	jb	short loc_check_fn_clc_rtn
 18195 00005C9F 3C2E                <1> 	cmp	al, 2Eh
 18196 00005CA1 75E9                <1> 	jne	short loc_check_fn_stc_rtn
 18197 00005CA3 EBDE                <1> 	jmp	short loc_check_filename_ext_0
 18198                              <1> 
 18199                              <1> loc_check_filename_ext_1:
 18200 00005CA5 AC                  <1> 	lodsb
 18201 00005CA6 38E0                <1> 	cmp	al, ah ; 21h
 18202 00005CA8 7212                <1> 	jb	short loc_check_fn_clc_rtn
 18203 00005CAA 3C2E                <1> 	cmp	al, 2Eh
 18204 00005CAC 74DE                <1> 	je	short loc_check_fn_stc_rtn
 18205 00005CAE AC                  <1> 	lodsb
 18206 00005CAF 38E0                <1> 	cmp	al, ah ; 21h
 18207 00005CB1 7209                <1> 	jb	short loc_check_fn_clc_rtn
 18208 00005CB3 3C2E                <1> 	cmp	al, 2Eh
 18209 00005CB5 74D5                <1> 	je	short loc_check_fn_stc_rtn
 18210 00005CB7 AC                  <1> 	lodsb
 18211 00005CB8 38E0                <1> 	cmp	al, ah ; 21h
 18212 00005CBA 73D0                <1> 	jnb	short loc_check_fn_stc_rtn
 18213                              <1> 
 18214                              <1> loc_check_fn_clc_rtn:
 18215 00005CBC 5E                  <1> 	pop	esi
 18216 00005CBD F8                  <1> 	clc
 18217 00005CBE C3                  <1> 	retn
 18218                              <1> 
 18219                              <1> loc_print_deleted_message:
 18220 00005CBF BE[33990000]        <1> 	mov	esi, Msg_Deleted
 18221 00005CC4 E871DFFFFF          <1> 	call	print_msg
 18222                              <1> 
 18223                              <1> 	;clc
 18224                              <1> 
 18225                              <1> loc_file_rw_restore_retn:
 18226                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18227                              <1> 	; 28/02/2010 (CMD_INTR.ASM)
 18228                              <1> loc_file_rw_cmd_failed:
 18229 00005CC9 9C                  <1> 	pushf 
 18230 00005CCA E85FF7FFFF          <1> 	call	restore_cdir_after_cmd_fail	
 18231 00005CCF 9D                  <1> 	popf
 18232 00005CD0 720D                <1> 	jc	short loc_file_rw_check_write_fault
 18233 00005CD2 C3                  <1> 	retn
 18234                              <1> 
 18235                              <1> loc_permission_denied:
 18236                              <1> 	; 27/02/2016
 18237 00005CD3 BE[40990000]        <1> 	mov	esi, Msg_Permission_Denied
 18238 00005CD8 E85DDFFFFF          <1> 	call	print_msg
 18239 00005CDD EBEA                <1> 	jmp	short loc_file_rw_restore_retn
 18240                              <1> 
 18241                              <1> loc_file_rw_check_write_fault:
 18242 00005CDF 3C1D                <1> 	cmp	al, 1Dh ; Write Fault
 18243 00005CE1 0F85F2F6FFFF        <1>         jne     loc_run_cmd_failed_cmp_al
 18244 00005CE7 BE[2A970000]        <1> 	mov	esi, Msg_Not_Ready_Write_Err
 18245                              <1> 	;call	print_msg
 18246                              <1> 	;retn
 18247 00005CEC E949DFFFFF          <1> 	jmp	print_msg
 18248                              <1> 
 18249                              <1> make_directory:
 18250                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18251                              <1> 	; 12/03/2011 (CMD_INTR.ASM, 'cmp_cmd_mkdir')
 18252                              <1> 	; 14/08/2010
 18253                              <1> 	; 10/07/2010
 18254                              <1> 	; 29/11/2009
 18255                              <1> 	;
 18256                              <1> get_mkdir_fchar:
 18257                              <1> 	; esi = directory name
 18258 00005CF1 803E20              <1> 	cmp	byte [esi], 20h
 18259                              <1> 	;je	short get_mkdir_fchar
 18260                              <1>         ;ja	short loc_mkdir_parse_path_name
 18261 00005CF4 7701                <1>         ja	short loc_mkdir_parse_path_name
 18262                              <1> 
 18263                              <1> loc_mkdir_nodirname_retn:
 18264 00005CF6 C3                  <1> 	retn
 18265                              <1> 
 18266                              <1> loc_mkdir_parse_path_name:
 18267 00005CF7 BF[B2AC0000]        <1> 	mov	edi, FindFile_Drv
 18268 00005CFC E83D0C0000          <1>         call    parse_path_name
 18269 00005D01 0F82A2F6FFFF        <1> 	jc	loc_cmd_failed
 18270                              <1> 
 18271                              <1> loc_mkdir_check_dirname_exists:
 18272 00005D07 BE[F4AC0000]        <1> 	mov	esi, FindFile_Name
 18273 00005D0C 803E20              <1> 	cmp	byte [esi], 20h
 18274 00005D0F 0F8694F6FFFF        <1> 	jna	loc_cmd_failed
 18275 00005D15 8935[6CAD0000]      <1> 	mov	[DelFile_FNPointer], esi
 18276 00005D1B E839FFFFFF          <1> 	call	check_filename
 18277 00005D20 7259                <1> 	jc	short loc_mkdir_invalid_dir_name_chars
 18278                              <1> 
 18279                              <1> loc_mkdir_drv:
 18280 00005D22 8A35[0EA30000]      <1> 	mov	dh, [Current_Drv]
 18281 00005D28 8835[6EAB0000]      <1> 	mov	[RUN_CDRV], dh
 18282                              <1> 	
 18283 00005D2E 8A15[B2AC0000]      <1> 	mov	dl, [FindFile_Drv]
 18284 00005D34 38F2                <1> 	cmp	dl, dh
 18285 00005D36 7407                <1> 	je	short loc_mkdir_change_directory
 18286                              <1> 
 18287 00005D38 E801E8FFFF          <1> 	call	change_current_drive
 18288 00005D3D 728A                <1> 	jc	loc_file_rw_cmd_failed
 18289                              <1> 
 18290                              <1> loc_mkdir_change_directory:
 18291 00005D3F 803D[B3AC0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18292 00005D46 7614                <1> 	jna	short loc_mkdir_find_directory
 18293                              <1> 
 18294 00005D48 FE05[41940000]      <1> 	inc	byte [Restore_CDIR]
 18295 00005D4E BE[B3AC0000]        <1> 	mov	esi, FindFile_Directory
 18296 00005D53 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18297 00005D55 E8E0050000          <1> 	call	change_current_directory
 18298 00005D5A 722E                <1> 	jc	short loc_mkdir_check_error_code
 18299                              <1> 
 18300                              <1> ;loc_mkdir_change_prompt_dir_string:
 18301                              <1> 	;call	change_prompt_dir_string
 18302                              <1> 
 18303                              <1> loc_mkdir_find_directory:
 18304                              <1> 	;mov	esi, FindFile_Name
 18305 00005D5C 8B35[6CAD0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18306                              <1> 	;xor	eax, eax
 18307 00005D62 6631C0              <1> 	xor	ax, ax ; any name (dir, file, volume)
 18308 00005D65 E83BFBFFFF          <1> 	call	find_first_file
 18309 00005D6A 721E                <1> 	jc	short loc_mkdir_check_error_code
 18310                              <1> 
 18311                              <1> loc_mkdir_directory_found:
 18312 00005D6C BE[8B980000]        <1> 	mov	esi, Msg_Name_Exists
 18313 00005D71 E8C4DEFFFF          <1> 	call	print_msg
 18314                              <1> 
 18315 00005D76 E94EFFFFFF          <1>         jmp     loc_file_rw_restore_retn
 18316                              <1> 
 18317                              <1> loc_mkdir_invalid_dir_name_chars:
 18318 00005D7B BE[5E980000]        <1> 	mov	esi, Msg_invalid_name_chars
 18319 00005D80 E8B5DEFFFF          <1> 	call	print_msg
 18320                              <1> 
 18321 00005D85 E93FFFFFFF          <1>         jmp     loc_file_rw_restore_retn
 18322                              <1> 
 18323                              <1> loc_mkdir_check_error_code:
 18324 00005D8A 3C02                <1> 	cmp	al, 2
 18325                              <1> 	;je	short loc_mkdir_directory_not_found
 18326 00005D8C 7406                <1> 	je	short loc_mkdir_ask_for_yes_no
 18327 00005D8E F9                  <1> 	stc
 18328 00005D8F E935FFFFFF          <1>         jmp     loc_file_rw_cmd_failed
 18329                              <1> 
 18330                              <1> loc_mkdir_directory_not_found:
 18331                              <1> loc_mkdir_ask_for_yes_no:
 18332 00005D94 BE[AC980000]        <1> 	mov	esi, Msg_DoYouWantMkdir
 18333 00005D99 E89CDEFFFF          <1> 	call	print_msg
 18334 00005D9E 8B35[6CAD0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18335 00005DA4 E891DEFFFF          <1> 	call	print_msg
 18336 00005DA9 BE[CB980000]        <1> 	mov	esi, Msg_YesNo
 18337 00005DAE E887DEFFFF          <1> 	call	print_msg
 18338                              <1> 
 18339 00005DB3 C605[D5980000]20    <1> 	mov	byte [Y_N_nextline], 20h
 18340                              <1> 
 18341                              <1> loc_mkdir_ask_again:
 18342 00005DBA 30E4                <1> 	xor	ah, ah
 18343 00005DBC E826AEFFFF          <1> 	call	int16h
 18344 00005DC1 3C1B                <1> 	cmp	al, 1Bh
 18345                              <1> 	;je	short loc_do_not_make_directory
 18346 00005DC3 7447                <1> 	je	short loc_mkdir_y_n_escape
 18347 00005DC5 24DF                <1> 	and	al, 0DFh ; y -> Y, n -> N
 18348 00005DC7 3C59                <1> 	cmp	al, 'Y' ; 'yes'
 18349 00005DC9 7404                <1> 	je	short loc_mkdir_yes_make_directory
 18350 00005DCB 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18351 00005DCD 75EB                <1> 	jne	short loc_mkdir_ask_again
 18352                              <1> 
 18353                              <1> loc_do_not_make_directory:
 18354                              <1> loc_mkdir_yes_make_directory:
 18355 00005DCF A2[D5980000]        <1> 	mov	[Y_N_nextline], al
 18356 00005DD4 6650                <1> 	push	ax
 18357 00005DD6 BE[D5980000]        <1> 	mov	esi, Y_N_nextline
 18358 00005DDB E85ADEFFFF          <1> 	call	print_msg
 18359 00005DE0 6658                <1> 	pop	ax
 18360                              <1> 	;cmp	al, 'Y' ; 'yes'
 18361                              <1> 	;cmc
 18362                              <1>         ;jnc	loc_file_rw_restore_retn
 18363 00005DE2 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18364 00005DE4 0F84DFFEFFFF        <1>         je	loc_file_rw_restore_retn  
 18365                              <1> 
 18366                              <1> loc_mkdir_call_make_sub_directory:
 18367 00005DEA 8B35[6CAD0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18368 00005DF0 B110                <1> 	mov	cl, 10h ; Directory attributes 
 18369 00005DF2 E8460C0000          <1> 	call	make_sub_directory
 18370 00005DF7 0F82CCFEFFFF        <1>         jc	loc_file_rw_cmd_failed
 18371                              <1> 
 18372 00005DFD BE[D9980000]        <1> 	mov	esi, Msg_OK
 18373 00005E02 E833DEFFFF          <1> 	call	print_msg
 18374 00005E07 E9BDFEFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18375                              <1> 
 18376                              <1> loc_mkdir_y_n_escape:
 18377 00005E0C B04E                <1> 	mov	al, 'N' ; 'no'
 18378 00005E0E EBBF                <1> 	jmp	short loc_do_not_make_directory
 18379                              <1> 
 18380                              <1> delete_directory:
 18381                              <1> 	; 29/02/2016
 18382                              <1> 	; 28/02/2016
 18383                              <1> 	; 27/02/2016
 18384                              <1> 	; 26/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18385                              <1> 	; 16/10/2010 (CMD_INTR.ASM, 'cmp_cmd_rmdir')
 18386                              <1> 	; 05/06/2010
 18387                              <1> 	;
 18388                              <1> get_rmdir_fchar:
 18389                              <1> 	; esi = directory name
 18390 00005E10 803E20              <1> 	cmp	byte [esi], 20h
 18391                              <1> 	;je	short get_rmdir_fchar
 18392                              <1>         ;ja	short loc_rmdir_parse_path_name
 18393 00005E13 7701                <1>         ja	short loc_rmdir_parse_path_name
 18394                              <1> 
 18395                              <1> loc_rmdir_nodirname_retn:
 18396 00005E15 C3                  <1> 	retn
 18397                              <1> 
 18398                              <1> loc_rmdir_parse_path_name:
 18399 00005E16 BF[B2AC0000]        <1> 	mov	edi, FindFile_Drv
 18400 00005E1B E81E0B0000          <1> 	call	parse_path_name
 18401 00005E20 0F8283F5FFFF        <1> 	jc	loc_cmd_failed
 18402                              <1> 
 18403                              <1> loc_rmdir_check_dirname_exists:
 18404 00005E26 BE[F4AC0000]        <1> 	mov	esi, FindFile_Name
 18405 00005E2B 803E20              <1> 	cmp	byte [esi], 20h
 18406 00005E2E 0F8675F5FFFF        <1> 	jna	loc_cmd_failed
 18407 00005E34 8935[6CAD0000]      <1> 	mov	[DelFile_FNPointer], esi 
 18408                              <1> 
 18409                              <1> loc_rmdir_drv:
 18410 00005E3A 8A35[0EA30000]      <1> 	mov	dh, [Current_Drv]
 18411 00005E40 8835[6EAB0000]      <1> 	mov	[RUN_CDRV], dh
 18412                              <1> 
 18413 00005E46 8A15[B2AC0000]      <1> 	mov	dl, [FindFile_Drv]
 18414 00005E4C 38F2                <1> 	cmp	dl, dh
 18415 00005E4E 740B                <1> 	je	short loc_rmdir_change_directory
 18416                              <1> 
 18417 00005E50 E8E9E6FFFF          <1> 	call	change_current_drive
 18418 00005E55 0F826EFEFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18419                              <1> 
 18420                              <1> loc_rmdir_change_directory:
 18421 00005E5B 803D[B3AC0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18422 00005E62 7614                <1> 	jna	short loc_rmdir_find_directory
 18423                              <1> 
 18424 00005E64 FE05[41940000]      <1> 	inc	byte [Restore_CDIR]
 18425 00005E6A BE[B3AC0000]        <1> 	mov	esi, FindFile_Directory
 18426 00005E6F 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18427 00005E71 E8C4040000          <1> 	call	change_current_directory
 18428 00005E76 7211                <1> 	jc	short loc_rmdir_check_error_code
 18429                              <1> 
 18430                              <1> ;loc_rmdir_change_prompt_dir_string:
 18431                              <1> 	;call	change_prompt_dir_string
 18432                              <1> 
 18433                              <1> loc_rmdir_find_directory:
 18434                              <1> 	;mov	esi, FindFile_Name
 18435 00005E78 8B35[6CAD0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18436 00005E7E 66B81008            <1> 	mov	ax, 0810h ; Only directories
 18437 00005E82 E81EFAFFFF          <1> 	call	find_first_file
 18438 00005E87 730A                <1> 	jnc	short loc_rmdir_ambgfn_check
 18439                              <1> 
 18440                              <1> loc_rmdir_check_error_code:
 18441 00005E89 3C02                <1> 	cmp	al, 2
 18442 00005E8B 740B                <1> 	je	short loc_rmdir_directory_not_found
 18443 00005E8D F9                  <1> 	stc
 18444 00005E8E E936FEFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18445                              <1> 
 18446                              <1> loc_rmdir_ambgfn_check:
 18447 00005E93 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 18448 00005E96 740F                <1> 	jz	short loc_rmdir_directory_found
 18449                              <1> 
 18450                              <1> loc_rmdir_directory_not_found:
 18451 00005E98 BE[4C970000]        <1> 	mov	esi, Msg_Dir_Not_Found
 18452 00005E9D E898DDFFFF          <1> 	call	print_msg
 18453                              <1> 
 18454 00005EA2 E922FEFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18455                              <1> 
 18456                              <1> loc_rmdir_directory_found:
 18457 00005EA7 80E307              <1> 	and	bl, 07h ; Attributes
 18458 00005EAA 0F8523FEFFFF        <1> 	jnz	loc_permission_denied
 18459                              <1> 
 18460                              <1> loc_rmdir_save_lnel: ; 28/02/2016
 18461                              <1>        ;mov	bh, [LongName_EntryLength]
 18462 00005EB0 883D[76AD0000]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 18463                              <1> 	; edi = Directory Entry Offset (DirBuff)
 18464                              <1> 	; esi = Directory Entry (FFF Structure)
 18465                              <1> 	;mov	[DelFile_DirEntryAddr], edi ; not required
 18466                              <1> 	;mov	ax, [edi+20] ; First Cluster High Word
 18467                              <1>         ;shl	eax, 16
 18468                              <1> 	;mov	ax, [edi+26] ; First Cluster Low Word
 18469                              <1> 	; ROOT Dir First Cluster = 0
 18470                              <1>         ;cmp	eax, 2
 18471                              <1> 	;jb	loc_update_direntry_1
 18472                              <1> 
 18473                              <1> pass_rmdir_fc_check:
 18474 00005EB6 57                  <1> 	push	edi ; * (29/02/2016)
 18475                              <1> 
 18476 00005EB7 BE[DF980000]        <1> 	mov	esi, Msg_DoYouWantRmDir
 18477 00005EBC E879DDFFFF          <1> 	call	print_msg
 18478 00005EC1 8B35[6CAD0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18479 00005EC7 E86EDDFFFF          <1> 	call	print_msg
 18480 00005ECC BE[CB980000]        <1> 	mov	esi, Msg_YesNo
 18481 00005ED1 E864DDFFFF          <1> 	call	print_msg
 18482                              <1> 
 18483                              <1> loc_rmdir_ask_again:
 18484 00005ED6 30E4                <1> 	xor	ah, ah
 18485 00005ED8 E80AADFFFF          <1> 	call	int16h
 18486 00005EDD 3C0B                <1> 	cmp	al, 0Bh
 18487 00005EDF 740F                <1> 	je	short loc_do_not_delete_directory
 18488 00005EE1 24DF                <1> 	and	al, 0DFh
 18489 00005EE3 A2[D5980000]        <1> 	mov	[Y_N_nextline], al
 18490 00005EE8 3C59                <1> 	cmp	al, 'Y'
 18491 00005EEA 7404                <1> 	je	short loc_rmdir_yes_delete_directory
 18492 00005EEC 3C4E                <1> 	cmp	al, 'N'
 18493 00005EEE 75E6                <1> 	jne	short loc_rmdir_ask_again
 18494                              <1> 
 18495                              <1> loc_do_not_delete_directory:
 18496                              <1> loc_rmdir_yes_delete_directory:
 18497 00005EF0 A2[D5980000]        <1> 	mov	[Y_N_nextline], al
 18498 00005EF5 6650                <1> 	push	ax
 18499 00005EF7 BE[D5980000]        <1> 	mov	esi, Y_N_nextline
 18500 00005EFC E839DDFFFF          <1> 	call	print_msg
 18501 00005F01 6658                <1> 	pop	ax
 18502 00005F03 5F                  <1> 	pop	edi ; * (29/02/2016)
 18503                              <1> 	;cmp	al, 'Y' ; 'yes'
 18504                              <1> 	;cmc
 18505                              <1>         ;jnc	loc_file_rw_restore_retn
 18506 00005F04 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18507 00005F06 0F84BDFDFFFF        <1>         je	loc_file_rw_restore_retn  
 18508                              <1> 
 18509                              <1> loc_rmdir_delete_short_name_check_dir_empty:
 18510                              <1> 	; EDI = Directory buffer entry offset/address 
 18511 00005F0C 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 18512 00005F10 C1E010              <1>         shl	eax, 16
 18513 00005F13 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 18514                              <1> 
 18515 00005F17 A3[70AD0000]        <1> 	mov 	[DelFile_FCluster], eax
 18516                              <1> 
 18517                              <1> 	;mov	bx, [DirBuff_EntryCounter]
 18518 00005F1C 668B1D[2CAD0000]    <1> 	mov	bx, [FindFile_DirEntryNumber] ; 27/02/2016
 18519 00005F23 66891D[74AD0000]    <1> 	mov	[DelFile_EntryCounter], bx
 18520                              <1> 
 18521 00005F2A 29DB                <1>     	sub	ebx, ebx
 18522 00005F2C 8A3D[B2AC0000]      <1> 	mov	bh, [FindFile_Drv]
 18523 00005F32 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 18524 00005F37 01DE                <1> 	add	esi, ebx
 18525                              <1> 
 18526 00005F39 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h
 18527 00005F3F 742E                <1> 	je	short loc_rmdir_delete_fs_directory
 18528                              <1> 
 18529                              <1> 	;cmp	byte [esi+LD_FATType], 1
 18530                              <1> 	;jnb	short loc_rmdir_get__last_cluster_0
 18531                              <1> 	;mov	eax, 0Bh ; Invalid Format
 18532                              <1> 	;jmp	loc_file_rw_cmd_failed
 18533                              <1>   
 18534                              <1> ;loc_rmdir_get_last_cluster_0:
 18535 00005F41 8B15[3DAB0000]      <1> 	mov	edx, [DirBuff_Cluster]
 18536 00005F47 8915[9CAD0000]      <1> 	mov	[RmDir_ParentDirCluster], edx
 18537                              <1> 
 18538 00005F4D 893D[9AAD0000]      <1> 	mov	[RmDir_DirEntryOffset], edi
 18539                              <1> 
 18540                              <1> loc_rmdir_get_last_cluster:
 18541 00005F53 E8241A0000          <1> 	call	get_last_cluster
 18542 00005F58 0F826BFDFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18543                              <1> 	
 18544 00005F5E 3B05[70AD0000]      <1> 	cmp	eax, [DelFile_FCluster]
 18545 00005F64 7528                <1> 	jne	short loc_rmdir_multi_dir_clusters
 18546                              <1> 
 18547 00005F66 C605[99AD0000]00    <1> 	mov	byte [RmDir_MultiClusters], 0
 18548 00005F6D EB26                <1> 	jmp	short pass_rmdir_multi_dir_clusters
 18549                              <1> 
 18550                              <1> loc_rmdir_delete_fs_directory:
 18551 00005F6F 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 18552 00005F73 0F855AFDFFFF        <1> 	jne	loc_permission_denied
 18553                              <1> 
 18554 00005F79 E8D9020000          <1> 	call	delete_fs_directory
 18555 00005F7E 0F833BFDFFFF        <1> 	jnc	loc_print_deleted_message
 18556                              <1> 
 18557 00005F84 09C0                <1> 	or	eax, eax
 18558 00005F86 7461                <1> 	jz	loc_rmdir_directory_not_empty_2         
 18559 00005F88 F9                  <1> 	stc
 18560 00005F89 E93BFDFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18561                              <1>  
 18562                              <1> loc_rmdir_multi_dir_clusters:
 18563 00005F8E C605[99AD0000]01    <1> 	mov	byte [RmDir_MultiClusters], 1
 18564                              <1> 
 18565                              <1> pass_rmdir_multi_dir_clusters:
 18566 00005F95 A3[A0AD0000]        <1> 	mov 	[RmDir_DirLastCluster], eax
 18567 00005F9A 890D[A4AD0000]      <1> 	mov	[RmDir_PreviousCluster], ecx
 18568                              <1> 
 18569                              <1> loc_rmdir_load_fat_sub_directory:
 18570 00005FA0 E86E130000          <1> 	call	load_FAT_sub_directory
 18571 00005FA5 0F821EFDFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18572                              <1> 
 18573                              <1> loc_rmdir_find_last_dir_entry:
 18574 00005FAB 56                  <1> 	push	esi
 18575 00005FAC BE[96AC0000]        <1> 	mov	esi, Dir_File_Name
 18576 00005FB1 C6062A              <1> 	mov	byte [esi], '*'
 18577 00005FB4 C646082A            <1> 	mov	byte [esi+8], '*'
 18578 00005FB8 31DB                <1> 	xor	ebx, ebx ; Entry offset  = 0
 18579                              <1> loc_rmdir_find_last_dir_entry_next:
 18580 00005FBA 66B80008            <1> 	mov	ax, 0800h ; Except volume/long names
 18581 00005FBE 6631C9              <1> 	xor	cx, cx ; 0 = Find a valid file or dir name
 18582 00005FC1 E8CA060000          <1> 	call	find_directory_entry
 18583 00005FC6 7230                <1> 	jc	short loc_rmdir_empty_dir_cluster
 18584 00005FC8 83FB01              <1> 	cmp	ebx, 1
 18585 00005FCB 771B                <1> 	ja	short loc_rmdir_directory_not_empty_1
 18586                              <1> loc_rmdir_dot_entry_check:
 18587 00005FCD 80FD2E              <1> 	cmp	ch, '.' ; The first char of the dir entry
 18588 00005FD0 7516                <1> 	jne	short loc_rmdir_directory_not_empty_1
 18589 00005FD2 08DB                <1> 	or	bl, bl
 18590 00005FD4 7506                <1> 	jnz	short loc_rmdir_dotdot_entry_check
 18591 00005FD6 807F0120            <1> 	cmp	byte [edi+1], 20h
 18592 00005FDA EB06                <1> 	jmp	short pass_rmdir_dot_entry_check
 18593                              <1> 
 18594                              <1> loc_rmdir_dotdot_entry_check:
 18595 00005FDC 66817F012E20        <1> 	cmp	word [edi+1], '. '
 18596                              <1> pass_rmdir_dot_entry_check:	
 18597 00005FE2 7504                <1> 	jne	short loc_rmdir_directory_not_empty_1 
 18598 00005FE4 FEC3                <1> 	inc	bl
 18599 00005FE6 EBD2                <1> 	jmp	short loc_rmdir_find_last_dir_entry_next  
 18600                              <1> 
 18601                              <1> loc_rmdir_directory_not_empty_1:
 18602 00005FE8 58                  <1> 	pop	eax ; pushed esi 
 18603                              <1> loc_rmdir_directory_not_empty_2:
 18604 00005FE9 BE[00990000]        <1> 	mov	esi, Msg_Dir_Not_Empty
 18605 00005FEE E847DCFFFF          <1> 	call	print_msg
 18606 00005FF3 E9D1FCFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18607                              <1> 
 18608                              <1> loc_rmdir_empty_dir_cluster:
 18609 00005FF8 5E                  <1> 	pop	esi
 18610                              <1> 
 18611                              <1> loc_rmdir_set_prev_cluster_dir_last_cluster:
 18612 00005FF9 803D[99AD0000]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
 18613 00006000 7626                <1> 	jna	short loc_rmdir_unlink_dir_last_cluster
 18614                              <1> 
 18615 00006002 A1[A4AD0000]        <1> 	mov	eax, [RmDir_PreviousCluster]
 18616 00006007 31C9                <1> 	xor	ecx, ecx
 18617 00006009 49                  <1> 	dec	ecx ; FFFFFFFFh
 18618 0000600A E838140000          <1> 	call	update_cluster
 18619 0000600F 7317                <1> 	jnc	short loc_rmdir_unlink_dir_last_cluster
 18620                              <1> 
 18621                              <1> loc_rmdir_unlink_stc_retn:
 18622 00006011 83F801              <1> 	cmp	eax, 1  ; eax = 0 -> end of cluster chain
 18623 00006014 F5                  <1> 	cmc 
 18624 00006015 0F82AEFCFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18625 0000601B EB23                <1> 	jmp	short loc_rmdir_save_fat_buffer 
 18626                              <1> 
 18627                              <1> loc_rmdir_unlink_stc_retn_0Bh:
 18628 0000601D B80B000000          <1> 	mov	eax, 0Bh ; Invalid format
 18629 00006022 F9                  <1> 	stc
 18630 00006023 E9A1FCFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18631                              <1>  
 18632                              <1> loc_rmdir_unlink_dir_last_cluster:
 18633 00006028 A1[A0AD0000]        <1> 	mov	eax, [RmDir_DirLastCluster]
 18634 0000602D 31C9                <1> 	xor	ecx, ecx ; 0
 18635 0000602F E813140000          <1> 	call	update_cluster
 18636 00006034 73E7                <1> 	jnc	short loc_rmdir_unlink_stc_retn_0Bh 
 18637                              <1> 	; Because of it is the last cluster
 18638                              <1> 	; 'update_cluster' must return with eocc error 
 18639 00006036 09C0                <1> 	or	eax, eax
 18640 00006038 7406                <1> 	jz	short loc_rmdir_save_fat_buffer ; eocc	
 18641 0000603A F9                  <1> 	stc
 18642 0000603B E989FCFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18643                              <1> 	 
 18644                              <1> loc_rmdir_save_fat_buffer:
 18645 00006040 803D[25AB0000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 18646 00006047 750B                <1> 	jne	short loc_rmdir_calculate_FAT_freespace
 18647 00006049 E8C9160000          <1> 	call	save_fat_buffer
 18648 0000604E 0F8275FCFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18649                              <1> 
 18650                              <1> loc_rmdir_calculate_FAT_freespace:
 18651 00006054 C605[C1AD0000]00    <1> 	mov	byte [CFS_error], 0
 18652                              <1> loc_rmdir_calculate_FAT_freespace_next:
 18653 0000605B 31C0                <1> 	xor	eax, eax
 18654 0000605D FEC0                <1> 	inc	al ; 1
 18655 0000605F 6689C3              <1> 	mov	bx, ax ; 1
 18656                              <1> 	; BL = 1 -> Add EAX to free space count
 18657 00006062 FECF                <1> 	dec	bh 
 18658                              <1> 	; BH = FFh ->
 18659                              <1> 	; ESI = Logical DOS Drive Desc. Tbl. addr.
 18660 00006064 E845170000          <1> 	call	calculate_fat_freespace
 18661                              <1> 
 18662 00006069 21C9                <1> 	and	ecx, ecx ; ecx = 0 -> valid free sector count
 18663 0000606B 741C                <1> 	jz 	short pass_rmdir_recalculate_FAT_freespace
 18664                              <1> 
 18665 0000606D 803D[C1AD0000]00    <1> 	cmp	byte [CFS_error], 0
 18666 00006074 7713                <1> 	ja	short loc_rmdir_calculate_FAT_freespace_err
 18667                              <1> 
 18668                              <1> loc_rmdir_recalculate_FAT_freespace:
 18669 00006076 FE05[C1AD0000]      <1> 	inc	byte [CFS_error]
 18670 0000607C 66BB00FF            <1> 	mov	bx, 0FF00h
 18671 00006080 E829170000          <1> 	call	calculate_fat_freespace
 18672 00006085 21C9                <1> 	and	ecx, ecx
 18673 00006087 74D2                <1> 	jz	short loc_rmdir_calculate_FAT_freespace_next
 18674                              <1>               
 18675                              <1> loc_rmdir_calculate_FAT_freespace_err:
 18676                              <1> pass_rmdir_recalculate_FAT_freespace:
 18677                              <1> 
 18678 00006089 803D[99AD0000]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
 18679 00006090 7616                <1> 	jna	short loc_rmdir_delete_short_name_continue
 18680                              <1> 
 18681 00006092 A1[70AD0000]        <1> 	mov	eax, [DelFile_FCluster]
 18682 00006097 E9B7FEFFFF          <1>         jmp     loc_rmdir_get_last_cluster
 18683                              <1> 
 18684                              <1> loc_rmdir_delete_short_name_invalid_data:
 18685 0000609C B80D000000          <1> 	mov	eax, 0Dh ; Invalid data
 18686 000060A1 F9                  <1> 	stc
 18687 000060A2 0F8221FCFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18688                              <1> 	          
 18689                              <1> loc_rmdir_delete_short_name_continue:
 18690 000060A8 A1[9CAD0000]        <1> 	mov	eax, [RmDir_ParentDirCluster]
 18691 000060AD 83F802              <1> 	cmp	eax, 2
 18692 000060B0 730D                <1> 	jnb	short loc_rmdir_del_short_name_load_sub_dir
 18693 000060B2 E8D1110000          <1> 	call	load_FAT_root_directory
 18694 000060B7 0F820CFCFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18695 000060BD EB0B                <1> 	jmp	short loc_rmdir_del_short_name_ld_chk_fclust
 18696                              <1> 
 18697                              <1> loc_rmdir_del_short_name_load_sub_dir:	
 18698 000060BF E84F120000          <1> 	call	load_FAT_sub_directory
 18699 000060C4 0F82FFFBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18700                              <1> 
 18701                              <1> loc_rmdir_del_short_name_ld_chk_fclust:
 18702 000060CA 0FB73D[9AAD0000]    <1> 	movzx	edi, word [RmDir_DirEntryOffset]
 18703 000060D1 81C700000800        <1> 	add	edi, Directory_Buffer
 18704                              <1> 
 18705 000060D7 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 18706 000060DB C1E010              <1> 	shl	eax, 16
 18707 000060DE 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 18708                              <1>         ; Not necessary... 
 18709 000060E2 3B05[70AD0000]      <1> 	cmp	eax, [DelFile_FCluster]
 18710 000060E8 75B2                <1> 	jne	short loc_rmdir_delete_short_name_invalid_data
 18711                              <1> 	;
 18712 000060EA C607E5              <1> 	mov	byte [edi], 0E5h ; 'Deleted' sign
 18713                              <1> 	; 27/02/2016
 18714                              <1> 	; TRDOS v1 has a bug here! it does not set
 18715                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
 18716                              <1> 	; 'save_directory_buffer' would not save the change ! 
 18717 000060ED C605[38AB0000]02    <1>   	mov	byte [DirBuff_ValidData], 2 ; change sign
 18718                              <1> 	;
 18719 000060F4 E85D0C0000          <1> 	call	save_directory_buffer
 18720 000060F9 0F82CAFBFFFF        <1> 	jc	loc_file_rw_cmd_failed 
 18721                              <1> 
 18722                              <1> loc_rmdir_del_long_name:
 18723 000060FF 0FB615[76AD0000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 18724 00006106 08D2                <1> 	or	dl, dl
 18725 00006108 7414                <1> 	jz	short loc_rmdir_update_parent_dir_lmdt
 18726                              <1>              
 18727 0000610A 0FB705[74AD0000]    <1> 	movzx	eax, word [DelFile_EntryCounter]
 18728 00006111 29D0                <1> 	sub	eax, edx
 18729 00006113 0F82B0FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18730                              <1>  
 18731                              <1>  	; EAX = Directory Entry Number of the long name last entry
 18732 00006119 E8910D0000          <1> 	call	delete_longname
 18733                              <1> 	;jc	short loc_file_rw_cmd_failed
 18734                              <1> 
 18735                              <1> loc_rmdir_update_parent_dir_lmdt:
 18736 0000611E E8C70C0000          <1> 	call	update_parent_dir_lmdt
 18737                              <1> 	;jc	short loc_file_rw_cmd_failed
 18738                              <1> 
 18739 00006123 BE[D9980000]        <1> 	mov	esi, Msg_OK
 18740 00006128 E80DDBFFFF          <1> 	call	print_msg
 18741 0000612D E997FBFFFF          <1> 	jmp	loc_file_rw_restore_retn
 18742                              <1> 
 18743                              <1> delete_file:
 18744                              <1> 	; 29/02/2016
 18745                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
 18746                              <1> 	; 09/08/2010 (CMD_INTR.ASM, 'cmp_cmd_del')
 18747                              <1> 	; 28/02/2010
 18748                              <1> 
 18749                              <1> get_delfile_fchar:
 18750                              <1> 	; esi = file name
 18751 00006132 803E20              <1> 	cmp	byte [esi], 20h
 18752                              <1> 	;je	short get_delfile_fchar
 18753                              <1>         ;ja	short loc_delfile_parse_path_name
 18754 00006135 7701                <1>         ja	short loc_delfile_parse_path_name
 18755                              <1> 
 18756                              <1> loc_delfile_nofilename_retn:
 18757 00006137 C3                  <1> 	retn
 18758                              <1> 
 18759                              <1> loc_delfile_parse_path_name:
 18760 00006138 BF[B2AC0000]        <1> 	mov	edi, FindFile_Drv
 18761 0000613D E8FC070000          <1> 	call	parse_path_name
 18762 00006142 0F8261F2FFFF        <1> 	jc	loc_cmd_failed
 18763                              <1> 
 18764                              <1> loc_delfile_check_filename_exists:
 18765 00006148 BE[F4AC0000]        <1> 	mov	esi, FindFile_Name
 18766 0000614D 803E20              <1> 	cmp	byte [esi], 20h
 18767 00006150 0F8653F2FFFF        <1> 	jna	loc_cmd_failed
 18768 00006156 8935[6CAD0000]      <1> 	mov	[DelFile_FNPointer], esi 
 18769                              <1> 
 18770                              <1> loc_delfile_drv:
 18771 0000615C 8A15[B2AC0000]      <1> 	mov	dl, [FindFile_Drv]
 18772 00006162 8A35[0EA30000]      <1> 	mov	dh, [Current_Drv]
 18773 00006168 8835[6EAB0000]      <1> 	mov	[RUN_CDRV], dh
 18774 0000616E 38F2                <1> 	cmp	dl, dh
 18775 00006170 740B                <1> 	je	short loc_delfile_change_directory
 18776                              <1> 
 18777 00006172 E8C7E3FFFF          <1> 	call	change_current_drive
 18778 00006177 0F824CFBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18779                              <1> 
 18780                              <1> loc_delfile_change_directory:
 18781 0000617D 803D[B3AC0000]20    <1> 	cmp	byte [FindFile_Directory], 20h
 18782 00006184 7618                <1> 	jna	short loc_delfile_find
 18783                              <1> 
 18784 00006186 FE05[41940000]      <1> 	inc	byte [Restore_CDIR]
 18785 0000618C BE[B3AC0000]        <1> 	mov	esi, FindFile_Directory
 18786 00006191 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
 18787 00006193 E8A2010000          <1> 	call	change_current_directory
 18788 00006198 0F822BFBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18789                              <1> 
 18790                              <1> ;loc_delfile_change_prompt_dir_string:
 18791                              <1> 	;call	change_prompt_dir_string
 18792                              <1> 
 18793                              <1> loc_delfile_find:
 18794                              <1> 	;mov	esi, FindFile_Name
 18795 0000619E 8B35[6CAD0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18796 000061A4 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
 18797 000061A8 E8F8F6FFFF          <1> 	call	find_first_file
 18798 000061AD 0F8216FBFFFF        <1> 	jc	loc_file_rw_cmd_failed
 18799                              <1> 
 18800                              <1> loc_delfile_ambgfn_check:
 18801 000061B3 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 18802 000061B6 740B                <1> 	jz	short loc_delfile_found
 18803                              <1> 
 18804 000061B8 B802000000          <1> 	mov	eax, 2 ; File not found sign
 18805 000061BD F9                  <1> 	stc
 18806 000061BE E906FBFFFF          <1> 	jmp	loc_file_rw_cmd_failed   
 18807                              <1> 
 18808                              <1> loc_delfile_found:
 18809 000061C3 80E307              <1> 	and	bl, 07h ; Attributes
 18810 000061C6 0F8507FBFFFF        <1>         jnz     loc_permission_denied
 18811                              <1> 
 18812                              <1> ;loc_delfile_found_save_lnel:
 18813                              <1> ;	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 18814                              <1> 
 18815                              <1> loc_delfile_ask_for_delete:
 18816 000061CC 57                  <1> 	push	edi ; * (29/02/2016)
 18817                              <1> 
 18818 000061CD BE[17990000]        <1> 	mov	esi, Msg_DoYouWantDelete
 18819 000061D2 E863DAFFFF          <1> 	call	print_msg
 18820 000061D7 8B35[6CAD0000]      <1> 	mov	esi, [DelFile_FNPointer]
 18821 000061DD E858DAFFFF          <1> 	call	print_msg
 18822 000061E2 BE[CB980000]        <1> 	mov	esi, Msg_YesNo
 18823 000061E7 E84EDAFFFF          <1> 	call	print_msg
 18824                              <1> 
 18825                              <1> loc_delfile_ask_again:
 18826 000061EC 30E4                <1> 	xor	ah, ah
 18827 000061EE E8F4A9FFFF          <1> 	call	int16h
 18828 000061F3 3C0B                <1> 	cmp	al, 0Bh
 18829 000061F5 740F                <1> 	je	short loc_do_not_delete_file
 18830 000061F7 24DF                <1> 	and	al, 0DFh
 18831 000061F9 A2[D5980000]        <1> 	mov	[Y_N_nextline], al
 18832 000061FE 3C59                <1> 	cmp	al, 'Y'
 18833 00006200 7404                <1> 	je	short loc_yes_delete_file
 18834 00006202 3C4E                <1> 	cmp	al, 'N'
 18835 00006204 75E6                <1> 	jne	short loc_delfile_ask_again
 18836                              <1> 
 18837                              <1> loc_do_not_delete_file:
 18838                              <1> loc_yes_delete_file:
 18839 00006206 A2[D5980000]        <1> 	mov	[Y_N_nextline], al
 18840 0000620B 6650                <1> 	push	ax
 18841 0000620D BE[D5980000]        <1> 	mov	esi, Y_N_nextline
 18842 00006212 E823DAFFFF          <1> 	call	print_msg
 18843 00006217 6658                <1> 	pop	ax
 18844 00006219 5F                  <1> 	pop	edi ; * (29/02/2016)
 18845                              <1> 	;cmp	al, 'Y' ; 'yes'
 18846                              <1> 	;cmc
 18847                              <1>         ;jnc	loc_file_rw_restore_retn
 18848 0000621A 3C4E                <1> 	cmp	al, 'N' ; 'no'
 18849 0000621C 0F84A7FAFFFF        <1>         je	loc_file_rw_restore_retn  
 18850                              <1> 
 18851                              <1> loc_delete_file:
 18852 00006222 8A3D[B2AC0000]      <1> 	mov	bh, [FindFile_Drv]
 18853                              <1> 	;mov	bl, [DelFile_LNEL]
 18854 00006228 8A1D[01AD0000]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
 18855                              <1> 	;mov	cx, [DirBuff_EntryCounter]
 18856 0000622E 668B0D[2CAD0000]    <1> 	mov	cx, [FindFile_DirEntryNumber]
 18857                              <1> 	; (*) EDI = Directory buffer entry offset/address 
 18858 00006235 E85A0E0000          <1> 	call	remove_file ; (FILE.ASM, 'proc_delete_file')
 18859 0000623A 0F837FFAFFFF        <1> 	jnc	loc_print_deleted_message
 18860                              <1> 
 18861 00006240 3C05                <1> 	cmp	al, 05h
 18862 00006242 0F848BFAFFFF        <1> 	je	loc_permission_denied
 18863 00006248 F9                  <1> 	stc
 18864 00006249 E97BFAFFFF          <1> 	jmp	loc_file_rw_cmd_failed
 18865                              <1> 
 18866                              <1> copy_file:
 18867 0000624E C3                  <1> 	retn
 18868                              <1> move_file:
 18869 0000624F C3                  <1> 	retn
 18870                              <1> set_get_path:
 18871 00006250 C3                  <1> 	retn
 18872                              <1> find_and_list_files:
 18873 00006251 C3                  <1> 	retn
 18874                              <1> set_get_env:
 18875 00006252 C3                  <1> 	retn
 18876                              <1> set_exec_arguments:
 18877 00006253 C3                  <1> 	retn
 18878                              <1> load_and_execute_file:
 18879 00006254 C3                  <1> 	retn
 18880                              <1> set_file_attributes:
 18881 00006255 C3                  <1> 	retn
 18882                              <1> rename_file:
 18883 00006256 C3                  <1> 	retn
 18884                              <1> delete_fs_directory:
 18885 00006257 31C0                <1> 	xor eax, eax
 18886 00006259 C3                  <1> 	retn
 18887                                  %include 'trdosk4.s' ; 24/01/2016
 18888                              <1> ; ****************************************************************************
 18889                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - Directory Functions : trdosk4.s
 18890                              <1> ; ----------------------------------------------------------------------------
 18891                              <1> ; Last Update: 28/02/2016
 18892                              <1> ; ----------------------------------------------------------------------------
 18893                              <1> ; Beginning: 24/01/2016
 18894                              <1> ; ----------------------------------------------------------------------------
 18895                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 18896                              <1> ; ----------------------------------------------------------------------------
 18897                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 18898                              <1> ; DIR.ASM (09/10/2011)
 18899                              <1> ; ****************************************************************************
 18900                              <1> 
 18901                              <1> ; DIR.ASM  [ TRDOS KERNEL - COMMAND EXECUTER SECTION - DIRECTORY FUNCTIONS ]
 18902                              <1> ; (c) 2004-2010  Erdogan TAN  [ 17/01/2004 ]  Last Update: 09/10/2011
 18903                              <1> ; FILE.ASM [ FILE FUNCTIONS ] Last Update: 09/10/2011
 18904                              <1> 
 18905                              <1> change_prompt_dir_string:
 18906                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 18907                              <1> 	; 27/03/2011
 18908                              <1> 	; 09/10/2009
 18909                              <1> 	; INPUT/OUTPUT => none
 18910                              <1> 	; this procedure changes current directory string/text  
 18911                              <1> 	; 2005
 18912                              <1> 
 18913 0000625A BF[12A30000]        <1> 	mov	edi, Current_Directory
 18914 0000625F 8A25[0CA30000]      <1> 	mov	ah, [Current_Dir_Level]
 18915 00006265 BE[6FAB0000]        <1> 	mov	esi, PATH_Array
 18916 0000626A E807000000          <1> 	call	set_current_directory_string
 18917 0000626F 880D[6DA30000]      <1> 	mov	[Current_Dir_StrLen], cl
 18918                              <1> 
 18919 00006275 C3                  <1> 	retn
 18920                              <1> 
 18921                              <1> set_current_directory_string:
 18922                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 18923                              <1> 	; 27/03/2011
 18924                              <1> 	; 09/10/2009
 18925                              <1> 	; INPUT:
 18926                              <1> 	;    ESI = Path Array Address 
 18927                              <1> 	;    EDI = Current Directory String Buffer
 18928                              <1> 	;    AH = Current Directory Level
 18929                              <1> 	; OUTPUT => EAX, EBX, ESI will be changed
 18930                              <1> 	;    EDI will be same with input
 18931                              <1> 	;    ECX = Current Directory String Length 
 18932                              <1> 
 18933 00006276 57                  <1> 	push    edi
 18934 00006277 80FC00              <1> 	cmp     ah, 0
 18935 0000627A 7652                <1> 	jna	short pass_write_path
 18936 0000627C 83C610              <1> 	add	esi, 16
 18937 0000627F 89F3                <1> 	mov	ebx, esi
 18938                              <1> loc_write_path:
 18939 00006281 B908000000          <1> 	mov	ecx, 8
 18940                              <1> path_write_dirname1:
 18941 00006286 AC                  <1> 	lodsb
 18942 00006287 3C20                <1> 	cmp	al, 20h
 18943 00006289 7612                <1> 	jna	short pass_write_dirname1
 18944 0000628B AA                  <1> 	stosb
 18945 0000628C 81FF[6CA30000]      <1> 	cmp	edi, End_Of_Current_Dir_Str
 18946 00006292 733A                <1> 	jnb	short pass_write_path
 18947 00006294 E2F0                <1> 	loop	path_write_dirname1
 18948 00006296 803E20              <1> 	cmp	byte [esi], 20h
 18949 00006299 7624                <1> 	jna	short pass_write_dirname2
 18950 0000629B EB0A                <1> 	jmp     short loc_put_dot_cont_ext
 18951                              <1> pass_write_dirname1:
 18952 0000629D 89DE                <1> 	mov	esi, ebx
 18953 0000629F 83C608              <1> 	add	esi, 8
 18954 000062A2 803E20              <1> 	cmp	byte [esi], 20h
 18955 000062A5 7618                <1> 	jna	short pass_write_dirname2
 18956                              <1> loc_put_dot_cont_ext:
 18957 000062A7 C6072E              <1> 	mov	byte [edi], "."
 18958                              <1> 	;mov	ecx, 3
 18959 000062AA B103                <1> 	mov	cl, 3
 18960                              <1> loc_check_dir_name_ext:
 18961 000062AC AC                  <1> 	lodsb
 18962 000062AD 47                  <1> 	inc	edi
 18963 000062AE 3C20                <1> 	cmp	al, 20h
 18964 000062B0 760D                <1> 	jna	short pass_write_dirname2
 18965 000062B2 8807                <1> 	mov	[edi], al
 18966 000062B4 81FF[6CA30000]      <1> 	cmp	edi, End_Of_Current_Dir_Str
 18967 000062BA 7312                <1> 	jnb	short pass_write_path
 18968 000062BC E2EE                <1> 	loop    loc_check_dir_name_ext
 18969 000062BE 47                  <1> 	inc	edi
 18970                              <1> pass_write_dirname2:
 18971 000062BF FECC                <1> 	dec	ah
 18972 000062C1 740B                <1> 	jz      short pass_write_path
 18973 000062C3 83C310              <1> 	add	ebx, 16
 18974 000062C6 89DE                <1> 	mov	esi, ebx
 18975 000062C8 C6072F              <1> 	mov	byte [edi],"/"
 18976 000062CB 47                  <1> 	inc	edi
 18977 000062CC EBB3                <1> 	jmp	short loc_write_path
 18978                              <1> pass_write_path:
 18979 000062CE C60700              <1> 	mov	byte [edi], 0
 18980 000062D1 47                  <1> 	inc	edi
 18981 000062D2 89F9                <1> 	mov	ecx, edi
 18982 000062D4 5F                  <1> 	pop	edi
 18983 000062D5 29F9                <1> 	sub	ecx, edi
 18984                              <1> 	; ECX = Current Directory String Length
 18985 000062D7 C3                  <1> 	retn
 18986                              <1> 
 18987                              <1> get_current_directory:
 18988                              <1> 	; 14/02/2016
 18989                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
 18990                              <1> 	; 27/03/2011
 18991                              <1> 	;
 18992                              <1> 	; INPUT-> ESI = Current Directory Buffer
 18993                              <1> 	;         DL = TRDOS Logical Dos Drive Number + 1
 18994                              <1> 	;              (0= Default/Current Drive)
 18995                              <1> 	;           
 18996                              <1> 	;   Note: Required dir buffer length may be <= 92 bytes
 18997                              <1> 	;         for TRDOS (7*12 name chars + 7 slash + 0)
 18998                              <1> 	; OUTPUT ->  ESI = Current Directory Buffer
 18999                              <1> 	;            EAX, EBX, ECX, EDX, EDI will be changed
 19000                              <1> 	;            CX/CL = Current Directory String Length
 19001                              <1> 	;	     DL = Drive Number (0 based)
 19002                              <1> 	;            (If input is 0, output is current drv number) 
 19003                              <1> 	;            DH = same with input 
 19004                              <1> 	;   cf = 0 -> AL = 0
 19005                              <1> 	;   cf = 1 -> error code in AL 
 19006                              <1>               
 19007                              <1> loc_get_current_drive_0:
 19008 000062D8 80FA00              <1> 	cmp	dl, 0
 19009 000062DB 7708                <1> 	ja	short loc_get_current_drive_1
 19010 000062DD 8A15[0EA30000]      <1> 	mov	dl, [Current_Drv]
 19011 000062E3 EB17                <1> 	jmp	short loc_get_current_drive_2
 19012                              <1> loc_get_current_drive_1:
 19013 000062E5 FECA                <1> 	dec 	dl
 19014 000062E7 3A15[40940000]      <1> 	cmp	dl, [Last_DOS_DiskNo]
 19015 000062ED 760D                <1> 	jna	short loc_get_current_drive_2
 19016 000062EF B80F000000          <1> 	mov	eax, 0Fh ; Invalid drive
 19017 000062F4 F5                  <1> 	cmc 	; stc
 19018 000062F5 C3                  <1> 	retn
 19019                              <1> 
 19020                              <1> loc_get_current_drive_not_ready_retn:
 19021 000062F6 5E                  <1> 	pop	esi
 19022                              <1> 	;mov	eax, 15h
 19023 000062F7 66B81500            <1> 	mov	ax, 15h ; Drive not ready
 19024 000062FB C3                  <1> 	retn  
 19025                              <1>  
 19026                              <1> loc_get_current_drive_2:
 19027 000062FC 31C0                <1> 	xor	eax, eax
 19028 000062FE 88D4                <1> 	mov	ah, dl
 19029 00006300 56                  <1> 	push	esi
 19030 00006301 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 19031 00006306 01C6                <1> 	add	esi, eax
 19032 00006308 8A06                <1> 	mov	al, [esi+LD_Name] 
 19033 0000630A 3C41                <1> 	cmp	al, 'A'
 19034 0000630C 72E8                <1> 	jb	short loc_get_current_drive_not_ready_retn
 19035                              <1> 
 19036 0000630E 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
 19037 00006311 08E4                <1> 	or	ah, ah
 19038 00006313 7506                <1> 	jnz	short loc_get_current_drive_3
 19039                              <1> 
 19040                              <1> 	;xor	ah, ah ; mov ah, 0
 19041 00006315 8826                <1> 	mov	[esi], ah
 19042 00006317 31C9                <1> 	xor	ecx, ecx
 19043 00006319 EB1C                <1> 	jmp	short loc_get_current_drive_4
 19044                              <1> 
 19045                              <1> loc_get_current_drive_3:
 19046 0000631B BF[6FAB0000]        <1>         mov     edi, PATH_Array
 19047 00006320 57                  <1> 	push	edi
 19048 00006321 81C680000000        <1> 	add	esi, LD_CurrentDirectory
 19049 00006327 B920000000          <1> 	mov	ecx, 32
 19050 0000632C F3A5                <1> 	rep	movsd
 19051 0000632E 5E                  <1> 	pop	esi ; Path Array Address
 19052 0000632F 5F                  <1> 	pop	edi ; pushed esi (current dir buffer offset) 
 19053                              <1> 	;
 19054 00006330 E841FFFFFF          <1> 	call	set_current_directory_string
 19055 00006335 89FE                <1> 	mov	esi, edi
 19056                              <1> 
 19057                              <1> loc_get_current_drive_4:
 19058 00006337 30C0                <1> 	xor	al, al
 19059 00006339 C3                  <1> 	retn
 19060                              <1> 
 19061                              <1> change_current_directory:
 19062                              <1> 	; 19/02/2016
 19063                              <1> 	; 11/02/2016
 19064                              <1> 	; 10/02/2016
 19065                              <1> 	; 08/02/2016
 19066                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 19067                              <1> 	; 18/09/2011 (DIR.ASM, 09/10/2011)	
 19068                              <1> 	; 04/10/2009
 19069                              <1> 	; 2005
 19070                              <1> 	; INPUT -> 
 19071                              <1> 	;	ESI = Directory string
 19072                              <1> 	;	ah = CD command (CDh = save current dir string)
 19073                              <1> 	; OUTPUT -> 
 19074                              <1> 	; 	EDI = DOS Drive Description Table
 19075                              <1> 	; 	cf = 1 -> error
 19076                              <1> 	;	   EAX = Error code
 19077                              <1> 	;	cf = 0 -> succesful
 19078                              <1> 	;	   ESI = PATH_Array
 19079                              <1> 	;	   EAX = Current Directory First Cluster
 19080                              <1> 	;
 19081                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
 19082                              <1> 	
 19083 0000633A 8825[FDAB0000]      <1> 	mov	[CD_COMMAND], ah
 19084 00006340 803E2F              <1> 	cmp	byte [esi], '/'
 19085 00006343 7505                <1> 	jne	short loc_ccd_cdir_level
 19086 00006345 46                  <1> 	inc	esi
 19087 00006346 30C0                <1> 	xor	al, al
 19088 00006348 EB05                <1> 	jmp	short loc_ccd_parse_path_name
 19089                              <1> loc_ccd_cdir_level:
 19090 0000634A A0[0CA30000]        <1> 	mov	al, [Current_Dir_Level]
 19091                              <1> loc_ccd_parse_path_name:
 19092 0000634F 88C4                <1> 	mov	ah, al
 19093 00006351 BF[6FAB0000]        <1> 	mov	edi, PATH_Array
 19094                              <1> 
 19095                              <1> ; Reset directory levels > cdir level
 19096                              <1> 	; is this required !?
 19097                              <1> 	;
 19098                              <1> 	; Relations:
 19099                              <1> 	; MAINPROG.ASM (pass_ccdrv_reset_cdir_FAT_fcluster)
 19100                              <1> 	; proc_parse_dir_name,
 19101                              <1> 	; proc_change_current_directory (this procedure)
 19102                              <1> 	; proc_change_prompt_dir_string 
 19103                              <1>  
 19104 00006356 0FB6C8              <1> 	movzx	ecx, al
 19105 00006359 FEC1                <1> 	inc	cl
 19106 0000635B C0E104              <1> 	shl	cl, 4
 19107 0000635E 01CF                <1> 	add	edi, ecx
 19108 00006360 B107                <1> 	mov	cl, 7
 19109 00006362 28C1                <1> 	sub	cl, al
 19110 00006364 C0E102              <1> 	shl	cl, 2
 19111 00006367 89C3                <1> 	mov	ebx, eax
 19112 00006369 31C0                <1> 	xor	eax, eax ; 0
 19113 0000636B F3AB                <1> 	rep	stosd
 19114 0000636D 89D8                <1> 	mov	eax, ebx
 19115                              <1> 
 19116 0000636F BF[6FAB0000]        <1> 	mov	edi, PATH_Array
 19117                              <1> 
 19118 00006374 803E20              <1> 	cmp	byte [esi], 20h
 19119 00006377 F5                  <1> 	cmc
 19120 00006378 7305                <1> 	jnc	short pass_ccd_parse_dir_name
 19121                              <1> 
 19122                              <1> 		; ESI = Path name
 19123                              <1> 		; AL = CCD_Level
 19124 0000637A E872010000          <1>         call    parse_dir_name
 19125                              <1> 		; AL = CCD_Level 
 19126                              <1> 		; AH = Last_Dir_Level
 19127                              <1> 		; (EDI = PATH_Array)
 19128                              <1> 
 19129                              <1> pass_ccd_parse_dir_name:
 19130 0000637F 9C                  <1> 	pushf
 19131                              <1> 
 19132                              <1> 	;mov	[CCD_Level], al
 19133                              <1>         ;mov	[Last_Dir_Level], ah
 19134 00006380 66A3[F3AB0000]      <1> 	mov	[CCD_Level], ax
 19135                              <1> 
 19136 00006386 31DB                <1> 	xor	ebx, ebx
 19137 00006388 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 19138 0000638E BE00010900          <1> 	mov	esi, Logical_DOSDisks
 19139 00006393 01DE                <1> 	add	esi, ebx
 19140                              <1> 
 19141 00006395 9D                  <1> 	popf 
 19142 00006396 720A                <1> 	jc	short loc_ccd_bad_path_name_retn
 19143                              <1> 
 19144 00006398 8935[EFAB0000]      <1> 	mov	[CCD_DriveDT], esi
 19145                              <1> 
 19146 0000639E 3C07                <1> 	cmp	al, 7
 19147 000063A0 7209                <1> 	jb	short loc_ccd_load_child_dir
 19148                              <1> 
 19149                              <1> loc_ccd_bad_path_name_retn:
 19150 000063A2 87F7                <1> 	xchg	esi, edi
 19151                              <1> 	; DOS Error Code 
 19152 000063A4 B818000000          <1> 	mov	eax, 18h ; Bad request structure length 
 19153 000063A9 F9                  <1> 	stc
 19154                              <1> loc_ccd_retn_p:
 19155 000063AA C3                  <1> 	retn
 19156                              <1> 
 19157                              <1> loc_ccd_load_child_dir:
 19158                              <1> 	; AL = CCD_Level
 19159 000063AB 08C0                <1> 	or	al, al
 19160 000063AD 7468                <1> 	jz	short loc_ccd_load_root_dir
 19161                              <1> 
 19162 000063AF 6689C1              <1> 	mov	cx, ax
 19163 000063B2 C0E004              <1> 	shl	al, 4
 19164 000063B5 0FB6F0              <1> 	movzx	esi, al
 19165 000063B8 01FE                <1>      	add	esi, edi  ; offset PATH_Array
 19166                              <1> 
 19167 000063BA 8B460C              <1> 	mov	eax, [esi+12]
 19168 000063BD 38E9                <1> 	cmp	cl, ch
 19169 000063BF 0F84FA000000        <1>         je      loc_ccd_load_sub_directory
 19170 000063C5 A3[08A30000]        <1> 	mov	[Current_Dir_FCluster], eax
 19171                              <1> 
 19172                              <1> loc_ccd_load_child_dir_next:
 19173 000063CA 83C610              <1> 	add	esi, 16 ; DOS DirEntry Format FileName Address
 19174                              <1> 
 19175                              <1>  	; Directory attribute : 10h
 19176 000063CD B010                <1> 	mov	al, 00010000b ; 10h (Attrib AND mask)
 19177                              <1> 	;mov	ah, 11001000b ; C8h
 19178                              <1> 	; Volume name attribute: 8h
 19179 000063CF B408                <1> 	mov	ah, 00001000b ; 08h (Attrib NAND, AND --> zero mask)
 19180                              <1> 
 19181 000063D1 6631C9              <1> 	xor	cx, cx  
 19182 000063D4 E8B5010000          <1> 	call	locate_current_dir_file
 19183 000063D9 7353                <1> 	jnc	short loc_ccd_set_dir_cluster_ptr
 19184                              <1> 
 19185                              <1> 	 ; 19/02/2016
 19186                              <1> 	;mov	edi, [CCD_DriveDT]
 19187 000063DB 8A25[F3AB0000]      <1> 	mov	ah, [CCD_Level]
 19188 000063E1 803D[FDAB0000]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
 19189 000063E8 7509                <1> 	jne	short loc_ccd_load_child_dir_err
 19190                              <1> 	; It is better to save recent successful part 
 19191                              <1> 	; of the (requested) path as current directory.
 19192                              <1> 	; (Otherwise the path would be reset to back
 19193                              <1> 	; on the next 'CD' command.)
 19194 000063EA 88E1                <1> 	mov	cl, ah
 19195 000063EC 50                  <1> 	push	eax
 19196 000063ED E8E3000000          <1> 	call	loc_ccd_save_current_dir
 19197 000063F2 58                  <1> 	pop	eax
 19198                              <1> loc_ccd_load_child_dir_err:            
 19199 000063F3 3C03                <1> 	cmp	al, 3	; AL = 2 => File not found error
 19200 000063F5 7202                <1> 	jb	short loc_ccd_path_not_found_retn
 19201 000063F7 F9                  <1> 	stc
 19202 000063F8 C3                  <1> 	retn
 19203                              <1> 
 19204                              <1> loc_ccd_path_not_found_retn:
 19205 000063F9 B003                <1> 	mov	al, 3	; Path not found
 19206 000063FB C3                  <1> 	retn
 19207                              <1> 
 19208                              <1> loc_ccd_load_FAT_root_dir:
 19209 000063FC 803D[0DA30000]02    <1> 	cmp	byte [Current_FATType], 2
 19210 00006403 776B                <1> 	ja	short loc_ccd_load_FAT32_root_dir
 19211                              <1> 
 19212                              <1> 	;mov	esi, [CCD_DriveDT]
 19213                              <1> 	;push	esi
 19214 00006405 E87E0E0000          <1> 	call	load_FAT_root_directory
 19215                              <1> 	;pop	edi ; Dos Drv Description Table
 19216                              <1> 
 19217 0000640A 89F7                <1> 	mov	edi, esi
 19218 0000640C BE[6FAB0000]        <1> 	mov	esi, PATH_Array
 19219 00006411 7297                <1> 	jc	short loc_ccd_retn_p
 19220                              <1> 
 19221 00006413 31C0                <1> 	xor	eax, eax
 19222 00006415 EB78                <1>         jmp	short loc_ccd_set_cdfc
 19223                              <1> 
 19224                              <1> loc_ccd_load_root_dir:
 19225 00006417 803D[0DA30000]01    <1> 	cmp	byte [Current_FATType], 1
 19226 0000641E 73DC                <1> 	jnb	short loc_ccd_load_FAT_root_dir
 19227                              <1> 
 19228                              <1> loc_ccd_load_FS_root_dir:
 19229 00006420 E82A0F0000          <1> 	call	load_FS_root_directory
 19230 00006425 EB5C                <1> 	jmp	short pass_ccd_load_FAT_sub_directory
 19231                              <1> 
 19232                              <1> loc_ccd_load_FS_sub_directory_next:
 19233 00006427 E8240F0000          <1> 	call	load_FS_sub_directory
 19234 0000642C EB1F                <1> 	jmp	short pass_ccd_set_dir_cluster_ptr  
 19235                              <1> 
 19236                              <1> loc_ccd_set_dir_cluster_ptr:
 19237                              <1> 	; EDI = Directory Entry
 19238 0000642E 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 19239 00006432 C1E010              <1> 	shl	eax, 16
 19240 00006435 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 19241                              <1> 
 19242 00006439 8B35[EFAB0000]      <1> 	mov	esi, [CCD_DriveDT]
 19243 0000643F 803D[0DA30000]01    <1> 	cmp	byte [Current_FATType], 1
 19244 00006446 72DF                <1> 	jb	short loc_ccd_load_FS_sub_directory_next
 19245                              <1> 	;push	esi
 19246 00006448 E8C60E0000          <1> 	call	load_FAT_sub_directory
 19247                              <1> 	;pop	edi ; Dos Drv Description Table
 19248                              <1> 
 19249                              <1> pass_ccd_set_dir_cluster_ptr:
 19250                              <1> 	;mov	edi, esi
 19251 0000644D BE[6FAB0000]        <1> 	mov	esi, PATH_Array
 19252 00006452 7264                <1> 	jc	short loc_ccd_retn_c
 19253                              <1> 
 19254 00006454 A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 19255                              <1> 
 19256 00006459 FE05[F3AB0000]      <1> 	inc	byte [CCD_Level]
 19257 0000645F 0FB61D[F3AB0000]    <1> 	movzx	ebx, byte [CCD_Level]
 19258 00006466 C0E304              <1> 	shl	bl, 4 ; * 16 (<= 128)   
 19259 00006469 01DE                <1> 	add	esi, ebx ; 19/02/2016
 19260 0000646B 89460C              <1> 	mov	[esi+12], eax
 19261 0000646E EB1F                <1> 	jmp	short loc_ccd_set_cdfc
 19262                              <1> 
 19263                              <1> loc_ccd_load_FAT32_root_dir:
 19264 00006470 BE[6FAB0000]        <1> 	mov	esi, PATH_Array
 19265 00006475 8B460C              <1> 	mov	eax, [esi+12]
 19266 00006478 8B35[EFAB0000]      <1> 	mov	esi, [CCD_DriveDT]
 19267                              <1>  
 19268                              <1> loc_ccd_load_FAT_sub_directory:
 19269                              <1> 	;push	esi
 19270 0000647E E8900E0000          <1> 	call	load_FAT_sub_directory
 19271                              <1> 	;pop	edi ; Dos Drv Description Table
 19272                              <1> 
 19273                              <1> pass_ccd_load_FAT_sub_directory:
 19274                              <1> 	;mov	edi, esi
 19275 00006483 BE[6FAB0000]        <1> 	mov	esi, PATH_Array
 19276 00006488 722E                <1> 	jc	short loc_ccd_retn_c
 19277                              <1> 
 19278 0000648A A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 19279                              <1> 
 19280                              <1> loc_ccd_set_cdfc:
 19281 0000648F 8A0D[F3AB0000]      <1> 	mov	cl, [CCD_Level]
 19282 00006495 880D[0CA30000]      <1> 	mov	[Current_Dir_Level], cl
 19283 0000649B A3[08A30000]        <1> 	mov	[Current_Dir_FCluster], eax
 19284                              <1> 
 19285 000064A0 8A2D[F4AB0000]      <1> 	mov	ch, [Last_Dir_Level]
 19286 000064A6 38E9                <1> 	cmp	cl, ch 
 19287 000064A8 0F821CFFFFFF        <1> 	jb	loc_ccd_load_child_dir_next
 19288                              <1> 	
 19289 000064AE 803D[FDAB0000]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
 19290 000064B5 741E                <1> 	je	short loc_ccd_save_current_dir
 19291                              <1> 
 19292                              <1>         ; jne -> don't save, restore (the previous cdir) later !
 19293                              <1>         ; (saving the cdir would prevent previous cdir restoration!)
 19294                              <1> 
 19295 000064B7 F8                  <1> 	clc
 19296                              <1> 
 19297                              <1> loc_ccd_retn_c:
 19298 000064B8 8B3D[EFAB0000]      <1> 	mov	edi, [CCD_DriveDT]
 19299 000064BE C3                  <1> 	retn
 19300                              <1> 
 19301                              <1> loc_ccd_load_sub_directory:
 19302 000064BF 8B35[EFAB0000]      <1> 	mov	esi, [CCD_DriveDT]
 19303 000064C5 803D[0DA30000]01    <1> 	cmp	byte [Current_FATType], 1
 19304 000064CC 73B0                <1> 	jnb	short loc_ccd_load_FAT_sub_directory 
 19305 000064CE E87D0E0000          <1> 	call	load_FS_sub_directory
 19306 000064D3 EBAE                <1> 	jmp	short pass_ccd_load_FAT_sub_directory 
 19307                              <1> 
 19308                              <1> loc_ccd_save_current_dir:
 19309 000064D5 BE[6FAB0000]        <1> 	mov	esi, PATH_Array ; 19/02/2016
 19310 000064DA 8B3D[EFAB0000]      <1> 	mov	edi, [CCD_DriveDT]
 19311 000064E0 57                  <1> 	push	edi
 19312 000064E1 83C77F              <1>         add     edi, LD_CDirLevel
 19313 000064E4 880F                <1> 	mov	[edi], cl
 19314 000064E6 47                  <1> 	inc	edi ; LD_CurrentDirectory 
 19315 000064E7 56                  <1> 	push	esi
 19316                              <1> 	;mov	ecx, 32  ; always < 65536 (in this procedure)
 19317 000064E8 66B92000            <1> 	mov	cx, 32
 19318 000064EC F3A5                <1> 	rep	movsd
 19319                              <1> 	; Current directory has been saved to 
 19320                              <1> 	; the DOS drive description table, cdir area !
 19321 000064EE 5E                  <1> 	pop	esi  ; PATH_Array
 19322 000064EF 5F                  <1> 	pop	edi  ; Dos Drv Description Table
 19323                              <1> 
 19324 000064F0 C3                  <1> 	retn
 19325                              <1> 
 19326                              <1> parse_dir_name:
 19327                              <1> 	; 11/02/2016
 19328                              <1> 	; 10/02/2016
 19329                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
 19330                              <1> 	; 18/09/2011
 19331                              <1> 	; 17/10/2009
 19332                              <1> 	; INPUT ->
 19333                              <1> 	;	ESI = ASCIIZ Directory String Address
 19334                              <1> 	;	AL = Current Directory Level
 19335                              <1> 	;	EDI = Destination Adress
 19336                              <1> 	;	     (8 levels, each one 12+4 byte)
 19337                              <1> 	; OUTPUT ->
 19338                              <1> 	;	EDI = Dir Entry Formatted Array
 19339                              <1> 	;	     with zero cluster pointer at the last level
 19340                              <1> 	;	AH = Last Dir Level
 19341                              <1> 	;	AL = Current Dir Level
 19342                              <1> 	;
 19343                              <1> 	; (esi, ebx, ecx will be changed) 
 19344                              <1> 
 19345                              <1> 	;mov	[PATH_Array_Ptr], edi
 19346 000064F1 88C4                <1> 	mov	ah, al
 19347 000064F3 66A3[94AC0000]      <1> 	mov	[PATH_CDLevel], ax
 19348                              <1> repeat_ppdn_check_slash:
 19349 000064F9 AC                  <1> 	lodsb
 19350 000064FA 3C2F                <1> 	cmp	al, '/'
 19351 000064FC 74FB                <1> 	je	short repeat_ppdn_check_slash
 19352 000064FE 3C21                <1> 	cmp	al, 21h
 19353 00006500 7219                <1> 	jb	short loc_ppdn_retn
 19354 00006502 57                  <1> 	push	edi
 19355                              <1> loc_ppdn_get_dir_name:
 19356 00006503 B90C000000          <1> 	mov	ecx, 12
 19357 00006508 BF[96AC0000]        <1> 	mov	edi, Dir_File_Name
 19358                              <1> repeat_ppdn_get_dir_name:
 19359 0000650D AA                  <1> 	stosb
 19360 0000650E AC                  <1> 	lodsb
 19361 0000650F 3C2F                <1> 	cmp	al, '/'
 19362 00006511 740A                <1> 	je	short loc_check_level_dot_conv_dir_name
 19363 00006513 3C20                <1> 	cmp	al, 20h
 19364 00006515 7605                <1> 	jna	short loc_ppdn_end_of_path_scan
 19365 00006517 E2F4                <1> 	loop	repeat_ppdn_get_dir_name
 19366 00006519 5F                  <1> 	pop	edi
 19367 0000651A F9                  <1> 	stc
 19368                              <1> loc_ppdn_retn:
 19369 0000651B C3                  <1> 	retn
 19370                              <1> 
 19371                              <1> loc_ppdn_end_of_path_scan:
 19372 0000651C 4E                  <1> 	dec	esi
 19373                              <1> loc_check_level_dot_conv_dir_name:
 19374 0000651D 31C0                <1> 	xor	eax, eax
 19375 0000651F AA                  <1> 	stosb
 19376 00006520 89F3                <1> 	mov	ebx, esi
 19377 00006522 BE[96AC0000]        <1> 	mov	esi, Dir_File_Name
 19378 00006527 AC                  <1> 	lodsb
 19379                              <1> repeat_ppdn_name_check_dot:
 19380 00006528 3C2E                <1> 	cmp	al, '.'
 19381 0000652A 7509                <1> 	jne	short loc_ppdn_convert_sub_dir_name
 19382                              <1> repeat_ppdn_name_dot_dot:
 19383 0000652C AC                  <1> 	lodsb
 19384 0000652D 3C2E                <1> 	cmp	al, '.'
 19385 0000652F 743E                <1> 	je	short loc_ppdn_dot_dot
 19386 00006531 3C21                <1> 	cmp	al, 21h
 19387 00006533 7226                <1> 	jb	short pass_ppdn_convert_sub_dir_name
 19388                              <1> loc_ppdn_convert_sub_dir_name:
 19389 00006535 8A25[95AC0000]      <1> 	mov	ah, [PATH_Level]
 19390 0000653B 80FC07              <1> 	cmp	ah, 7
 19391 0000653E 731B                <1> 	jnb	short pass_ppdn_convert_sub_dir_name
 19392 00006540 FEC4                <1> 	inc	ah  
 19393 00006542 8825[95AC0000]      <1> 	mov	[PATH_Level], ah
 19394 00006548 BE[96AC0000]        <1> 	mov	esi, Dir_File_Name
 19395                              <1> 	;mov	edi, [PATH_Array_Ptr]
 19396 0000654D B010                <1> 	mov	al, 16
 19397 0000654F F6E4                <1> 	mul	ah
 19398 00006551 8B3C24              <1> 	mov	edi, [esp]
 19399                              <1> 	;push	edi 
 19400 00006554 01C7                <1> 	add	edi, eax
 19401 00006556 E828030000          <1> 	call	convert_file_name
 19402                              <1> 	;pop	edi
 19403                              <1> pass_ppdn_convert_sub_dir_name:
 19404 0000655B 89DE                <1> 	mov	esi, ebx
 19405                              <1> repeat_ppdn_check_last_slash:
 19406 0000655D AC                  <1> 	lodsb
 19407 0000655E 3C2F                <1> 	cmp	al, '/'
 19408 00006560 74FB                <1> 	je	short repeat_ppdn_check_last_slash
 19409 00006562 3C21                <1> 	cmp	al, 21h
 19410 00006564 739D                <1> 	jnb	short loc_ppdn_get_dir_name
 19411                              <1> end_of_parse_dir_name:
 19412 00006566 5F                  <1> 	pop	edi
 19413 00006567 F5                  <1> 	cmc  
 19414                              <1> 	;mov	al, [PATH_CDLevel]
 19415                              <1> 	;mov	ah, [PATH_Level]
 19416 00006568 66A1[94AC0000]      <1> 	mov	ax, [PATH_CDLevel]
 19417 0000656E C3                  <1> 	retn
 19418                              <1> 
 19419                              <1> loc_ppdn_dot_dot:
 19420 0000656F AC                  <1> 	lodsb
 19421 00006570 3C21                <1> 	cmp	al, 21h
 19422 00006572 73F2                <1> 	jnb	short end_of_parse_dir_name 
 19423                              <1> loc_ppdn_dot_dot_prev_level:
 19424 00006574 66A1[94AC0000]      <1> 	mov	ax, [PATH_CDLevel]
 19425 0000657A 80EC01              <1> 	sub	ah, 1
 19426 0000657D 80D400              <1> 	adc	ah, 0
 19427 00006580 38E0                <1> 	cmp	al, ah
 19428 00006582 7602                <1> 	jna	short pass_ppdn_set_al_to_ah
 19429 00006584 88E0                <1> 	mov	al, ah
 19430                              <1> pass_ppdn_set_al_to_ah:
 19431 00006586 66A3[94AC0000]      <1> 	mov	[PATH_CDLevel], ax
 19432 0000658C EBCD                <1> 	jmp	short pass_ppdn_convert_sub_dir_name
 19433                              <1> 
 19434                              <1> locate_current_dir_file:
 19435                              <1> 	; 14/02/2016
 19436                              <1> 	; 13/02/2016
 19437                              <1> 	; 10/02/2016
 19438                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 19439                              <1> 	; 14/08/2010
 19440                              <1> 	; 19/09/2009
 19441                              <1>         ; 2005
 19442                              <1> 	; INPUT ->
 19443                              <1> 	;	ESI = DOS DirEntry Format FileName Address
 19444                              <1> 	;	AL = Attributes Mask 
 19445                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
 19446                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
 19447                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
 19448                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
 19449                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
 19450                              <1> 	;	CL = E5h -> Return the 1st deleted entry
 19451                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
 19452                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
 19453                              <1> 	;	     proper entry (which fits with Atributes Masks)
 19454                              <1> 	;	CX = 0 Find Valid File/Directory/VolumeName
 19455                              <1> 	;	? = Any One Char
 19456                              <1> 	;	* = Every Chars
 19457                              <1> 	; OUTPUT ->
 19458                              <1> 	;	EDI = Directory Entry Address (in Directory Buffer)
 19459                              <1> 	;	ESI = DOS DirEntry Format FileName Address
 19460                              <1> 	;	CF = 0 -> No Error, Proper Entry,
 19461                              <1> 	;	DL = Attributes
 19462                              <1> 	;	DH = Previous Entry Attr (LongName Check)
 19463                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
 19464                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
 19465                              <1> 	;	AX = 0 -> Filename full fits with directory entry
 19466                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
 19467                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in EAX/AL
 19468                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
 19469                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
 19470                              <1> 	;	CL > 0 -> Entry not found, CH invalid
 19471                              <1> 	;	CF = 0 -> 
 19472                              <1> 	;	EBX = Current Directory Entry Index/Number (BX)
 19473                              <1> 
 19474                              <1> 	;mov	word [DirBuff_EntryCounter], 0 ; Zero Based
 19475                              <1> 
 19476 0000658E 8935[F7AB0000]      <1> 	mov	[CDLF_FNAddress], esi
 19477 00006594 66A3[F5AB0000]      <1> 	mov	[CDLF_AttributesMask], ax
 19478 0000659A 66890D[FBAB0000]    <1> 	mov	[CDLF_DEType], cx
 19479                              <1> 
 19480 000065A1 31DB                <1> 	xor	ebx, ebx
 19481 000065A3 881D[0CAC0000]      <1> 	mov	[PreviousAttr], bl ; 0  ; 13/02/2016
 19482                              <1> 
 19483 000065A9 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 19484 000065AF 381D[38AB0000]      <1> 	cmp	byte [DirBuff_ValidData], bl ; 0
 19485 000065B5 761D                <1> 	jna	short loc_lcdf_reload_current_dir2
 19486 000065B7 8A1D[36AB0000]      <1>         mov     bl, [DirBuff_DRV]
 19487 000065BD 80EB41              <1> 	sub	bl, 'A'
 19488 000065C0 38DF                <1> 	cmp	bh, bl
 19489 000065C2 750E                <1> 	jne	short loc_lcdf_reload_current_dir1
 19490 000065C4 8B15[3DAB0000]      <1> 	mov	edx, [DirBuff_Cluster]
 19491 000065CA 3B15[08A30000]      <1> 	cmp	edx, [Current_Dir_FCluster]
 19492 000065D0 7412                <1> 	je	short loc_cdir_locatefile_search
 19493                              <1> 
 19494                              <1> loc_lcdf_reload_current_dir1:
 19495 000065D2 30DB                <1> 	xor	bl, bl
 19496                              <1> loc_lcdf_reload_current_dir2:
 19497 000065D4 89DE                <1> 	mov	esi, ebx
 19498 000065D6 81C600010900        <1>         add     esi, Logical_DOSDisks
 19499 000065DC E872000000          <1> 	call	reload_current_directory 
 19500 000065E1 735B                <1> 	jnc	short loc_locatefile_search_again 
 19501 000065E3 C3                  <1> 	retn  
 19502                              <1> 
 19503                              <1> loc_cdir_locatefile_search:
 19504 000065E4 31DB                <1> 	xor	ebx, ebx
 19505 000065E6 E8A5000000          <1> 	call	find_directory_entry
 19506 000065EB 7349                <1> 	jnc	short loc_cdir_locate_file_retn
 19507                              <1> 
 19508                              <1> loc_locatefile_check_stc_reason:
 19509 000065ED 08ED                <1> 	or	ch, ch
 19510 000065EF 7444                <1> 	jz	short loc_cdir_locate_file_stc_retn
 19511                              <1> 
 19512                              <1> loc_locatefile_check_next_entryblock:
 19513 000065F1 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 19514 000065F7 28DB                <1> 	sub	bl, bl
 19515 000065F9 0FB7F3              <1> 	movzx	esi, bx
 19516 000065FC 81C600010900        <1>         add     esi, Logical_DOSDisks
 19517                              <1> 
 19518 00006602 803D[0CA30000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 19519 00006609 760A                <1> 	jna	short loc_locatefile_check_FAT_type
 19520                              <1>             
 19521 0000660B 803D[0DA30000]01    <1> 	cmp	byte [Current_FATType], 1
 19522 00006612 730A                <1> 	jnb	short loc_locatefile_load_subdir_cluster
 19523 00006614 C3                  <1> 	retn  
 19524                              <1> 
 19525                              <1> loc_locatefile_check_FAT_type:
 19526 00006615 803D[0DA30000]03    <1> 	cmp	byte [Current_FATType], 3
 19527 0000661C 7218                <1> 	jb	short loc_cdir_locate_file_retn
 19528                              <1> 
 19529                              <1> loc_locatefile_load_subdir_cluster:
 19530 0000661E A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 19531 00006623 E80A0B0000          <1> 	call	get_next_cluster
 19532 00006628 730D                <1> 	jnc	short loc_locatefile_next_cluster
 19533 0000662A 09C0                <1> 	or	eax, eax
 19534 0000662C 7507                <1> 	jnz	short loc_locatefile_drive_not_ready_read_err
 19535 0000662E F9                  <1> 	stc
 19536                              <1> loc_locatefile_file_notfound:
 19537 0000662F B802000000          <1> 	mov	eax, 2 ; File/Directory/VolName not found
 19538 00006634 C3                  <1> 	retn
 19539                              <1> loc_locatefile_drive_not_ready_read_err:
 19540                              <1> 	;mov	eax, 15h ;Drive not ready or read error
 19541                              <1> loc_cdir_locate_file_stc_retn:
 19542 00006635 F5                  <1> 	cmc ;stc
 19543                              <1> loc_cdir_locate_file_retn:
 19544 00006636 C3                  <1> 	retn
 19545                              <1> 
 19546                              <1> loc_locatefile_next_cluster:
 19547 00006637 E8D70C0000          <1> 	call	load_FAT_sub_directory
 19548                              <1> 	;jc	short loc_locatefile_drive_not_ready_read_err
 19549 0000663C 72F8                <1> 	jc	short loc_cdir_locate_file_retn 
 19550                              <1> 
 19551                              <1> loc_locatefile_search_again:
 19552 0000663E 8B35[F7AB0000]      <1> 	mov	esi, [CDLF_FNAddress] 
 19553 00006644 66A1[F5AB0000]      <1> 	mov	ax, [CDLF_AttributesMask]
 19554 0000664A 668B0D[FBAB0000]    <1> 	mov	cx, [CDLF_DEType] 
 19555 00006651 EB91                <1> 	jmp	short loc_cdir_locatefile_search
 19556                              <1> 
 19557                              <1> reload_current_directory:
 19558                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 19559                              <1> 	; 13/06/2010
 19560                              <1> 	; 22/09/2009
 19561                              <1>         ;
 19562                              <1> 	; INPUT ->
 19563                              <1> 	;	ESI = Dos drive description table address
 19564                              <1> 	
 19565                              <1> 	;mov	al, [esi+LD_FATType]
 19566 00006653 A0[0DA30000]        <1> 	mov	al, [Current_FATType]
 19567 00006658 3C02                <1> 	cmp	al, 2
 19568 0000665A 7729                <1> 	ja	short loc_reload_FAT_sub_directory
 19569 0000665C 8A25[0CA30000]      <1> 	mov	ah, [Current_Dir_Level]
 19570 00006662 08C0                <1> 	or	al, al
 19571 00006664 740A                <1> 	jz	short loc_reload_FS_directory
 19572 00006666 08E4                <1> 	or	ah, ah
 19573 00006668 751B                <1> 	jnz	short loc_reload_FAT_sub_directory
 19574                              <1> loc_reload_FAT_12_16_root_directory:
 19575 0000666A E8190C0000          <1> 	call	load_FAT_root_directory
 19576 0000666F C3                  <1> 	retn
 19577                              <1> loc_reload_FS_directory:
 19578 00006670 20E4                <1> 	and	ah, ah
 19579 00006672 7506                <1> 	jnz	short loc_reload_FS_sub_directory 
 19580                              <1> loc_reload_FS_root_directory: 
 19581 00006674 E8D60C0000          <1> 	call	load_FS_root_directory
 19582 00006679 C3                  <1> 	retn
 19583                              <1> loc_reload_FS_sub_directory:
 19584 0000667A A1[08A30000]        <1> 	mov	eax, [Current_Dir_FCluster]
 19585 0000667F E8CC0C0000          <1> 	call	load_FS_sub_directory
 19586 00006684 C3                  <1> 	retn 
 19587                              <1> loc_reload_FAT_sub_directory:
 19588 00006685 A1[08A30000]        <1> 	mov	eax, [Current_Dir_FCluster]
 19589 0000668A E8840C0000          <1> 	call	load_FAT_sub_directory
 19590 0000668F C3                  <1> 	retn
 19591                              <1> 
 19592                              <1> find_directory_entry:
 19593                              <1> 	; 14/02/2016
 19594                              <1> 	; 13/02/2016
 19595                              <1> 	; 10/02/2016
 19596                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 19597                              <1> 	; 14/08/2010 (DIR.ASM, "proc_find_direntry")
 19598                              <1> 	; 19/09/2009
 19599                              <1> 	; 2005
 19600                              <1> 	; INPUT ->
 19601                              <1> 	;	ESI = Sub Dir or File Name Address
 19602                              <1> 	;	AL = Attributes Mask 
 19603                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
 19604                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
 19605                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
 19606                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
 19607                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
 19608                              <1> 	;	CL = E5h -> Return the 1st deleted entry
 19609                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
 19610                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
 19611                              <1> 	;            proper entry (which fits with Atributes Masks)
 19612                              <1> 	;	CX = 0 -> Find Valid File/Directory/VolumeName
 19613                              <1> 	;	? = Any One Char
 19614                              <1> 	;	* = Every Chars
 19615                              <1> 	;	EBX = Current Dir Entry (BX)
 19616                              <1> 	;
 19617                              <1> 	; OUTPUT -> 
 19618                              <1> 	;	EDI = Directory Entry Address (in DirectoryBuffer)
 19619                              <1> 	;	ESI = Sub Dir or File Name Address
 19620                              <1> 	;	CF = 0 -> No Error, Proper Entry,
 19621                              <1> 	;	DL = Attributes
 19622                              <1> 	;	DH = Previous Entry Attr (LongName Check)
 19623                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
 19624                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
 19625                              <1> 	;	AX = 0 -> Filename full fits with directory entry
 19626                              <1> 	;	EBX = CurrentDirEntry (BX)
 19627                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
 19628                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in AX/AL
 19629                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
 19630                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
 19631                              <1> 	;	CL > 0 -> Entry not found, CH invalid
 19632                              <1> 	;
 19633                              <1> 	; (EAX, EBX, ECX, EDX, EDI, EBP will be changed)	 
 19634                              <1> 
 19635 00006690 663B1D[3BAB0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 19636 00006697 0F8739010000        <1>         ja      loc_ffde_stc_retn_255
 19637                              <1> 
 19638                              <1> 	;mov    [DirBuff_CurrentEntry], bx  
 19639                              <1> 
 19640 0000669D BF00000800          <1>   	mov	edi, Directory_Buffer
 19641 000066A2 66A3[08AC0000]      <1> 	mov	[FDE_AttrMask], ax
 19642                              <1> 
 19643 000066A8 29C0                <1> 	sub	eax, eax
 19644                              <1>             
 19645                              <1> 	;;mov	[PreviousAttr], al ; 0 ;; 13/02/2016
 19646 000066AA 66A3[0AAC0000]      <1> 	mov	[AmbiguousFileName], ax ; 0
 19647                              <1> 
 19648 000066B0 6689D8              <1> 	mov	ax, bx
 19649 000066B3 66C1E005            <1> 	shl	ax, 5 ; ; * 32 ; Directory entry size
 19650 000066B7 01C7                <1> 	add     edi, eax
 19651                              <1> 
 19652 000066B9 08ED                <1> 	or	ch, ch
 19653 000066BB 0F852C010000        <1>         jnz     loc_find_free_deleted_entry_0
 19654                              <1> 
 19655 000066C1 08C9                <1> 	or      cl, cl
 19656 000066C3 0F850D010000        <1>         jnz     loc_ffde_stc_retn_255
 19657                              <1>  
 19658                              <1> check_find_dir_entry:
 19659 000066C9 66A1[08AC0000]      <1> 	mov	ax, [FDE_AttrMask]
 19660 000066CF 8A2F                <1> 	mov	ch, [edi]
 19661 000066D1 80FD00              <1> 	cmp     ch, 0 ; Is it never used entry?
 19662 000066D4 0F86FF000000        <1> 	jna	loc_find_direntry_stc_retn 
 19663 000066DA 56                  <1> 	push	esi
 19664 000066DB 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
 19665 000066DE 80FDE5              <1> 	cmp	ch, 0E5h ; Is it a deleted file?
 19666 000066E1 746D                <1> 	je	short loc_find_dir_next_entry_prevdeleted
 19667                              <1> 
 19668 000066E3 80FA0F              <1> 	cmp     dl, 0Fh ; longname sub component check
 19669 000066E6 7505                <1> 	jne     short loc_check_attributes_mask
 19670 000066E8 E8DD010000          <1> 	call	save_longname_sub_component
 19671                              <1> 
 19672                              <1> loc_check_attributes_mask:
 19673 000066ED 88C6                <1> 	mov	dh, al
 19674 000066EF 20D6                <1> 	and	dh, dl    
 19675 000066F1 38F0                <1> 	cmp	al, dh
 19676 000066F3 0F85BA000000        <1>         jne     loc_find_dir_next_entry
 19677 000066F9 20D4                <1> 	and	ah, dl
 19678 000066FB 0F85B2000000        <1>         jnz     loc_find_dir_next_entry
 19679 00006701 80FA0F              <1> 	cmp	dl, 0Fh
 19680 00006704 751A                <1> 	jne	short pass_direntry_attr_check
 19681                              <1> 
 19682 00006706 3C0F                <1> 	cmp	al, 0Fh ; AL = 0Fh -> find long name
 19683 00006708 0F85A5000000        <1>         jne     loc_find_dir_next_entry
 19684                              <1> 
 19685 0000670E 5E                  <1> 	pop	esi
 19686 0000670F 6631C0              <1> 	xor	ax, ax
 19687 00006712 8A35[0CAC0000]      <1> 	mov	dh, [PreviousAttr]
 19688 00006718 66891D[39AB0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 19689 0000671F C3                  <1> 	retn
 19690                              <1> 
 19691                              <1> pass_direntry_attr_check:
 19692 00006720 89FD                <1> 	mov	ebp, edi ; 14/02/2016
 19693 00006722 B908000000          <1> 	mov	ecx, 8
 19694                              <1> loc_lodsb_find_dir:
 19695 00006727 AC                  <1> 	lodsb
 19696 00006728 3C2A                <1> 	cmp	al, '*'
 19697 0000672A 7508                <1> 	jne	short pass_fde_ambiguous1_check
 19698 0000672C FE05[0BAC0000]      <1>         inc     byte [AmbiguousFileName+1]
 19699 00006732 EB28                <1> 	jmp	short loc_check_direntry_extension
 19700                              <1> 
 19701                              <1> pass_fde_ambiguous1_check:
 19702 00006734 3C3F                <1> 	cmp	al, '?'
 19703 00006736 750D                <1> 	jne	short pass_fde_ambiguous2_check
 19704 00006738 FE05[0AAC0000]      <1> 	inc	byte [AmbiguousFileName]
 19705 0000673E 803F20              <1> 	cmp	byte [edi], 20h
 19706 00006741 764E                <1> 	jna	short loc_find_dir_next_entry_ebp
 19707 00006743 EB14                <1> 	jmp	short loc_scasb_find_dir_inc_di
 19708                              <1> 
 19709                              <1> pass_fde_ambiguous2_check:
 19710 00006745 3C20                <1> 	cmp	al, 20h
 19711 00006747 750C                <1> 	jne	short loc_scasb_find_dir
 19712 00006749 803F20              <1> 	cmp	byte [edi], 20h
 19713 0000674C 7543                <1> 	jne	short loc_find_dir_next_entry_ebp
 19714 0000674E EB0C                <1> 	jmp	short loc_check_direntry_extension
 19715                              <1> 
 19716                              <1> loc_find_dir_next_entry_prevdeleted:
 19717 00006750 80CA80              <1> 	or	dl, 80h  ; Bit 7 -> deleted entry sign
 19718 00006753 EB5E                <1> 	jmp	short loc_find_dir_next_entry
 19719                              <1> 
 19720                              <1> loc_scasb_find_dir:
 19721 00006755 3A07                <1> 	cmp	al, [edi]
 19722 00006757 7538                <1> 	jne	short loc_find_dir_next_entry_ebp
 19723                              <1> loc_scasb_find_dir_inc_di:
 19724 00006759 47                  <1> 	inc	edi
 19725 0000675A E2CB                <1> 	loop	loc_lodsb_find_dir
 19726                              <1> 
 19727                              <1> loc_check_direntry_extension:
 19728 0000675C BE08000000          <1> 	mov	esi, 8
 19729 00006761 89F7                <1> 	mov	edi, esi ; 8
 19730 00006763 033424              <1> 	add	esi, [esp] ; Sub Dir or File Name Address
 19731 00006766 01EF                <1> 	add	edi, ebp
 19732 00006768 B103                <1> 	mov	cl, 3
 19733                              <1> loc_lodsb_find_dir_ext:
 19734 0000676A AC                  <1> 	lodsb
 19735 0000676B 3C2A                <1> 	cmp	al, '*'
 19736 0000676D 7508                <1> 	jne	short pass_fde_ambiguous3_check
 19737 0000676F FE05[0BAC0000]      <1> 	inc	byte [AmbiguousFileName+1]
 19738 00006775 EB1E                <1> 	jmp	short loc_find_dir_proper_direntry
 19739                              <1> 
 19740                              <1> pass_fde_ambiguous3_check:
 19741 00006777 3C3F                <1> 	cmp	al, '?'
 19742 00006779 750D                <1> 	jne	short pass_fde_ambiguous4_check
 19743 0000677B FE05[0AAC0000]      <1> 	inc	byte [AmbiguousFileName]
 19744 00006781 803F20              <1> 	cmp	byte [edi], 20h
 19745 00006784 760B                <1> 	jna	short loc_find_dir_next_entry_ebp
 19746 00006786 EB49                <1> 	jmp	short loc_scasb_find_dir_ext_inc_di
 19747                              <1> 
 19748                              <1> pass_fde_ambiguous4_check:
 19749 00006788 3C20                <1> 	cmp	al, 20h
 19750 0000678A 7541                <1> 	jne	short loc_scasb_find_dir_ext
 19751 0000678C 803F20              <1> 	cmp	byte [edi], 20h
 19752 0000678F 7404                <1> 	je	short loc_find_dir_proper_direntry
 19753                              <1> 
 19754                              <1> loc_find_dir_next_entry_ebp:
 19755 00006791 89EF                <1> 	mov	edi, ebp ; 14/02/2016
 19756 00006793 EB1E                <1> 	jmp	short loc_find_dir_next_entry
 19757                              <1> 
 19758                              <1> loc_find_dir_proper_direntry:
 19759 00006795 30C9                <1> 	xor	cl, cl
 19760                              <1> loc_find_dir_proper_direntry_1:
 19761 00006797 5E                  <1> 	pop	esi
 19762 00006798 89EF                <1>         mov     edi, ebp
 19763 0000679A 8A2F                <1> 	mov	ch, [edi]
 19764 0000679C 8A570B              <1> 	mov     dl, [edi+0Bh] ; Dir entry attributes
 19765 0000679F 66A1[0AAC0000]      <1> 	mov	ax, [AmbiguousFileName]
 19766                              <1> loc_find_dir_proper_direntry_2:
 19767 000067A5 8A35[0CAC0000]      <1> 	mov     dh, [PreviousAttr]
 19768 000067AB 66891D[39AB0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 19769 000067B2 C3                  <1> 	retn
 19770                              <1> 
 19771                              <1> loc_find_dir_next_entry:
 19772 000067B3 8815[0CAC0000]      <1> 	mov	byte [PreviousAttr], dl ; LongName check
 19773                              <1> loc_find_dir_next_entry_1:
 19774 000067B9 5E                  <1> 	pop	esi
 19775 000067BA 83C720              <1> 	add	edi, 32
 19776                              <1> 	;inc	word [DirBuff_EntryCounter]
 19777 000067BD 6643                <1> 	inc	bx
 19778 000067BF 663B1D[3BAB0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 19779 000067C6 770E                <1> 	ja	short loc_ffde_stc_retn_255
 19780 000067C8 E9FCFEFFFF          <1>         jmp     check_find_dir_entry 
 19781                              <1> 
 19782                              <1> loc_scasb_find_dir_ext:
 19783 000067CD 3A07                <1> 	cmp	al, [edi]
 19784 000067CF 75C0                <1> 	jne	short loc_find_dir_next_entry_ebp
 19785                              <1> loc_scasb_find_dir_ext_inc_di:
 19786 000067D1 47                  <1> 	inc	edi
 19787 000067D2 E296                <1> 	loop    loc_lodsb_find_dir_ext
 19788 000067D4 EBC1                <1> 	jmp	short loc_find_dir_proper_direntry_1
 19789                              <1> 
 19790                              <1> loc_ffde_stc_retn_255:
 19791                              <1> 	;mov	cx, 0FFFFh
 19792 000067D6 31C9                <1> 	xor	ecx, ecx
 19793 000067D8 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 19794                              <1> 	;xor	eax, eax
 19795                              <1> loc_find_direntry_stc_retn:
 19796                              <1> loc_check_ffde_retn_1:
 19797                              <1> 	;mov	ax, 2
 19798 000067D9 B802000000          <1> 	mov	eax, 2 ; File Not Found
 19799 000067DE 8A35[0CAC0000]      <1> 	mov	dh, [PreviousAttr]
 19800 000067E4 66891D[39AB0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 19801 000067EB F9                  <1> 	stc
 19802 000067EC C3                  <1> 	retn
 19803                              <1> 
 19804                              <1> loc_find_free_deleted_entry_0:
 19805 000067ED 66A1[08AC0000]      <1> 	mov	ax, [FDE_AttrMask]
 19806 000067F3 8A2F                <1> 	mov	ch, [edi]
 19807 000067F5 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
 19808 000067F8 08C9                <1> 	or	cl, cl 
 19809 000067FA 7407                <1> 	jz	short loc_check_ffde_0_repeat
 19810                              <1> 	;cmp	cl, 0E5h
 19811                              <1> 	;je	short pass_loc_check_ffde_0_err
 19812 000067FC 80F9FF              <1> 	cmp	cl, 0FFh
 19813 000067FF 7432                <1> 	je	short loc_find_free_deleted_entry_1
 19814 00006801 EB4D                <1> 	jmp	short pass_loc_check_ffde_0_err
 19815                              <1> 
 19816                              <1> loc_check_ffde_0_repeat:
 19817 00006803 08ED                <1> 	or	ch, ch
 19818 00006805 7511                <1> 	jnz	short loc_check_ffde_0_next
 19819                              <1> 
 19820                              <1> loc_check_ffde_retn_2:
 19821 00006807 6629C0              <1> 	sub	ax, ax
 19822 0000680A 8A35[0CAC0000]      <1> 	mov	dh, [PreviousAttr]
 19823 00006810 66891D[39AB0000]    <1> 	mov	[DirBuff_CurrentEntry], bx
 19824 00006817 C3                  <1> 	retn
 19825                              <1>  
 19826                              <1> loc_check_ffde_0_next:
 19827 00006818 6643                <1> 	inc	bx
 19828 0000681A 83C720              <1> 	add	edi, 32
 19829                              <1> 	;inc	word [DirBuff_EntryCounter]
 19830                              <1> 	 
 19831 0000681D 663B1D[3BAB0000]    <1>         cmp	bx, [DirBuff_LastEntry]
 19832 00006824 77B0                <1> 	ja	short loc_ffde_stc_retn_255
 19833 00006826 8815[0CAC0000]      <1> 	mov	[PreviousAttr], dl
 19834 0000682C 8A2F                <1> 	mov	ch, [edi]
 19835 0000682E 8A570B              <1> 	mov	dl, [edi+0Bh] ; file attributes
 19836 00006831 EBD0                <1> 	jmp	short loc_check_ffde_0_repeat
 19837                              <1> 
 19838                              <1> loc_find_free_deleted_entry_1:
 19839 00006833 28D2                <1> 	sub	dl, dl      
 19840                              <1> loc_find_free_deleted_entry_2:
 19841 00006835 20ED                <1> 	and	ch, ch  
 19842 00006837 74CE                <1> 	jz	short loc_check_ffde_retn_2
 19843 00006839 80FDE5              <1> 	cmp	ch, 0E5h
 19844 0000683C 74C9                <1> 	je	short loc_check_ffde_retn_2
 19845 0000683E 6643                <1> 	inc	bx
 19846 00006840 83C720              <1> 	add	edi, 32
 19847 00006843 663B1D[3BAB0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 19848 0000684A 778A                <1> 	ja	short loc_ffde_stc_retn_255
 19849 0000684C 8A2F                <1> 	mov	ch, [edi]
 19850 0000684E EBE5                <1> 	jmp	short loc_find_free_deleted_entry_2
 19851                              <1> 
 19852                              <1> pass_loc_check_ffde_0_err:
 19853 00006850 38CD                <1> 	cmp	ch, cl
 19854 00006852 741F                <1> 	je	short loc_check_ffde_attrib 
 19855                              <1> 
 19856 00006854 6643                <1> 	inc	bx
 19857 00006856 83C720              <1> 	add	edi, 32
 19858 00006859 663B1D[3BAB0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 19859 00006860 0F8770FFFFFF        <1>         ja      loc_ffde_stc_retn_255
 19860 00006866 8815[0CAC0000]      <1> 	mov	[PreviousAttr], dl
 19861 0000686C 8A2F                <1> 	mov	ch, [edi]
 19862 0000686E 8A570B              <1> 	mov	dl, [edi+0Bh]
 19863 00006871 EBDD                <1> 	jmp	short pass_loc_check_ffde_0_err
 19864                              <1> 
 19865                              <1> loc_check_ffde_attrib:
 19866 00006873 88C6                <1> 	mov	dh, al
 19867 00006875 20D6                <1> 	and	dh, dl    
 19868 00006877 38F0                <1> 	cmp	al, dh
 19869 00006879 759D                <1> 	jne	short loc_check_ffde_0_next
 19870 0000687B 20D4                <1> 	and	ah, dl
 19871 0000687D 7599                <1> 	jnz	short loc_check_ffde_0_next
 19872 0000687F 30C9                <1> 	xor	cl, cl 
 19873 00006881 EB84                <1>         jmp     loc_check_ffde_retn_2
 19874                              <1> 
 19875                              <1> convert_file_name:
 19876                              <1> 	; 11/02/2016
 19877                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
 19878                              <1> 	; 06/10/2009
 19879                              <1> 	; 2005
 19880                              <1> 	;
 19881                              <1> 	; INPUT  ->
 19882                              <1> 	;	ESI = Dot File Name Location
 19883                              <1> 	;	EDI = Dir Entry Format File Name Location
 19884                              <1> 	; OUTPUT ->
 19885                              <1> 	;	EDI = Dir Entry Format File Name Location
 19886                              <1> 	;	ESI = Dot File Name Location (capitalized)
 19887                              <1> 	;
 19888                              <1> 	; (ECX, AL will be changed) 
 19889                              <1>      
 19890 00006883 56                  <1> 	push	esi  
 19891 00006884 57                  <1> 	push	edi
 19892                              <1> 
 19893 00006885 B90B000000          <1> 	mov	ecx, 11
 19894 0000688A B020                <1> 	mov	al, 20h
 19895 0000688C F3AA                <1> 	rep	stosb
 19896                              <1> 
 19897 0000688E 8B3C24              <1> 	mov	edi, [esp]
 19898 00006891 B10C                <1> 	mov	cl, 12
 19899                              <1> loc_check_first_dot:
 19900 00006893 8A06                <1> 	mov	al, [esi]
 19901 00006895 3C2E                <1> 	cmp	al, 2Eh
 19902 00006897 750A                <1> 	jne	short pass_check_first_dot
 19903 00006899 8807                <1> 	mov	[edi], al
 19904 0000689B 47                  <1> 	inc	edi
 19905 0000689C 46                  <1> 	inc	esi
 19906 0000689D E2F4                <1> 	loop	loc_check_first_dot
 19907 0000689F EB26                <1> 	jmp	short stop_convert_file
 19908                              <1> 
 19909                              <1> loc_get_fchar:
 19910 000068A1 8A06                <1> 	mov	al, [esi]
 19911                              <1> pass_check_first_dot:
 19912 000068A3 3C61                <1> 	cmp	al, 61h ; 'a'
 19913 000068A5 7208                <1> 	jb	short pass_name_capitalize
 19914 000068A7 3C7A                <1> 	cmp	al, 7Ah ; 'z'
 19915 000068A9 7704                <1> 	ja	short pass_name_capitalize
 19916 000068AB 24DF                <1> 	and	al, 0DFh
 19917 000068AD 8806                <1> 	mov	[esi], al
 19918                              <1> pass_name_capitalize:
 19919 000068AF 3C21                <1> 	cmp	al, 21h
 19920 000068B1 7214                <1> 	jb	short stop_convert_file
 19921 000068B3 3C2E                <1> 	cmp	al, 2Eh ; '.'
 19922 000068B5 750A                <1> 	jne	short pass_dot_space
 19923                              <1> add_dot_space: 
 19924 000068B7 80F904              <1> 	cmp	cl, 4
 19925 000068BA 7608                <1> 	jna	short inc_and_loop
 19926 000068BC 47                  <1> 	inc	edi
 19927 000068BD FEC9                <1> 	dec	cl
 19928 000068BF EBF6                <1> 	jmp	short add_dot_space
 19929                              <1> 	
 19930                              <1> 	;mov	al, 4
 19931                              <1> 	;cmp	cl, al
 19932                              <1> 	;jna	short inc_and_loop
 19933                              <1> 	;sub	cl, al
 19934                              <1> 	;add	edi, ecx
 19935                              <1> 	;mov	cl, al
 19936                              <1> 	;jmp	short inc_and_loop	
 19937                              <1> 
 19938                              <1> pass_dot_space:
 19939 000068C1 8807                <1> 	mov	[edi], al
 19940                              <1> loc_after_double_dot:
 19941 000068C3 47                  <1> 	inc	edi
 19942                              <1> inc_and_loop:
 19943 000068C4 46                  <1> 	inc	esi
 19944 000068C5 E2DA                <1> 	loop	loc_get_fchar
 19945                              <1> 
 19946                              <1> stop_convert_file:
 19947 000068C7 5F                  <1> 	pop	edi
 19948 000068C8 5E                  <1> 	pop	esi
 19949 000068C9 C3                  <1> 	retn
 19950                              <1>  
 19951                              <1> save_longname_sub_component:
 19952                              <1> 	; 13/02/2016
 19953                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
 19954                              <1> 	; 28/02/2010
 19955                              <1> 	; 17/10/2009
 19956                              <1> 	; INPUT ->
 19957                              <1> 	;	EDI = Directory Entry    
 19958                              <1> 	;     	// This procedure is called
 19959                              <1> 	;	// from 'find_directory_entry' procedure.
 19960                              <1> 	;	// If the last entry returns with
 19961                              <1> 	;	// a non-zero LongnameFound value and
 19962                              <1> 	;	// if LFN_CheckSum value is equal to
 19963                              <1> 	;	// the next shortname checksum,
 19964                              <1> 	;	// long name is valid.
 19965                              <1> 	;	// If a longname is longer than 65 bytes,
 19966                              <1> 	;	// it is invalid for trdos. (>45h)
 19967                              <1>  
 19968 000068CA 57                  <1> 	push	edi
 19969 000068CB 56                  <1> 	push	esi
 19970                              <1> 	;push	ebx
 19971                              <1> 	;push	ecx
 19972                              <1> 	;push	edx
 19973 000068CC 50                  <1> 	push	eax
 19974                              <1>            
 19975 000068CD 29C9                <1> 	sub	ecx, ecx
 19976                              <1> 	;sub	eax, eax
 19977 000068CF B11A                <1> 	mov	cl, 26
 19978                              <1> 
 19979 000068D1 0FB607              <1> 	movzx	eax, byte [edi] ; LDIR_Order
 19980 000068D4 3C41                <1> 	cmp	al, 41h  ; 40h (last long entry sign) + 1
 19981 000068D6 722B                <1> 	jb	short pass_pslnsc_last_long_entry
 19982                              <1> 
 19983 000068D8 88C4                <1> 	mov	ah, al
 19984 000068DA 80EC40              <1> 	sub	ah, 40h
 19985 000068DD 8825[0EAC0000]      <1> 	mov	[LFN_EntryLength], ah
 19986                              <1> 	
 19987 000068E3 3C45                <1> 	cmp	al, 45h  ; 40h (last long entry sign) + 5
 19988                              <1>  		; Max 130 byte length is usable in TRDOS
 19989                              <1> ; 26*5 = 130
 19990 000068E5 7753                <1> 	ja	short loc_pslnsc_retn
 19991                              <1> 
 19992 000068E7 2407                <1> 	and	al, 07h ; 0Fh
 19993 000068E9 A2[0DAC0000]        <1> 	mov	[LongNameFound], al
 19994                              <1> 
 19995 000068EE FEC8                <1> 	dec	al
 19996                              <1> 	;mov	cl, 26
 19997 000068F0 F6E1                <1> 	mul	cl
 19998                              <1> 
 19999 000068F2 89C6                <1> 	mov	esi, eax
 20000 000068F4 01CE                <1> 	add	esi, ecx
 20001                              <1> 		; to make is an ASCIZZ string
 20002                              <1> 		; with ax+26 bytes length
 20003 000068F6 81C6[10AC0000]      <1> 	add	esi, LongFileName
 20004 000068FC 66C7060000          <1> 	mov	word [esi], 0   
 20005 00006901 EB16                <1> 	jmp	short loc_pslsc_move_ldir_name2 
 20006                              <1> 
 20007                              <1> pass_pslnsc_last_long_entry:
 20008 00006903 3C04                <1> 	cmp	al, 04h
 20009 00006905 7733                <1> 	ja	short loc_pslnsc_retn
 20010 00006907 FE0D[0DAC0000]      <1> 	dec	byte [LongNameFound]
 20011 0000690D 3A05[0DAC0000]      <1> 	cmp	al, [LongNameFound]
 20012 00006913 7525                <1> 	jne	short loc_pslnsc_retn
 20013                              <1> 
 20014                              <1> loc_pslsc_move_ldir_name1:
 20015 00006915 FEC8                <1> 	dec	al
 20016                              <1> 	;mov	cl, 26
 20017 00006917 F6E1                <1> 	mul	cl
 20018                              <1> 
 20019                              <1> loc_pslsc_move_ldir_name2:
 20020 00006919 8A4F0D              <1> 	mov	cl, [edi+0Dh] ; long name checksum
 20021 0000691C 880D[0FAC0000]      <1> 	mov	[LFN_CheckSum], cl 
 20022 00006922 89FE                <1> 	mov	esi, edi ; LDIR_Order
 20023 00006924 BF[10AC0000]        <1> 	mov	edi, LongFileName
 20024 00006929 01C7                <1> 	add	edi, eax
 20025 0000692B 46                  <1> 	inc	esi
 20026 0000692C B105                <1> 	mov	cl, 5 ; chars 1 to 5
 20027 0000692E F366A5              <1> 	rep	movsw
 20028 00006931 83C603              <1> 	add	esi, 3
 20029 00006934 A5                  <1> 	movsd	; char 6 & 7 
 20030 00006935 A5                  <1> 	movsd	; char 8 & 9
 20031 00006936 A5                  <1> 	movsd	; char 10 & 11
 20032 00006937 46                  <1> 	inc	esi
 20033 00006938 46                  <1> 	inc	esi 
 20034 00006939 A5                  <1> 	movsd   ; char 12 & 13 
 20035                              <1> 
 20036                              <1> loc_pslnsc_retn:
 20037 0000693A 58                  <1>  	pop	eax
 20038                              <1> 	;pop	edx
 20039                              <1> 	;pop	ecx
 20040                              <1> 	;pop	ebx
 20041 0000693B 5E                  <1> 	pop	esi  
 20042 0000693C 5F                  <1> 	pop	edi
 20043                              <1>  
 20044 0000693D C3                  <1>     	retn
 20045                              <1> 
 20046                              <1> parse_path_name:
 20047                              <1> 	; 10/02/2016
 20048                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
 20049                              <1> 	; 10/009/2011 ('proc_parse_pathname')
 20050                              <1> 	; 27/11/2009
 20051                              <1> 	; 05/12/2004
 20052                              <1> 	;
 20053                              <1> 	; INPUT ->
 20054                              <1> 	;	ESI = Beginning of ASCIIZ pathname string
 20055                              <1> 	;       EDI = Destination Address
 20056                              <1> 	;	      (which is TR-DOS FindFile data buffer)
 20057                              <1> 	; OUTPUT ->
 20058                              <1> 	;	CF = 1 -> Error
 20059                              <1> 	;	     EAX = Error Code (AL)
 20060                              <1> 	; 
 20061                              <1> 	
 20062                              <1> 	; Clear the pathname bytes in TR-DOS Findfile data buffer 
 20063 0000693E 57                  <1> 	push	edi
 20064 0000693F B914000000          <1> 	mov	ecx, 20  ; 80 bytes
 20065 00006944 31C0                <1> 	xor	eax, eax
 20066 00006946 F3AB                <1> 	rep	stosd 
 20067 00006948 5F                  <1> 	pop	edi
 20068                              <1> 
 20069 00006949 668B06              <1> 	mov	ax, [esi]
 20070 0000694C 80FC3A              <1> 	cmp	ah, ':'
 20071 0000694F 741C                <1> 	je	short loc_ppn_change_drive
 20072 00006951 A0[0EA30000]        <1> 	mov	al, [Current_Drv]
 20073 00006956 EB33                <1> 	jmp	short pass_ppn_change_drive
 20074                              <1> 
 20075                              <1> pass_ppn_cdir:
 20076 00006958 8B35[30AD0000]      <1> 	mov	esi, [First_Path_Pos]
 20077 0000695E AC                  <1> 	lodsb
 20078                              <1> loc_ppn_get_filename:
 20079 0000695F 83C741              <1> 	add	edi, 65 ; FindFile_Name location
 20080                              <1> 	; TRDOS Filename length must not be more than 12 bytes
 20081                              <1> 	;mov	ecx, 12
 20082 00006962 B10C                <1> 	mov	cl, 12
 20083                              <1> loc_ppn_get_fnchar_next:
 20084 00006964 AA                  <1> 	stosb
 20085 00006965 AC                  <1> 	lodsb
 20086 00006966 3C21                <1> 	cmp	al, 21h
 20087 00006968 7274                <1> 	jb	short loc_ppn_clc_return 
 20088 0000696A E2F8                <1>         loop    loc_ppn_get_fnchar_next
 20089                              <1> loc_ppn_return:
 20090 0000696C C3                  <1> 	retn
 20091                              <1> 
 20092                              <1> loc_ppn_change_drive:
 20093 0000696D 24DF                <1> 	and	al, 0DFh
 20094 0000696F 2C41                <1> 	sub	al, 'A'; A:
 20095 00006971 726F                <1> 	jc	short loc_ppn_invalid_drive
 20096 00006973 3805[40940000]      <1> 	cmp	[Last_DOS_DiskNo], al
 20097 00006979 7267                <1> 	jb	short loc_ppn_invalid_drive
 20098                              <1> 
 20099 0000697B 46                  <1> 	inc	esi
 20100 0000697C 46                  <1> 	inc	esi
 20101 0000697D 8A26                <1> 	mov	ah, [esi]
 20102 0000697F 80FC21              <1> 	cmp	ah, 21h
 20103 00006982 7307                <1> 	jnb	short pass_ppn_change_drive
 20104                              <1> 
 20105                              <1> loc_ppn_cmd_failed:
 20106                              <1> 	; File or directory name is not existing
 20107 00006984 8807                <1> 	mov	[edi], al ; Drv 
 20108 00006986 66B80100            <1> 	mov	ax, 1 ; eax = 1
 20109                              <1> 	; TR-DOS Error Code 1h = Bad Command Argument
 20110                              <1> 	; MS-DOS Error Code 1h : Invalid Function Number
 20111                              <1> 	;stc
 20112                              <1> 	; (MainProg ErrMsg: "Bad command or file name!")
 20113 0000698A C3                  <1> 	retn
 20114                              <1> 
 20115                              <1> pass_ppn_change_drive:
 20116 0000698B 8935[30AD0000]      <1> 	mov	[First_Path_Pos], esi
 20117 00006991 C705[34AD0000]0000- <1> 	mov	dword [Last_Slash_Pos], 0
 20118 00006999 0000                <1>
 20119 0000699B AA                  <1> 	stosb
 20120 0000699C 8A06                <1> 	mov	al, [esi]
 20121                              <1> loc_scan_ppn_dslash:
 20122 0000699E 3C2F                <1> 	cmp	al, '/'
 20123 000069A0 7506                <1>   	jne	short loc_scan_next_slash_pos
 20124 000069A2 8935[34AD0000]      <1> 	mov	[Last_Slash_Pos], esi
 20125                              <1> loc_scan_next_slash_pos:
 20126 000069A8 46                  <1> 	inc	esi
 20127 000069A9 8A06                <1> 	mov	al, [esi]
 20128 000069AB 3C20                <1> 	cmp	al, 20h
 20129 000069AD 77EF                <1> 	ja	short loc_scan_ppn_dslash
 20130 000069AF 833D[34AD0000]00    <1> 	cmp	dword [Last_Slash_Pos], 0
 20131 000069B6 76A0                <1> 	jna	short pass_ppn_cdir
 20132                              <1> 	
 20133 000069B8 8B0D[34AD0000]      <1> 	mov	ecx, [Last_Slash_Pos]
 20134 000069BE 8B35[30AD0000]      <1> 	mov	esi, [First_Path_Pos]
 20135 000069C4 29F1                <1> 	sub	ecx, esi
 20136 000069C6 41                  <1> 	inc	ecx
 20137                              <1> 	;cmp	ecx, 64
 20138 000069C7 80F940              <1> 	cmp	cl, 64
 20139 000069CA 7715                <1> 	ja	short loc_ppn_invalid_drive_stc
 20140                              <1> 
 20141 000069CC 89F8                <1> 	mov	eax, edi ; Dest Dir String Location (65 byte)
 20142 000069CE F3A4                <1> 	rep	movsb
 20143                              <1> 	;mov	[edi], cl ; 0, End of Dir String
 20144 000069D0 8B35[34AD0000]      <1> 	mov	esi, [Last_Slash_Pos]
 20145 000069D6 46                  <1> 	inc	esi
 20146 000069D7 89C7                <1> 	mov	edi, eax
 20147 000069D9 AC                  <1> 	lodsb
 20148 000069DA 3C21                <1> 	cmp	al, 21h
 20149 000069DC 7381                <1> 	jnb	short loc_ppn_get_filename
 20150                              <1> loc_ppn_clc_return:
 20151                              <1> 	;clc
 20152 000069DE 31C0                <1> 	xor	eax, eax
 20153 000069E0 C3                  <1> 	retn
 20154                              <1> 
 20155                              <1> loc_ppn_invalid_drive_stc:
 20156 000069E1 F5                  <1> 	cmc	 ; stc
 20157                              <1> loc_ppn_invalid_drive:
 20158                              <1> 	; cf = 1
 20159                              <1> 	; The Drive Letter/Char < "A" or > "Z"
 20160 000069E2 66B80F00            <1> 	mov ax, 0Fh
 20161                              <1> 	; MS-DOS Error Code 0Fh = Disk Drive Invalid 
 20162                              <1> 	; (MainProg ErrMsg: "Drive not ready or read error!")
 20163 000069E6 C3                  <1> 	retn
 20164                              <1> 
 20165                              <1> find_longname:
 20166                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
 20167                              <1> 	; 24/01/2010 (DIR.ASM, 'proc_find_longname')
 20168                              <1> 	; 17/10/2009
 20169                              <1> 	
 20170                              <1> 	; INPUT -> 
 20171                              <1> 	;	ESI = DOS short file name address
 20172                              <1> 	; 	for example: "filename.ext"
 20173                              <1> 	;
 20174                              <1> 	; OUTPUT ->
 20175                              <1> 	; 	ESI = ASCIIZ longname address (cf = 0)
 20176                              <1> 	;	cf = 1 -> error number returns in EAX (AL)
 20177                              <1> 	;	AL = 0 & CF=1 -> longname not found
 20178                              <1> 	;	     the file/directory has no longname
 20179                              <1> 	; 	cf = 0 -> AL = FAT Type 
 20180                              <1>  
 20181                              <1> 	; 17/10/2009
 20182                              <1> 	; ASCIIZ string will be returned
 20183                              <1> 	; as LongFileName
 20184                              <1> 	; clearing/reset is not needed
 20185                              <1> 	;mov	ecx, 33
 20186                              <1> 	;mov	edi, LongFileName
 20187                              <1> 	;sub	ax, ax ; 0
 20188                              <1> 	;rep	stosw
 20189                              <1> 
 20190                              <1> 	;mov	byte [LongNameFound], 0
 20191                              <1> 
 20192                              <1> 	; ESI = ASCIIZ file/directory name address
 20193                              <1> 	;   AL = Attributes AND mask 
 20194                              <1> 	;	(Result of AND must be equal to AL)
 20195                              <1> 	;   AH = Negative attributes mask 
 20196                              <1> 	;	(Result of AND must be ZERO)
 20197 000069E7 66B80008            <1> 	mov	ax, 0800h 
 20198                              <1> 		; it must not be volume name or longname
 20199 000069EB E8B5EEFFFF          <1> 	call	find_first_file
 20200 000069F0 7216                <1> 	jc	short loc_fln_retn
 20201                              <1>  
 20202                              <1> loc_fln_check_FAT_Type:
 20203 000069F2 803D[0DA30000]01    <1> 	cmp	byte [Current_FATType], 1
 20204 000069F9 7306                <1> 	jnb	short loc_fln_check_longname_yes_sign
 20205                              <1> 
 20206 000069FB E839000000          <1> 	call	get_fs_longname
 20207 00006A00 C3                  <1> 	retn
 20208                              <1> 
 20209                              <1> loc_fln_check_longname_yes_sign:
 20210 00006A01 08FF                <1> 	or	bh, bh
 20211 00006A03 7504                <1> 	jnz	short loc_fln_check_longnamefound_number
 20212                              <1> loc_fln_longname_not_found_retn:
 20213 00006A05 31C0                <1> 	xor	eax, eax 
 20214                              <1> 	; cf = 1 & al = 0 -> longname not found
 20215 00006A07 F9                  <1> 	stc
 20216                              <1> loc_fln_retn:
 20217 00006A08 C3                  <1> 	retn
 20218                              <1> 
 20219                              <1> loc_fln_check_longnamefound_number:
 20220                              <1> 	; 'LongNameFound' is set by
 20221                              <1>         ; by 'save_longname_sub_component'
 20222                              <1> 	; which is called from
 20223                              <1> 	; 'find_directory_entry' 
 20224                              <1> 	; which is called from 
 20225                              <1> 	; 'find_first_file'
 20226                              <1> 	; It must 1 if the longname is valid
 20227 00006A09 803D[0DAC0000]01    <1>         cmp     byte [LongNameFound], 1
 20228 00006A10 75F3                <1> 	jne	short loc_fln_longname_not_found_retn
 20229                              <1>              
 20230                              <1> loc_fln_calculate_checksum: 
 20231 00006A12 E813000000          <1> 	call	calculate_checksum
 20232                              <1> 	; AL = shortname checksum
 20233                              <1> 
 20234                              <1> loc_fln_longname_validation:
 20235                              <1> 	; 'LFN_CheckSum' has been set already
 20236                              <1> 	; by 'save_longname_sub_component'
 20237                              <1> 	; which is called from
 20238                              <1> 	; 'find_directory_entry' 
 20239                              <1> 	; which is called from 
 20240                              <1> 	; 'find_first_file'
 20241 00006A17 3805[0FAC0000]      <1> 	cmp	[LFN_CheckSum], al
 20242 00006A1D 75E6                <1> 	jne	short loc_fln_longname_not_found_retn
 20243                              <1> 
 20244 00006A1F BE[10AC0000]        <1> 	mov	esi, LongFileName
 20245 00006A24 A0[0DA30000]        <1> 	mov	al, [Current_FATType]
 20246 00006A29 C3                  <1> 	retn
 20247                              <1> 
 20248                              <1> calculate_checksum:
 20249                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
 20250                              <1> 	; 17/10/2009 (DIR.ASM, 'proc_calculate_checksum')
 20251                              <1>         ;    
 20252                              <1> 	; INPUT ->
 20253                              <1> 	;	ESI = 11 byte DOS File Name location
 20254                              <1> 	;	(in DOS Directory Entry Format)
 20255                              <1> 	; OUTPUT ->
 20256                              <1> 	;	 AL = 8 bit checksum (CRC) value
 20257                              <1> 	;
 20258                              <1> 	; (Modified registers: EAX, ECX, ESI)
 20259                              <1> 
 20260                              <1> 	; Erdogan Tan [ 17-10-2009 ]
 20261                              <1> 	;  'ror al, 1' instruction
 20262                              <1> 
 20263                              <1> 	; Erdogan Tan [ 20-06-2004 ]
 20264                              <1> 	; This 8086 assembly code is an original code
 20265                              <1> 	; which is adapted from C code in
 20266                              <1> 	; Microsoft FAT32 File System Specification
 20267                              <1> 	; Version 1.03, December 6, 2000
 20268                              <1> 	; Page 28
 20269                              <1> 
 20270 00006A2A 30C0                <1> 	xor	al, al
 20271 00006A2C B90B000000          <1> 	mov	ecx, 11
 20272                              <1> loc_next_sum:
 20273                              <1> 	;xor	ah, ah
 20274                              <1> 	;test	al, 1
 20275                              <1> 	;jz	short pass_ah_80h
 20276                              <1> 	;mov	ah, 80h
 20277                              <1> ;pass_ah_80h:
 20278                              <1> 	;shr	al, 1
 20279 00006A31 D0C8                <1> 	ror	al, 1 ; 17/10/2009  
 20280 00006A33 0206                <1> 	add	al, [esi]
 20281 00006A35 46                  <1> 	inc	esi
 20282                              <1> 	;add	al, ah
 20283 00006A36 E2F9                <1> 	loop	loc_next_sum
 20284 00006A38 C3                  <1> 	retn
 20285                              <1> 
 20286                              <1> get_fs_longname:
 20287                              <1> 	; temporary (13/02/2016)
 20288 00006A39 31C0                <1> 	xor eax, eax
 20289 00006A3B F9                  <1> 	stc
 20290 00006A3C C3                  <1> 	retn
 20291                              <1> 
 20292                              <1> make_sub_directory:
 20293                              <1> 	; 27/02/2026
 20294                              <1> 	; 26/02/2016
 20295                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 20296                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_make_directory')
 20297                              <1> 	; 10/07/2010
 20298                              <1> 	; INPUT ->
 20299                              <1> 	; 	ESI = ASCIIZ Directory Name
 20300                              <1> 	;	CL = Directory Attributes
 20301                              <1> 	; OUTPUT ->
 20302                              <1> 	;	EAX = New sub dir's first cluster
 20303                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
 20304                              <1> 	;	CF = 1 -> error code in AL (EAX)
 20305                              <1> 
 20306                              <1> 	;test	cl, 10h  ; directory
 20307                              <1> 	;jz	short loc_make_directory_access_denied
 20308                              <1> 	;test	cl, 08h ; volume name
 20309                              <1> 	;jnz	short loc_make_directory_access_denied
 20310                              <1> 
 20311 00006A3D 80E107              <1> 	and	cl, 07h
 20312 00006A40 880D[88AD0000]      <1> 	mov	byte [mkdir_attrib], cl
 20313                              <1> 
 20314 00006A46 56                  <1> 	push	esi
 20315 00006A47 31DB                <1> 	xor	ebx, ebx
 20316 00006A49 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 20317 00006A4F BE00010900          <1> 	mov	esi, Logical_DOSDisks
 20318 00006A54 01DE                <1> 	add	esi, ebx
 20319 00006A56 5B                  <1> 	pop	ebx
 20320                              <1> 
 20321                              <1> 	; 10/07/2010 -> 1st writable disk check for trdos
 20322                              <1> 	; LD_DiskType = 0 for write protection (read only) 
 20323 00006A57 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
 20324 00006A5B 730B                <1> 	jnb	short loc_mkdir_check_file_sytem
 20325 00006A5D B813000000          <1> 	mov	eax, 13h ; MSDOS err => Disk write-protected 
 20326 00006A62 BA00000000          <1> 	mov	edx, 0
 20327                              <1> 	; err retn: EDX = 0, EBX = Dir name offset
 20328                              <1> 	;ESI = Logical DOS drive description table address
 20329 00006A67 C3                  <1> 	retn
 20330                              <1> 
 20331                              <1> ;loc_make_directory_access_denied:
 20332                              <1> 	;mov	ax, 05h ; access denied (invalid attributes input)
 20333                              <1> 	;stc
 20334                              <1> 	;retn
 20335                              <1> 
 20336                              <1> loc_mkdir_check_file_sytem:
 20337 00006A68 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 20338 00006A6C 730B                <1> 	jnb	short loc_mkdir_check_free_sectors
 20339                              <1> 
 20340                              <1> loc_make_fs_directory:
 20341 00006A6E A1[08A30000]        <1> 	mov	eax, [Current_Dir_FCluster]
 20342                              <1> 	; EAX = Parent directory DDT Address
 20343                              <1> 	; ESI = Logical DOS Drive DT Address
 20344                              <1> 	; EBX = Directory name offset (as ASCIIZ name)
 20345 00006A73 E8B8060000          <1> 	call	make_fs_directory
 20346 00006A78 C3                  <1> 	retn
 20347                              <1> 
 20348                              <1> loc_mkdir_check_free_sectors:
 20349 00006A79 0FB64613            <1>         movzx   eax, byte [esi+LD_BPB+SecPerClust]
 20350 00006A7D 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
 20351 00006A80 39C1                <1> 	cmp	ecx, eax
 20352 00006A82 7256                <1> 	jb	short loc_mkdir_insufficient_disk_space
 20353                              <1> 
 20354                              <1> loc_make_fat_directory:
 20355 00006A84 891D[78AD0000]      <1> 	mov	[mkdir_DirName_Offset], ebx
 20356 00006A8A 890D[84AD0000]      <1> 	mov	[mkdir_FreeSectors], ecx
 20357                              <1> 
 20358                              <1> 	;mov	al, [esi+LD_BPB+SecPerClust]
 20359 00006A90 A2[8AAD0000]        <1> 	mov	byte [mkdir_SecPerClust], al
 20360                              <1> 
 20361                              <1> loc_mkdir_gffc_1:
 20362 00006A95 E8E6080000          <1> 	call	get_first_free_cluster
 20363 00006A9A 722B                <1> 	jc	short loc_mkdir_gffc_retn
 20364                              <1> 
 20365                              <1> ;loc_mkdir_gffc_1_cont: 
 20366                              <1> 	;cmp	eax, 2
 20367                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
 20368                              <1> 
 20369                              <1> ;loc_mkdir_gffc_1_save_fcluster:  
 20370 00006A9C A3[7CAD0000]        <1> 	mov	[mkdir_FFCluster], eax
 20371                              <1> 
 20372                              <1> loc_mkdir_locate_ffe:
 20373                              <1> 	; Current directory fcluster <> Directory buffer cluster
 20374                              <1> 	; Current directory will be reloaded by
 20375                              <1> 	; 'locate_current_dir_file' procedure
 20376                              <1> 	;
 20377                              <1> 	; ESI = Logical DOS Drive Description Table Adress 
 20378                              <1> 	;push	esi ; 27/02/2016
 20379 00006AA1 31C0                <1> 	xor	eax, eax
 20380 00006AA3 89C1                <1>         mov	ecx, eax
 20381 00006AA5 6649                <1> 	dec	cx ; FFFFh  
 20382                              <1> 	; CX = FFFFh -> find first deleted or free entry
 20383                              <1> 	; ESI would be ASCIIZ filename address if the call
 20384                              <1> 	; would not be for first free or deleted dir entry
 20385 00006AA7 E8E2FAFFFF          <1> 	call	locate_current_dir_file
 20386 00006AAC 734F                <1> 	jnc	short loc_mkdir_set_ff_dir_entry_1
 20387                              <1> 	;pop	esi 
 20388                              <1> 	; ESI = Logical DOS Drive Description Table Address 
 20389 00006AAE 83F802              <1> 	cmp	eax, 2  ; cmp al, 2
 20390 00006AB1 752E                <1> 	jne	short loc_mkdir_stc_return
 20391                              <1> 
 20392                              <1> loc_mkdir_add_new_cluster:
 20393 00006AB3 803D[0DA30000]02    <1> 	cmp	byte [Current_FATType], 2
 20394                              <1> 	;cmp	byte ptr [esi+LD_FATType], 2
 20395 00006ABA 770C                <1> 	ja	short loc_mkdir_add_new_cluster_check_fsc
 20396 00006ABC 803D[0CA30000]01    <1> 	cmp	byte [Current_Dir_Level], 1
 20397                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
 20398 00006AC3 7303                <1> 	jnb	short loc_mkdir_add_new_cluster_check_fsc
 20399                              <1> 
 20400 00006AC5 B00C                <1> 	mov	al, 12 ; No more files 
 20401                              <1> loc_mkdir_gffc_retn:
 20402 00006AC7 C3                  <1> 	retn
 20403                              <1> 
 20404                              <1> loc_mkdir_add_new_cluster_check_fsc:
 20405 00006AC8 8B0D[84AD0000]      <1> 	mov	ecx, [mkdir_FreeSectors]
 20406                              <1> 	;movzx	eax, byte [mkdir_SecPerClust]
 20407 00006ACE A0[8AAD0000]        <1> 	mov	al, [mkdir_SecPerClust]
 20408 00006AD3 66D1E0              <1> 	shl	ax, 1 ; AX = 2 * AX
 20409 00006AD6 39C1                <1> 	cmp	ecx, eax
 20410 00006AD8 7352                <1> 	jnb	short loc_mkdir_add_new_subdir_cluster
 20411                              <1> 
 20412                              <1> loc_mkdir_insufficient_disk_space:
 20413 00006ADA 89CA                <1> 	mov	edx, ecx
 20414                              <1> ;loc_mkdir_gffc_insufficient_disk_space:
 20415 00006ADC 66B82700            <1> 	mov	ax, 27h ; MSDOS err => insufficient disk space
 20416                              <1> 	; err retn: EDX = Free sectors, EBX = Dir name offset
 20417                              <1>         ; ESI -> Dos drive description table address
 20418                              <1> 	; ecx = edx
 20419                              <1> 	;
 20420 00006AE0 C3                  <1> 	retn
 20421                              <1> 
 20422                              <1> loc_mkdir_stc_return:
 20423 00006AE1 F9                  <1> 	stc
 20424 00006AE2 C3                  <1> 	retn 
 20425                              <1> 
 20426                              <1> loc_mkdir_gffc_2:
 20427 00006AE3 E898080000          <1> 	call	get_first_free_cluster
 20428 00006AE8 72DD                <1> 	jc	short loc_mkdir_gffc_retn
 20429                              <1> 
 20430                              <1> ;loc_mkdir_gffc_1_cont: 
 20431                              <1> 	;cmp	eax, 2
 20432                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
 20433                              <1> 
 20434                              <1> ;loc_mkdir_gffc_2_save_fcluster:  
 20435 00006AEA A3[7CAD0000]        <1> 	mov	[mkdir_FFCluster], eax
 20436                              <1> 
 20437 00006AEF A1[80AD0000]        <1> 	mov	eax, [mkdir_LastDirCluster]
 20438                              <1> 
 20439 00006AF4 E81A080000          <1> 	call	load_FAT_sub_directory 
 20440 00006AF9 72CC                <1> 	jc	short loc_mkdir_gffc_retn
 20441                              <1> 
 20442 00006AFB 31FF                <1> 	xor	edi, edi
 20443                              <1> loc_mkdir_set_ff_dir_entry_1:
 20444                              <1> 	; 27/02/2016
 20445 00006AFD 56                  <1> 	push	esi ; Logical DOS Drv Desc. Tbl. address
 20446                              <1> 	; EDI = Directory Entry Address
 20447 00006AFE 8B35[78AD0000]      <1> 	mov	esi, [mkdir_DirName_Offset]
 20448 00006B04 A1[7CAD0000]        <1> 	mov	eax, [mkdir_FFCluster]
 20449                              <1> 
 20450 00006B09 66B91000            <1> 	mov	cx, 10h	; CL = Directory attribute
 20451                              <1> 			; CH = 0 -> File size is 0
 20452 00006B0D 0A0D[88AD0000]      <1> 	or	cl, [mkdir_attrib] ; S, H, R  
 20453 00006B13 E861010000          <1> 	call	make_directory_entry
 20454                              <1> 
 20455 00006B18 5E                  <1> 	pop	esi
 20456                              <1> 
 20457 00006B19 C605[38AB0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 20458 00006B20 E831020000          <1> 	call	save_directory_buffer
 20459 00006B25 0F8391000000        <1>         jnc     loc_mkdir_set_ff_dir_entry_2
 20460                              <1> 
 20461                              <1> loc_mkdir_return:
 20462 00006B2B C3                  <1> 	retn
 20463                              <1> 
 20464                              <1> loc_mkdir_add_new_subdir_cluster:
 20465 00006B2C 8B15[3DAB0000]      <1> 	mov	edx, [DirBuff_Cluster]
 20466 00006B32 8915[80AD0000]      <1> 	mov	[mkdir_LastDirCluster], edx       
 20467                              <1> 
 20468 00006B38 A1[7CAD0000]        <1> 	mov	eax, [mkdir_FFCluster]
 20469 00006B3D E8D1070000          <1> 	call	load_FAT_sub_directory 
 20470 00006B42 72E7                <1> 	jc	short loc_mkdir_return
 20471                              <1> 	; eax = 0
 20472                              <1> 	; ecx =  directory buffer sector count (<= 128)
 20473                              <1> 
 20474                              <1> pass_mkdir_add_new_subdir_cluster:
 20475 00006B44 29FF                <1> 	sub	edi, edi ; 0
 20476                              <1> 	;mov	al, 128 ; double word
 20477                              <1> 	;mul	ecx ; ecx =  directory buffer sector count
 20478                              <1> 	;mov	ecx, eax
 20479                              <1> 	;shl	cx, 7 ; 128 * sector count	
 20480 00006B46 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
 20481 00006B4A 66C1E802            <1> 	shr	ax, 2 ; 'byte count / 4' for 'stosd'
 20482 00006B4E 66F7E1              <1> 	mul	cx ; max = 128*(512/4) -> 16384 (stosd)
 20483 00006B51 6689C1              <1> 	mov	cx, ax
 20484 00006B54 6629C0              <1> 	sub	ax, ax ; 0
 20485 00006B57 F3AB                <1> 	rep	stosd ; clear directory buffer
 20486                              <1> 
 20487 00006B59 C605[38AB0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 20488 00006B60 E8F1010000          <1> 	call	save_directory_buffer 
 20489 00006B65 72C4                <1> 	jc	short loc_mkdir_return
 20490                              <1> 
 20491                              <1> loc_mkdir_save_added_cluster:
 20492 00006B67 A1[80AD0000]        <1> 	mov	eax, [mkdir_LastDirCluster]
 20493 00006B6C 8B0D[7CAD0000]      <1> 	mov	ecx, [mkdir_FFCluster]
 20494 00006B72 E8D0080000          <1> 	call	update_cluster
 20495 00006B77 7304                <1> 	jnc	short loc_mkdir_save_fat_buffer_0
 20496 00006B79 09C0                <1> 	or	eax, eax ;EAX = 0 -> cluster value is 0 or eoc
 20497 00006B7B 7518                <1> 	jnz	short loc_mkdir_save_fat_buffer_stc_retn
 20498                              <1> 
 20499                              <1> loc_mkdir_save_fat_buffer_0:
 20500 00006B7D A1[7CAD0000]        <1> 	mov	eax, [mkdir_FFCluster]
 20501 00006B82 A3[80AD0000]        <1> 	mov	[mkdir_LastDirCluster], eax
 20502                              <1> 
 20503 00006B87 31C9                <1> 	xor	ecx, ecx
 20504 00006B89 49                  <1> 	dec	ecx ; FFFFFFFFh
 20505                              <1> 	; ESI = Logical DOS Drive Descisption Table address 
 20506 00006B8A E8B8080000          <1> 	call	update_cluster
 20507 00006B8F 7306                <1> 	jnc	short loc_mkdir_save_fat_buffer_1
 20508 00006B91 09C0                <1> 	or	eax, eax
 20509 00006B93 7402                <1> 	jz	short loc_mkdir_save_fat_buffer_1
 20510                              <1> 
 20511                              <1> loc_mkdir_save_fat_buffer_stc_retn:
 20512 00006B95 F9                  <1> 	stc
 20513                              <1> loc_mkdir_save_fat_buffer_retn:
 20514 00006B96 C3                  <1> 	retn
 20515                              <1> 
 20516                              <1> loc_mkdir_save_fat_buffer_1:
 20517                              <1> 	; byte [FAT_BuffValidData] = 2 
 20518 00006B97 E87B0B0000          <1> 	call	save_fat_buffer
 20519 00006B9C 72F8                <1> 	jc	short loc_mkdir_save_fat_buffer_retn
 20520                              <1> 
 20521 00006B9E C605[8BAD0000]01    <1> 	mov	byte [mkdir_add_new_cluster], 1
 20522 00006BA5 EB7F                <1> 	jmp	loc_mkdir_upd_parent_dir_lmdt
 20523                              <1> 
 20524                              <1> loc_mkdir_update_sub_dir_cluster:
 20525 00006BA7 A1[7CAD0000]        <1> 	mov	eax, [mkdir_FFCluster]
 20526 00006BAC 29C9                <1> 	sub	ecx, ecx
 20527 00006BAE 49                  <1> 	dec	ecx ; FFFFFFFFh
 20528                              <1> 	; ESI = Logical DOS Drive Descisption Table address  
 20529 00006BAF E893080000          <1> 	call	update_cluster
 20530 00006BB4 7362                <1> 	jnc	short loc_mkdir_save_fat_buffer_2
 20531 00006BB6 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
 20532 00006BB8 745E                <1> 	jz	short loc_mkdir_save_fat_buffer_2
 20533 00006BBA F9                  <1> 	stc
 20534 00006BBB C3                  <1>         retn
 20535                              <1> 
 20536                              <1> loc_mkdir_set_ff_dir_entry_2:
 20537                              <1> 	; ESI = Logical DOS Drive Descisption Table address  
 20538 00006BBC A1[7CAD0000]        <1> 	mov	eax, [mkdir_FFCluster]
 20539                              <1> 	; Load disk sectors as a directory cluster
 20540 00006BC1 E84D070000          <1> 	call	load_FAT_sub_directory 
 20541 00006BC6 724F                <1> 	jc	short retn_make_fat_directory
 20542                              <1> 	
 20543                              <1> 	; eax = 0
 20544                              <1> 	; ecx =  directory buffer sector count (<= 128)
 20545                              <1> 
 20546 00006BC8 BF40000800          <1> 	mov	edi, Directory_Buffer + 64 ; 26/02/2016
 20547                              <1> 
 20548                              <1> 	;mov	al, 128 ; double word
 20549                              <1> 	;mul	ecx ; ecx =  directory buffer sector count
 20550                              <1> 	;mov	ecx, eax
 20551 00006BCD 66C1E107            <1> 	shl	cx, 7 ; 128 * sector count	
 20552                              <1> 	;sub	eax, eax
 20553 00006BD1 28C0                <1> 	sub	al, al ; 0
 20554 00006BD3 F3AB                <1> 	rep	stosd ; clear directory buffer
 20555                              <1> 
 20556 00006BD5 BF00000800          <1> 	mov	edi, Directory_Buffer ; 26/02/2016
 20557                              <1> 	
 20558 00006BDA 56                  <1> 	push	esi
 20559                              <1> 
 20560 00006BDB BE[8CAD0000]        <1> 	mov	esi, mkdir_Name
 20561 00006BE0 66C7062E00          <1> 	mov	word [esi], 2Eh ; db '.', '0'
 20562                              <1> 
 20563 00006BE5 A1[7CAD0000]        <1> 	mov	eax, [mkdir_FFCluster]
 20564 00006BEA 66B91000            <1> 	mov	cx, 10h ; CL = Directory attribute
 20565                              <1> 			; CH = 0 -> File size is 0
 20566 00006BEE E886000000          <1> 	call	make_directory_entry
 20567                              <1> 
 20568 00006BF3 BF20000800          <1> 	mov	edi, Directory_Buffer + 32 ; 26/02/2016
 20569                              <1> 
 20570 00006BF8 A1[08A30000]        <1> 	mov	eax, [Current_Dir_FCluster] ; parent dir
 20571 00006BFD 66C746012E00        <1> 	mov	word [esi+1], 2Eh ; db '.', '0'
 20572                              <1> 
 20573                              <1> 	;mov	cx, 10h
 20574 00006C03 E871000000          <1> 	call	make_directory_entry
 20575                              <1> 
 20576 00006C08 5E                  <1> 	pop	esi
 20577                              <1> 
 20578 00006C09 C605[38AB0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 20579 00006C10 E841010000          <1> 	call	save_directory_buffer
 20580 00006C15 7390                <1> 	jnc	short loc_mkdir_update_sub_dir_cluster
 20581                              <1>  
 20582                              <1> retn_make_fat_directory:
 20583 00006C17 C3                  <1> 	retn
 20584                              <1> 
 20585                              <1> loc_mkdir_save_fat_buffer_2:
 20586                              <1> 	; byte [FAT_BuffValidData] = 2 
 20587 00006C18 E8FA0A0000          <1> 	call	save_fat_buffer
 20588 00006C1D 72F8                <1> 	jc	short retn_make_fat_directory
 20589                              <1> 
 20590 00006C1F C605[8BAD0000]00    <1> 	mov	byte [mkdir_add_new_cluster], 0
 20591                              <1> 
 20592                              <1> loc_mkdir_upd_parent_dir_lmdt:
 20593 00006C26 E8BF010000          <1> 	call	update_parent_dir_lmdt
 20594                              <1> 
 20595                              <1> loc_mkdir_calculate_FAT_freespace:
 20596 00006C2B C605[C1AD0000]00    <1> 	mov	byte [CFS_error], 0
 20597                              <1> 
 20598                              <1> loc_mkdir_calculate_FAT_freespace_next:
 20599 00006C32 31D2                <1> 	xor	edx, edx
 20600 00006C34 B801000000          <1> 	mov	eax, 1 ; Only one Cluster
 20601 00006C39 BB02FF0000          <1> 	mov	ebx, 0FF02h ; BH = FFh -> ESI = Dos drv desc. table
 20602                              <1> 			    ; BL = 2 -> subtract (1 cluster)
 20603 00006C3E E86B0B0000          <1> 	call	calculate_fat_freespace
 20604 00006C43 21C9                <1> 	and	ecx, ecx ; ecx = 0 -> valid free sector count
 20605 00006C45 741D                <1> 	jz	short pass_mkdir_recalculate_FAT_freespace
 20606 00006C47 803D[C1AD0000]00    <1> 	cmp	byte [CFS_error], 0
 20607 00006C4E 7714                <1> 	ja	short loc_mkdir_calculate_FAT_freespace_err
 20608                              <1> 
 20609                              <1> loc_mkdir_recalculate_FAT_freespace:
 20610 00006C50 FE05[C1AD0000]      <1> 	inc	byte [CFS_error]
 20611 00006C56 BB00FF0000          <1> 	mov	ebx, 0FF00h
 20612 00006C5B E84E0B0000          <1> 	call	calculate_fat_freespace
 20613 00006C60 21C9                <1> 	and	ecx, ecx
 20614 00006C62 74CE                <1> 	jz	short loc_mkdir_calculate_FAT_freespace_next
 20615                              <1>               
 20616                              <1> loc_mkdir_calculate_FAT_freespace_err:
 20617                              <1> pass_mkdir_recalculate_FAT_freespace:
 20618 00006C64 803D[8BAD0000]00    <1> 	cmp	byte [mkdir_add_new_cluster], 0
 20619 00006C6B 0F8772FEFFFF        <1>         ja      loc_mkdir_gffc_2
 20620                              <1> 
 20621                              <1> loc_mkdir_retn_new_dir_cluster:
 20622 00006C71 A1[7CAD0000]        <1> 	mov	eax, [mkdir_FFCluster]
 20623 00006C76 31D2                <1> 	xor	edx, edx
 20624                              <1> loc_mkdir_retn:
 20625 00006C78 C3                  <1> 	retn
 20626                              <1> 
 20627                              <1> make_directory_entry:
 20628                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 20629                              <1> 	; 09/08/2010 (DIR.ASM, 'proc_make_directory_entry')
 20630                              <1> 	; 17/07/2010
 20631                              <1> 	; INPUT ->
 20632                              <1> 	; 	EDI = Directory Entry Address
 20633                              <1> 	;	ESI = Dot File Name Location
 20634                              <1> 	;	EAX = First Cluster
 20635                              <1> 	;	File Size = 0 (Must be set later)
 20636                              <1> 	;	CL = Attributes
 20637                              <1> 	;	CH = 0 (File size = 0) 
 20638                              <1> 	;	(If CH>0, File size is in dword [EBX]) (*)
 20639                              <1> 	; OUTPUT -> 
 20640                              <1> 	;	EDI = Directory Entry Address
 20641                              <1> 	;	ESI = Dot File Name Location (Capitalized)
 20642                              <1> 	;	If CH input = 0, File Size = 0
 20643                              <1> 	;	Otherwise file size is as dword [EBX] (*)
 20644                              <1> 	;	DX = Date, AX = Time in DOS Dir Entry format
 20645                              <1> 	;	EBX = same
 20646                              <1> 	;	ECX = same
 20647                              <1> 
 20648 00006C79 51                  <1> 	push	ecx
 20649                              <1> 
 20650 00006C7A 884F0B              <1> 	mov	[edi+11], cl ; Attributes
 20651 00006C7D 6689471A            <1> 	mov	[edi+26], ax ; FClusterLw, 26
 20652 00006C81 C1E810              <1> 	shr	eax, 16
 20653 00006C84 66895714            <1> 	mov	[edi+20], dx ; FClusterHw, 20
 20654 00006C88 6631C0              <1> 	xor	ax, ax 
 20655 00006C8B 6689470C            <1> 	mov	[edi+12], ax ; NTReserved, 12
 20656                              <1> 			     ; CrtTimeTenth, 13
 20657 00006C8F 08ED                <1> 	or	ch, ch
 20658 00006C91 7402                <1> 	jz	short loc_make_direntry_set_filesize
 20659                              <1> 
 20660 00006C93 8B03                <1> 	mov	eax, [ebx]
 20661                              <1>         
 20662                              <1> loc_make_direntry_set_filesize:
 20663 00006C95 89471C              <1> 	mov	[edi+28], eax ; FileSize, 28
 20664                              <1> 	
 20665 00006C98 E8E6FBFFFF          <1> 	call	convert_file_name
 20666                              <1> 	;EDI = Dir Entry Format File Name Location
 20667                              <1> 	;ESI = Dot File Name Location (capitalized)
 20668                              <1> 
 20669 00006C9D E816000000          <1> 	call	convert_current_date_time
 20670                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 20671                              <1>         ; 	    AX = Time in dos dir entry format
 20672 00006CA2 6689470E            <1> 	mov	[edi+14], ax ; CrtTime, 14
 20673 00006CA6 66895710            <1> 	mov	[edi+16], dx ; CrtDate, 16
 20674 00006CAA 66895712            <1> 	mov	[edi+18], dx ; LastAccDate, 18
 20675 00006CAE 66894716            <1> 	mov	[edi+22], ax ; WrtTime, 14
 20676 00006CB2 66895718            <1> 	mov	[edi+24], dx ; WrtDate, 16
 20677 00006CB6 59                  <1> 	pop	ecx
 20678                              <1> 
 20679 00006CB7 C3                  <1> 	retn
 20680                              <1> 
 20681                              <1> convert_current_date_time:
 20682                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
 20683                              <1> 	; 13/06/2010 (DIR.ASM, 'proc_convert_current_date_time')
 20684                              <1> 	; converts date&time to dos dir entry format
 20685                              <1> 	; INPUT -> none
 20686                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 20687                              <1> 	;           AX = Time in dos dir entry format
 20688                              <1>  
 20689 00006CB8 B404                <1> 	mov	ah, 04h ; Return Current Date
 20690 00006CBA E834CCFFFF          <1> 	call	int1Ah 
 20691                              <1> 
 20692 00006CBF 88E8                <1> 	mov	al, ch ; <- century BCD
 20693 00006CC1 240F                <1> 	and	al, 0Fh
 20694 00006CC3 88EC                <1> 	mov	ah, ch
 20695 00006CC5 C0EC04              <1> 	shr	ah, 4
 20696 00006CC8 D50A                <1> 	aad
 20697 00006CCA 88C5                <1> 	mov	ch, al ; -> century 
 20698                              <1> 
 20699 00006CCC 88C8                <1> 	mov	al, cl ; <- year BCD
 20700 00006CCE 240F                <1> 	and	al, 0Fh
 20701 00006CD0 88CC                <1> 	mov	ah, cl
 20702 00006CD2 C0EC04              <1> 	shr	ah, 4
 20703 00006CD5 D50A                <1> 	aad
 20704 00006CD7 88C1                <1> 	mov	cl, al ; -> year
 20705                              <1> 
 20706 00006CD9 88E8                <1> 	mov	al, ch
 20707 00006CDB B464                <1> 	mov	ah, 100
 20708 00006CDD F6E4                <1> 	mul	ah
 20709 00006CDF 30ED                <1> 	xor	ch, ch
 20710 00006CE1 6601C8              <1> 	add	ax, cx
 20711 00006CE4 662DBC07            <1> 	sub	ax, 1980 ; ms-dos epoch
 20712 00006CE8 6689C1              <1> 	mov	cx, ax
 20713                              <1> 
 20714 00006CEB 88F0                <1> 	mov	al, dh ; <- month in bcd
 20715 00006CED 240F                <1> 	and	al, 0Fh
 20716 00006CEF 88F4                <1> 	mov	ah, dh
 20717 00006CF1 C0EC04              <1> 	shr	ah, 4
 20718 00006CF4 D50A                <1> 	aad
 20719 00006CF6 88C6                <1> 	mov	dh, al ; -> month
 20720                              <1> 
 20721 00006CF8 88D0                <1> 	mov	al, dl ; <- day BCD
 20722 00006CFA 240F                <1> 	and	al, 0Fh
 20723 00006CFC 88D4                <1> 	mov	ah, dl
 20724 00006CFE C0EC04              <1> 	shr	ah, 4
 20725 00006D01 D50A                <1> 	aad
 20726 00006D03 88C2                <1> 	mov	dl, al ; -> day
 20727                              <1> 
 20728 00006D05 88C8                <1> 	mov	al, cl ; count of years from 1980
 20729 00006D07 66C1E004            <1> 	shl	ax, 4
 20730 00006D0B 08F0                <1> 	or	al, dh ; month of year, 1 to 12
 20731 00006D0D 66C1E005            <1> 	shl	ax, 5
 20732 00006D11 08D0                <1> 	or	al, dl ; day of year, 1 to 31
 20733                              <1> 	
 20734 00006D13 6650                <1> 	push	ax ; push date
 20735                              <1> 
 20736 00006D15 B402                <1> 	mov	ah, 02h ; Return Current Time
 20737 00006D17 E8D7CBFFFF          <1> 	call	int1Ah
 20738                              <1> 
 20739 00006D1C 88E8                <1> 	mov	al, ch ; <- hours BCD
 20740 00006D1E 240F                <1> 	and	al, 0Fh
 20741 00006D20 88EC                <1> 	mov	ah, ch
 20742 00006D22 C0EC04              <1> 	shr	ah, 4
 20743 00006D25 D50A                <1> 	aad
 20744 00006D27 88C5                <1> 	mov	ch, al ; -> hours
 20745                              <1> 
 20746 00006D29 88C8                <1> 	mov	al, cl ; <- minutes BCD
 20747 00006D2B 240F                <1> 	and	al, 0Fh
 20748 00006D2D 88CC                <1> 	mov	ah, cl
 20749 00006D2F C0EC04              <1> 	shr	ah, 4
 20750 00006D32 D50A                <1> 	aad
 20751 00006D34 88C1                <1> 	mov	cl, al ; -> minutes
 20752                              <1> 
 20753 00006D36 88F0                <1> 	mov	al, dh ; <- seconds BCD
 20754 00006D38 240F                <1> 	and	al, 0Fh
 20755 00006D3A 88F4                <1> 	mov	ah, dh
 20756 00006D3C C0EC04              <1> 	shr	ah, 4
 20757 00006D3F D50A                <1> 	aad
 20758 00006D41 88C6                <1> 	mov	dh, al ; -> seconds
 20759                              <1> 
 20760 00006D43 88E8                <1> 	mov	al, ch ; hours
 20761 00006D45 66C1E006            <1> 	shl	ax, 6
 20762 00006D49 08C8                <1> 	or	al, cl ; minutes
 20763 00006D4B 66C1E005            <1> 	shl	ax, 5
 20764 00006D4F D0EE                <1> 	shr	dh, 1 ; 2 seconds
 20765                              <1> 	; There is a bug in TRDOS v1 here !
 20766                              <1> 	; it was 'or al, dl' ! 
 20767 00006D51 08F0                <1> 	or	al, dh ; seconds
 20768                              <1> 
 20769 00006D53 665A                <1> 	pop	dx ; pop date
 20770                              <1> 	
 20771 00006D55 C3                  <1> 	retn
 20772                              <1> 
 20773                              <1> save_directory_buffer:
 20774                              <1> 	; 26/02/2016
 20775                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
 20776                              <1> 	; 01/08/2011
 20777                              <1> 	; 14/03/2010
 20778                              <1> 	; INPUT ->
 20779                              <1> 	; 	 none
 20780                              <1> 	; OUTPUT ->
 20781                              <1> 	;  cf = 0 -> write OK...
 20782                              <1> 	;  cf = 1 -> error code in AL (EAX)
 20783                              <1> 	;  cf = 1 & AL = 0Dh => CH & CL = FS & FAT type
 20784                              <1> 	;  EBX = Directory Buffer Address
 20785                              <1> 	;
 20786                              <1> 	;  (EAX, ECX, EDX will be modified)
 20787                              <1>  
 20788 00006D56 BB00000800          <1> 	mov	ebx, Directory_Buffer
 20789 00006D5B 803D[38AB0000]02    <1> 	cmp	byte [DirBuff_ValidData], 2
 20790 00006D62 7403                <1> 	je	short loc_save_dir_buffer
 20791 00006D64 31C0                <1> 	xor	eax, eax
 20792 00006D66 C3                  <1> 	retn            
 20793                              <1> 
 20794                              <1> loc_save_dir_buffer:
 20795 00006D67 56                  <1> 	push	esi
 20796 00006D68 31DB                <1> 	xor	ebx, ebx 
 20797 00006D6A 8A3D[36AB0000]      <1>         mov     bh, [DirBuff_DRV]
 20798 00006D70 80EF41              <1> 	sub	bh, 'A'
 20799 00006D73 BE00010900          <1>         mov     esi, Logical_DOSDisks
 20800 00006D78 01DE                <1> 	add	esi, ebx
 20801 00006D7A 668B4E03            <1>         mov     cx, [esi+LD_FATType]
 20802                              <1> 	; CH = FS Type (A1h for FS)
 20803                              <1> 	; CL = FAT Type (0 for FS)
 20804 00006D7E 08C9                <1> 	or	cl, cl
 20805 00006D80 7433                <1> 	jz	short loc_save_dir_buff_stc_retn
 20806                              <1> 
 20807                              <1> loc_save_dir_buffer_check_cluster_no:    
 20808 00006D82 A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 20809 00006D87 28FF                <1> 	sub	bh, bh ; ebx = 0
 20810 00006D89 09C0                <1> 	or	eax, eax
 20811 00006D8B 7539                <1> 	jnz	short loc_save_sub_dir_buffer
 20812 00006D8D 8A25[37AB0000]      <1> 	mov	ah, [DirBuff_FATType]
 20813 00006D93 FEC3                <1> 	inc	bl ;  bl = 1
 20814 00006D95 38DC                <1> 	cmp	ah, bl
 20815 00006D97 721D                <1> 	jb	short loc_save_dir_buff_inv_data_retn
 20816 00006D99 FEC3                <1> 	inc	bl ; bl = 2
 20817 00006D9B 38E3                <1> 	cmp	bl, ah
 20818 00006D9D 7217                <1> 	jb	short loc_save_dir_buff_inv_data_retn
 20819                              <1> 
 20820                              <1> loc_save_root_dir_buffer:
 20821 00006D9F 668B5E17            <1> 	mov	bx, [esi+LD_BPB+RootDirEnts]
 20822 00006DA3 6683C30F            <1> 	add	bx, 15
 20823 00006DA7 66C1EB04            <1> 	shr	bx, 4 ; 16 dir entries per sector
 20824 00006DAB 6609DB              <1> 	or	bx, bx
 20825 00006DAE 7405                <1> 	jz	short loc_save_dir_buff_stc_retn
 20826                              <1> 	;mov	ecx, ebx 
 20827 00006DB0 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin] ; 26/02/2016
 20828 00006DB3 EB1C                <1> 	jmp	short loc_write_directory_to_disk
 20829                              <1> 
 20830                              <1> loc_save_dir_buff_stc_retn:
 20831 00006DB5 F9                  <1> 	stc
 20832                              <1> loc_save_dir_buff_inv_data_retn:
 20833 00006DB6 B00D                <1> 	mov	al, 0Dh ; Invalid data !
 20834 00006DB8 C605[38AB0000]00    <1> 	mov	byte [DirBuff_ValidData], 0 
 20835                              <1> loc_write_directory_to_disk_err:
 20836                              <1> loc_save_dir_buff_retn:
 20837 00006DBF BB00000800          <1> 	mov	ebx, Directory_Buffer
 20838 00006DC4 5E                  <1> 	pop	esi
 20839 00006DC5 C3                  <1> 	retn 
 20840                              <1> 
 20841                              <1> loc_save_sub_dir_buffer:
 20842                              <1> 	; ebx  = 0
 20843 00006DC6 83E802              <1> 	sub	eax, 2
 20844 00006DC9 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
 20845 00006DCC F7E3                <1> 	mul	ebx
 20846 00006DCE 034668              <1>         add     eax, [esi+LD_DATABegin]
 20847                              <1>  	;mov	ecx, ebx
 20848                              <1> 
 20849                              <1> loc_write_directory_to_disk:
 20850 00006DD1 89D9                <1>  	mov	ecx, ebx
 20851 00006DD3 BB00000800          <1> 	mov	ebx, Directory_Buffer
 20852 00006DD8 E81B230000          <1> 	call	disk_write
 20853 00006DDD 72E0                <1> 	jc	short loc_write_directory_to_disk_err
 20854                              <1> 
 20855                              <1> loc_save_dir_buff_validate_retn:
 20856 00006DDF C605[38AB0000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 20857 00006DE6 31C0                <1> 	xor	eax, eax
 20858                              <1> 	; 26/02/2016
 20859 00006DE8 EBD5                <1> 	jmp	short loc_save_dir_buff_retn
 20860                              <1> 
 20861                              <1> update_parent_dir_lmdt:
 20862                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
 20863                              <1> 	; 01/08/2011
 20864                              <1> 	; 16/10/2010 
 20865                              <1> 	; 
 20866                              <1> 	; INPUT -> 
 20867                              <1> 	;	none
 20868                              <1>  	; OUTPUT ->
 20869                              <1> 	;	(last modification date & time of the parent dir
 20870                              <1> 	;	will be changed/updated)
 20871                              <1> 	;
 20872                              <1> 	; (EAX, EBX, ECX, EDX, EDI will be changed)
 20873                              <1> 
 20874 00006DEA 29C0                <1> 	sub	eax, eax
 20875 00006DEC 8A25[0CA30000]      <1> 	mov	ah, [Current_Dir_Level]
 20876 00006DF2 A0[0DA30000]        <1> 	mov	al, [Current_FATType]
 20877 00006DF7 3C01                <1> 	cmp	al, 1
 20878 00006DF9 723A                <1> 	jb	short loc_UPDLMDT_proc_retn
 20879                              <1>     
 20880                              <1> loc_update_parent_dir_lm_date_time:
 20881 00006DFB 08E4                <1> 	or	ah, ah
 20882 00006DFD 7436                <1> 	jz	short loc_UPDLMDT_proc_retn
 20883                              <1> 
 20884 00006DFF 56                  <1> 	push	esi ; *
 20885 00006E00 8825[A8AD0000]      <1> 	mov	[UPDLMDT_CDirLevel], ah
 20886 00006E06 8B15[08A30000]      <1> 	mov	edx, [Current_Dir_FCluster]
 20887 00006E0C 8915[A9AD0000]      <1> 	mov	[UPDLMDT_CDirFCluster], edx
 20888                              <1> 
 20889 00006E12 FECC                <1> 	dec	ah
 20890 00006E14 B90C000000          <1> 	mov	ecx, 12
 20891 00006E19 BE[6FAB0000]        <1>         mov     esi, PATH_Array
 20892                              <1> 
 20893 00006E1E 8825[0CA30000]      <1> 	mov	[Current_Dir_Level], ah
 20894 00006E24 08E4                <1> 	or	ah, ah
 20895 00006E26 750E                <1> 	jnz	short loc_update_parent_dir_lmdt_load_sub_dir_1
 20896 00006E28 803D[0DA30000]02    <1> 	cmp	byte [Current_FATType], 2
 20897 00006E2F 770B                <1> 	ja	short loc_update_parent_dir_lmdt_load_sub_dir_2
 20898 00006E31 28C0                <1> 	sub	al, al ; eax = 0
 20899 00006E33 EB0A                <1> 	jmp	short loc_update_parent_dir_lmdt_load_sub_dir_3
 20900                              <1> 
 20901                              <1> loc_UPDLMDT_proc_retn:
 20902 00006E35 C3                  <1> 	retn
 20903                              <1>          
 20904                              <1> loc_update_parent_dir_lmdt_load_sub_dir_1:
 20905 00006E36 B010                <1> 	mov	al, 16
 20906 00006E38 F6E4                <1> 	mul	ah 
 20907 00006E3A 01C6                <1> 	add	esi, eax
 20908                              <1> 
 20909                              <1> loc_update_parent_dir_lmdt_load_sub_dir_2:  
 20910 00006E3C 8B460C              <1> 	mov	eax, [esi+12] ; Parent Dir First Cluster
 20911                              <1> 
 20912                              <1> loc_update_parent_dir_lmdt_load_sub_dir_3:
 20913 00006E3F A3[08A30000]        <1> 	mov	[Current_Dir_FCluster], eax
 20914                              <1> 
 20915 00006E44 83C610              <1> 	add	esi, 16
 20916 00006E47 66BF[96AC]          <1> 	mov	di, Dir_File_Name  
 20917 00006E4B F3A4                <1> 	rep	movsb
 20918                              <1> 	
 20919 00006E4D BE00010900          <1> 	mov	esi, Logical_DOSDisks
 20920 00006E52 29DB                <1> 	sub	ebx, ebx
 20921 00006E54 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 20922 00006E5A 01DE                <1> 	add	esi, ebx
 20923 00006E5C E8F2F7FFFF          <1> 	call	reload_current_directory
 20924 00006E61 7232                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
 20925                              <1> 
 20926                              <1> loc_update_parent_dir_lmdt_locate_dir: 
 20927 00006E63 BE[96AC0000]        <1> 	mov	esi, Dir_File_Name        
 20928 00006E68 6631C9              <1> 	xor	cx, cx
 20929 00006E6B 66B81008            <1> 	mov	ax, 0810h ; Only directories
 20930 00006E6F E81AF7FFFF          <1>         call    locate_current_dir_file
 20931                              <1> 	; EDI = DirBuff Directory Entry Address
 20932 00006E74 721F                <1> 	jc short loc_update_parent_dir_lmdt_restore_cdirlevel
 20933                              <1> 
 20934 00006E76 E83DFEFFFF          <1> 	call	convert_current_date_time
 20935 00006E7B 66895712            <1> 	mov	[edi+18], dx ; Last Access Date
 20936 00006E7F 66895718            <1> 	mov	[edi+24], dx ; Last Write Date
 20937 00006E83 66894716            <1> 	mov	[edi+22], ax ; Last Write Time
 20938                              <1> 
 20939 00006E87 C605[38AB0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 20940 00006E8E E8C3FEFFFF          <1> 	call	save_directory_buffer
 20941 00006E93 7200                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
 20942                              <1> 	;xor	al, al 
 20943                              <1> loc_update_parent_dir_lmdt_restore_cdirlevel:
 20944                              <1>  	;current directory level restoration
 20945 00006E95 8A25[A8AD0000]      <1> 	mov	ah, [UPDLMDT_CDirLevel]
 20946 00006E9B 8825[0CA30000]      <1> 	mov	[Current_Dir_Level], ah
 20947 00006EA1 8B15[A9AD0000]      <1>         mov     edx, [UPDLMDT_CDirFCluster]
 20948 00006EA7 8915[08A30000]      <1> 	mov	[Current_Dir_FCluster], edx
 20949                              <1> 
 20950 00006EAD 5E                  <1> 	pop	esi ; *
 20951 00006EAE C3                  <1> 	retn
 20952                              <1> 
 20953                              <1> delete_longname:
 20954                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
 20955                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_longname')
 20956                              <1> 	; 14/03/2010
 20957                              <1> 	; INPUT ->
 20958                              <1> 	; 	EAX = Directory Entry (Index) Number (< 65536)
 20959                              <1> 	; OUTPUT ->
 20960                              <1> 	;	cf = 0 -> OK  (EAX = 0)
 20961                              <1> 	; 	cf = 1 -> error code in EAX (AL)
 20962                              <1> 	;
 20963                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
 20964                              <1> 
 20965 00006EAF 66A3[D4AD0000]      <1> 	mov	[DLN_EntryNumber], ax
 20966 00006EB5 C605[D6AD0000]40    <1>         mov     byte [DLN_40h], 40h
 20967                              <1> 
 20968 00006EBC E858000000          <1> 	call	locate_current_dir_entry
 20969 00006EC1 7308                <1> 	jnc	short loc_dln_check_attributes
 20970 00006EC3 C3                  <1> 	retn
 20971                              <1> 
 20972                              <1> loc_dln_longname_not_found:
 20973 00006EC4 B802000000          <1> 	mov	eax, 2
 20974 00006EC9 F9                  <1> 	stc
 20975 00006ECA C3                  <1> 	retn
 20976                              <1> 
 20977                              <1> loc_dln_check_attributes:
 20978 00006ECB B00F                <1> 	mov	al, 0Fh  ; long name
 20979 00006ECD 8A670B              <1> 	mov	ah, [edi+0Bh] ; dir entry attributes
 20980 00006ED0 38C4                <1> 	cmp	ah, al
 20981 00006ED2 75F0                <1> 	jne	short loc_dln_longname_not_found
 20982 00006ED4 8A27                <1> 	mov	ah, [edi]
 20983 00006ED6 2A25[D6AD0000]      <1> 	sub	ah, [DLN_40h]
 20984 00006EDC 76E6                <1> 	jna	short loc_dln_longname_not_found         
 20985 00006EDE 80FC14              <1> 	cmp	ah, 14h ; 84-64=20 -> 20*13=260 bytes
 20986 00006EE1 77E1                <1> 	ja	short loc_dln_longname_not_found
 20987                              <1>              
 20988 00006EE3 C607E5              <1> 	mov	byte [edi], 0E5h  ; deleted sign
 20989 00006EE6 C605[38AB0000]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; changed/write sign
 20990 00006EED C605[D6AD0000]00    <1> 	mov	byte [DLN_40h], 0 ; 40h -> 0
 20991                              <1> 	  
 20992                              <1> loc_dln_delete_next_ln_entry:
 20993 00006EF4 80FC01              <1> 	cmp	ah, 1
 20994 00006EF7 7616                <1> 	jna	short loc_dln_longname_retn
 20995                              <1> loc_dln_delete_next_ln_entry_0:
 20996 00006EF9 66FF05[D4AD0000]    <1> 	inc	word [DLN_EntryNumber]
 20997 00006F00 0FB705[D4AD0000]    <1> 	movzx	eax, word [DLN_EntryNumber] 
 20998 00006F07 E80D000000          <1> 	call	locate_current_dir_entry
 20999 00006F0C 73BD                <1> 	jnc	short loc_dln_check_attributes
 21000                              <1> 
 21001                              <1> loc_dln_longname_stc_retn:
 21002 00006F0E C3                  <1> 	retn 
 21003                              <1> 	   
 21004                              <1> loc_dln_longname_retn:
 21005                              <1> 	;cmp	byte [DirBuff_ValidData], 2
 21006                              <1> 	;jne	short loc_dln_longname_retn_xor_eax
 21007 00006F0F E842FEFFFF          <1> 	call	save_directory_buffer
 21008 00006F14 72F8                <1> 	jc	short loc_dln_longname_stc_retn
 21009                              <1> 
 21010                              <1> loc_dln_longname_retn_xor_eax:
 21011 00006F16 31C0                <1> 	xor	eax, eax
 21012 00006F18 C3                  <1> 	retn
 21013                              <1> 
 21014                              <1> locate_current_dir_entry:
 21015                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
 21016                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_locate_current_dir_entry')
 21017                              <1> 	; 07/03/2010
 21018                              <1> 	; INPUT ->
 21019                              <1> 	;	EAX = Directory Entry (Index) Number (< 65536) 
 21020                              <1> 	; OUTPUT ->
 21021                              <1> 	;	EDI = Directory Entry Address
 21022                              <1> 	; 	EAX = Cluster Number of Directory Buffer
 21023                              <1> 	;	EBX = Directory Buffer Entry Offset
 21024                              <1> 	;	ECX = DirBuff Valid Data identifier (CL)
 21025                              <1> 	;   	If CF = 0 and CL = 2 then
 21026                              <1> 	;	   directory buffer modified and
 21027                              <1> 	;	   must be written to disk.
 21028                              <1> 	; 	If CF = 0  and CL = 1 then
 21029                              <1> 	;	   dir buffer has been written to disk, already.
 21030                              <1> 	;	CF = 1 -> Error code in EAX (AL)
 21031                              <1> 	;
 21032                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI) 
 21033                              <1> 
 21034                              <1> loc_locate_current_dir_entry:
 21035 00006F19 56                  <1> 	push	esi
 21036 00006F1A 89C1                <1> 	mov	ecx, eax
 21037 00006F1C BA20000000          <1> 	mov	edx, 32
 21038 00006F21 F7E2                <1> 	mul	edx 
 21039 00006F23 A3[E0AD0000]        <1> 	mov	[LCDE_ByteOffset], eax
 21040 00006F28 31DB                <1> 	xor	ebx, ebx
 21041 00006F2A 8A3D[0EA30000]      <1> 	mov	bh, [Current_Drv]
 21042 00006F30 A0[36AB0000]        <1>         mov     al, [DirBuff_DRV]
 21043 00006F35 2C41                <1> 	sub	al, 'A'
 21044 00006F37 BE00010900          <1>         mov     esi, Logical_DOSDisks
 21045 00006F3C 01DE                <1> 	add	esi, ebx
 21046 00006F3E 38C7                <1> 	cmp	bh, al
 21047 00006F40 0F8592000000        <1>         jne     loc_lcde_reload_current_directory
 21048                              <1> loc_lcde_cdl_check:
 21049 00006F46 803D[0CA30000]00    <1> 	cmp	byte [Current_Dir_Level], 0
 21050 00006F4D 772A                <1> 	ja	short loc_lcde_calc_dirbuff_cluster_offset
 21051                              <1> 	; 27/02/2016
 21052                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
 21053                              <1> 	; (Root Directory Entries for FAT32 = 0)
 21054 00006F4F 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
 21055 00006F53 7324                <1> 	jnb	short loc_lcde_calc_dirbuff_cluster_offset
 21056                              <1> 
 21057                              <1> loc_lcde_cdl_check_FAT12_16:
 21058 00006F55 668B4617            <1> 	mov	ax, [esi+LD_BPB+RootDirEnts]
 21059 00006F59 6648                <1> 	dec	ax
 21060                              <1> 	;xor	dx, dx  
 21061 00006F5B 6639C8              <1> 	cmp	ax, cx ; cx = Directory Entry (Index) Number
 21062 00006F5E 720E                <1> 	jb	short loc_lcde_stc_12h_retn
 21063 00006F60 66890D[D8AD0000]    <1> 	mov	[LCDE_EntryIndex], cx
 21064 00006F67 31C0                <1> 	xor	eax, eax
 21065 00006F69 E993000000          <1>         jmp     loc_lcde_check_dir_buffer_cluster
 21066                              <1> 
 21067                              <1> loc_lcde_stc_12h_retn:
 21068 00006F6E 5E                  <1> 	pop	esi
 21069 00006F6F 89CB                <1> 	mov	ebx, ecx
 21070 00006F71 89D1                <1> 	mov	ecx, edx
 21071 00006F73 B812000000          <1> 	mov	eax, 12h ; No more files
 21072 00006F78 C3                  <1> 	retn 
 21073                              <1> 
 21074                              <1> loc_lcde_calc_dirbuff_cluster_offset:
 21075 00006F79 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
 21076 00006F7C 30FF                <1> 	xor	bh, bh
 21077 00006F7E 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
 21078 00006F82 66F7E3              <1> 	mul	bx
 21079 00006F85 6609D2              <1>  	or	dx, dx ; If bytes per cluster > 32KB it is invalid
 21080 00006F88 755D                <1> 	jnz	short loc_lcde_invalid_format
 21081                              <1> 	;mov	ecx, eax
 21082 00006F8A 6689C1              <1> 	mov	cx, ax ; BYTES PER CLUSTER
 21083 00006F8D A1[E0AD0000]        <1> 	mov	eax, [LCDE_ByteOffset]
 21084                              <1> 	;sub	edx, edx
 21085 00006F92 F7F1                <1> 	div	ecx
 21086 00006F94 3DFFFF0000          <1> 	cmp	eax, 65535
 21087 00006F99 774C                <1> 	ja	short loc_lcde_invalid_format
 21088                              <1> 
 21089                              <1> 	; cluster sequence number of directory (< 65536)
 21090 00006F9B 66A3[DAAD0000]      <1> 	mov	[LCDE_ClusterSN], ax 
 21091                              <1> 
 21092 00006FA1 6689D0              <1> 	mov	ax, dx ; byte offset in cluster (directory buffer)
 21093 00006FA4 66BB2000            <1> 	mov	bx, 32 ; ; 1 dir entry = 32 bytes
 21094 00006FA8 6629D2              <1>         sub     dx, dx  ; 0
 21095 00006FAB 66F7F3              <1> 	div	bx 
 21096 00006FAE 66A3[D8AD0000]      <1> 	mov	[LCDE_EntryIndex], ax ; dir entry index/sequence number
 21097                              <1> 				      ; (in directory buffer/cluster)	  
 21098                              <1> loc_lcde_get_current_sub_dir_fcluster:
 21099 00006FB4 A1[08A30000]        <1> 	mov	eax, [Current_Dir_FCluster]
 21100                              <1> 
 21101                              <1> loc_lcde_get_next_cluster:
 21102 00006FB9 66833D[DAAD0000]00  <1> 	cmp	word [LCDE_ClusterSN], 0
 21103 00006FC1 763E                <1> 	jna	short loc_lcde_check_dir_buffer_cluster
 21104 00006FC3 A3[DCAD0000]        <1> 	mov	[LCDE_Cluster], eax
 21105 00006FC8 E865010000          <1> 	call	get_next_cluster
 21106 00006FCD 7220                <1> 	jc	short loc_lcde_check_gnc_error
 21107 00006FCF 66FF0D[DAAD0000]    <1>   	dec	word [LCDE_ClusterSN]
 21108 00006FD6 EBE1                <1> 	jmp	short loc_lcde_get_next_cluster
 21109                              <1> 
 21110                              <1> loc_lcde_reload_current_directory:
 21111 00006FD8 51                  <1> 	push	ecx
 21112 00006FD9 E875F6FFFF          <1> 	call	reload_current_directory
 21113 00006FDE 59                  <1> 	pop	ecx
 21114 00006FDF 0F8361FFFFFF        <1>         jnc     loc_lcde_cdl_check
 21115 00006FE5 5E                  <1> 	pop	esi
 21116 00006FE6 C3                  <1> 	retn
 21117                              <1> 
 21118                              <1> loc_lcde_invalid_format:
 21119 00006FE7 B80B000000          <1> 	mov	eax, 0Bh ; MSDOS Error code: Invalid Format
 21120                              <1> 	;mov	eax, 0Dh ; MSDOS Error code: Invalid Data
 21121                              <1> loc_lcde_drive_not_ready_read_err:
 21122 00006FEC F9                  <1> 	stc
 21123 00006FED 5E                  <1> 	pop	esi 
 21124 00006FEE C3                  <1> 	retn  
 21125                              <1> 
 21126                              <1> loc_lcde_check_gnc_error:
 21127 00006FEF 09C0                <1> 	or	eax, eax
 21128 00006FF1 75F9                <1> 	jnz	short loc_lcde_drive_not_ready_read_err
 21129 00006FF3 66FF0D[DAAD0000]    <1> 	dec	word [LCDE_ClusterSN]
 21130 00006FFA 75EB                <1> 	jnz	short loc_lcde_invalid_format 
 21131 00006FFC A1[DCAD0000]        <1> 	mov	eax, [LCDE_Cluster]
 21132                              <1> 
 21133                              <1> loc_lcde_check_dir_buffer_cluster:
 21134 00007001 3B05[3DAB0000]      <1> 	cmp	eax, [DirBuff_Cluster]
 21135 00007007 7555                <1> 	jne	short loc_lcde_load_dir_cluster
 21136 00007009 803D[38AB0000]00    <1> 	cmp	byte [DirBuff_ValidData], 0
 21137 00007010 7720                <1> 	ja	short lcde_check_dir_buffer_cluster_next
 21138 00007012 803D[0CA30000]00    <1> 	cmp	byte [Current_Dir_Level], 0    
 21139 00007019 7758                <1> 	ja	short loc_lcde_load_dir_cluster_0
 21140                              <1> 	; 27/02/2016
 21141                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
 21142 0000701B 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
 21143 0000701F 7352                <1> 	jnb	short loc_lcde_load_dir_cluster_0
 21144                              <1> 	;
 21145 00007021 0FB74E17            <1> 	movzx	ecx, word [esi+LD_BPB+RootDirEnts]
 21146 00007025 6683C10F            <1> 	add	cx, 15 ; round up (16 entries per sector)
 21147 00007029 66C1E904            <1> 	shr	cx, 4 ; 1 sector contains 16 dir entries	
 21148                              <1> 
 21149 0000702D 8B4664              <1>         mov     eax, [esi+LD_ROOTBegin]
 21150 00007030 EB4D                <1> 	jmp	short loc_lcde_load_dir_cluster_1 
 21151                              <1> 
 21152                              <1> lcde_check_dir_buffer_cluster_next:
 21153 00007032 0FB71D[D8AD0000]    <1> 	movzx	ebx, word [LCDE_EntryIndex]
 21154 00007039 663B1D[3BAB0000]    <1> 	cmp	bx, [DirBuff_LastEntry]
 21155 00007040 77A5                <1> 	ja	short loc_lcde_invalid_format 
 21156 00007042 B820000000          <1> 	mov	eax, 32
 21157 00007047 F7E3                <1> 	mul	ebx
 21158                              <1> 	;or	edx, edx
 21159                              <1> 	;jnz	short loc_lcde_invalid_format
 21160                              <1> 
 21161 00007049 BF00000800          <1> 	mov	edi, Directory_Buffer  
 21162 0000704E 01C7                <1> 	add	edi, eax ; add entry offset to buffer address
 21163                              <1> 
 21164                              <1> loc_lcde_dir_buffer_last_check:
 21165 00007050 A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 21166 00007055 0FB60D[38AB0000]    <1> 	movzx	ecx, byte [DirBuff_ValidData]
 21167                              <1> 
 21168                              <1> loc_lcde_retn:
 21169 0000705C 5E                  <1> 	pop	esi
 21170 0000705D C3                  <1> 	retn
 21171                              <1> 
 21172                              <1> loc_lcde_load_dir_cluster:
 21173                              <1> 	;cmp	byte [DirBuff_ValidData], 2
 21174                              <1> 	;jne	short loc_lcde_load_dir_cluster_n2
 21175 0000705E 50                  <1> 	push	eax
 21176 0000705F E8F2FCFFFF          <1> 	call	save_directory_buffer
 21177 00007064 58                  <1> 	pop	eax
 21178 00007065 72F5                <1> 	jc	short loc_lcde_retn
 21179                              <1> 
 21180                              <1> loc_lcde_load_dir_cluster_n2:
 21181 00007067 C605[38AB0000]00    <1> 	mov	byte [DirBuff_ValidData], 0
 21182 0000706E A3[3DAB0000]        <1> 	mov	[DirBuff_Cluster], eax
 21183                              <1> 
 21184                              <1> loc_lcde_load_dir_cluster_0:
 21185 00007073 83E802              <1> 	sub	eax, 2
 21186 00007076 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 21187 0000707A F7E1                <1> 	mul	ecx
 21188 0000707C 034668              <1>         add     eax, [esi+LD_DATABegin]
 21189                              <1> 
 21190                              <1> loc_lcde_load_dir_cluster_1:
 21191 0000707F BB00000800          <1> 	mov	ebx, Directory_Buffer
 21192                              <1> 	; ecx = sector count
 21193 00007084 E87E200000          <1> 	call	disk_read
 21194 00007089 72D1                <1> 	jc	short loc_lcde_retn
 21195                              <1> 
 21196                              <1> loc_lcde_validate_dirBuff:
 21197 0000708B C605[38AB0000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 21198 00007092 EB9E                <1> 	jmp	short lcde_check_dir_buffer_cluster_next
 21199                              <1> 
 21200                              <1> remove_file:
 21201                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
 21202                              <1> 	; 10/04/2011 (FILE.ASM, 'proc_delete_file')
 21203                              <1> 	; 09/08/2010
 21204                              <1> 	; INPUT ->
 21205                              <1> 	;	EDI = Directory Buffer Entry Address
 21206                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
 21207                              <1> 	;	 BL = Longname Entry Length
 21208                              <1> 	;	 BH = Logical DOS Drive Number 
 21209                              <1> 
 21210 00007094 29C0                <1> 	sub	eax, eax
 21211 00007096 88FC                <1> 	mov	ah, bh
 21212 00007098 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 21213 0000709D 01C6                <1> 	add	esi, eax
 21214                              <1> 
 21215 0000709F 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
 21216 000070A3 7312                <1> 	jnb	short loc_del_fat_file 
 21217                              <1>               
 21218 000070A5 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
 21219 000070A9 7406                <1> 	je	short loc_del_fs_file
 21220                              <1> 
 21221                              <1> loc_del_file_invalid_format:
 21222 000070AB 30E4                <1> 	xor	ah, ah
 21223 000070AD B00B                <1> 	mov	al, 0Bh ; Invalid Format
 21224 000070AF F9                  <1> 	stc 
 21225 000070B0 C3                  <1> 	retn
 21226                              <1> 
 21227                              <1> loc_del_fs_file:
 21228 000070B1 E87B000000          <1> 	call	delete_fs_file
 21229 000070B6 C3                  <1> 	retn
 21230                              <1> 
 21231                              <1> loc_del_fat_file:
 21232 000070B7 E808000000          <1> 	call	delete_directory_entry
 21233 000070BC 7205                <1> 	jc	short loc_del_file_err_retn 
 21234                              <1> 
 21235                              <1> loc_delfile_unlink_cluster_chain:
 21236 000070BE E8D8080000          <1> 	call	truncate_cluster_chain
 21237                              <1> 	;jc	short loc_del_file_err_retn
 21238                              <1> 
 21239                              <1> loc_delfile_return:
 21240                              <1> loc_del_file_err_retn:
 21241 000070C3 C3                  <1> 	retn
 21242                              <1> 
 21243                              <1> delete_directory_entry:
 21244                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
 21245                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_directory_entry')
 21246                              <1> 	; 10/04/2011 
 21247                              <1> 	; INPUT ->
 21248                              <1> 	; 	ESI = Logical Dos Drive Descripton Table Address 
 21249                              <1> 	;	EDI = Directory Buffer Entry Address
 21250                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
 21251                              <1> 	;	 BL = Longname Entry Length
 21252                              <1> 	;	 BH = Logical DOS Drive Number 
 21253                              <1> 	; OUTPUT ->
 21254                              <1> 	; 	ESI = Logical dos drive descripton table address 
 21255                              <1> 	;	EAX = First cluster to be truncated/unlinked
 21256                              <1> 	;       CF = 1 -> Error code in EAX (AL)
 21257                              <1> 	;       CF = 0 & BH <> 0 -> LMDT write error  (BH = 1)
 21258                              <1> 	;       CF = 0 & BL <> 0 -> Long name delete error (BL = FFh) 
 21259                              <1> 	;
 21260                              <1> 	;  (EDI, EBX, ECX register contents will be changed)
 21261                              <1> 
 21262 000070C4 881D[76AD0000]      <1> 	mov	[DelFile_LNEL], bl
 21263 000070CA 66890D[74AD0000]    <1> 	mov	[DelFile_EntryCounter], cx
 21264                              <1> 
 21265 000070D1 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
 21266 000070D5 C1E010              <1> 	shl	eax, 16
 21267 000070D8 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
 21268                              <1> 
 21269 000070DC A3[70AD0000]        <1> 	mov	[DelFile_FCluster], eax
 21270                              <1> 
 21271                              <1> loc_del_short_name:
 21272 000070E1 C607E5              <1> 	mov	byte [edi], 0E5h  ; Deleted sign
 21273                              <1> 
 21274 000070E4 C605[38AB0000]02    <1> 	mov	byte [DirBuff_ValidData], 2
 21275 000070EB E866FCFFFF          <1> 	call	save_directory_buffer
 21276 000070F0 723D                <1> 	jc	short loc_delete_direntry_err_return
 21277                              <1>  
 21278                              <1> loc_del_long_name:
 21279 000070F2 0FB615[76AD0000]    <1> 	movzx	edx, byte [DelFile_LNEL]
 21280 000070F9 08D2                <1> 	or	dl, dl
 21281 000070FB 7416                <1> 	jz	short loc_del_dir_entry_update_parent_dir_lm_date
 21282                              <1> 
 21283 000070FD 8835[76AD0000]      <1> 	mov	byte [DelFile_LNEL], dh ; 0              
 21284                              <1>   
 21285 00007103 0FB705[74AD0000]    <1> 	movzx	eax,  word [DelFile_EntryCounter]
 21286 0000710A 29D0                <1> 	sub	eax, edx
 21287                              <1> 	;jnc	short loc_del_long_name_continue
 21288 0000710C 7205                <1> 	jc	short loc_del_dir_entry_update_parent_dir_lm_date   
 21289                              <1> 
 21290                              <1> ;loc_del_direntry_inv_data_return:
 21291                              <1> ;	mov	eax, 0Dh ; Invalid data
 21292                              <1> ;	retn
 21293                              <1> 
 21294                              <1> loc_del_long_name_continue: 
 21295                              <1> 	; AX = Directory Entry Number of the long name last entry
 21296 0000710E E89CFDFFFF          <1> 	call	delete_longname
 21297                              <1> 	;jc	short loc_delete_direntry_err_return
 21298                              <1> 
 21299                              <1> loc_del_dir_entry_update_parent_dir_lm_date:
 21300 00007113 801D[76AD0000]00    <1> 	sbb	byte [DelFile_LNEL], 0 ; 0FFh if cf = 1
 21301                              <1> 
 21302 0000711A E8CBFCFFFF          <1> 	call	update_parent_dir_lmdt
 21303 0000711F B700                <1> 	mov	bh, 0
 21304 00007121 80D700              <1> 	adc	bh, 0
 21305                              <1> 
 21306 00007124 8A1D[76AD0000]      <1> 	mov	bl, byte [DelFile_LNEL]
 21307                              <1>  
 21308                              <1> loc_delete_direntry_return:
 21309 0000712A A1[70AD0000]        <1> 	mov	eax, [DelFile_FCluster]
 21310                              <1> loc_delete_direntry_err_return:
 21311 0000712F C3                  <1> 	retn
 21312                              <1> 
 21313                              <1> make_fs_directory:
 21314                              <1> 	; temporary (21/02/2016)
 21315 00007130 C3                  <1> 	retn
 21316                              <1> 
 21317                              <1> delete_fs_file:
 21318                              <1> 	; temporary (28/02/2016)
 21319 00007131 C3                  <1> 	retn
 21320                                  %include 'trdosk5.s' ; 24/01/2016
 21321                              <1> ; ****************************************************************************
 21322                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - File System Procedures : trdosk5s
 21323                              <1> ; ----------------------------------------------------------------------------
 21324                              <1> ; Last Update: 29/02/2016
 21325                              <1> ; ----------------------------------------------------------------------------
 21326                              <1> ; Beginning: 24/01/2016
 21327                              <1> ; ----------------------------------------------------------------------------
 21328                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 21329                              <1> ; ----------------------------------------------------------------------------
 21330                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 21331                              <1> ; DRV_FAT.ASM (21/08/2011)
 21332                              <1> ; ****************************************************************************
 21333                              <1> ; DRV_FAT.ASM (c) 2005-2011 Erdogan TAN [ 07/07/2009 ] Last Update: 21/08/2011
 21334                              <1> 
 21335                              <1> get_next_cluster:
 21336                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21337                              <1> 	; 05/07/2011
 21338                              <1> 	; 07/07/2009
 21339                              <1> 	; 2005
 21340                              <1> 	; INPUT ->
 21341                              <1> 	;	EAX = Cluster Number (32 bit)
 21342                              <1> 	;	ESI = Logical DOS Drive Parameters Table
 21343                              <1> 	; OUTPUT ->
 21344                              <1> 	;	cf = 0 -> No Error, EAX valid
 21345                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
 21346                              <1> 	;	cf = 1 & EAX > 0 -> Error
 21347                              <1> 	;	ECX = Current/Previous cluster (if CF = 0)
 21348                              <1> 	;	EAX = Next Cluster Number (32 bit)
 21349                              <1> 	;
 21350                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 21351                              <1> 
 21352 00007132 A3[21AB0000]        <1> 	mov	[FAT_CurrentCluster], eax
 21353                              <1> check_next_cluster_fat_type:
 21354 00007137 29D2                <1> 	sub	edx, edx ; 0
 21355 00007139 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
 21356 0000713D 7250                <1> 	jb	short get_FAT12_next_cluster
 21357 0000713F 0F87AF000000        <1>         ja      get_FAT32_next_cluster
 21358                              <1> get_FAT16_next_cluster:
 21359 00007145 BB00030000          <1> 	mov	ebx, 300h ;768
 21360 0000714A F7F3                <1> 	div	ebx
 21361                              <1> 	; EAX = Count of 3 FAT sectors
 21362                              <1> 	; EDX = Cluster Offset (< 768)
 21363 0000714C 66D1E2              <1> 	shl	dx, 1 ; Multiply by 2
 21364 0000714F 89D3                <1> 	mov	ebx, edx ; Byte Offset
 21365 00007151 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 21366 00007157 66BA0300            <1> 	mov	dx, 3
 21367 0000715B F7E2                <1> 	mul	edx  
 21368                              <1> 	; EAX = FAT Sector (<= 256)
 21369                              <1> 	; EDX = 0
 21370 0000715D 8A0E                <1> 	mov	cl, [esi+LD_Name]
 21371 0000715F 803D[25AB0000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 21372 00007166 0F86CC000000        <1>         jna     load_FAT_sectors0
 21373 0000716C 3A0D[26AB0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 21374 00007172 0F85C0000000        <1>         jne     load_FAT_sectors0
 21375 00007178 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 21376 0000717E 0F85BA000000        <1>         jne     load_FAT_sectors1
 21377                              <1> 	;movzx	eax, word [ebx]
 21378 00007184 668B03              <1> 	mov	ax, [ebx]
 21379                              <1> 	; 01/02/2016
 21380                              <1> 	; DRV_FAT.ASM (21/08/2011) had a FATal bug here !
 21381                              <1> 	; (cmp ah, 0Fh) ! (ax >= FF7h)
 21382                              <1> 	; (how can i do a such mistake!?)
 21383                              <1> 	;cmp	al, 0F7h
 21384                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 21385                              <1> 	;cmp	ah, 0FFh
 21386                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 21387 00007187 6683F8F7            <1> 	cmp	ax, 0FFF7h
 21388 0000718B 725A                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
 21389                              <1> 	; ax >= FFF7h (cluster 0002h to FFF6h is valid, in use)
 21390 0000718D EB56                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
 21391                              <1> 
 21392                              <1> get_FAT12_next_cluster:
 21393 0000718F BB00040000          <1> 	mov	ebx, 400h ;1024
 21394 00007194 F7F3                <1> 	div	ebx
 21395                              <1> 	; EAX = Count of 3 FAT sectors
 21396                              <1> 	; EDX = Cluster Offset (< 1024)
 21397 00007196 6650                <1> 	push	ax
 21398 00007198 66B80300            <1> 	mov	ax, 3	
 21399 0000719C 66F7E2              <1> 	mul	dx    	; Multiply by 3
 21400 0000719F 66D1E8              <1> 	shr	ax, 1	; Divide by 2
 21401 000071A2 6689C3              <1>         mov	bx, ax 	; Byte Offset
 21402 000071A5 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 21403 000071AB 6658                <1> 	pop	ax
 21404 000071AD 66BA0300            <1> 	mov	dx, 3
 21405 000071B1 F7E2                <1> 	mul	edx 
 21406                              <1> 	; EAX = FAT Sector (<= 12)
 21407                              <1> 	; EDX = 0
 21408 000071B3 8A0E                <1> 	mov	cl, [esi+LD_Name]
 21409 000071B5 803D[25AB0000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 21410 000071BC 767A                <1> 	jna	short load_FAT_sectors0
 21411 000071BE 3A0D[26AB0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 21412 000071C4 7572                <1> 	jne	short load_FAT_sectors0
 21413 000071C6 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 21414 000071CC 7570                <1> 	jne	short load_FAT_sectors1
 21415 000071CE A1[21AB0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 21416 000071D3 66D1E8              <1> 	shr	ax, 1
 21417                              <1> 	;movzx	eax, word [ebx]
 21418 000071D6 668B03              <1> 	mov	ax, [ebx]
 21419 000071D9 7314                <1> 	jnc	short get_FAT12_nc_even
 21420 000071DB 66C1E804            <1> 	shr	ax, 4
 21421                              <1> loc_gnc_fat12_eoc_check:
 21422                              <1> 	;cmp	al, 0F7h
 21423                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 21424                              <1> 	;cmp	ah, 0Fh
 21425                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
 21426 000071DF 663DF70F            <1> 	cmp	ax, 0FF7h
 21427 000071E3 7202                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
 21428                              <1> 	; ax >= FF7h (cluster 0002h to FF6h is valid, in use)
 21429                              <1> 
 21430                              <1> loc_pass_gnc_FAT16_eoc_check_xor_eax:
 21431 000071E5 31C0                <1> 	xor	eax, eax ; 0
 21432                              <1> loc_pass_gnc_FAT16_eoc_check:
 21433                              <1> loc_pass_gnc_FAT32_eoc_check:
 21434 000071E7 8B0D[21AB0000]      <1> 	mov	ecx, [FAT_CurrentCluster]
 21435 000071ED F5                  <1> 	cmc
 21436 000071EE C3                  <1> 	retn
 21437                              <1> 
 21438                              <1> get_FAT12_nc_even:
 21439 000071EF 80E40F              <1> 	and	ah, 0Fh
 21440 000071F2 EBEB                <1> 	jmp	short loc_gnc_fat12_eoc_check
 21441                              <1> 
 21442                              <1> get_FAT32_next_cluster:
 21443 000071F4 BB80010000          <1> 	mov	ebx, 180h ;384
 21444 000071F9 F7F3                <1> 	div	ebx
 21445                              <1> 	; EAX = Count of 3 FAT sectors
 21446                              <1> 	; EDX = Cluster Offset (< 384)
 21447 000071FB 66C1E202            <1> 	shl	dx, 2	; Multiply by 4
 21448 000071FF 89D3                <1> 	mov	ebx, edx ; Byte Offset
 21449 00007201 81C3001C0900        <1> 	add	ebx, FAT_Buffer
 21450 00007207 66BA0300            <1> 	mov	dx, 3
 21451 0000720B F7E2                <1> 	mul	edx	
 21452                              <1>         ; EAX = FAT Sector (<= 2097152) ; (FFFFFF7h * 4) / 512
 21453                              <1> 	; 	for 32KB cluster size:
 21454                              <1> 	;	EAX <= 1024 = (4GB / 32KB) * 4) / 512 	
 21455                              <1> 	; EDX = 0
 21456 0000720D 8A0E                <1> 	mov	cl, [esi+LD_Name]
 21457 0000720F 803D[25AB0000]00    <1> 	cmp	byte [FAT_BuffValidData], 0
 21458 00007216 7620                <1> 	jna	short load_FAT_sectors0
 21459 00007218 3A0D[26AB0000]      <1> 	cmp	cl, [FAT_BuffDrvName]
 21460 0000721E 7518                <1> 	jne	short load_FAT_sectors0
 21461 00007220 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector] ; 0, 3, 6, 9 ...
 21462 00007226 7516                <1> 	jne	short load_FAT_sectors1
 21463 00007228 8B03                <1> 	mov	eax, [ebx]
 21464 0000722A 25FFFFFF0F          <1>  	and	eax, 0FFFFFFFh ; 28 bit Cluster
 21465 0000722F 3DF7FFFF0F          <1> 	cmp	eax, 0FFFFFF7h
 21466 00007234 72B1                <1> 	jb	short loc_pass_gnc_FAT32_eoc_check
 21467                              <1> 	; eax >= FFFFFF7h (cluster 0002h to FFFFFF6h is valid)
 21468 00007236 EBAD                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
 21469                              <1> 
 21470                              <1> load_FAT_sectors0:
 21471 00007238 880D[26AB0000]      <1> 	mov	[FAT_BuffDrvName], cl
 21472                              <1> load_FAT_sectors1:
 21473 0000723E A3[29AB0000]        <1> 	mov	[FAT_BuffSector], eax
 21474 00007243 89C3                <1> 	mov	ebx, eax
 21475 00007245 034660              <1>         add     eax, [esi+LD_FATBegin]
 21476 00007248 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 21477 0000724C 7706                <1>         ja      short load_FAT_sectors3
 21478 0000724E 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
 21479 00007252 EB03                <1> 	jmp	short load_FAT_sectors4
 21480                              <1> load_FAT_sectors3:
 21481 00007254 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+BPB_FATSz32]
 21482                              <1> load_FAT_sectors4:
 21483 00007257 29D9                <1> 	sub	ecx, ebx ; [FAT_BuffSector]
 21484 00007259 83F903              <1>         cmp     ecx, 3
 21485 0000725C 7605                <1>         jna     short load_FAT_sectors5
 21486 0000725E B903000000          <1> 	mov	ecx, 3
 21487                              <1> load_FAT_sectors5:
 21488 00007263 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 21489 00007268 E89A1E0000          <1> 	call	disk_read
 21490 0000726D 7308                <1> 	jnc	short load_FAT_sectors_ok
 21491 0000726F C605[25AB0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 21492 00007276 C3                  <1> 	retn
 21493                              <1> load_FAT_sectors_ok:
 21494 00007277 C605[25AB0000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 21495 0000727E A1[21AB0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 21496 00007283 E9AFFEFFFF          <1>         jmp     check_next_cluster_fat_type
 21497                              <1> 
 21498                              <1> load_FAT_root_directory:
 21499                              <1> 	; 07/02/2016
 21500                              <1> 	; 02/02/2016
 21501                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21502                              <1> 	; 21/05/2011
 21503                              <1> 	; 22/08/2009
 21504                              <1> 	;
 21505                              <1> 	; INPUT ->
 21506                              <1> 	;	ESI = Logical DOS Drive Description Table
 21507                              <1> 	; OUTPUT ->
 21508                              <1> 	;	cf = 1 -> Root directory could not be loaded
 21509                              <1> 	;	    EAX > 0 -> Error number
 21510                              <1> 	;	cf = 0 -> EAX = 0
 21511                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 21512                              <1> 	;	EBX = Directory buffer address
 21513                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 21514                              <1> 	;
 21515                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 21516                              <1> 
 21517                              <1> 	; NOTE: Only for FAT12 and FAT16 file systems !
 21518                              <1> 	; (FAT32 fs root dir must be loaded as sub directory)
 21519                              <1> 
 21520 00007288 8A1E                <1> 	mov	bl, [esi+LD_Name]
 21521 0000728A 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 21522                              <1> 
 21523                              <1> 	;mov	[DirBuff_DRV], bl
 21524                              <1> 	;mov	[DirBuff_FATType], bh
 21525 0000728D 66891D[36AB0000]    <1> 	mov	[DirBuff_DRV], bx
 21526                              <1> 	
 21527                              <1> 	;cmp	bh, 2
 21528                              <1> 	;ja	short load_FAT32_root_dir0 ; FAT32 root dir
 21529                              <1> 
 21530 00007294 0FB75617            <1> 	movzx	edx, word [esi+LD_BPB+RootDirEnts]
 21531                              <1> 
 21532                              <1> 	;or	dx, dx ; 0 for FAT32 file systems
 21533                              <1> 	;jz	short load_FAT32_root_dir0 ; FAT32 root dir
 21534                              <1> 
 21535 00007298 6681FA0002          <1> 	cmp	dx, 512 ; Number of Root Dir Entries
 21536 0000729D 7414                <1> 	je	short lrd_mov_ecx_32
 21537 0000729F 89D0                <1> 	mov	eax, edx
 21538 000072A1 6683C00F            <1> 	add	ax, 15 ; round up 
 21539 000072A5 66C1E804            <1> 	shr	ax, 4  ; 16 entries per sector (512/32)
 21540 000072A9 89C1                <1> 	mov	ecx, eax ; Root directory size in sectors
 21541 000072AB 66C1E009            <1> 	shl	ax, 9 ; Root directory size in bytes
 21542 000072AF 664A                <1> 	dec	dx    ; Last entry number of root dir
 21543                              <1> 	; cx = Dir Buffer sector count             
 21544 000072B1 EB0B                <1> 	jmp	short lrd_check_dir_buffer
 21545                              <1> 
 21546                              <1> lrd_mov_ecx_32:
 21547 000072B3 B920000000          <1> 	mov	ecx, 32
 21548 000072B8 664A                <1> 	dec	dx ; 511
 21549 000072BA 66B80040            <1> 	mov	ax, 32*512 
 21550                              <1>  
 21551                              <1> lrd_check_dir_buffer:
 21552 000072BE 29DB                <1> 	sub	ebx, ebx ; 0
 21553 000072C0 881D[38AB0000]      <1> 	mov	[DirBuff_ValidData], bl ; 0
 21554 000072C6 668915[3BAB0000]    <1> 	mov	[DirBuff_LastEntry], dx
 21555 000072CD 891D[3DAB0000]      <1> 	mov	[DirBuff_Cluster], ebx ; 0
 21556 000072D3 66A3[41AB0000]      <1> 	mov	[DirBuffer_Size], ax
 21557                              <1> 
 21558 000072D9 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin]
 21559                              <1> read_directory:
 21560 000072DC BB00000800          <1> 	mov	ebx, Directory_Buffer
 21561 000072E1 51                  <1> 	push	ecx ; Directory buffer sector count
 21562 000072E2 53                  <1> 	push	ebx
 21563 000072E3 E81F1E0000          <1> 	call	disk_read
 21564 000072E8 5B                  <1> 	pop	ebx
 21565 000072E9 720B                <1> 	jc	short load_DirBuff_error
 21566                              <1> 
 21567                              <1> validate_DirBuff_and_return:
 21568 000072EB 59                  <1> 	pop	ecx ; Number of loaded sectors
 21569 000072EC C605[38AB0000]01    <1> 	mov	byte [DirBuff_ValidData], 1
 21570 000072F3 31C0                <1> 	xor	eax, eax ; 0 = no error
 21571 000072F5 C3                  <1> 	retn
 21572                              <1> 
 21573                              <1> load_DirBuff_error:
 21574 000072F6 89C8                <1> 	mov	eax, ecx ; remaining sectors
 21575 000072F8 59                  <1> 	pop	ecx ; sector count
 21576 000072F9 29C1                <1> 	sub	ecx, eax ; Number of loaded sectors
 21577 000072FB B815000000          <1> 	mov	eax, 15h ; DRV NOT READY OR READ ERROR !
 21578 00007300 F9                  <1> 	stc
 21579 00007301 C3                  <1>         retn
 21580                              <1> 
 21581                              <1> load_FAT32_root_directory:
 21582                              <1> 	; 02/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21583                              <1> 	;
 21584                              <1> 	; INPUT ->
 21585                              <1> 	;	ESI = Logical DOS Drive Description Table
 21586                              <1> 	; OUTPUT ->
 21587                              <1> 	;	cf = 1 -> Root directory could not be loaded
 21588                              <1> 	;	    EAX > 0 -> Error number
 21589                              <1> 	;	cf = 0 -> EAX = 0
 21590                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 21591                              <1> 	;	EBX = Directory buffer address
 21592                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 21593                              <1> 	;
 21594                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 21595                              <1> 
 21596                              <1> 
 21597 00007302 8A1E                <1> 	mov	bl, [esi+LD_Name]
 21598 00007304 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 21599                              <1> 
 21600                              <1> 	;mov	[DirBuff_DRV], bl
 21601                              <1> 	;mov	[DirBuff_FATType], bh
 21602 00007307 66891D[36AB0000]    <1> 	mov	[DirBuff_DRV], bx
 21603                              <1> 
 21604                              <1> load_FAT32_root_dir0:
 21605 0000730E 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
 21606 00007311 EB0C                <1> 	jmp	short load_FAT_sub_dir0
 21607                              <1> 	
 21608                              <1> load_FAT_sub_directory:
 21609                              <1> 	; 01/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21610                              <1> 	; 05/07/2011
 21611                              <1> 	; 23/08/2009
 21612                              <1> 	;
 21613                              <1> 	; INPUT ->
 21614                              <1> 	;	ESI = Logical DOS Drive Description Table
 21615                              <1> 	;	EAX = Cluster Number
 21616                              <1> 	; OUTPUT ->
 21617                              <1> 	;	cf = 1 -> Sub directory could not be loaded
 21618                              <1> 	;	    EAX > 0 -> Error number
 21619                              <1> 	;	cf = 0 -> EAX = 0
 21620                              <1> 	;	ECX = Directory buffer size in sectors (CL)
 21621                              <1> 	;	EBX = Directory buffer address
 21622                              <1> 	;
 21623                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
 21624                              <1> 	;
 21625                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 21626                              <1> 
 21627 00007313 8A1E                <1> 	mov	bl, [esi+LD_Name]
 21628 00007315 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
 21629                              <1> 
 21630                              <1> 	;mov	[DirBuff_DRV], bl
 21631                              <1> 	;mov	[DirBuff_FATType], bh
 21632 00007318 66891D[36AB0000]    <1> 	mov	[DirBuff_DRV], bx
 21633                              <1> 
 21634                              <1> load_FAT_sub_dir0:
 21635 0000731F 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 21636                              <1> 
 21637 00007323 882D[38AB0000]      <1> 	mov	[DirBuff_ValidData], ch ; 0
 21638 00007329 A3[3DAB0000]        <1> 	mov	[DirBuff_Cluster], eax
 21639                              <1> 
 21640 0000732E 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
 21641 00007332 F7E1                <1> 	mul	ecx
 21642 00007334 C1E805              <1> 	shr	eax, 5 ; directory entry count (dir size / 32)
 21643 00007337 6648                <1> 	dec	ax ; last entry
 21644 00007339 66A3[3BAB0000]      <1> 	mov	[DirBuff_LastEntry], ax
 21645                              <1> 
 21646 0000733F A1[3DAB0000]        <1> 	mov	eax, [DirBuff_Cluster]
 21647 00007344 83E802              <1> 	sub	eax, 2
 21648 00007347 F7E1                <1> 	mul	ecx
 21649 00007349 034668              <1> 	add	eax, [esi+LD_DATABegin]
 21650                              <1> 	; ecx = sector per cluster (dir buffer size = 32 sectors)
 21651 0000734C EB8E                <1> 	jmp	short read_directory
 21652                              <1> 
 21653                              <1> ; DRV_FS.ASM
 21654                              <1> 
 21655                              <1> load_current_FS_directory:
 21656 0000734E C3                  <1> 	retn
 21657                              <1> load_FS_root_directory:
 21658 0000734F C3                  <1> 	retn
 21659                              <1> load_FS_sub_directory:
 21660 00007350 C3                  <1> 	retn
 21661                              <1> 
 21662                              <1> read_cluster:
 21663                              <1> 	; 17/02/2016
 21664                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21665                              <1> 	;
 21666                              <1> 	; INPUT ->
 21667                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
 21668                              <1> 	;	ESI = Logical DOS Drive Description Table address
 21669                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
 21670                              <1> 	;	Only for SINGLIX FS:
 21671                              <1> 	;	EDX = File Number (The 1st FDT address) 
 21672                              <1> 	; OUTPUT ->
 21673                              <1> 	;	cf = 1 -> Cluster can not be loaded at the buffer
 21674                              <1> 	;	    EAX > 0 -> Error number
 21675                              <1> 	;	cf = 0 -> Cluster has been loaded at the buffer
 21676                              <1> 	;
 21677                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 21678                              <1> 	
 21679 00007351 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
 21680                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
 21681                              <1> 
 21682 00007355 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 21683 00007359 7618                <1> 	jna	short read_fs_cluster
 21684                              <1> 
 21685 0000735B 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
 21686 0000735E F7E1                <1> 	mul	ecx
 21687 00007360 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
 21688                              <1> 	
 21689 00007363 E89F1D0000          <1> 	call	disk_read
 21690 00007368 7306                <1> 	jnc	short rclust_retn
 21691                              <1> 	
 21692 0000736A B815000000          <1> 	mov	eax, 15h ; Drive not ready or read error !
 21693 0000736F C3                  <1> 	retn
 21694                              <1> 
 21695                              <1> rclust_retn:
 21696 00007370 29C0                <1> 	sub	eax, eax ; 0
 21697 00007372 C3                  <1> 	retn
 21698                              <1> 
 21699                              <1> read_fs_cluster:
 21700                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21701                              <1> 	; Singlix FS
 21702                              <1> 	
 21703                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
 21704                              <1> 	
 21705                              <1> 	; EDX = File number is the first File Descriptor Table address 
 21706                              <1> 	;	of the file. (Absolute address of the FDT).
 21707                              <1> 	
 21708                              <1> 	; eax = sector index (0 for the first sector)
 21709                              <1> 	; edx = FDT0 address
 21710                              <1> 		; 64 KB buffer = 128 sectors (limit) 
 21711 00007373 B980000000          <1> 	mov	ecx, 128 ; maximum count of sectors (before eof) 
 21712 00007378 E801000000          <1> 	call	read_fs_sectors
 21713 0000737D C3                  <1> 	retn
 21714                              <1> 
 21715                              <1> read_fs_sectors:
 21716                              <1> 	; 15/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21717 0000737E F9                  <1> 	stc
 21718 0000737F C3                  <1> 	retn
 21719                              <1> 
 21720                              <1> get_first_free_cluster:
 21721                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21722                              <1> 	; 26/10/2010 (DRV_FAT.ASM, 'proc_get_first_free_cluster')
 21723                              <1> 	; 10/07/2010
 21724                              <1> 	; INPUT ->
 21725                              <1> 	;	ESI = Logical DOS Drive Description Table address
 21726                              <1> 	; OUTPUT ->
 21727                              <1> 	;	cf = 1 -> Error code in AL (EAX)
 21728                              <1> 	;	cf = 0 -> 
 21729                              <1> 	;	  If EAX = FFFFFFFFh -> no free space
 21730                              <1> 	;	  EBX = FAT32 FSI sector buffer address (if > 0)
 21731                              <1> 
 21732 00007380 8B4678              <1> 	mov	eax, [esi+LD_Clusters]
 21733 00007383 40                  <1> 	inc	eax ; add eax, 1
 21734 00007384 A3[B8AD0000]        <1> 	mov	[gffc_last_free_cluster], eax
 21735                              <1> 
 21736 00007389 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 21737 0000738D 760E                <1> 	jna	short loc_gffc_get_first_fat_free_cluster0
 21738                              <1> 
 21739                              <1> loc_gffc_get_first_fat32_free_cluster:
 21740                              <1> 	; 29/02/2016
 21741 0000738F E8A6060000          <1> 	call	get_fat32_fsinfo_sector_parms
 21742 00007394 7207                <1> 	jc	short loc_gffc_get_first_fat_free_cluster0
 21743                              <1> 
 21744                              <1> loc_gffc_check_fsinfo_parms:
 21745                              <1> 	;;mov	ebx, DOSBootSectorBuff
 21746                              <1> 	;cmp	dword [ebx], 41615252h
 21747                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
 21748                              <1> 	;cmp	dword [ebx+484], 61417272h
 21749                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
 21750                              <1> 	;mov	eax, [ebx+492] ; FSI_Next_Free
 21751                              <1> 	;EAX = First free cluster 
 21752                              <1> 	;(from FAT32 FSInfo sector)
 21753 00007396 89D0                <1> 	mov	eax, edx ; FSI_Next_Free (First Free Cluster)
 21754 00007398 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; invalid (unknown) !
 21755 0000739B 7205                <1> 	jb	short loc_gffc_get_first_fat_free_cluster1
 21756                              <1> 
 21757                              <1> 	; Start from the 1st cluster of the FAT(32) file system
 21758                              <1> loc_gffc_get_first_fat_free_cluster0:
 21759 0000739D B802000000          <1> 	mov	eax, 2
 21760                              <1> 	;xor	edx, edx
 21761                              <1> 
 21762                              <1> loc_gffc_get_first_fat_free_cluster1:   
 21763 000073A2 A3[B4AD0000]        <1> 	mov	[gffc_first_free_cluster], eax
 21764 000073A7 A3[B0AD0000]        <1> 	mov	[gffc_next_free_cluster], eax
 21765                              <1> 
 21766                              <1> loc_gffc_get_first_fat_free_cluster2:
 21767 000073AC E881FDFFFF          <1> 	call	get_next_cluster
 21768 000073B1 7306                <1> 	jnc	short loc_gffc_get_first_fat_free_cluster3
 21769 000073B3 09C0                <1> 	or	eax, eax
 21770 000073B5 740A                <1> 	jz	short loc_gffc_first_free_fat_cluster_next
 21771 000073B7 F5                  <1> 	cmc 
 21772 000073B8 C3                  <1> 	retn
 21773                              <1> 
 21774                              <1> loc_gffc_get_first_fat_free_cluster3:
 21775 000073B9 21C0                <1> 	and	eax, eax ; next cluster value
 21776 000073BB 7504                <1> 	jnz	short loc_gffc_first_free_fat_cluster_next
 21777 000073BD 89C8                <1> 	mov	eax, ecx ; current (previous cluster) value
 21778 000073BF EB22                <1> 	jmp	short loc_gffc_check_for_set
 21779                              <1>  
 21780                              <1> loc_gffc_first_free_fat_cluster_next:
 21781 000073C1 A1[B0AD0000]        <1> 	mov	eax, [gffc_next_free_cluster]
 21782 000073C6 3B05[B8AD0000]      <1> 	cmp	eax, [gffc_last_free_cluster]
 21783 000073CC 7308                <1> 	jnb	short retn_stc_from_get_first_free_cluster
 21784                              <1> pass_gffc_last_cluster_eax_check:
 21785 000073CE 40                  <1> 	inc	eax ; add eax, 1
 21786 000073CF A3[B0AD0000]        <1> 	mov	[gffc_next_free_cluster], eax
 21787 000073D4 EBD6                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster2
 21788                              <1> 
 21789                              <1> retn_stc_from_get_first_free_cluster:
 21790 000073D6 A1[B4AD0000]        <1> 	mov	eax, [gffc_first_free_cluster]
 21791 000073DB 83F802              <1> 	cmp	eax, 2
 21792 000073DE 770C                <1> 	ja	short loc_gffc_check_previous_clusters
 21793 000073E0 29C0                <1> 	sub	eax, eax
 21794 000073E2 48                  <1> 	dec	eax ; FFFFFFFFh
 21795                              <1> 
 21796                              <1> loc_gffc_check_for_set:
 21797 000073E3 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
 21798 000073E7 7310                <1> 	jnb	short loc_gffc_set_ffree_fat32_cluster
 21799                              <1> 
 21800 000073E9 31DB                <1> 	xor	ebx, ebx ; 0
 21801 000073EB C3                  <1> 	retn
 21802                              <1> 
 21803                              <1> loc_gffc_check_previous_clusters:
 21804 000073EC 48                  <1> 	dec	eax ; sub eax, 1
 21805 000073ED A3[B8AD0000]        <1> 	mov	[gffc_last_free_cluster], eax 
 21806 000073F2 B802000000          <1> 	mov	eax, 2
 21807                              <1> 	;xor	edx, edx
 21808 000073F7 EBA9                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster1
 21809                              <1> 
 21810                              <1> loc_gffc_set_ffree_fat32_cluster:
 21811                              <1> 	;call	set_first_free_cluster
 21812                              <1> 	;retn
 21813                              <1> 	;jmp	short set_first_free_cluster	
 21814                              <1> 
 21815                              <1> set_first_free_cluster:
 21816                              <1> 	; 29/02/2016
 21817                              <1> 	; 26/02/2016
 21818                              <1> 	; 21/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21819                              <1> 	; 21/08/2011 (DRV_FAT.ASM, 'proc_set_first_free_cluster')
 21820                              <1> 	; 11/07/2010
 21821                              <1> 	; INPUT -> 
 21822                              <1> 	;	ESI = Logical DOS Drive Description Table address
 21823                              <1> 	;	EAX = First free cluster
 21824                              <1> 	;	EBX = FSINFO sector buffer address
 21825                              <1> 	;  	;;If EBX > 0, it is FSINFO sector buffer address
 21826                              <1> 	;	;;EBX = 0, if FSINFO sector is not loaded
 21827                              <1> 	; OUTPUT->
 21828                              <1> 	;	ESI = Logical DOS Drive Description Table address
 21829                              <1> 	;  	If EBX > 0, it is FSINFO sector buffer address
 21830                              <1> 	;	EBX = 0, if FSINFO sector could not be loaded
 21831                              <1> 	; 	CF = 1 -> Error code in AL (EAX)
 21832                              <1> 	;	CF = 0 -> first free cluster is successfully updated 
 21833                              <1> 
 21834                              <1> 	;cmp	byte [esi+LD_FATType], 3
 21835                              <1> 	;jb	short loc_sffc_invalid_drive
 21836                              <1> 
 21837                              <1> 	; Save First Free Cluster value for 'update_cluster'
 21838 000073F9 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First free Cluster	
 21839                              <1> 
 21840                              <1> 	;or	ebx, ebx
 21841                              <1> 	;jnz	short loc_sffc_read_fsinfo_sector
 21842                              <1> 
 21843 000073FC 813B52526141        <1> 	cmp     dword [ebx], 41615252h
 21844 00007402 7535                <1> 	jne	short loc_sffc_read_fsinfo_sector
 21845 00007404 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 21846 0000740D 61                  <1>
 21847 0000740E 7529                <1> 	jne	short loc_sffc_read_fsinfo_sector
 21848                              <1> 
 21849 00007410 3B83EC010000        <1> 	cmp	eax, [ebx+492]  ; FSI_Next_Free
 21850 00007416 7419                <1> 	je	short loc_sffc_retn
 21851                              <1> 
 21852                              <1> loc_sffc_write_fsinfo_sector:
 21853                              <1> 	; EBX = FSINFO sector buffer
 21854                              <1> 	; [CFS_FAT32FSINFOSEC] is set in 'get_fat32_fsinfo_sector_parms'
 21855 00007418 8983EC010000        <1> 	mov	[ebx+492], eax
 21856 0000741E A1[C8AD0000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC] 
 21857 00007423 B901000000          <1> 	mov	ecx, 1
 21858 00007428 53                  <1> 	push	ebx
 21859 00007429 E8CA1C0000          <1> 	call	disk_write
 21860 0000742E 7202                <1> 	jc      short loc_sffc_read_fsinfo_sector_err
 21861 00007430 5B                  <1> 	pop	ebx
 21862                              <1> 
 21863                              <1> loc_sffc_retn:
 21864 00007431 C3                  <1> 	retn
 21865                              <1> 
 21866                              <1> ;loc_sffc_invalid_drive:
 21867                              <1> ;	mov	eax, 0Fh ; MSDOS Error : Invalid drive
 21868                              <1> ;	push	edx
 21869                              <1> 
 21870                              <1> loc_sffc_read_fsinfo_sector_err:
 21871 00007432 5A                  <1> 	pop	edx
 21872 00007433 BB00000000          <1> 	mov	ebx, 0
 21873 00007438 C3                  <1> 	retn
 21874                              <1> 	
 21875                              <1> loc_sffc_read_fsinfo_sector:
 21876 00007439 50                  <1> 	push	eax
 21877                              <1> 
 21878 0000743A E8FB050000          <1> 	call	get_fat32_fsinfo_sector_parms
 21879 0000743F 72F1                <1> 	jc	short loc_sffc_read_fsinfo_sector_err
 21880                              <1> 
 21881 00007441 58                  <1> 	pop	eax
 21882                              <1> 	; EDX = First (Next) Free Cluster value from FSINFO sector
 21883                              <1> 	; EAX = First Free Cluster value from 'get_next_cluster'
 21884                              <1> 	; (edx = old value)
 21885 00007442 39D0                <1> 	cmp	eax, edx ; First free Cluster (eax = new value) 
 21886 00007444 75D2                <1> 	jne	short loc_sffc_write_fsinfo_sector
 21887                              <1> 
 21888 00007446 C3                  <1> 	retn	
 21889                              <1> 
 21890                              <1> update_cluster:
 21891                              <1> 	; 29/02/2016
 21892                              <1> 	; 27/02/2016
 21893                              <1> 	; 26/02/2016
 21894                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 21895                              <1> 	; 11/08/2011  
 21896                              <1> 	; 09/02/2005
 21897                              <1> 	; INPUT ->
 21898                              <1> 	;	EAX = Cluster Number
 21899                              <1> 	;	ECX = New Cluster Value
 21900                              <1> 	;	ESI = Logical Dos Drive Parameters Table
 21901                              <1> 	; OUTPUT ->
 21902                              <1> 	;	cf = 0 -> No Error, EAX is valid
 21903                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
 21904                              <1> 	; 	cf = 1 & EAX > 0 -> Error
 21905                              <1> 	;		(ECX -> any value)
 21906                              <1> 	; 	EAX = Next Cluster
 21907                              <1> 	;	ECX = New Cluster Value
 21908                              <1> 	;
 21909                              <1> 	; (Modified registers: EAX, EBX, -ECX-, EDX)
 21910                              <1> 	
 21911 00007447 A3[21AB0000]        <1> 	mov	[FAT_CurrentCluster], eax
 21912 0000744C 890D[BCAD0000]      <1> 	mov	[ClusterValue], ecx
 21913                              <1> 
 21914                              <1> loc_update_cluster_check_fat_buffer:
 21915 00007452 8A1E                <1> 	mov	bl, [esi+LD_Name]
 21916 00007454 381D[26AB0000]      <1> 	cmp	[FAT_BuffDrvName], bl
 21917 0000745A 741A                <1> 	je	short loc_update_cluster_check_fat_type
 21918 0000745C 803D[25AB0000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 21919 00007463 0F84B1000000        <1>         je      loc_uc_save_fat_buffer
 21920                              <1> 
 21921                              <1> loc_uc_reset_fat_buffer_validation:
 21922 00007469 C605[25AB0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 21923                              <1> 
 21924                              <1> loc_uc_check_fat_type_reset_drvname:
 21925 00007470 881D[26AB0000]      <1> 	mov	[FAT_BuffDrvName], bl
 21926                              <1> 
 21927                              <1> loc_update_cluster_check_fat_type:
 21928 00007476 29D2                <1> 	sub	edx, edx ; 26/02/2016
 21929 00007478 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
 21930 0000747B 83F802              <1> 	cmp	eax, 2
 21931 0000747E 0F82AB000000        <1>         jb      update_cluster_inv_data
 21932 00007484 80FB02              <1> 	cmp	bl, 2 
 21933 00007487 0F8767010000        <1>         ja      update_fat32_cluster
 21934                              <1> 	;or	bl, bl
 21935                              <1> 	;jz	short update_cluster_inv_data
 21936 0000748D 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
 21937 00007490 41                  <1> 	inc	ecx  
 21938 00007491 890D[31AB0000]      <1> 	mov	[LastCluster], ecx
 21939 00007497 39C8                <1> 	cmp	eax, ecx ; dword [LastCluster]
 21940 00007499 777B                <1> 	ja	short return_uc_fat_stc
 21941                              <1> 	; TRDOS v1 has a FATal bug here ! 
 21942                              <1> 		; or bl, bl ; cmp bl, 0
 21943                              <1> 		; jz short update_fat12_cluster
 21944                              <1> 	; !! It would destroy FAT12 floppy disk fs here !!
 21945                              <1> 	; ('A:' disks of TRDOS v1 operating system project
 21946                              <1> 	; had 'singlix fs', so, I could not differ this mistake
 21947                              <1> 	; on a drive 'A:')
 21948 0000749B 80FB01              <1> 	cmp	bl, 1 ; correct comparison is this !
 21949 0000749E 0F868E000000        <1>         jna     update_fat12_cluster 
 21950                              <1> 
 21951                              <1> update_fat16_cluster:
 21952                              <1> pass_uc_fat16_errc:
 21953                              <1> 	;sub	edx, edx
 21954 000074A4 BB00030000          <1> 	mov	ebx, 300h ;768
 21955 000074A9 F7F3                <1> 	div	ebx
 21956                              <1> 	; EAX = Count of 3 FAT sectors
 21957                              <1> 	; DX = Cluster offset in FAT buffer
 21958 000074AB 6689D3              <1> 	mov	bx, dx  
 21959 000074AE 66D1E3              <1> 	shl	bx, 1 ; Multiply by 2
 21960 000074B1 66BA0300            <1> 	mov	dx, 3
 21961 000074B5 F7E2                <1> 	mul	edx  
 21962                              <1> 	; EAX = FAT Sector
 21963                              <1> 	; EDX = 0
 21964                              <1> 	; EBX = Byte offset in FAT buffer
 21965 000074B7 8A0D[25AB0000]      <1> 	mov	cl, [FAT_BuffValidData]
 21966 000074BD 80F902              <1> 	cmp	cl, 2
 21967 000074C0 750A                <1> 	jne	short loc_uc_check_fat16_buff_sector_load
 21968                              <1> 
 21969                              <1> loc_uc_check_fat16_buff_sector_save:
 21970 000074C2 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 21971 000074C8 7550                <1> 	jne	short loc_uc_save_fat_buffer
 21972 000074CA EB15                <1> 	jmp	short loc_update_fat16_cell
 21973                              <1> 
 21974                              <1> loc_uc_check_fat16_buff_sector_load:
 21975 000074CC 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
 21976 000074CF 0F8512020000        <1>         jne     loc_uc_load_fat_sectors
 21977 000074D5 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 21978 000074DB 0F8506020000        <1>         jne     loc_uc_load_fat_sectors
 21979                              <1> 
 21980                              <1> loc_update_fat16_cell:
 21981                              <1> loc_update_fat16_buffer:
 21982 000074E1 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 21983                              <1> 	;movzx	eax, word [ebx]
 21984 000074E7 668B03              <1> 	mov	ax, [ebx]
 21985 000074EA A3[21AB0000]        <1> 	mov	[FAT_CurrentCluster], eax
 21986 000074EF 8B0D[BCAD0000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 21987 000074F5 66890B              <1> 	mov	[ebx], cx ; 16 bits !
 21988 000074F8 66FF05[2DAB0000]    <1> 	inc	word [FAT_ClusterCounter]
 21989 000074FF C605[25AB0000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 21990                              <1> 	
 21991 00007506 6683F802            <1> 	cmp	ax, 2
 21992 0000750A 720A                <1> 	jb	short return_uc_fat_stc
 21993 0000750C 3B05[31AB0000]      <1> 	cmp	eax, [LastCluster]
 21994 00007512 7702                <1> 	ja	short return_uc_fat_stc
 21995                              <1> 
 21996                              <1> loc_fat_buffer_updated:
 21997 00007514 F8                  <1> 	clc
 21998 00007515 C3                  <1> 	retn
 21999                              <1> 
 22000                              <1> return_uc_fat_stc:
 22001 00007516 31C0                <1> 	xor	eax, eax
 22002                              <1> 	;xor	edx, edx
 22003 00007518 F9                  <1> 	stc
 22004 00007519 C3                  <1> 	retn
 22005                              <1> 
 22006                              <1> loc_uc_save_fat_buffer:
 22007                              <1> 	; byte [FAT_BuffValidData] = 2 
 22008 0000751A E8F8010000          <1> 	call	save_fat_buffer
 22009 0000751F 0F82BB010000        <1>         jc      loc_fat_sectors_rw_error2
 22010                              <1> 	;mov	byte [FAT_BuffValidData], 1
 22011 00007525 A1[21AB0000]        <1> 	mov	eax, [FAT_CurrentCluster]
 22012                              <1> 	;mov	ecx, [ClusterValue]
 22013                              <1> 	;jmp	short loc_update_cluster_check_fat_buffer
 22014 0000752A E93AFFFFFF          <1>         jmp     loc_uc_reset_fat_buffer_validation
 22015                              <1> 
 22016                              <1> update_cluster_inv_data:
 22017                              <1> 	;mov	eax, 0Dh
 22018 0000752F B00D                <1> 	mov	al, 0Dh  ; Invalid Data
 22019 00007531 C3                  <1> 	retn 
 22020                              <1> 
 22021                              <1> update_fat12_cluster:
 22022                              <1> pass_uc_fat12_errc:
 22023                              <1> 	;sub	edx, edx
 22024 00007532 BB00040000          <1> 	mov	ebx, 400h ;1024
 22025 00007537 F7F3                <1> 	div	ebx
 22026                              <1> 	; EAX = Count of 3 FAT sectors
 22027                              <1> 	; DX = Cluster offset in FAT buffer
 22028 00007539 66B90300            <1> 	mov	cx, 3
 22029 0000753D 6689C3              <1> 	mov	bx, ax
 22030 00007540 6689C8              <1> 	mov	ax, cx ; 3
 22031 00007543 66F7E2              <1> 	mul	dx     ; Multiply by 3
 22032 00007546 66D1E8              <1> 	shr	ax, 1  ; Divide by 2
 22033 00007549 6693                <1> 	xchg	bx, ax
 22034                              <1> 	; EAX = Count of 3 FAT sectors
 22035                              <1> 	; EBX = Byte Offset in FAT buffer   
 22036 0000754B 66F7E1              <1> 	mul	cx  ; 3 * AX
 22037                              <1> 	; EAX = FAT Beginning Sector
 22038                              <1> 	; EDX = 0
 22039 0000754E 8A0D[25AB0000]      <1> 	mov	cl, [FAT_BuffValidData]
 22040                              <1> 	; TRDOS v1 has a FATal bug here ! 
 22041                              <1> 	; (it does not have 'cmp cl, 2' instruction here !
 22042                              <1> 	;  while 'jne' is existing !)
 22043 00007554 80F902              <1> 	cmp	cl, 2 ; 2 = dirty buffer (must be written to disk)
 22044 00007557 750A                <1> 	jne	short loc_uc_check_fat12_buff_sector_load
 22045                              <1> 
 22046                              <1> loc_uc_check_fat12_buff_sector_save:
 22047 00007559 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 22048 0000755F 75B9                <1>         jne     short loc_uc_save_fat_buffer
 22049 00007561 EB15                <1> 	jmp	short loc_update_fat12_cell
 22050                              <1> 
 22051                              <1> loc_uc_check_fat12_buff_sector_load:
 22052 00007563 80F901              <1> 	cmp	cl, 1 ; byte ptr [FAT_BuffValidData]
 22053 00007566 0F857B010000        <1>         jne     loc_uc_load_fat_sectors
 22054 0000756C 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 22055 00007572 0F856F010000        <1>         jne     loc_uc_load_fat_sectors
 22056                              <1> 
 22057                              <1> loc_update_fat12_cell:
 22058 00007578 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 22059 0000757E 668B0D[21AB0000]    <1> 	mov	cx, [FAT_CurrentCluster]
 22060 00007585 66D1E9              <1> 	shr	cx, 1
 22061 00007588 668B03              <1> 	mov	ax, [ebx]
 22062 0000758B 6689C2              <1> 	mov	dx, ax
 22063 0000758E 7349                <1> 	jnc	short uc_fat12_nc_even
 22064                              <1> 
 22065 00007590 6683E00F            <1> 	and	ax, 0Fh
 22066 00007594 8B0D[BCAD0000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 22067 0000759A 66C1E104            <1> 	shl	cx, 4
 22068 0000759E 6609C1              <1> 	or	cx, ax
 22069 000075A1 6689D0              <1> 	mov	ax, dx
 22070 000075A4 66890B              <1> 	mov	[ebx], cx  ; 16 bits !
 22071 000075A7 66C1E804            <1> 	shr	ax, 4
 22072                              <1> 
 22073                              <1> update_fat12_buffer:
 22074 000075AB 66FF05[2DAB0000]    <1> 	inc	word [FAT_ClusterCounter]
 22075 000075B2 A3[21AB0000]        <1> 	mov	[FAT_CurrentCluster], eax
 22076 000075B7 C605[25AB0000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 22077 000075BE 6683F802            <1> 	cmp	ax, 2
 22078 000075C2 0F824EFFFFFF        <1>         jb      return_uc_fat_stc
 22079 000075C8 3B05[31AB0000]      <1> 	cmp	eax, [LastCluster]
 22080 000075CE 0F8742FFFFFF        <1> 	ja	return_uc_fat_stc
 22081 000075D4 E93BFFFFFF          <1>         jmp     loc_fat_buffer_updated
 22082                              <1> 
 22083                              <1> uc_fat12_nc_even:
 22084 000075D9 662500F0            <1> 	and	ax, 0F000h
 22085 000075DD 8B0D[BCAD0000]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
 22086 000075E3 80E50F              <1> 	and	ch, 0Fh
 22087 000075E6 6609C1              <1> 	or	cx, ax
 22088 000075E9 6689D0              <1> 	mov	ax, dx
 22089 000075EC 66890B              <1> 	mov	[ebx], cx ; 16 bits !
 22090 000075EF 80E40F              <1> 	and	ah, 0Fh
 22091 000075F2 EBB7                <1> 	jmp	short update_fat12_buffer
 22092                              <1> 
 22093                              <1> update_fat32_cluster:
 22094 000075F4 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
 22095 000075F7 41                  <1> 	inc	ecx
 22096 000075F8 890D[31AB0000]      <1> 	mov	[LastCluster], ecx
 22097                              <1> 
 22098 000075FE 39C8                <1> 	cmp	eax, ecx
 22099 00007600 0F8710FFFFFF        <1>         ja      return_uc_fat_stc
 22100                              <1> 
 22101                              <1> pass_uc_fat32_errc:
 22102                              <1> 	;sub	edx, edx
 22103 00007606 BB80010000          <1> 	mov	ebx, 180h ;384
 22104 0000760B F7F3                <1> 	div	ebx
 22105                              <1> 	; EAX = Count of 3 FAT sectors
 22106                              <1> 	; DX = Cluster offset in FAT buffer
 22107 0000760D 89D3                <1> 	mov	ebx, edx
 22108 0000760F C1E302              <1> 	shl	ebx, 2 ; Multiply by 4
 22109 00007612 BA03000000          <1> 	mov	edx, 3	
 22110 00007617 F7E2                <1> 	mul	edx
 22111                              <1> 	; EBX = Cluster Offset in FAT buffer
 22112                              <1> 	; EAX = FAT Sector
 22113                              <1> 	; EDX = 0
 22114 00007619 8A0D[25AB0000]      <1> 	mov	cl, [FAT_BuffValidData]
 22115 0000761F 80F902              <1> 	cmp	cl, 2
 22116 00007622 750E                <1> 	jne	short loc_uc_check_fat32_buff_sector_load
 22117                              <1> 
 22118                              <1> loc_uc_check_fat32_buff_sector_save:
 22119 00007624 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 22120 0000762A 0F85EAFEFFFF        <1>         jne     loc_uc_save_fat_buffer
 22121 00007630 EB15                <1> 	jmp	short loc_update_fat32_cell
 22122                              <1> 
 22123                              <1> loc_uc_check_fat32_buff_sector_load:
 22124 00007632 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
 22125 00007635 0F85AC000000        <1>         jne     loc_uc_load_fat_sectors
 22126 0000763B 3B05[29AB0000]      <1> 	cmp	eax, [FAT_BuffSector]
 22127 00007641 0F85A0000000        <1>         jne     loc_uc_load_fat_sectors
 22128                              <1> 
 22129                              <1> loc_update_fat32_cell:
 22130                              <1> loc_update_fat32_buffer:
 22131 00007647 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
 22132 0000764D 8B03                <1> 	mov	eax, [ebx]
 22133 0000764F 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh ; 28 bit cluster value
 22134 00007654 8B15[21AB0000]      <1> 	mov	edx, [FAT_CurrentCluster]
 22135 0000765A A3[21AB0000]        <1> 	mov 	[FAT_CurrentCluster], eax
 22136 0000765F 8B0D[BCAD0000]      <1> 	mov	ecx, [ClusterValue]
 22137 00007665 890B                <1> 	mov	[ebx], ecx ; 29/02/2016 
 22138 00007667 FF05[2DAB0000]      <1> 	inc	dword [FAT_ClusterCounter]
 22139 0000766D C605[25AB0000]02    <1> 	mov	byte [FAT_BuffValidData], 2
 22140                              <1> 	
 22141                              <1>  	; 29/02/2016
 22142 00007674 21C9                <1> 	and	ecx, ecx
 22143 00007676 752D                <1> 	jnz	short loc_upd_fat32_c2
 22144                              <1> 	; new value of the cluster = 0 (free)
 22145 00007678 8B4E3A              <1> 	mov	ecx, [esi+LD_BPB+BPB_Reserved] ; 0FFFFFFFFh = invalid!
 22146 0000767B 41                  <1> 	inc	ecx ; 0FFFFFFFFh -> 0
 22147 0000767C 7444                <1> 	jz	short loc_upd_fat32_c3
 22148 0000767E 894E3A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], ecx ; free cluster count
 22149 00007681 8B4E3E              <1>         mov     ecx, [esi+LD_BPB+BPB_Reserved+4] ; 0FFFFFFFFh = invalid!
 22150 00007684 41                  <1> 	inc	ecx ; 0FFFFFFFFh -> 0
 22151 00007685 740C                <1> 	jz	short loc_upd_fat32_c0 ; set current cluster as ffc
 22152 00007687 31C9                <1> 	xor	ecx, ecx ; 0 again
 22153                              <1> 	; EDX contains cluster number of the new free cluster
 22154 00007689 3B563E              <1>         cmp     edx, [esi+LD_BPB+BPB_Reserved+4] ; first free cluster
 22155 0000768C 7305                <1> 	jnb	short loc_upd_fat32_c0
 22156                              <1> 	;
 22157 0000768E 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
 22158 00007691 EB07                <1> 	jmp	short loc_upd_fat32_c1
 22159                              <1> loc_upd_fat32_c0:
 22160                              <1> 	; EAX = next cluster value (0FFFFFFFh = 0 -> End of cluster chain)
 22161 00007693 3DFFFFFF0F          <1> 	cmp	eax, 0FFFFFFFh ; 28 bit value (of a FAT32 last cluster)
 22162 00007698 7528                <1> 	jne	short loc_upd_fat32_c3 ; Do not set FSINFO parameters
 22163                              <1> 				       ; if current cluster is not the last
 22164                              <1> 				       ; in it's cluster chain.
 22165                              <1> 				       ; (We need to keep update speed!)
 22166                              <1> loc_upd_fat32_c1:  
 22167                              <1> 	; Save/Record new FFC and FCC values on FSINFO sector of the disk
 22168 0000769A 50                  <1> 	push	eax ; save next cluster number
 22169 0000769B E871030000          <1> 	call	set_fat32_fsinfo_sector_parms ; save new FFC and FCC on disk
 22170 000076A0 58                  <1> 	pop	eax ; restore next cluster number
 22171 000076A1 29C9                <1> 	sub	ecx, ecx ; reset (new value of current cluster) to 0 again
 22172 000076A3 EB1D                <1> 	jmp	short loc_upd_fat32_c3
 22173                              <1> 
 22174                              <1> loc_upd_fat32_c2:
 22175                              <1> 	; new value of the cluster > 0
 22176 000076A5 09C0                <1> 	or	eax, eax
 22177 000076A7 7519                <1> 	jnz	short loc_upd_fat32_c3
 22178                              <1> 	; old value of the cluster = 0 (it was free cluster)
 22179 000076A9 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved] ; 0FFFFFFFFh = invalid!
 22180 000076AC 40                  <1> 	inc	eax ; 0FFFFFFFFh -> 0
 22181                              <1> 	;jz	short loc_upd_fat32_c3
 22182 000076AD 0F8463FEFFFF        <1>         jz      return_uc_fat_stc
 22183 000076B3 48                  <1> 	dec	eax ; restore free cluster count (after increase)
 22184 000076B4 48                  <1> 	dec	eax ; decrease
 22185 000076B5 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; free cluster count
 22186 000076B8 31C0                <1> 	xor	eax, eax ; 0 again
 22187                              <1> 	; EDX = cluster number
 22188 000076BA 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; first free cluster
 22189 000076BD 7503                <1> 	jne	short loc_upd_fat32_c3
 22190 000076BF FF463E              <1> 	inc	dword [esi+LD_BPB+BPB_Reserved+4] ; set to EDX+1, at least
 22191                              <1> 
 22192                              <1> loc_upd_fat32_c3:
 22193 000076C2 83F802              <1> 	cmp	eax, 2
 22194 000076C5 0F824BFEFFFF        <1>         jb      return_uc_fat_stc
 22195                              <1> 
 22196                              <1> pass_uc_fat32_c_zero_check_2:
 22197 000076CB 3B05[31AB0000]      <1> 	cmp	eax, [LastCluster]
 22198 000076D1 0F873FFEFFFF        <1>         ja      return_uc_fat_stc
 22199                              <1> 
 22200 000076D7 F8                  <1> 	clc
 22201 000076D8 C3                  <1> 	retn
 22202                              <1> 	
 22203                              <1>         ;jmp     loc_fat_buffer_updated
 22204                              <1> 
 22205                              <1> loc_fat_sectors_rw_error1:
 22206 000076D9 C605[25AB0000]00    <1> 	mov	byte [FAT_BuffValidData], 0
 22207                              <1> 
 22208                              <1> loc_fat_sectors_rw_error2:
 22209                              <1> 	;mov	eax, error code
 22210                              <1> 	;mov	edx, 0
 22211 000076E0 8B0D[BCAD0000]      <1> 	mov	ecx, [ClusterValue]
 22212 000076E6 C3                  <1> 	retn
 22213                              <1> 
 22214                              <1> loc_uc_load_fat_sectors:
 22215 000076E7 A3[29AB0000]        <1> 	mov	[FAT_BuffSector], eax
 22216                              <1> 
 22217                              <1> load_uc_fat_sectors_zero:
 22218 000076EC 034660              <1> 	add	eax, [esi+LD_FATBegin]
 22219 000076EF BB001C0900          <1> 	mov	ebx, FAT_Buffer
 22220 000076F4 B903000000          <1> 	mov	ecx, 3
 22221 000076F9 E8091A0000          <1> 	call	disk_read
 22222 000076FE 72D9                <1> 	jc	short loc_fat_sectors_rw_error1
 22223                              <1> 
 22224 00007700 C605[25AB0000]01    <1>         mov     byte [FAT_BuffValidData], 1
 22225 00007707 A1[21AB0000]        <1> 	mov 	eax, [FAT_CurrentCluster]
 22226 0000770C 8B0D[BCAD0000]      <1> 	mov	ecx, [ClusterValue]
 22227 00007712 E95FFDFFFF          <1>         jmp     loc_update_cluster_check_fat_type
 22228                              <1> 
 22229                              <1> save_fat_buffer:
 22230                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 22231                              <1> 	; 11/08/2011
 22232                              <1> 	; 09/02/2005 
 22233                              <1> 	; INPUT ->
 22234                              <1> 	;	None
 22235                              <1> 	; OUTPUT ->
 22236                              <1> 	;	cf = 0 -> OK.
 22237                              <1> 	;	cf = 1 -> error code in AL (EAX)
 22238                              <1> 	;
 22239                              <1> 	; (EAX, EDX, ECX will be modified)
 22240                              <1> 	; EBX = FAT_Buffer address
 22241                              <1> 
 22242                              <1> 	;cmp	byte [FAT_BuffValidData], 2 
 22243                              <1> 	;je	short loc_save_fat_buff
 22244                              <1> 
 22245                              <1> ;loc_save_fat_buffer_retn:
 22246                              <1> 	;xor	eax, eax
 22247                              <1> 	;retn
 22248                              <1> 
 22249                              <1> loc_save_fat_buff:
 22250 00007717 31D2                <1> 	xor	edx, edx
 22251 00007719 8A35[26AB0000]      <1> 	mov	dh, [FAT_BuffDrvName]
 22252 0000771F 80FE41              <1> 	cmp	dh, 'A'
 22253 00007722 7235                <1> 	jb	short loc_save_fat_buffer_inv_data_retn
 22254 00007724 80EE41              <1> 	sub	dh, 'A'
 22255 00007727 56                  <1> 	push	esi ; *
 22256 00007728 BE00010900          <1>         mov     esi, Logical_DOSDisks
 22257 0000772D 01D6                <1> 	add	esi, edx
 22258                              <1> 	
 22259 0000772F 8A5603              <1> 	mov	dl, [esi+LD_FATType]
 22260 00007732 20D2                <1> 	and	dl, dl
 22261 00007734 7422                <1> 	jz	short loc_save_fat_buffer_inv_data_pop_retn 
 22262                              <1> 
 22263 00007736 A1[29AB0000]        <1> 	mov	eax, [FAT_BuffSector]
 22264 0000773B 80FA02              <1> 	cmp	dl, 2
 22265 0000773E 7711                <1> 	ja	short loc_save_fat32_buff
 22266                              <1> 
 22267                              <1> loc_save_fat_12_16_buff:
 22268 00007740 668B15[29AB0000]    <1> 	mov	dx, [FAT_BuffSector]
 22269 00007747 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+FATSecs] 
 22270 0000774B 29C1                <1> 	sub	ecx, eax
 22271                              <1> 	; TRDOS v1 has a bug here... ('pop esi' was forgotten!)
 22272                              <1> 	;jna	short loc_save_fat_buffer_inv_data_retn ; wrong addr!
 22273 0000774D 7609                <1> 	jna	short loc_save_fat_buffer_inv_data_pop_retn ; correct addr.
 22274 0000774F EB15                <1> 	jmp	short loc_save_fat_buffer_check_rs3
 22275                              <1> 
 22276                              <1> loc_save_fat32_buff:
 22277 00007751 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+FAT32_FAT_Size]
 22278 00007754 29C1                <1> 	sub	ecx, eax
 22279 00007756 770E                <1> 	ja	short loc_save_fat_buffer_check_rs3
 22280                              <1> 
 22281                              <1> loc_save_fat_buffer_inv_data_pop_retn:
 22282 00007758 5E                  <1> 	pop	esi ; *
 22283                              <1> loc_save_fat_buffer_inv_data_retn:
 22284 00007759 B80D000000          <1> 	mov	eax, 0Dh ; Invalid DATA
 22285 0000775E C3                  <1> 	retn
 22286                              <1> 
 22287                              <1> loc_save_fat_buff_remain_sectors_3:
 22288 0000775F B903000000          <1> 	mov	ecx, 3
 22289 00007764 EB05                <1> 	jmp	short loc_save_fat_buff_continue
 22290                              <1> 
 22291                              <1> loc_save_fat_buffer_check_rs3:
 22292 00007766 83F903              <1> 	cmp	ecx, 3
 22293 00007769 77F4                <1> 	ja	short loc_save_fat_buff_remain_sectors_3
 22294                              <1> 
 22295                              <1> loc_save_fat_buff_continue:
 22296 0000776B BB001C0900          <1> 	mov	ebx, FAT_Buffer
 22297 00007770 034660              <1> 	add	eax, [esi+LD_FATBegin]
 22298 00007773 51                  <1> 	push	ecx
 22299 00007774 E87F190000          <1> 	call	disk_write
 22300 00007779 59                  <1> 	pop	ecx
 22301 0000777A 722B                <1> 	jc	short loc_save_FAT_buff_write_err
 22302                              <1> 	
 22303 0000777C 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 22304 00007780 7605                <1> 	jna	short loc_calc_2nd_fat12_16_addr
 22305                              <1> 
 22306                              <1> loc_calc_2nd_fat32_addr:
 22307 00007782 8B462A              <1> 	mov	eax, [esi+LD_BPB+FAT32_FAT_Size]
 22308 00007785 EB04                <1> 	jmp	short loc_calc_2nd_fat_addr
 22309                              <1> 
 22310                              <1> loc_calc_2nd_fat12_16_addr:
 22311 00007787 0FB7461C            <1> 	movzx	eax, word [esi+LD_BPB+FATSecs]
 22312                              <1> 
 22313                              <1> loc_calc_2nd_fat_addr:
 22314 0000778B 034660              <1> 	add	eax, [esi+LD_FATBegin]
 22315 0000778E 0305[29AB0000]      <1> 	add	eax, [FAT_BuffSector]
 22316 00007794 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 22317                              <1> 	; ecx = 1 to 3
 22318 00007799 E85A190000          <1> 	call	disk_write
 22319 0000779E 7207                <1> 	jc	short loc_save_FAT_buff_write_err
 22320                              <1>  	; Valid  buffer (1 = valid but do not save)
 22321 000077A0 C605[25AB0000]01    <1> 	mov	byte [FAT_BuffValidData], 1
 22322                              <1> 
 22323                              <1> loc_save_FAT_buff_write_err:
 22324 000077A7 5E                  <1> 	pop	esi ; *
 22325 000077A8 BB001C0900          <1> 	mov	ebx, FAT_Buffer
 22326 000077AD C3                  <1> 	retn
 22327                              <1> 
 22328                              <1> calculate_fat_freespace:
 22329                              <1> 	; 29/02/2016
 22330                              <1> 	; 22/02/2016 (TRDOS 386 =  TRDOS v2.0)
 22331                              <1> 	; 30/04/2011
 22332                              <1> 	; 03/04/2010
 22333                              <1> 	; 2005
 22334                              <1> 	; INPUT ->
 22335                              <1> 	;	EAX = Cluster count to be added or subtracted
 22336                              <1> 	; 	If BH = FFh, ESI = TR-DOS Logical Drive Description Table
 22337                              <1> 	; 	If BH < FFh, BH = TR-DOS Logical Drive Number
 22338                              <1> 	; 	BL: 
 22339                              <1> 	;	0 = Calculate, 1 = Add, 2 = Subtract, 3 = Get (Not Set/Calc)
 22340                              <1> 	; OUTPUT ->
 22341                              <1> 	;	EAX = Free Space in sectors
 22342                              <1> 	;	ESI = Logical Dos Drive Description Table address
 22343                              <1> 	;	BH = Logical Dos Drive Number (same with input value of BH)
 22344                              <1> 	;	BL = Type of operation (same with input value of BL)
 22345                              <1> 	;	ECX = 0 -> valid
 22346                              <1> 	;	ECX > 0 -> error or invalid
 22347                              <1> 	;	If EAX = FFFFFFFFh, it is 're-calculation needed'
 22348                              <1> 	;			          sign due to r/w error   
 22349                              <1> 
 22350 000077AE 66891D[C2AD0000]    <1> 	mov	[CFS_OPType], bx
 22351 000077B5 A3[C4AD0000]        <1> 	mov	[CFS_CC], eax
 22352                              <1> 	
 22353 000077BA 80FFFF              <1> 	cmp	bh, 0FFh
 22354 000077BD 740B                <1> 	je	short pass_calculate_freespace_get_drive_dt_offset
 22355                              <1> 
 22356                              <1> loc_calculate_freespace_get_drive_dt_offset:     
 22357 000077BF 31C0                <1> 	xor	eax, eax
 22358 000077C1 88FC                <1>         mov     ah, bh
 22359 000077C3 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 22360 000077C8 01C6                <1>         add     esi, eax
 22361                              <1> 
 22362                              <1> pass_calculate_freespace_get_drive_dt_offset:
 22363 000077CA 08DB                <1> 	or	bl, bl
 22364 000077CC 7430                <1> 	jz	short loc_reset_fcc
 22365                              <1> 	
 22366                              <1> loc_get_free_sectors:
 22367 000077CE 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
 22368 000077D1 31C9                <1> 	xor	ecx, ecx
 22369 000077D3 49                  <1> 	dec	ecx ; 0FFFFFFFFh
 22370 000077D4 39C8                <1> 	cmp	eax, ecx ; 29/02/2016
 22371 000077D6 7406                <1> 	je	short loc_get_free_sectors_retn ; recalculation is needed!
 22372                              <1> 
 22373                              <1> loc_get_free_sectors_check_optype:
 22374 000077D8 80FB03              <1> 	cmp	bl, 3
 22375 000077DB 7202                <1> 	jb	short loc_set_fcc
 22376 000077DD 41                  <1> 	inc	ecx ; 0
 22377                              <1> loc_get_free_sectors_retn:
 22378 000077DE C3                  <1> 	retn	
 22379                              <1> 
 22380                              <1> loc_set_fcc:
 22381 000077DF 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 22382 000077E3 0F87D5000000        <1>         ja      loc_update_FAT32_fs_info_fcc
 22383                              <1> 
 22384 000077E9 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
 22385 000077EC 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
 22386 000077F0 29D2                <1> 	sub	edx, edx
 22387 000077F2 F7F1                <1> 	div	ecx
 22388                              <1> 	;or	dx, dx 
 22389                              <1> 	;	; DX -> Remain sectors < SecPerClust
 22390                              <1> 	;	; DX > 0 -> invalid free sector count
 22391                              <1> 	;jnz	short loc_reset_fcc 
 22392                              <1> 
 22393                              <1> ;pass_set_fcc_div32:
 22394 000077F4 A3[43AB0000]        <1> 	mov	[FreeClusterCount], eax
 22395 000077F9 E98B000000          <1>         jmp     loc_set_free_sectors_FAT12_FAT16
 22396                              <1> 
 22397                              <1> loc_reset_fcc:
 22398 000077FE 31C0                <1> 	xor	eax, eax
 22399 00007800 A3[43AB0000]        <1> 	mov	[FreeClusterCount], eax ; 0
 22400 00007805 8B5678              <1> 	mov	edx, [esi+LD_Clusters]
 22401 00007808 42                  <1> 	inc	edx
 22402 00007809 8915[31AB0000]      <1> 	mov	[LastCluster], edx
 22403                              <1> 
 22404 0000780F 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 22405 00007813 764A                <1> 	jna	short loc_count_free_fat_clusters_0  
 22406                              <1> 
 22407 00007815 48                  <1> 	dec	eax ; FFFFFFFFh
 22408 00007816 A3[CCAD0000]        <1> 	mov	[CFS_FAT32FC], eax
 22409                              <1> 
 22410                              <1> 	; 29/02/2016
 22411 0000781B 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; reset
 22412 0000781E 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; reset
 22413                              <1> 	
 22414 00007821 B802000000          <1> 	mov 	eax, 2
 22415                              <1> 
 22416                              <1> loc_count_fc_next_cluster_0:
 22417 00007826 50                  <1> 	push	eax
 22418 00007827 E806F9FFFF          <1> 	call	get_next_cluster
 22419 0000782C 7313                <1> 	jnc	short loc_check_fat32_ff_cluster
 22420 0000782E 09C0                <1> 	or	eax, eax
 22421 00007830 7421                <1> 	jz	short pass_inc_cfs_fcc_0
 22422                              <1> 
 22423                              <1> loc_put_fcc_unknown_sign:
 22424 00007832 58                  <1> 	pop	eax
 22425                              <1> 	; "Free count is Unknown" sign
 22426                              <1> 	;mov	dword [FreeClusterCount], 0FFFFFFFFh
 22427                              <1> 
 22428                              <1> 	; 29/02/2016
 22429                              <1> 	; Save Free Cluster Count value in FAT32 'BPB_Reserved' area
 22430                              <1> 	;mov	[esi+LD_BPB+BPB_Reserved], 0FFFFFFFFh ; unknown!
 22431 00007833 8B15[CCAD0000]      <1> 	mov	edx, [CFS_FAT32FC] ; First Free Cluster
 22432                              <1> 	; Save First Free Cluster value in FAT32 'BPB_Reserved+4' area
 22433 00007839 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
 22434                              <1> 	
 22435 0000783C E984000000          <1>         jmp     loc_put_fcc_invalid_sign
 22436                              <1> 
 22437                              <1> loc_check_fat32_ff_cluster:
 22438 00007841 09C0                <1> 	or	eax, eax
 22439 00007843 750E                <1> 	jnz	short pass_inc_cfs_fcc_0
 22440 00007845 58                  <1> 	pop	eax
 22441 00007846 A3[CCAD0000]        <1> 	mov	[CFS_FAT32FC], eax
 22442                              <1> 	;mov	dword [FreeClusterCount], 1
 22443 0000784B FF05[43AB0000]      <1> 	inc	dword [FreeClusterCount]
 22444 00007851 EB27                <1> 	jmp	short pass_inc_cfs_fcc_1
 22445                              <1> 
 22446                              <1> pass_inc_cfs_fcc_0:
 22447 00007853 58                  <1> 	pop	eax
 22448                              <1> 
 22449                              <1> pass_inc_cfs_fcc_0c:
 22450 00007854 40                  <1> 	inc	eax ; add eax, 1
 22451 00007855 3B05[31AB0000]      <1> 	cmp	eax, [LastCluster]
 22452 0000785B 76C9                <1> 	jna 	short loc_count_fc_next_cluster_0
 22453 0000785D EB5F                <1> 	jmp	short loc_update_FAT32_fs_info_fcc
 22454                              <1> 
 22455                              <1> loc_count_free_fat_clusters_0:
 22456                              <1> 	;mov	eax, 2
 22457 0000785F B002                <1> 	mov	al, 2
 22458                              <1> 
 22459                              <1> loc_count_fc_next_cluster:
 22460 00007861 50                  <1> 	push	eax
 22461 00007862 E8CBF8FFFF          <1> 	call	get_next_cluster
 22462 00007867 720C                <1> 	jc	short loc_count_fcc_stc
 22463                              <1> 
 22464                              <1> loc_count_free_clusters_1:
 22465 00007869 21C0                <1> 	and	eax, eax
 22466 0000786B 750C                <1> 	jnz	short pass_inc_cfs_fcc
 22467                              <1> 
 22468 0000786D FF05[43AB0000]      <1> 	inc	dword [FreeClusterCount]
 22469 00007873 EB04                <1> 	jmp	short pass_inc_cfs_fcc
 22470                              <1> 
 22471                              <1> loc_count_fcc_stc:
 22472 00007875 09C0                <1> 	or	eax, eax
 22473 00007877 75B9                <1> 	jnz	short loc_put_fcc_unknown_sign ; 29/02/2016
 22474                              <1> 
 22475                              <1> pass_inc_cfs_fcc:
 22476 00007879 58                  <1> 	pop	eax
 22477                              <1> 
 22478                              <1> pass_inc_cfs_fcc_1:
 22479 0000787A 40                  <1> 	inc	eax ; add eax, 1
 22480 0000787B 3B05[31AB0000]      <1> 	cmp	eax, [LastCluster]
 22481 00007881 76DE                <1> 	jna	short loc_count_fc_next_cluster
 22482                              <1> 
 22483                              <1> loc_set_free_sectors:
 22484 00007883 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
 22485 00007887 7735                <1> 	ja	short loc_update_FAT32_fs_info_fcc
 22486                              <1> 
 22487                              <1> loc_set_free_sectors_FAT12_FAT16:
 22488 00007889 803D[C2AD0000]00    <1> 	cmp	byte [CFS_OPType], 0
 22489 00007890 761C                <1> 	jna	short pass_FAT_add_sub_fcc
 22490 00007892 A1[C4AD0000]        <1> 	mov	eax, [CFS_CC]
 22491 00007897 803D[C2AD0000]01    <1> 	cmp	byte [CFS_OPType], 1
 22492 0000789E 7708                <1> 	ja	short pass_FAT_add_fcc
 22493 000078A0 0105[43AB0000]      <1> 	add 	[FreeClusterCount], eax
 22494 000078A6 EB06                <1> 	jmp	short pass_FAT_add_sub_fcc
 22495                              <1> 
 22496                              <1> pass_FAT_add_fcc:
 22497 000078A8 2905[43AB0000]      <1> 	sub	[FreeClusterCount], eax
 22498                              <1> 
 22499                              <1> pass_FAT_add_sub_fcc:
 22500 000078AE 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
 22501 000078B2 8B15[43AB0000]      <1> 	mov	edx, [FreeClusterCount]
 22502 000078B8 F7E2                <1> 	mul	edx
 22503                              <1> 
 22504 000078BA 31C9                <1> 	xor	ecx, ecx 
 22505 000078BC EB0C                <1> 	jmp	short loc_cfs_retn_params
 22506                              <1> 
 22507                              <1> loc_update_FAT32_fs_info_fcc:
 22508                              <1> 	; 29/02/2016
 22509 000078BE E877010000          <1> 	call	get_fat32_fsinfo_sector_parms
 22510 000078C3 7310                <1> 	jnc	short loc_check_fcc_FSINFO_op
 22511                              <1> 
 22512                              <1> loc_put_fcc_invalid_sign:
 22513 000078C5 29C0                <1>        	sub	eax, eax ; 0
 22514 000078C7 48                  <1> 	dec	eax ; FFFFFFFFh
 22515                              <1> loc_fat32_ffc_recalc_needed:
 22516 000078C8 89C1                <1> 	mov	ecx, eax
 22517                              <1> 
 22518                              <1> loc_cfs_retn_params:
 22519 000078CA 894674              <1> 	mov 	[esi+LD_FreeSectors], eax
 22520 000078CD 0FB71D[C2AD0000]    <1> 	movzx	ebx, word [CFS_OPType]
 22521 000078D4 C3                  <1> 	retn
 22522                              <1> 
 22523                              <1> loc_check_fcc_FSINFO_op:
 22524                              <1> 	; 29/02/2016
 22525                              <1> 	; EAX = Free cluster count (before this update) ; value from disk
 22526                              <1> 	; EDX = First Free Cluster (before this update) ; value from disk
 22527 000078D5 803D[C2AD0000]01    <1> 	cmp	byte [CFS_OPType], 1
 22528 000078DC 722A                <1> 	jb	short loc_cfs_FAT32_get_rcalc_parms ; 0 = recalculated
 22529 000078DE 7406                <1> 	je	short loc_check_fcc_FSINFO_op1 ; 1 = add
 22530                              <1> loc_check_fcc_FSINFO_op2: ; subtract
 22531 000078E0 F71D[C4AD0000]      <1> 	neg	dword [CFS_CC] ; prepare to subtract ; 2 = sub (add negative)
 22532                              <1> loc_check_fcc_FSINFO_op1:
 22533 000078E6 0305[C4AD0000]      <1>         add     eax, [CFS_CC] ; free cluster count on disk + current count
 22534 000078EC 3B463A              <1> 	cmp	eax, [esi+LD_BPB+BPB_Reserved] ; value from 'update_cluster' 
 22535 000078EF 7505                <1> 	jne	short loc_cfs_FSINFO_parms_rcns
 22536                              <1> 
 22537 000078F1 8B563E              <1> 	mov	edx, [esi+LD_BPB+BPB_Reserved+4] ; value from 'update_cluster'
 22538 000078F4 EB1D                <1> 	jmp	short loc_cfs_write_FSINFO_sector
 22539                              <1> 
 22540                              <1> loc_cfs_FSINFO_parms_rcns:
 22541 000078F6 29D2                <1> 	sub	edx, edx ; 0
 22542 000078F8 4A                  <1> 	dec	edx ; 0FFFFFFFFh ; recalculation is needed sign	!
 22543 000078F9 89D0                <1> 	mov	eax, edx
 22544 000078FB 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count (reset)
 22545 000078FE 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free cluster (reset)	
 22546 00007901 A3[43AB0000]        <1> 	mov	[FreeClusterCount], eax
 22547 00007906 EB0B                <1> 	jmp	short loc_cfs_write_FSINFO_sector 	
 22548                              <1> 
 22549                              <1> loc_cfs_FAT32_get_rcalc_parms:
 22550 00007908 8B15[CCAD0000]      <1> 	mov	edx, [CFS_FAT32FC]
 22551 0000790E A1[43AB0000]        <1> 	mov	eax, [FreeClusterCount]
 22552                              <1> 
 22553                              <1> loc_cfs_write_FSINFO_sector:
 22554                              <1> 	; 29/02/2016
 22555 00007913 8983E8010000        <1> 	mov	[ebx+488], eax ; Free cluster count
 22556 00007919 8993E8010000        <1> 	mov	[ebx+488], edx ; First (Next) Free Cluster
 22557 0000791F A1[C8AD0000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
 22558 00007924 BB[21A90000]        <1>         mov     ebx, DOSBootSectorBuff
 22559 00007929 B901000000          <1> 	mov	ecx, 1
 22560 0000792E E8C5170000          <1> 	call	disk_write
 22561 00007933 7290                <1>         jc      loc_put_fcc_invalid_sign
 22562                              <1> 
 22563                              <1> loc_set_FAT32_free_sectors:
 22564                              <1> 	; 29/02/2016
 22565 00007935 A1[43AB0000]        <1> 	mov	eax, [FreeClusterCount]
 22566 0000793A 89C1                <1> 	mov	ecx, eax
 22567 0000793C 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; Invalid !
 22568 0000793F 7489                <1> 	je	short loc_cfs_retn_params
 22569                              <1> 	;
 22570 00007941 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
 22571 00007945 F7E1                <1> 	mul	ecx
 22572                              <1> 	; 29/02/2016
 22573 00007947 31C9                <1> 	xor	ecx, ecx ; 0
 22574 00007949 09D2                <1> 	or	edx, edx ; 0 ?
 22575 0000794B 0F8574FFFFFF        <1>         jnz     loc_put_fcc_invalid_sign
 22576 00007951 394670              <1> 	cmp	[esi+LD_TotalSectors], eax ; Volume size in sectors
 22577 00007954 0F866BFFFFFF        <1>         jna     loc_put_fcc_invalid_sign
 22578                              <1> 	;
 22579 0000795A 803D[C2AD0000]01    <1> 	cmp	byte [CFS_OPType], 1
 22580 00007961 7312                <1> 	jnb	short loc_set_FAT32_free_sectors_ok
 22581                              <1>  
 22582                              <1> 	; CFS_OptType = 0 -> calculation (by using 'get_next_cluster')
 22583                              <1> 	; Recalculated values must be saved for 'update_cluster' procedure.
 22584 00007963 8B15[43AB0000]      <1> 	mov	edx, [FreeClusterCount]
 22585 00007969 89563A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], edx ; Free cluster count
 22586 0000796C 8B15[CCAD0000]      <1> 	mov	edx, [CFS_FAT32FC]
 22587 00007972 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free Cluster
 22588                              <1> 
 22589                              <1> loc_set_FAT32_free_sectors_ok:
 22590 00007975 31D2                <1> 	xor	edx, edx ; 0
 22591 00007977 E94EFFFFFF          <1>         jmp     loc_cfs_retn_params 
 22592                              <1> 	;
 22593                              <1> 
 22594                              <1> get_last_cluster:
 22595                              <1> 	; 27/02/2016 (TRDOS 386 =  TRDOS v2.0)
 22596                              <1> 	; 12/06/2010 (DRV_FAT.ASM, 'proc_get_last_custer')
 22597                              <1> 	; 06/06/2010
 22598                              <1> 	; INPUT ->
 22599                              <1> 	;	EAX = First Cluster Number
 22600                              <1> 	; 	ESI = Logical Dos Drive Parameters Table
 22601                              <1> 	; OUTPUT ->
 22602                              <1> 	;	cf = 0 -> No Error, EAX is valid
 22603                              <1> 	;	cf = 1 -> EAX > 0 -> Error
 22604                              <1> 	;	EAX = Last Cluster Number
 22605                              <1> 	;       ECX = Previous Cluster -just before the last cluster-
 22606                              <1> 	;
 22607                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
 22608                              <1> 
 22609 0000797C 89C1                <1> 	mov	ecx, eax	
 22610                              <1> 
 22611                              <1> loc_glc_get_next_cluster_1:
 22612 0000797E 890D[D0AD0000]      <1> 	mov	[glc_prevcluster], ecx
 22613                              <1> 
 22614                              <1> loc_glc_get_next_cluster_2:
 22615 00007984 E8A9F7FFFF          <1> 	call	get_next_cluster
 22616                              <1> 	; ecx = current/previous cluster 
 22617                              <1> 	; eax = next/last cluster
 22618 00007989 73F3                <1> 	jnc	short loc_glc_get_next_cluster_1
 22619                              <1> 
 22620 0000798B 09C0                <1> 	or	eax, eax
 22621 0000798D 7509                <1> 	jnz	short loc_glc_stc_retn
 22622                              <1> 
 22623                              <1> 	; ecx = previous cluster
 22624 0000798F 89C8                <1>         mov	eax, ecx
 22625                              <1> 
 22626                              <1> 	; previous cluster becomes last cluster (ecx -> eax)
 22627                              <1> 	; previous of previous cluster becomes previous cluster (ecx)
 22628                              <1> 
 22629                              <1> loc_glc_prev_cluster_retn:
 22630 00007991 8B0D[D0AD0000]      <1> 	mov	ecx, [glc_prevcluster] 
 22631 00007997 C3                  <1> 	retn
 22632                              <1> 
 22633                              <1> loc_glc_stc_retn:
 22634 00007998 F5                  <1> 	cmc	;stc
 22635 00007999 EBF6                <1>         jmp	short loc_glc_prev_cluster_retn
 22636                              <1> 
 22637                              <1> truncate_cluster_chain:
 22638                              <1> 	; 28/02/2016 (TRDOS 386 =  TRDOS v2.0)
 22639                              <1> 	; 22/01/2011 (DRV_FAT.ASM, 'proc_truncate_cluster_chain')
 22640                              <1> 	; 11/09/2010
 22641                              <1> 	; INPUT ->
 22642                              <1> 	;	ESI = Logical dos drive description table address
 22643                              <1> 	;	EAX = First cluster to be truncated/unlinked 
 22644                              <1> 	; OUTPUT ->
 22645                              <1> 	;	ESI = Logical dos drive description table address
 22646                              <1> 	; 	ECX = Count of truncated/removed clusters
 22647                              <1> 	; 	CF = 0 -> EAX = Free sectors
 22648                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
 22649                              <1> 
 22650                              <1> 	; NOTE: This procedure does not update lm date&time ! 
 22651                              <1> 
 22652                              <1> loc_truncate_cc:	
 22653 0000799B 31C9                <1> 	xor	ecx, ecx ; mov ecx, 0
 22654                              <1> 	;mov	byte [FAT_BuffValidData], 0
 22655 0000799D 890D[2DAB0000]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0
 22656                              <1> 
 22657                              <1> loc_ttc_unlink_clusters:
 22658 000079A3 E89FFAFFFF          <1> 	call	update_cluster
 22659                              <1> 	; EAX = Next Cluster
 22660                              <1> 	; ECX = Cluster Value
 22661                              <1> 	; Note:
 22662                              <1> 	; Returns count of unlinked clusters in
 22663                              <1> 	; dword ptr FAT_ClusterCounter
 22664 000079A8 73F9                <1> 	jnc short loc_ttc_unlink_clusters
 22665                              <1> 
 22666                              <1> pass_tcc_unlink_clusters:
 22667 000079AA A2[D7AD0000]        <1> 	mov	byte [TCC_FATErr], al
 22668 000079AF 803D[25AB0000]02    <1> 	cmp	byte [FAT_BuffValidData], 2
 22669 000079B6 750C                <1> 	jne	short loc_truncate_cc_calculate_FAT_freespace
 22670 000079B8 E85AFDFFFF          <1> 	call	save_fat_buffer
 22671 000079BD 7305                <1> 	jnc	short loc_truncate_cc_calculate_FAT_freespace
 22672 000079BF A2[D7AD0000]        <1> 	mov	byte [TCC_FATErr], al ; Error
 22673                              <1> 	;mov	byte [FAT_BuffValidData], 0
 22674                              <1> 
 22675                              <1> loc_truncate_cc_calculate_FAT_freespace:
 22676 000079C4 C605[C1AD0000]00    <1> 	mov	byte	[CFS_error], 0
 22677                              <1> 
 22678                              <1> loc_tcc_calculate_FAT_freespace_next:
 22679 000079CB A1[2DAB0000]        <1> 	mov	eax, [FAT_ClusterCounter]
 22680 000079D0 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI = Dos drv desc. table
 22681                              <1> 			   ; BL = 1 -> add cluster
 22682 000079D4 E8D5FDFFFF          <1> 	call	calculate_fat_freespace
 22683 000079D9 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
 22684 000079DB 741C                <1> 	jz	short pass_truncate_cc_recalc_FAT_freespace
 22685 000079DD 803D[C1AD0000]00    <1> 	cmp	byte [CFS_error], 0
 22686 000079E4 7713                <1> 	ja	short loc_tcc_calculate_FAT_freespace_err
 22687                              <1> 
 22688                              <1> loc_tcc_recalculate_FAT_freespace:
 22689 000079E6 FE05[C1AD0000]      <1> 	inc	byte [CFS_error]
 22690 000079EC 66BB00FF            <1> 	mov	bx, 0FF00h
 22691 000079F0 E8B9FDFFFF          <1> 	call	calculate_fat_freespace
 22692 000079F5 21C9                <1> 	and	ecx, ecx
 22693 000079F7 74D2                <1> 	jz	short loc_tcc_calculate_FAT_freespace_next
 22694                              <1>               
 22695                              <1> loc_tcc_calculate_FAT_freespace_err:
 22696                              <1> pass_truncate_cc_recalc_FAT_freespace:
 22697 000079F9 8B0D[2DAB0000]      <1> 	mov	ecx, [FAT_ClusterCounter]
 22698                              <1> 
 22699 000079FF 803D[D7AD0000]00    <1> 	cmp	byte [TCC_FATErr], 0
 22700 00007A06 7608                <1> 	jna	short loc_tcc_unlink_clusters_retn
 22701                              <1> 
 22702                              <1> loc_tcc_unlink_clusters_error:
 22703 00007A08 0FB605[D7AD0000]    <1> 	movzx	eax, byte [TCC_FATErr]
 22704 00007A0F F9                  <1> 	stc
 22705                              <1> loc_tcc_unlink_clusters_retn:
 22706 00007A10 C3                  <1> 	retn
 22707                              <1> 
 22708                              <1> set_fat32_fsinfo_sector_parms:
 22709                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
 22710                              <1> 	; INPUT ->
 22711                              <1> 	;	ESI = Logical dos drive description table address
 22712                              <1> 	;	[esi+LD_BPB+BPB_Reserved] = Free Cluster Count
 22713                              <1> 	;	[esi+LD_BPB+BPB_Reserved+4] = First free Cluster 
 22714                              <1> 	; OUTPUT ->
 22715                              <1> 	;	ESI = Logical dos drive description table address
 22716                              <1> 	; 	CF = 0 -> OK..
 22717                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
 22718                              <1> 	;
 22719                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 22720                              <1> 
 22721 00007A11 E824000000          <1> 	call	get_fat32_fsinfo_sector_parms
 22722 00007A16 7221                <1> 	jc	short update_fat32_fsinfo_sector_retn
 22723                              <1> 
 22724 00007A18 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved] ; Free Cluster Count
 22725 00007A1B 8B563E              <1> 	mov	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free Cluster	
 22726                              <1> 
 22727                              <1>         ;mov	ebx, DOSBootSectorBuff
 22728 00007A1E 8983E8010000        <1> 	mov	[ebx+488], eax
 22729 00007A24 8993EC010000        <1> 	mov	[ebx+492], edx	
 22730                              <1> 
 22731 00007A2A A1[C8AD0000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
 22732 00007A2F B901000000          <1> 	mov	ecx, 1
 22733 00007A34 E8BF160000          <1> 	call	disk_write
 22734                              <1>        ;jc      short update_fat32_fsinfo_sector_retn
 22735                              <1> 
 22736                              <1> update_fat32_fsinfo_sector_retn:
 22737 00007A39 C3                  <1> 	retn
 22738                              <1> 
 22739                              <1> get_fat32_fsinfo_sector_parms:
 22740                              <1> 	; 29/02/2016 (TRDOS 386 =  TRDOS v2.0)
 22741                              <1> 	; INPUT ->
 22742                              <1> 	;	ESI = Logical dos drive description table address
 22743                              <1> 	; OUTPUT ->
 22744                              <1> 	;	ESI = Logical dos drive description table address
 22745                              <1> 	;	EBX = FSINFO sector buffer address (DOSBootSectorBuff)	
 22746                              <1> 	;	CF = 0 -> OK..
 22747                              <1> 	;	   EAX = Free cluster count
 22748                              <1> 	;	   EDX = First Free Cluster 	
 22749                              <1> 	;	CF = 1 -> Error code in AL (EAX)
 22750                              <1> 	;	[CFS_FAT32FSINFOSEC] = FAT32 FSINFO sector address
 22751                              <1>         ;
 22752                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 22753                              <1> 
 22754 00007A3A 0FB74636            <1> 	movzx	eax, word [esi+LD_BPB+FAT32_FSInfoSec]
 22755 00007A3E 03466C              <1> 	add	eax, [esi+LD_StartSector]
 22756 00007A41 A3[C8AD0000]        <1> 	mov	[CFS_FAT32FSINFOSEC], eax
 22757                              <1> 	
 22758 00007A46 BB[21A90000]        <1>         mov     ebx, DOSBootSectorBuff
 22759 00007A4B B901000000          <1> 	mov	ecx, 1
 22760 00007A50 E8B2160000          <1> 	call	disk_read
 22761 00007A55 7231                <1> 	jc	short loc_read_FAT32_fsinfo_sec_err
 22762                              <1> 
 22763 00007A57 BB[21A90000]        <1> 	mov	ebx, DOSBootSectorBuff
 22764                              <1> 
 22765 00007A5C 813B52526141        <1> 	cmp	dword [ebx], 41615252h
 22766 00007A62 751E                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
 22767                              <1> 
 22768 00007A64 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
 22769 00007A6D 61                  <1>
 22770 00007A6E 7512                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
 22771                              <1> 
 22772 00007A70 A1[C8AD0000]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
 22773 00007A75 8B8BE8010000        <1> 	mov	ecx, [ebx+488] ; free cluster count
 22774 00007A7B 8B93EC010000        <1> 	mov	edx, [ebx+492] ; first (next) free cluster	
 22775                              <1> 
 22776 00007A81 C3                  <1> 	retn
 22777                              <1> 
 22778                              <1> loc_read_FAT32_fsinfo_sec_stc:
 22779 00007A82 B80B000000          <1> 	mov	 eax, 0Bh ; Invalid format!
 22780 00007A87 F9                  <1> 	stc
 22781                              <1> loc_read_FAT32_fsinfo_sec_err:
 22782 00007A88 C3                  <1> 	retn
 22783                                  %include 'trdosk6.s' ; 24/01/2016
 22784                              <1> ; ****************************************************************************
 22785                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk6.s
 22786                              <1> ; ----------------------------------------------------------------------------
 22787                              <1> ; Last Update: 24/01/2016
 22788                              <1> ; ----------------------------------------------------------------------------
 22789                              <1> ; Beginning: 24/01/2016
 22790                              <1> ; ----------------------------------------------------------------------------
 22791                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 22792                              <1> ; ----------------------------------------------------------------------------
 22793                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 22794                              <1> ; XXXXXXXX.ASM (XX/XX/2011)
 22795                              <1> ;
 22796                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 22797                              <1> ; u1.s (27/17/2015)
 22798                              <1> ; ****************************************************************************
 22799                              <1> 
 22800                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u1.s
 22801                              <1> ; Last Modification: 27/12/2015
 22802                              <1> 
 22803                              <1> sysent: ; < enter to system call >
 22804                              <1> 	 ;19/10/2015
 22805                              <1> 	; 21/09/2015
 22806                              <1> 	; 01/07/2015
 22807                              <1> 	; 19/05/2015
 22808                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 22809                              <1> 	; 10/04/2013 - 18/01/2014 (Retro UNIX 8086 v1)
 22810                              <1> 	;
 22811                              <1> 	; 'unkni' or 'sysent' is sytem entry from various traps. 
 22812                              <1> 	; The trap type is determined and an indirect jump is made to 
 22813                              <1> 	; the appropriate system call handler. If there is a trap inside
 22814                              <1> 	; the system a jump to panic is made. All user registers are saved 
 22815                              <1> 	; and u.sp points to the end of the users stack. The sys (trap)
 22816                              <1> 	; instructor is decoded to get the the system code part (see
 22817                              <1> 	; trap instruction in the PDP-11 handbook) and from this 
 22818                              <1> 	; the indirect jump address is calculated. If a bad system call is
 22819                              <1> 	; made, i.e., the limits of the jump table are exceeded, 'badsys'
 22820                              <1> 	; is called. If the call is legitimate control passes to the
 22821                              <1> 	; appropriate system routine.
 22822                              <1> 	;
 22823                              <1> 	; Calling sequence:
 22824                              <1> 	;	Through a trap caused by any sys call outside the system.
 22825                              <1> 	; Arguments:
 22826                              <1> 	;	Arguments of particular system call.	
 22827                              <1> 	; ...............................................................
 22828                              <1> 	;	
 22829                              <1> 	; Retro UNIX 8086 v1 modification: 
 22830                              <1> 	;       System call number is in EAX register.
 22831                              <1> 	;
 22832                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
 22833                              <1> 	;	registers depending of function details.
 22834                              <1>   	;
 22835                              <1> 	; 16/04/2015
 22836 00007A89 368925[08B10000]    <1>         mov     [ss:u.sp], esp ; Kernel stack points to return address
 22837                              <1> 	; save user registers
 22838 00007A90 1E                  <1> 	push	ds
 22839 00007A91 06                  <1> 	push	es
 22840 00007A92 0FA0                <1> 	push	fs
 22841 00007A94 0FA8                <1> 	push	gs
 22842 00007A96 60                  <1> 	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
 22843                              <1> 	;
 22844                              <1> 	; ESPACE = esp - [ss:u.sp] ; 4*12 = 48 ; 17/09/2015
 22845                              <1> 	; 	(ESPACE is size of space in kernel stack 
 22846                              <1> 	;	for saving/restoring user registers.)
 22847                              <1> 	;
 22848 00007A97 50                  <1> 	push	eax ; 01/07/2015
 22849 00007A98 66B81000            <1> 	mov     ax, KDATA
 22850 00007A9C 8ED8                <1>         mov     ds, ax
 22851 00007A9E 8EC0                <1>         mov     es, ax
 22852 00007AA0 8EE0                <1>         mov     fs, ax
 22853 00007AA2 8EE8                <1>         mov     gs, ax
 22854 00007AA4 A1[48A20000]        <1> 	mov	eax, [k_page_dir]
 22855 00007AA9 0F22D8              <1> 	mov	cr3, eax
 22856 00007AAC 58                  <1> 	pop	eax ; 01/07/2015
 22857                              <1> 	; 19/10/2015
 22858 00007AAD FC                  <1> 	cld
 22859                              <1> 	;
 22860 00007AAE FE05[05B10000]      <1> 	inc	byte [sysflg]
 22861                              <1> 		; incb sysflg / indicate a system routine is in progress
 22862 00007AB4 FB                  <1>         sti 	; 18/01/2014
 22863 00007AB5 0F85D2C1FFFF        <1> 	jnz     panic ; 24/05/2013
 22864                              <1> 		; beq 1f
 22865                              <1> 		; jmp panic ; / called if trap inside system
 22866                              <1> ;1:
 22867                              <1> 	; 16/04/2015
 22868 00007ABB A3[10B10000]        <1> 	mov	[u.r0], eax
 22869 00007AC0 8925[0CB10000]      <1> 	mov	[u.usp], esp ; kernel stack points to user's registers
 22870                              <1> 	;
 22871                              <1> 		; mov $s.syst+2,clockp
 22872                              <1> 		; mov r0,-(sp) / save user registers 
 22873                              <1> 		; mov sp,u.r0 / pointer to bottom of users stack 
 22874                              <1> 			   ; / in u.r0
 22875                              <1> 		; mov r1,-(sp)
 22876                              <1> 		; mov r2,-(sp)
 22877                              <1> 		; mov r3,-(sp)
 22878                              <1> 		; mov r4,-(sp)
 22879                              <1> 		; mov r5,-(sp)
 22880                              <1> 		; mov ac,-(sp) / "accumulator" register for extended
 22881                              <1> 		             ; / arithmetic unit
 22882                              <1> 		; mov mq,-(sp) / "multiplier quotient" register for the
 22883                              <1> 		             ; / extended arithmetic unit
 22884                              <1> 		; mov sc,-(sp) / "step count" register for the extended
 22885                              <1> 		             ; / arithmetic unit
 22886                              <1> 		; mov sp,u.sp / u.sp points to top of users stack
 22887                              <1> 		; mov 18.(sp),r0 / store pc in r0
 22888                              <1> 		; mov -(r0),r0 / sys inst in r0      10400xxx
 22889                              <1> 		; sub $sys,r0 / get xxx code
 22890 00007AC6 C1E002              <1> 	shl	eax, 2
 22891                              <1> 		; asl r0 / multiply by 2 to jump indirect in bytes
 22892 00007AC9 3D94000000          <1> 	cmp	eax, end_of_syscalls - syscalls
 22893                              <1> 		; cmp r0,$2f-1f / limit of table (35) exceeded
 22894                              <1> 	;jnb	short badsys
 22895                              <1> 		; bhis badsys / yes, bad system call
 22896 00007ACE F5                  <1> 	cmc
 22897 00007ACF 9C                  <1> 	pushf	
 22898 00007AD0 50                  <1> 	push	eax
 22899 00007AD1 8B2D[08B10000]      <1>  	mov 	ebp, [u.sp] ; Kernel stack at the beginning of sys call
 22900 00007AD7 B0FE                <1> 	mov	al, 0FEh ; 11111110b
 22901 00007AD9 1400                <1> 	adc	al, 0 ; al = al + cf
 22902 00007ADB 204508              <1> 	and	[ebp+8], al ; flags (reset carry flag)
 22903                              <1> 		; bic $341,20.(sp) / set users processor priority to 0 
 22904                              <1> 				 ; / and clear carry bit
 22905 00007ADE 5D                  <1> 	pop	ebp ; eax
 22906 00007ADF 9D                  <1> 	popf
 22907 00007AE0 0F8248010000        <1>         jc      badsys
 22908 00007AE6 A1[10B10000]        <1> 	mov	eax, [u.r0]
 22909                              <1> 	; system call registers: EAX, EDX, ECX, EBX, ESI, EDI
 22910 00007AEB FFA5[F17A0000]      <1> 	jmp	dword [ebp+syscalls]
 22911                              <1> 		; jmp *1f(r0) / jump indirect thru table of addresses
 22912                              <1> 		            ; / to proper system routine.
 22913                              <1> syscalls: ; 1:
 22914                              <1> 	; 21/09/2015
 22915                              <1> 	; 01/07/2015
 22916                              <1> 	; 16/04/2015 (32 bit address modification) 
 22917 00007AF1 [F87B0000]          <1> 	dd sysrele	; / 0
 22918 00007AF5 [9E7C0000]          <1> 	dd sysexit 	; / 1
 22919 00007AF9 [C37D0000]          <1> 	dd sysfork 	; / 2
 22920 00007AFD [D67E0000]          <1> 	dd sysread 	; / 3
 22921 00007B01 [F17E0000]          <1> 	dd syswrite 	; / 4
 22922 00007B05 [5B7F0000]          <1> 	dd sysopen 	; / 5
 22923 00007B09 [95800000]          <1> 	dd sysclose 	; / 6
 22924 00007B0D [457D0000]          <1> 	dd syswait 	; / 7
 22925 00007B11 [0B800000]          <1> 	dd syscreat 	; / 8
 22926 00007B15 [BC830000]          <1> 	dd syslink 	; / 9
 22927 00007B19 [7E840000]          <1> 	dd sysunlink 	; / 10
 22928 00007B1D [51850000]          <1> 	dd sysexec 	; / 11
 22929 00007B21 [B88B0000]          <1> 	dd syschdir 	; / 12
 22930 00007B25 [9C8C0000]          <1> 	dd systime 	; / 13
 22931 00007B29 [4C800000]          <1> 	dd sysmkdir 	; / 14
 22932 00007B2D [0A8C0000]          <1> 	dd syschmod 	; / 15
 22933 00007B31 [6C8C0000]          <1> 	dd syschown 	; / 16
 22934 00007B35 [CF8C0000]          <1> 	dd sysbreak 	; / 17
 22935 00007B39 [29890000]          <1> 	dd sysstat 	; / 18
 22936 00007B3D [948D0000]          <1> 	dd sysseek 	; / 19
 22937 00007B41 [A68D0000]          <1> 	dd systell 	; / 20
 22938 00007B45 [A78E0000]          <1> 	dd sysmount 	; / 21
 22939 00007B49 [598F0000]          <1> 	dd sysumount 	; / 22
 22940 00007B4D [248E0000]          <1> 	dd syssetuid 	; / 23
 22941 00007B51 [558E0000]          <1> 	dd sysgetuid 	; / 24
 22942 00007B55 [AB8C0000]          <1> 	dd sysstime 	; / 25
 22943 00007B59 [188E0000]          <1> 	dd sysquit 	; / 26
 22944 00007B5D [0C8E0000]          <1> 	dd sysintr 	; / 27
 22945 00007B61 [05890000]          <1> 	dd sysfstat 	; / 28
 22946 00007B65 [B1800000]          <1> 	dd sysemt 	; / 29
 22947 00007B69 [DF800000]          <1> 	dd sysmdate 	; / 30
 22948 00007B6D [2A810000]          <1> 	dd sysstty 	; / 31
 22949 00007B71 [A9820000]          <1> 	dd sysgtty 	; / 32
 22950 00007B75 [DA800000]          <1> 	dd sysilgins 	; / 33
 22951 00007B79 [B48F0000]          <1> 	dd syssleep 	; 34 ; Retro UNIX 8086 v1 feature only !
 22952                              <1> 			     ; 11/06/2014
 22953 00007B7D [E38F0000]          <1> 	dd sysmsg	; 35 ; Retro UNIX 386 v1 feature only !
 22954                              <1> 			     ; 01/07/2015
 22955 00007B81 [BA900000]          <1> 	dd sysgeterr	; 36 ; Retro UNIX 386 v1 feature only !
 22956                              <1> 			     ; 21/09/2015 - get last error number
 22957                              <1> end_of_syscalls:
 22958                              <1> 
 22959                              <1> error:
 22960                              <1> 	; 17/09/2015
 22961                              <1> 	; 03/09/2015
 22962                              <1> 	; 01/09/2015
 22963                              <1> 	; 09/06/2015
 22964                              <1> 	; 13/05/2015
 22965                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 22966                              <1> 	; 10/04/2013 - 07/08/2013 (Retro UNIX 8086 v1)
 22967                              <1> 	;
 22968                              <1> 	; 'error' merely sets the error bit off the processor status (c-bit)
 22969                              <1> 	; then falls right into the 'sysret', 'sysrele' return sequence.
 22970                              <1> 	;
 22971                              <1> 	; INPUTS -> none
 22972                              <1> 	; OUTPUTS ->
 22973                              <1> 	;	processor status - carry (c) bit is set (means error)
 22974                              <1> 	;
 22975                              <1> 	; 26/05/2013 (Stack pointer must be reset here! 
 22976                              <1> 	; 	      Because, jumps to error procedure
 22977                              <1> 	;	      disrupts push-pop nesting balance)
 22978                              <1> 	;
 22979 00007B85 8B2D[08B10000]      <1> 	mov	ebp, [u.sp] ; interrupt (system call) return (iretd) address
 22980 00007B8B 804D0801            <1> 	or	byte [ebp+8], 1  ; set carry bit of flags register
 22981                              <1> 				 ; (system call will return with cf = 1)
 22982                              <1> 		; bis $1,20.(r1) / set c bit in processor status word below
 22983                              <1> 		               ; / users stack
 22984                              <1> 	; 17/09/2015
 22985 00007B8F 83ED30              <1> 	sub	ebp, ESPACE ; 48 ; total size of stack frame ('sysdefs.inc')
 22986                              <1> 				 ; for saving/restoring user registers	
 22987                              <1> 	;cmp	ebp, [u.usp]
 22988                              <1> 	;je	short err0	
 22989 00007B92 892D[0CB10000]      <1> 	mov	[u.usp], ebp
 22990                              <1> ;err0:
 22991                              <1> 	; 01/09/2015
 22992 00007B98 8B25[0CB10000]      <1> 	mov	esp, [u.usp] 	    ; Retro Unix 8086 v1 modification!
 22993                              <1> 				    ; 10/04/2013
 22994                              <1> 				    ; (If an I/O error occurs during disk I/O,
 22995                              <1> 				    ; related procedures will jump to 'error'
 22996                              <1> 				    ; procedure directly without returning to 
 22997                              <1> 				    ; the caller procedure. So, stack pointer
 22998                              <1>                                     ; must be restored here.)
 22999                              <1> 	; 13/05/2015
 23000                              <1> 	; NOTE: (The last) error code is in 'u.error', it can be retrieved by
 23001                              <1> 	;	'get last error' system call later. 	
 23002                              <1> 
 23003                              <1> 	; 03/09/2015 - 09/06/2015 - 07/08/2013
 23004 00007B9E C605[77B10000]00    <1> 	mov 	byte [u.kcall], 0 ; namei_r, mkdir_w reset
 23005                              <1> 
 23006                              <1> sysret: ; < return from system call>
 23007                              <1> 	; 10/09/2015
 23008                              <1> 	; 29/07/2015
 23009                              <1> 	; 25/06/2015
 23010                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 23011                              <1> 	; 10/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
 23012                              <1> 	;
 23013                              <1> 	; 'sysret' first checks to see if process is about to be 
 23014                              <1> 	; terminated (u.bsys). If it is, 'sysexit' is called.
 23015                              <1> 	; If not, following happens:	 
 23016                              <1> 	; 	1) The user's stack pointer is restored.
 23017                              <1> 	;	2) r1=0 and 'iget' is called to see if last mentioned
 23018                              <1> 	;	   i-node has been modified. If it has, it is written out
 23019                              <1> 	;	   via 'ppoke'.
 23020                              <1> 	;	3) If the super block has been modified, it is written out
 23021                              <1> 	;	   via 'ppoke'.				
 23022                              <1> 	;	4) If the dismountable file system's super block has been
 23023                              <1> 	;	   modified, it is written out to the specified device
 23024                              <1> 	;	   via 'ppoke'.
 23025                              <1> 	;	5) A check is made if user's time quantum (uquant) ran out
 23026                              <1> 	;	   during his execution. If so, 'tswap' is called to give
 23027                              <1> 	;	   another user a chance to run.
 23028                              <1> 	;	6) 'sysret' now goes into 'sysrele'. 
 23029                              <1> 	;	    (See 'sysrele' for conclusion.)		
 23030                              <1> 	;
 23031                              <1> 	; Calling sequence:
 23032                              <1> 	;	jump table or 'br sysret'
 23033                              <1> 	; Arguments: 
 23034                              <1> 	;	-	
 23035                              <1> 	; ...............................................................
 23036                              <1> 	;	
 23037                              <1> 	; ((AX=r1 for 'iget' input))
 23038                              <1> 	;	
 23039 00007BA5 6631C0              <1> 	xor	ax, ax ; 04/05/2013
 23040                              <1> sysret0: ; 29/07/2015 (eax = 0, jump from sysexec)
 23041 00007BA8 FEC0                <1> 	inc	al ; 04/05/2013
 23042 00007BAA 3805[5EB10000]      <1> 	cmp	[u.bsys], al ; 1
 23043                              <1> 		; tstb u.bsys / is a process about to be terminated because
 23044 00007BB0 0F83E8000000        <1>         jnb     sysexit ; 04/05/2013
 23045                              <1> 		; bne sysexit / of an error? yes, go to sysexit
 23046                              <1> 	;mov	esp, [u.usp] ; 24/05/2013 (that is not needed here)
 23047                              <1> 		; mov u.sp,sp / no point stack to users stack
 23048 00007BB6 FEC8                <1> 	dec 	al ; mov ax, 0
 23049                              <1> 		; clr r1 / zero r1 to check last mentioned i-node
 23050 00007BB8 E820150000          <1> 	call	iget
 23051                              <1> 		; jsr r0,iget / if last mentioned i-node has been modified
 23052                              <1> 		            ; / it is written out
 23053 00007BBD 6631C0              <1> 	xor 	ax, ax ; 0
 23054 00007BC0 3805[03B10000]      <1> 	cmp	[smod], al ; 0
 23055                              <1> 		; tstb	smod / has the super block been modified
 23056 00007BC6 7614                <1> 	jna	short sysret1
 23057                              <1> 		; beq	1f / no, 1f
 23058 00007BC8 A2[03B10000]        <1> 	mov	[smod], al ; 0
 23059                              <1> 		; clrb smod / yes, clear smod
 23060 00007BCD BB[B5B90000]        <1> 	mov	ebx, sb0 ;; 07/08//2013
 23061 00007BD2 66810B0002          <1>    	or	word [ebx], 200h ;;
 23062                              <1> 	;or	word [sb0], 200h ; write bit, bit 9
 23063                              <1> 		; bis $1000,sb0 / set write bit in I/O queue for super block
 23064                              <1> 		      	      ; / output
 23065                              <1> 	; AX = 0
 23066 00007BD7 E802150000          <1> 	call 	poke ; 07/08/2013
 23067                              <1> 	; call	ppoke
 23068                              <1> 	; AX = 0
 23069                              <1> 		; jsr r0,ppoke / write out modified super block to disk
 23070                              <1> sysret1: ;1:
 23071 00007BDC 3805[04B10000]      <1> 	cmp	[mmod], al ; 0
 23072                              <1> 		; tstb	mmod / has the super block for the dismountable file
 23073                              <1> 		           ; / system
 23074 00007BE2 7614                <1> 	jna	short sysrel0
 23075                              <1> 		; beq 1f / been modified?  no, 1f
 23076 00007BE4 A2[04B10000]        <1> 	mov	[mmod], al ; 0	
 23077                              <1> 		; clrb	mmod / yes, clear mmod
 23078                              <1>         ;mov    ax, [mntd]
 23079                              <1>         ;;mov   al, [mdev] ; 26/04/2013
 23080 00007BE9 BB[BDBB0000]        <1> 	mov	ebx, sb1 ;; 07/08//2013
 23081                              <1>         ;;mov	[ebx], al
 23082                              <1> 	;mov    [sb1], al
 23083                              <1> 		; movb	mntd,sb1 / set the I/O queue
 23084 00007BEE 66810B0002          <1> 	or	word [ebx], 200h
 23085                              <1> 	;or	word [sb1], 200h ; write bit, bit 9
 23086                              <1> 		; bis $1000,sb1 / set write bit in I/O queue for detached sb
 23087 00007BF3 E8E6140000          <1> 	call	poke ; 07/08/2013
 23088                              <1> 	;call	ppoke 
 23089                              <1> 		; jsr r0,ppoke / write it out to its device
 23090                              <1>         ;xor    al, al ; 26/04/2013       
 23091                              <1> ;1:
 23092                              <1> 		; tstb uquant / is the time quantum 0?
 23093                              <1> 		; bne 1f / no, don't swap it out
 23094                              <1> 
 23095                              <1> sysrele: ; < release >
 23096                              <1> 	; 14/10/2015
 23097                              <1> 	; 01/09/2015
 23098                              <1> 	; 24/07/2015
 23099                              <1> 	; 14/05/2015
 23100                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 23101                              <1> 	; 10/04/2013 - 07/03/2014 (Retro UNIX 8086 v1)
 23102                              <1> 	;
 23103                              <1> 	; 'sysrele' first calls 'tswap' if the time quantum for a user is
 23104                              <1> 	;  zero (see 'sysret'). It then restores the user's registers and
 23105                              <1> 	; turns off the system flag. It then checked to see if there is
 23106                              <1> 	; an interrupt from the user by calling 'isintr'. If there is, 
 23107                              <1> 	; the output gets flashed (see isintr) and interrupt action is
 23108                              <1> 	; taken by a branch to 'intract'. If there is no interrupt from
 23109                              <1> 	; the user, a rti is made.
 23110                              <1> 	;
 23111                              <1> 	; Calling sequence:
 23112                              <1> 	;	Fall through a 'bne' in 'sysret' & ?
 23113                              <1> 	; Arguments:
 23114                              <1> 	;	-	
 23115                              <1> 	; ...............................................................
 23116                              <1> 	;	
 23117                              <1> 	; 23/02/2014 (swapret)
 23118                              <1> 	; 22/09/2013
 23119                              <1> sysrel0: ;1:
 23120 00007BF8 803D[52B10000]00    <1> 	cmp	byte [u.quant], 0 ; 16/05/2013
 23121                              <1> 		; tstb uquant / is the time quantum 0?
 23122 00007BFF 7705                <1>         ja      short swapret
 23123                              <1> 		; bne 1f / no, don't swap it out
 23124                              <1> sysrelease: ; 07/12/2013 (jump from 'clock')
 23125 00007C01 E8D9140000          <1> 	call	tswap
 23126                              <1> 		; jsr r0,tswap / yes, swap it out
 23127                              <1> ;
 23128                              <1> ; Retro Unix 8086 v1 feature: return from 'swap' to 'swapret' address.
 23129                              <1> swapret: ;1:
 23130                              <1> 	; 10/09/2015
 23131                              <1> 	; 01/09/2015
 23132                              <1> 	; 14/05/2015
 23133                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit, pm modifications)
 23134                              <1> 	; 26/05/2013 (Retro UNIX 8086 v1)
 23135                              <1> 	; cli
 23136                              <1> 	; 24/07/2015
 23137                              <1> 	;
 23138                              <1> 	;; 'esp' must be already equal to '[u.usp]' here ! 
 23139                              <1> 	;; mov	esp, [u.usp]
 23140                              <1> 
 23141                              <1> 	; 22/09/2013
 23142 00007C06 E8D5140000          <1> 	call	isintr
 23143                              <1> 	; 20/10/2013
 23144 00007C0B 7405                <1> 	jz	short sysrel1
 23145 00007C0D E875000000          <1> 	call	intract
 23146                              <1> 		; jsr r0,isintr / is there an interrupt from the user
 23147                              <1> 		;     br intract / yes, output gets flushed, take interrupt
 23148                              <1> 		               ; / action
 23149                              <1> sysrel1:
 23150 00007C12 FA                  <1> 	cli ; 14/10/2015
 23151 00007C13 FE0D[05B10000]      <1> 	dec	byte [sysflg]
 23152                              <1> 		; decb sysflg / turn system flag off
 23153 00007C19 A1[69B10000]        <1> 	mov     eax, [u.pgdir]
 23154 00007C1E 0F22D8              <1> 	mov	cr3, eax  ; 1st PDE points to Kernel Page Table 0 (1st 4 MB)
 23155                              <1> 			  ; (others are different than kernel page tables) 
 23156                              <1> 	; 10/09/2015
 23157 00007C21 61                  <1> 	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
 23158                              <1> 		; mov (sp)+,sc / restore user registers
 23159                              <1> 		; mov (sp)+,mq
 23160                              <1> 		; mov (sp)+,ac
 23161                              <1> 		; mov (sp)+,r5
 23162                              <1> 		; mov (sp)+,r4
 23163                              <1> 		; mov (sp)+,r3
 23164                              <1> 		; mov (sp)+,r2
 23165                              <1> 	;
 23166 00007C22 A1[10B10000]        <1> 	mov	eax, [u.r0]  ; ((return value in EAX))
 23167 00007C27 0FA9                <1> 	pop	gs
 23168 00007C29 0FA1                <1> 	pop	fs
 23169 00007C2B 07                  <1> 	pop	es
 23170 00007C2C 1F                  <1> 	pop	ds
 23171 00007C2D CF                  <1> 	iretd	
 23172                              <1> 		; rti / no, return from interrupt
 23173                              <1> 
 23174                              <1> badsys:
 23175                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 23176                              <1> 	; (Major Modification: 'core' dumping procedure in
 23177                              <1>         ;       original UNIX v1 and Retro UNIX 8086 v1
 23178                              <1> 	;	has been changed to print 'Invalid System Call !'
 23179                              <1> 	;	message on the user's console tty.)
 23180                              <1> 	; (EIP, EAX values will be shown on screen with error message)
 23181                              <1> 	; (EIP = Return address just after the system call -INT 30h-)
 23182                              <1> 	; (EAX = Function number)  
 23183                              <1> 	;
 23184 00007C2E FE05[5EB10000]      <1> 	inc	byte [u.bsys]
 23185                              <1> 	;
 23186 00007C34 8B1D[08B10000]      <1> 	mov	ebx, [u.sp] ; esp at the beginning of 'sysent'
 23187 00007C3A 8B03                <1> 	mov	eax, [ebx] ; EIP (return address, not 'INT 30h' address)
 23188 00007C3C E8A59DFFFF          <1> 	call	dwordtohex
 23189 00007C41 8915[739F0000]      <1> 	mov	[bsys_msg_eip], edx
 23190 00007C47 A3[779F0000]        <1> 	mov	[bsys_msg_eip+4], eax
 23191 00007C4C A1[10B10000]        <1> 	mov	eax, [u.r0]
 23192 00007C51 E8909DFFFF          <1> 	call	dwordtohex
 23193 00007C56 8915[639F0000]      <1> 	mov	[bsys_msg_eax], edx
 23194 00007C5C A3[679F0000]        <1> 	mov	[bsys_msg_eax+4], eax
 23195 00007C61 31C0                <1> 	xor	eax, eax
 23196 00007C63 C705[30B10000]-     <1>         mov     dword [u.base], badsys_msg ; "Invalid System call !"
 23197 00007C69 [449F0000]          <1>
 23198 00007C6D 8B1D[20B10000]      <1> 	mov	ebx, [u.fofp]
 23199 00007C73 8903                <1> 	mov	[ebx], eax
 23200                              <1> 	;mov	eax, 1 ; inode number of console tty (for user)	
 23201 00007C75 40                  <1> 	inc	eax
 23202 00007C76 C705[34B10000]3B00- <1> 	mov	dword [u.count], BSYS_M_SIZE
 23203 00007C7E 0000                <1>
 23204                              <1> 		; writei
 23205                              <1> 		; INPUTS ->
 23206                              <1> 		;    r1 - inode number
 23207                              <1> 		;    u.count - byte count to be written
 23208                              <1> 		;    u.base - points to user buffer
 23209                              <1> 		;    u.fofp - points to word with current file offset
 23210                              <1> 		; OUTPUTS ->
 23211                              <1> 		;    u.count - cleared
 23212                              <1> 		;    u.nread - accumulates total bytes passed back	
 23213                              <1> 		;
 23214                              <1> 		; ((Modified registers: EDX, EBX, ECX, ESI, EDI, EBP)) 	
 23215 00007C80 E85C140000          <1> 	call	writei
 23216                              <1> 	;mov	eax, 1
 23217 00007C85 EB17                <1> 	jmp	sysexit
 23218                              <1> 
 23219                              <1> 		; incb u.bsys / turn on the user's bad-system flag
 23220                              <1> 		; mov $3f,u.namep / point u.namep to "core\0\0"
 23221                              <1> 		; jsr r0,namei / get the i-number for the core image file
 23222                              <1> 		; br 1f / error
 23223                              <1> 		; neg r1 / negate the i-number to open the core image file
 23224                              <1> 		       ; / for writing
 23225                              <1> 		; jsr r0,iopen / open the core image file
 23226                              <1> 		; jsr r0,itrunc / free all associated blocks
 23227                              <1> 		; br 2f
 23228                              <1> ;1:
 23229                              <1> 		; mov $17,r1 / put i-node mode (17) in r1
 23230                              <1> 		; jsr r0,maknod / make an i-node
 23231                              <1> 		; mov u.dirbuf,r1 / put i-node number in r1
 23232                              <1> ;2:
 23233                              <1> 		; mov $core,u.base / move address core to u.base
 23234                              <1> 		; mov $ecore-core,u.count / put the byte count in u.count
 23235                              <1> 		; mov $u.off,u.fofp / more user offset to u.fofp
 23236                              <1> 		; clr u.off / clear user offset
 23237                              <1> 		; jsr r0,writei / write out the core image to the user
 23238                              <1> 		; mov $user,u.base / pt. u.base to user
 23239                              <1> 		; mov $64.,u.count / u.count = 64
 23240                              <1> 		; jsr r0,writei / write out all the user parameters
 23241                              <1> 		; neg r1 / make i-number positive
 23242                              <1> 		; jsr r0,iclose / close the core image file
 23243                              <1> 		; br sysexit /
 23244                              <1> ;3:
 23245                              <1> 		; <core\0\0>
 23246                              <1> 
 23247                              <1> intract: ; / interrupt action
 23248                              <1> 	; 14/10/2015
 23249                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 23250                              <1> 	; 09/05/2013 - 07/12/2013 (Retro UNIX 8086 v1)
 23251                              <1> 	;
 23252                              <1> 	; Retro UNIX 8086 v1 modification !
 23253                              <1> 	; (Process/task switching and quit routine by using
 23254                              <1> 	; Retro UNIX 8086 v1 keyboard interrupt output.))
 23255                              <1> 	;
 23256                              <1> 	; input -> 'u.quit'  (also value of 'u.intr' > 0)
 23257                              <1> 	; output -> If value of 'u.quit' = FFFFh ('ctrl+brk' sign)
 23258                              <1> 	;		'intract' will jump to 'sysexit'.
 23259                              <1> 	;	    Intract will return to the caller 
 23260                              <1> 	;		if value of 'u.quit' <> FFFFh. 	 
 23261                              <1> 	; 14/10/2015
 23262 00007C87 FB                  <1> 	sti
 23263                              <1> 	; 07/12/2013	
 23264 00007C88 66FF05[56B10000]    <1> 	inc 	word [u.quit]
 23265 00007C8F 7408                <1> 	jz	short intrct0 ; FFFFh -> 0
 23266 00007C91 66FF0D[56B10000]    <1> 	dec	word [u.quit]
 23267                              <1> 	; 16/04/2015
 23268 00007C98 C3                  <1> 	retn
 23269                              <1> intrct0:	
 23270 00007C99 58                  <1> 	pop	eax ; call intract -> retn
 23271                              <1> 	;
 23272 00007C9A 31C0                <1> 	xor 	eax, eax
 23273 00007C9C FEC0                <1> 	inc	al  ; mov ax, 1
 23274                              <1> ;;;
 23275                              <1> 	; UNIX v1 original 'intract' routine... 
 23276                              <1> 	; / interrupt action
 23277                              <1> 		;cmp *(sp),$rti / are you in a clock interrupt?
 23278                              <1> 		; bne 1f / no, 1f
 23279                              <1> 		; cmp (sp)+,(sp)+ / pop clock pointer
 23280                              <1> 	; 1: / now in user area
 23281                              <1> 		; mov r1,-(sp) / save r1
 23282                              <1> 		; mov u.ttyp,r1 
 23283                              <1> 			; / pointer to tty buffer in control-to r1
 23284                              <1> 		; cmpb 6(r1),$177
 23285                              <1> 			; / is the interrupt char equal to "del"
 23286                              <1> 		; beq 1f / yes, 1f
 23287                              <1> 		; clrb 6(r1) 
 23288                              <1> 		        ; / no, clear the byte 
 23289                              <1> 			; / (must be a quit character)
 23290                              <1> 		; mov (sp)+,r1 / restore r1
 23291                              <1> 		; clr u.quit / clear quit flag
 23292                              <1> 		; bis $20,2(sp) 
 23293                              <1> 		    	; / set trace for quit (sets t bit of 
 23294                              <1> 			; / ps-trace trap)
 23295                              <1> 		; rti   ;  / return from interrupt
 23296                              <1> 	; 1: / interrupt char = del
 23297                              <1> 		; clrb 6(r1) / clear the interrupt byte 
 23298                              <1> 			   ; / in the buffer
 23299                              <1> 		; mov (sp)+,r1 / restore r1
 23300                              <1> 		; cmp u.intr,$core / should control be 
 23301                              <1> 				; / transferred to loc core?
 23302                              <1> 		; blo 1f
 23303                              <1> 		; jmp *u.intr / user to do rti yes, 
 23304                              <1> 				; / transfer to loc core
 23305                              <1> 	; 1:
 23306                              <1> 		; sys 1 / exit
 23307                              <1> 
 23308                              <1> sysexit: ; <terminate process>
 23309                              <1> 	; 01/09/2015
 23310                              <1> 	; 31/08/2015
 23311                              <1> 	; 14/05/2015
 23312                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 23313                              <1> 	; 19/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
 23314                              <1> 	;
 23315                              <1> 	; 'sysexit' terminates a process. First each file that
 23316                              <1> 	; the process has opened is closed by 'flose'. The process
 23317                              <1> 	; status is then set to unused. The 'p.pid' table is then
 23318                              <1> 	; searched to find children of the dying process. If any of
 23319                              <1> 	; children are zombies (died by not waited for), they are
 23320                              <1> 	; set free. The 'p.pid' table is then searched to find the
 23321                              <1> 	; dying process's parent. When the parent is found, it is
 23322                              <1> 	; checked to see if it is free or it is a zombie. If it is
 23323                              <1> 	; one of these, the dying process just dies. If it is waiting
 23324                              <1> 	; for a child process to die, it notified that it doesn't 
 23325                              <1> 	; have to wait anymore by setting it's status from 2 to 1
 23326                              <1> 	; (waiting to active). It is awakened and put on runq by
 23327                              <1> 	; 'putlu'. The dying process enters a zombie state in which
 23328                              <1> 	; it will never be run again but stays around until a 'wait'
 23329                              <1> 	; is completed by it's parent process. If the parent is not
 23330                              <1> 	; found, process just dies. This means 'swap' is called with
 23331                              <1> 	; 'u.uno=0'. What this does is the 'wswap' is not called
 23332                              <1> 	; to write out the process and 'rswap' reads the new process
 23333                              <1> 	; over the one that dies..i.e., the dying process is 
 23334                              <1> 	; overwritten and destroyed.	
 23335                              <1>  	;
 23336                              <1> 	; Calling sequence:
 23337                              <1> 	;	sysexit or conditional branch.
 23338                              <1> 	; Arguments:
 23339                              <1> 	;	-	
 23340                              <1> 	; ...............................................................
 23341                              <1> 	;	
 23342                              <1> 	; Retro UNIX 8086 v1 modification: 
 23343                              <1> 	;       System call number (=1) is in EAX register.
 23344                              <1> 	;
 23345                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
 23346                              <1> 	;       registers depending of function details.
 23347                              <1> 	;
 23348                              <1> 	; ('swap' procedure is mostly different than original UNIX v1.)
 23349                              <1> 	;
 23350                              <1> ; / terminate process
 23351                              <1> 	; AX = 1
 23352 00007C9E 6648                <1> 	dec 	ax ; 0
 23353 00007CA0 66A3[54B10000]      <1> 	mov	[u.intr], ax ; 0
 23354                              <1> 		; clr u.intr / clear interrupt control word
 23355                              <1> 		; clr r1 / clear r1
 23356                              <1> 	; AX = 0
 23357                              <1> sysexit_1: ; 1:
 23358                              <1> 	; AX = File descriptor
 23359                              <1> 		; / r1 has file descriptor (index to u.fp list)
 23360                              <1> 		; / Search the whole list
 23361 00007CA6 E8140D0000          <1> 	call	fclose
 23362                              <1> 		; jsr r0,fclose / close all files the process opened
 23363                              <1> 	;; ignore error return
 23364                              <1> 		; br .+2 / ignore error return
 23365                              <1> 	;inc	ax
 23366 00007CAB FEC0                <1> 	inc	al
 23367                              <1> 		; inc r1 / increment file descriptor
 23368                              <1> 	;cmp	ax, 10
 23369 00007CAD 3C0A                <1> 	cmp	al, 10
 23370                              <1> 		; cmp r1,$10. / end of u.fp list?
 23371 00007CAF 72F5                <1> 	jb	short sysexit_1
 23372                              <1> 		; blt 1b / no, go back
 23373 00007CB1 0FB61D[5FB10000]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
 23374                              <1> 		; movb	u.uno,r1 / yes, move dying process's number to r1
 23375 00007CB8 88A3[93AE0000]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE, 05/02/2014
 23376                              <1> 		; clrb p.stat-1(r1) / free the process
 23377                              <1> 	;shl	bx, 1
 23378 00007CBE D0E3                <1> 	shl	bl, 1
 23379                              <1> 		; asl r1 / use r1 for index into the below tables
 23380 00007CC0 668B8B[02AE0000]    <1> 	mov	cx, [ebx+p.pid-2]
 23381                              <1> 		; mov p.pid-2(r1),r3 / move dying process's name to r3
 23382 00007CC7 668B93[22AE0000]    <1> 	mov	dx, [ebx+p.ppid-2]
 23383                              <1> 		; mov p.ppid-2(r1),r4 / move its parents name to r4
 23384                              <1> 	; xor 	bx, bx ; 0
 23385 00007CCE 30DB                <1> 	xor	bl, bl ; 0
 23386                              <1> 		; clr r2
 23387 00007CD0 31F6                <1> 	xor	esi, esi ; 0
 23388                              <1> 		; clr r5 / initialize reg
 23389                              <1> sysexit_2: ; 1:
 23390                              <1> 	        ; / find children of this dying process, 
 23391                              <1> 		; / if they are zombies, free them
 23392                              <1> 	;add	bx, 2
 23393 00007CD2 80C302              <1> 	add	bl, 2
 23394                              <1> 		; add $2,r2 / search parent process table 
 23395                              <1> 		          ; / for dying process's name
 23396 00007CD5 66398B[22AE0000]    <1> 	cmp	[ebx+p.ppid-2], cx
 23397                              <1> 		; cmp p.ppid-2(r2),r3 / found it?
 23398 00007CDC 7513                <1> 	jne	short sysexit_4
 23399                              <1> 		; bne 3f / no
 23400                              <1> 	;shr	bx, 1
 23401 00007CDE D0EB                <1> 	shr	bl, 1
 23402                              <1> 		; asr r2 / yes, it is a parent
 23403 00007CE0 80BB[93AE0000]03    <1> 	cmp	byte [ebx+p.stat-1], 3 ; SZOMB, 05/02/2014
 23404                              <1> 		; cmpb p.stat-1(r2),$3 / is the child of this 
 23405                              <1> 				     ; / dying process a zombie
 23406 00007CE7 7506                <1> 	jne	short sysexit_3 
 23407                              <1> 		; bne 2f / no
 23408 00007CE9 88A3[93AE0000]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE, 05/02/2014
 23409                              <1> 		; clrb p.stat-1(r2) / yes, free the child process
 23410                              <1> sysexit_3: ; 2:
 23411                              <1> 	;shr	bx, 1
 23412 00007CEF D0E3                <1> 	shl	bl, 1
 23413                              <1> 		; asl r2
 23414                              <1> sysexit_4: ; 3:
 23415                              <1> 		; / search the process name table 
 23416                              <1> 		; / for the dying process's parent
 23417 00007CF1 663993[02AE0000]    <1> 	cmp	[ebx+p.pid-2], dx ; 17/09/2013	
 23418                              <1> 		; cmp p.pid-2(r2),r4 / found it?
 23419 00007CF8 7502                <1> 	jne	short sysexit_5
 23420                              <1> 		; bne 3f / no
 23421 00007CFA 89DE                <1> 	mov	esi, ebx
 23422                              <1> 		; mov r2,r5 / yes, put index to p.pid table (parents
 23423                              <1> 		          ; / process # x2) in r5
 23424                              <1> sysexit_5: ; 3:
 23425                              <1> 	;cmp	bx, nproc + nproc
 23426 00007CFC 80FB20              <1> 	cmp	bl, nproc + nproc
 23427                              <1> 		; cmp r2,$nproc+nproc / has whole table been searched?
 23428 00007CFF 72D1                <1> 	jb	short sysexit_2
 23429                              <1> 		; blt 1b / no, go back
 23430                              <1> 		; mov r5,r1 / yes, r1 now has parents process # x2
 23431 00007D01 21F6                <1> 	and	esi, esi ; r5=r1
 23432 00007D03 7431                <1> 	jz	short sysexit_6
 23433                              <1> 		; beq 2f / no parent has been found. 
 23434                              <1> 		       ; / The process just dies
 23435 00007D05 66D1EE              <1> 	shr	si, 1
 23436                              <1> 		; asr r1 / set up index to p.stat
 23437 00007D08 8A86[93AE0000]      <1> 	mov	al, [esi+p.stat-1]
 23438                              <1> 		; movb p.stat-1(r1),r2 / move status of parent to r2
 23439 00007D0E 20C0                <1> 	and	al, al
 23440 00007D10 7424                <1> 	jz	short sysexit_6
 23441                              <1> 		; beq 2f / if its been freed, 2f
 23442 00007D12 3C03                <1> 	cmp	al, 3
 23443                              <1> 		; cmp r2,$3 / is parent a zombie?
 23444 00007D14 7420                <1> 	je	short sysexit_6
 23445                              <1> 		; beq 2f / yes, 2f
 23446                              <1> 	; BH = 0
 23447 00007D16 8A1D[5FB10000]      <1> 	mov	bl, [u.uno]
 23448                              <1> 		; movb u.uno,r3 / move dying process's number to r3
 23449 00007D1C C683[93AE0000]03    <1> 	mov	byte [ebx+p.stat-1], 3  ; SZOMB, 05/02/2014
 23450                              <1> 		; movb $3,p.stat-1(r3) / make the process a zombie
 23451                              <1> 	; 05/02/2014
 23452 00007D23 3C01                <1> 	cmp	al, 1 ; SRUN
 23453 00007D25 740F                <1> 	je	short sysexit_6
 23454                              <1> 	;cmp	al, 2
 23455                              <1> 		; cmp r2,$2 / is the parent waiting for 
 23456                              <1> 			  ; / this child to die
 23457                              <1> 	;jne	short sysexit_6	
 23458                              <1> 		; bne 2f / yes, notify parent not to wait any more
 23459                              <1> 	; 05/02/2014
 23460                              <1> 	; p.stat = 2 --> waiting
 23461                              <1> 	; p.stat = 4 --> sleeping
 23462 00007D27 C686[93AE0000]01    <1> 	mov	byte [esi+p.stat-1], 1 ; SRUN ; 05/02/2014
 23463                              <1> 	;dec	byte [esi+p.stat-1]
 23464                              <1> 		; decb	p.stat-1(r1) / awaken it by putting it (parent)
 23465 00007D2E 6689F0              <1> 	mov	ax, si ; r1  (process number in AL)
 23466                              <1> 	; 
 23467                              <1> 	;mov	ebx, runq + 4
 23468                              <1> 		; mov $runq+4,r2 / on the runq
 23469 00007D31 E8AD130000          <1> 	call	putlu
 23470                              <1> 		; jsr r0, putlu
 23471                              <1> sysexit_6: ; 2:
 23472                              <1> 	; 31/08/2015
 23473                              <1> 		; / the process dies
 23474 00007D36 C605[5FB10000]00    <1> 	mov	byte [u.uno], 0
 23475                              <1> 		; clrb u.uno / put zero as the process number, 
 23476                              <1> 	           ; / so "swap" will
 23477 00007D3D E8A2130000          <1> 	call	swap
 23478                              <1> 		; jsr r0,swap / overwrite process with another process
 23479                              <1> hlt_sys:
 23480                              <1> 	;sti ; 18/01/2014
 23481                              <1> hlts0:
 23482 00007D42 F4                  <1> 	hlt
 23483 00007D43 EBFD                <1> 	jmp	short hlts0
 23484                              <1> 		; 0 / and thereby kill it; halt?
 23485                              <1> 
 23486                              <1> 
 23487                              <1> syswait: ; < wait for a processs to die >
 23488                              <1> 	; 17/09/2015
 23489                              <1> 	; 02/09/2015
 23490                              <1> 	; 01/09/2015
 23491                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
 23492                              <1> 	; 24/05/2013 - 05/02/2014 (Retro UNIX 8086 v1)
 23493                              <1> 	;
 23494                              <1> 	; 'syswait' waits for a process die. 
 23495                              <1> 	; It works in following way:
 23496                              <1> 	;    1) From the parent process number, the parent's 
 23497                              <1> 	; 	process name is found. The p.ppid table of parent
 23498                              <1> 	;	names is then searched for this process name.
 23499                              <1> 	;	If a match occurs, r2 contains child's process
 23500                              <1> 	;	number. The child status is checked to see if it is
 23501                              <1> 	;	a zombie, i.e; dead but not waited for (p.stat=3)
 23502                              <1> 	;	If it is, the child process is freed and it's name
 23503                              <1> 	;	is put in (u.r0). A return is then made via 'sysret'.
 23504                              <1> 	;	If the child is not a zombie, nothing happens and
 23505                              <1> 	;	the search goes on through the p.ppid table until
 23506                              <1> 	;	all processes are checked or a zombie is found.
 23507                              <1> 	;    2) If no zombies are found, a check is made to see if
 23508                              <1> 	;	there are any children at all. If there are none,
 23509                              <1> 	;	an error return is made. If there are, the parent's
 23510                              <1> 	;	status is set to 2 (waiting for child to die),
 23511                              <1> 	;	the parent is swapped out, and a branch to 'syswait'
 23512                              <1> 	;	is made to wait on the next process.
 23513                              <1> 	;
 23514                              <1> 	; Calling sequence:
 23515                              <1> 	;	?
 23516                              <1> 	; Arguments:
 23517                              <1> 	;	-
 23518                              <1> 	; Inputs: - 
 23519                              <1> 	; Outputs: if zombie found, it's name put in u.r0.	
 23520                              <1> 	; ...............................................................
 23521                              <1> 	;				
 23522                              <1> 	
 23523                              <1> ; / wait for a process to die
 23524                              <1> 
 23525                              <1> syswait_0:
 23526 00007D45 0FB61D[5FB10000]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
 23527                              <1> 		; movb u.uno,r1 / put parents process number in r1
 23528 00007D4C D0E3                <1> 	shl	bl, 1
 23529                              <1> 	;shl	bx, 1
 23530                              <1> 		; asl r1 / x2 to get index into p.pid table
 23531 00007D4E 668B83[02AE0000]    <1> 	mov	ax, [ebx+p.pid-2]
 23532                              <1> 		; mov p.pid-2(r1),r1 / get the name of this process
 23533 00007D55 31F6                <1> 	xor	esi, esi
 23534                              <1> 		; clr r2
 23535 00007D57 31C9                <1> 	xor	ecx, ecx ; 30/10/2013
 23536                              <1> 	;xor 	cl, cl
 23537                              <1> 		; clr r3 / initialize reg 3
 23538                              <1> syswait_1: ; 1:
 23539 00007D59 6683C602            <1> 	add	si, 2
 23540                              <1> 		; add $2,r2 / use r2 for index into p.ppid table
 23541                              <1> 			  ; / search table of parent processes 
 23542                              <1> 			  ; / for this process name
 23543 00007D5D 663B86[22AE0000]    <1> 	cmp	ax, [esi+p.ppid-2]
 23544                              <1> 		; cmp p.ppid-2(r2),r1 / r2 will contain the childs 
 23545                              <1> 			            ; / process number
 23546 00007D64 7535                <1> 	jne	short syswait_3
 23547                              <1> 		;bne 3f / branch if no match of parent process name
 23548                              <1> 	;inc	cx
 23549 00007D66 FEC1                <1> 	inc	cl
 23550                              <1> 		;inc r3 / yes, a match, r3 indicates number of children
 23551 00007D68 66D1EE              <1> 	shr	si, 1
 23552                              <1> 		; asr r2 / r2/2 to get index to p.stat table
 23553                              <1> 	; The possible states ('p.stat' values) of a process are:
 23554                              <1> 	;	0 = free or unused
 23555                              <1> 	;	1 = active
 23556                              <1> 	;	2 = waiting for a child process to die
 23557                              <1> 	;	3 = terminated, but not yet waited for (zombie).	
 23558 00007D6B 80BE[93AE0000]03    <1> 	cmp	byte [esi+p.stat-1], 3 ; SZOMB, 05/02/2014
 23559                              <1> 		; cmpb p.stat-1(r2),$3 / is the child process a zombie?
 23560 00007D72 7524                <1> 	jne	short syswait_2
 23561                              <1> 		; bne 2f / no, skip it
 23562 00007D74 88BE[93AE0000]      <1> 	mov	[esi+p.stat-1], bh ; 0
 23563                              <1> 		; clrb p.stat-1(r2) / yes, free it
 23564 00007D7A 66D1E6              <1> 	shl	si, 1
 23565                              <1> 		; asl r2 / r2x2 to get index into p.pid table
 23566 00007D7D 0FB786[02AE0000]    <1> 	movzx	eax, word [esi+p.pid-2]
 23567 00007D84 A3[10B10000]        <1> 	mov	[u.r0], eax
 23568                              <1> 		; mov p.pid-2(r2),*u.r0 
 23569                              <1> 			      ; / put childs process name in (u.r0)
 23570                              <1> 	;
 23571                              <1> 	; Retro UNIX 386 v1 modification ! (17/09/2015)
 23572                              <1> 	;
 23573                              <1> 	; Parent process ID -p.ppid- field (of the child process)
 23574                              <1> 	; must be cleared in order to prevent infinitive 'syswait'
 23575                              <1> 	; system call loop from the application/program if it calls
 23576                              <1> 	; 'syswait' again (mistakenly) while there is not a zombie
 23577                              <1> 	; or running child process to wait. ('forktest.s', 17/09/2015)
 23578                              <1> 	;
 23579                              <1> 	; Note: syswait will return with error if there is not a
 23580                              <1> 	;       zombie or running process to wait.	
 23581                              <1> 	;
 23582 00007D89 6629C0              <1> 	sub	ax, ax
 23583 00007D8C 668986[22AE0000]    <1> 	mov 	[esi+p.ppid-2], ax ; 0 ; 17/09/2015
 23584 00007D93 E910FEFFFF          <1> 	jmp	sysret0 ; ax = 0
 23585                              <1> 	;
 23586                              <1> 	;jmp	sysret
 23587                              <1> 		; br sysret1 / return cause child is dead
 23588                              <1> syswait_2: ; 2:
 23589 00007D98 66D1E6              <1> 	shl	si, 1
 23590                              <1> 		; asl r2 / r2x2 to get index into p.ppid table
 23591                              <1> syswait_3: ; 3:
 23592 00007D9B 6683FE20            <1> 	cmp	si, nproc+nproc
 23593                              <1> 		; cmp r2,$nproc+nproc / have all processes been checked?
 23594 00007D9F 72B8                <1> 	jb	short syswait_1
 23595                              <1> 		; blt 1b / no, continue search
 23596                              <1> 	;and	cx, cx
 23597 00007DA1 20C9                <1> 	and	cl, cl
 23598                              <1> 		; tst r3 / one gets here if there are no children 
 23599                              <1> 		       ; / or children that are still active
 23600                              <1> 	; 30/10/2013
 23601 00007DA3 750B                <1> 	jnz	short syswait_4
 23602                              <1> 	;jz	error
 23603                              <1> 		; beq error1 / there are no children, error
 23604 00007DA5 890D[10B10000]      <1> 	mov	[u.r0], ecx ; 0
 23605 00007DAB E9D5FDFFFF          <1> 	jmp	error
 23606                              <1> syswait_4:
 23607 00007DB0 8A1D[5FB10000]      <1> 	mov	bl, [u.uno]
 23608                              <1> 		; movb u.uno,r1 / there are children so put 
 23609                              <1> 			      ; / parent process number in r1
 23610 00007DB6 FE83[93AE0000]      <1> 	inc	byte [ebx+p.stat-1] ; 2, SWAIT, 05/02/2014
 23611                              <1> 		; incb p.stat-1(r1) / it is waiting for 
 23612                              <1> 				  ; / other children to die
 23613                              <1> 	; 04/11/2013
 23614 00007DBC E823130000          <1> 	call	swap
 23615                              <1> 		; jsr r0,swap / swap it out, because it's waiting
 23616 00007DC1 EB82                <1> 	jmp	syswait_0
 23617                              <1> 		; br syswait / wait on next process
 23618                              <1> 
 23619                              <1> sysfork: ; < create a new process >
 23620                              <1> 	; 18/09/2015
 23621                              <1> 	; 04/09/2015
 23622                              <1> 	; 02/09/2015
 23623                              <1> 	; 01/09/2015
 23624                              <1> 	; 28/08/2015
 23625                              <1> 	; 14/05/2015
 23626                              <1> 	; 10/05/2015
 23627                              <1> 	; 09/05/2015
 23628                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 - Beginning)
 23629                              <1> 	; 24/05/2013 - 14/02/2014 (Retro UNIX 8086 v1)
 23630                              <1> 	;
 23631                              <1> 	; 'sysfork' creates a new process. This process is referred
 23632                              <1> 	; to as the child process. This new process core image is
 23633                              <1> 	; a copy of that of the caller of 'sysfork'. The only
 23634                              <1> 	; distinction is the return location and the fact that (u.r0)
 23635                              <1> 	; in the old process (parent) contains the process id (p.pid)
 23636                              <1> 	; of the new process (child). This id is used by 'syswait'.
 23637                              <1> 	; 'sysfork' works in the following manner: 	
 23638                              <1> 	;    1) The process status table (p.stat) is searched to find
 23639                              <1> 	;	a process number that is unused. If none are found
 23640                              <1> 	;	an error occurs.
 23641                              <1> 	;    2) when one is found, it becomes the child process number
 23642                              <1> 	;	and it's status (p.stat) is set to active.
 23643                              <1> 	;    3) If the parent had a control tty, the interrupt 
 23644                              <1> 	;	character in that tty buffer is cleared.
 23645                              <1> 	;    4) The child process is put on the lowest priority run 
 23646                              <1> 	;	queue via 'putlu'.
 23647                              <1> 	;    5) A new process name is gotten from 'mpid' (actually 
 23648                              <1> 	;	it is a unique number) and is put in the child's unique
 23649                              <1> 	;	identifier; process id (p.pid).
 23650                              <1> 	;    6) The process name of the parent is then obtained and
 23651                              <1> 	;	placed in the unique identifier of the parent process
 23652                              <1> 	;	name is then put in 'u.r0'.	
 23653                              <1> 	;    7) The child process is then written out on disk by
 23654                              <1> 	;	'wswap',i.e., the parent process is copied onto disk
 23655                              <1> 	;	and the child is born. (The child process is written 
 23656                              <1> 	;	out on disk/drum with 'u.uno' being the child process
 23657                              <1> 	;	number.)
 23658                              <1> 	;    8) The parent process number is then restored to 'u.uno'.
 23659                              <1> 	;    9) The child process name is put in 'u.r0'.
 23660                              <1> 	;   10) The pc on the stack sp + 18 is incremented by 2 to
 23661                              <1> 	;	create the return address for the parent process.
 23662                              <1> 	;   11) The 'u.fp' list as then searched to see what files
 23663                              <1> 	;	the parent has opened. For each file the parent has
 23664                              <1> 	;	opened, the corresponding 'fsp' entry must be updated
 23665                              <1> 	;	to indicate that the child process also has opened
 23666                              <1> 	;	the file. A branch to 'sysret' is then made.	 			 				
 23667                              <1> 	;
 23668                              <1> 	; Calling sequence:
 23669                              <1> 	;	from shell ?
 23670                              <1> 	; Arguments:
 23671                              <1> 	;	-
 23672                              <1> 	; Inputs: -
 23673                              <1> 	; Outputs: *u.r0 - child process name
 23674                              <1> 	; ...............................................................
 23675                              <1> 	;	
 23676                              <1> 	; Retro UNIX 8086 v1 modification: 
 23677                              <1> 	;	AX = r0 = PID (>0) (at the return of 'sysfork')
 23678                              <1> 	;	= process id of child a parent process returns
 23679                              <1> 	;	= process id of parent when a child process returns
 23680                              <1> 	;
 23681                              <1> 	;       In original UNIX v1, sysfork is called and returns as
 23682                              <1> 	;	in following manner: (with an example: c library, fork)
 23683                              <1> 	;	
 23684                              <1> 	;	1:
 23685                              <1> 	;		sys	fork
 23686                              <1> 	;			br 1f  / child process returns here
 23687                              <1> 	;		bes	2f     / parent process returns here
 23688                              <1> 	;		/ pid of new process in r0
 23689                              <1> 	;		rts	pc
 23690                              <1> 	;	2: / parent process condionally branches here
 23691                              <1> 	;		mov	$-1,r0 / pid = -1 means error return
 23692                              <1> 	;		rts	pc
 23693                              <1> 	;
 23694                              <1> 	;	1: / child process brances here
 23695                              <1> 	;		clr	r0   / pid = 0 in child process
 23696                              <1> 	;		rts	pc
 23697                              <1> 	;
 23698                              <1> 	;	In UNIX v7x86 (386) by Robert Nordier (1999)
 23699                              <1> 	;		// pid = fork();
 23700                              <1> 	;		//
 23701                              <1> 	;		// pid == 0 in child process; 
 23702                              <1> 	;		// pid == -1 means error return
 23703                              <1> 	;		// in child, 
 23704                              <1> 	;		//	parents id is in par_uid if needed
 23705                              <1> 	;		
 23706                              <1> 	;		_fork:
 23707                              <1> 	;			mov	$.fork,eax
 23708                              <1> 	;			int	$0x30
 23709                              <1> 	;			jmp	1f
 23710                              <1> 	;			jnc	2f
 23711                              <1> 	;			jmp	cerror
 23712                              <1> 	;		1:
 23713                              <1> 	;			mov	eax,_par_uid
 23714                              <1> 	;			xor	eax,eax
 23715                              <1> 	;		2:
 23716                              <1> 	;			ret
 23717                              <1> 	;
 23718                              <1> 	;	In Retro UNIX 8086 v1,
 23719                              <1> 	;	'sysfork' returns in following manner:
 23720                              <1> 	;	
 23721                              <1> 	;		mov	ax, sys_fork
 23722                              <1> 	;		mov	bx, offset @f ; routine for child
 23723                              <1> 	;		int	20h
 23724                              <1> 	;		jc	error
 23725                              <1> 	;		
 23726                              <1> 	;	; Routine for parent process here (just after 'jc')
 23727                              <1> 	;		mov	word ptr [pid_of_child], ax
 23728                              <1> 	;		jmp	next_routine_for_parent	
 23729                              <1> 	;
 23730                              <1> 	;	@@: ; routine for child process here				
 23731                              <1> 	;		....	
 23732                              <1> 	;	NOTE: 'sysfork' returns to specified offset
 23733                              <1> 	;	       for child process by using BX input.
 23734                              <1> 	;	      (at first, parent process will return then 
 23735                              <1> 	;	      child process will return -after swapped in-
 23736                              <1> 	;	      'syswait' is needed in parent process
 23737                              <1> 	;	      if return from child process will be waited for.)
 23738                              <1> 	;	  				
 23739                              <1> 	
 23740                              <1> ; / create a new process
 23741                              <1> 	; EBX = return address for child process 
 23742                              <1> 	     ; (Retro UNIX 8086 v1 modification !)
 23743 00007DC3 31F6                <1> 	xor 	esi, esi
 23744                              <1> 		; clr r1
 23745                              <1> sysfork_1: ; 1: / search p.stat table for unused process number
 23746 00007DC5 46                  <1> 	inc	esi
 23747                              <1> 		; inc r1
 23748 00007DC6 80BE[93AE0000]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE, 05/02/2014
 23749                              <1> 		; tstb p.stat-1(r1) / is process active, unused, dead
 23750 00007DCD 760B                <1> 	jna	short sysfork_2	
 23751                              <1> 		; beq 1f / it's unused so branch
 23752 00007DCF 6683FE10            <1> 	cmp	si, nproc
 23753                              <1> 		; cmp r1,$nproc / all processes checked
 23754 00007DD3 72F0                <1> 	jb	short sysfork_1
 23755                              <1> 		; blt 1b / no, branch back
 23756                              <1> 	;
 23757                              <1> 	; Retro UNIX 8086 v1. modification:
 23758                              <1> 	;	Parent process returns from 'sysfork' to address 
 23759                              <1> 	;	which is just after 'sysfork' system call in parent
 23760                              <1> 	;	process. Child process returns to address which is put
 23761                              <1> 	;	in BX register by parent process for 'sysfork'. 
 23762                              <1> 	;
 23763                              <1> 		;add $2,18.(sp) / add 2 to pc when trap occured, points
 23764                              <1> 		             ; / to old process return
 23765                              <1> 		; br error1 / no room for a new process
 23766 00007DD5 E9ABFDFFFF          <1> 	jmp	error
 23767                              <1> sysfork_2: ; 1:
 23768 00007DDA E828B3FFFF          <1> 	call	allocate_page
 23769 00007DDF 0F82A0FDFFFF        <1> 	jc	error
 23770 00007DE5 50                  <1> 	push	eax   ; UPAGE (user structure page) address
 23771                              <1> 	; Retro UNIX 386 v1 modification!
 23772 00007DE6 E825B5FFFF          <1> 	call	duplicate_page_dir
 23773                              <1> 		; EAX = New page directory 
 23774 00007DEB 730B                <1> 	jnc	short sysfork_3
 23775 00007DED 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
 23776 00007DEE E8ECB4FFFF          <1> 	call 	deallocate_page
 23777 00007DF3 E98DFDFFFF          <1> 	jmp	error
 23778                              <1> sysfork_3:
 23779                              <1> 	; Retro UNIX 386 v1 modification !
 23780 00007DF8 56                  <1> 	push	esi
 23781 00007DF9 E8E7120000          <1> 	call	wswap ; save current user (u) structure, user registers
 23782                              <1> 		      ; and interrupt return components (for IRET)
 23783 00007DFE 8705[69B10000]      <1> 	xchg	eax, [u.pgdir] ; page directory of the child process
 23784 00007E04 A3[6DB10000]        <1> 	mov	[u.ppgdir], eax ; page directory of the parent process
 23785 00007E09 5E                  <1> 	pop	esi
 23786 00007E0A 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
 23787                              <1> 		; [u.usp] = esp
 23788 00007E0B 89F7                <1> 	mov	edi, esi
 23789 00007E0D 66C1E702            <1> 	shl	di, 2
 23790 00007E11 8987[A0AE0000]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
 23791 00007E17 A3[60B10000]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
 23792                              <1> 	; 28/08/2015
 23793 00007E1C 0FB605[5FB10000]    <1> 	movzx	eax, byte [u.uno] ; parent process number
 23794                              <1> 		; movb u.uno,-(sp) / save parent process number
 23795 00007E23 89C7                <1> 	mov	edi, eax
 23796 00007E25 50                  <1>         push	eax ; ** 
 23797 00007E26 8A87[63AE0000]      <1> 	mov     al, [edi+p.ttyc-1] ; console tty (parent)
 23798                              <1> 	; 18/09/2015
 23799                              <1> 	;mov     [esi+p.ttyc-1], al ; set child's console tty
 23800                              <1> 	;mov     [esi+p.waitc-1], ah ; 0 ; reset child's wait channel
 23801 00007E2C 668986[63AE0000]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
 23802                              <1> 				   ; ah - reset child's wait channel	
 23803 00007E33 89F0                <1> 	mov	eax, esi
 23804 00007E35 A2[5FB10000]        <1> 	mov	[u.uno], al ; child process number
 23805                              <1> 		;movb r1,u.uno / set child process number to r1
 23806 00007E3A FE86[93AE0000]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN, 05/02/2014
 23807                              <1> 		; incb p.stat-1(r1) / set p.stat entry for child 
 23808                              <1> 				; / process to active status
 23809                              <1> 		; mov u.ttyp,r2 / put pointer to parent process' 
 23810                              <1> 			      ; / control tty buffer in r2
 23811                              <1>                 ; beq 2f / branch, if no such tty assigned
 23812                              <1> 		; clrb 6(r2) / clear interrupt character in tty buffer
 23813                              <1> 	; 2:
 23814 00007E40 53                  <1> 	push	ebx  ; * return address for the child process
 23815                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
 23816                              <1> 	; (Retro UNIX 8086 v1 modification!)
 23817                              <1> 		; mov $runq+4,r2
 23818 00007E41 E89D120000          <1> 	call	putlu 
 23819                              <1>  		; jsr r0,putlu / put child process on lowest priority 
 23820                              <1> 			   ; / run queue
 23821 00007E46 66D1E6              <1> 	shl	si, 1
 23822                              <1> 		; asl r1 / multiply r1 by 2 to get index 
 23823                              <1> 		       ; / into p.pid table
 23824 00007E49 66FF05[FCB00000]    <1> 	inc	word [mpid]
 23825                              <1> 		; inc mpid / increment m.pid; get a new process name
 23826 00007E50 66A1[FCB00000]      <1> 	mov	ax, [mpid]
 23827 00007E56 668986[02AE0000]    <1> 	mov	[esi+p.pid-2], ax
 23828                              <1> 		;mov mpid,p.pid-2(r1) / put new process name 
 23829                              <1> 				    ; / in child process' name slot
 23830 00007E5D 5A                  <1> 	pop	edx  ; * return address for the child process
 23831                              <1> 		     ; * Retro UNIX 8086 v1 feature only !	
 23832 00007E5E 5B                  <1>   	pop	ebx  ; **
 23833                              <1> 	;mov	ebx, [esp] ; ** parent process number
 23834                              <1> 		; movb (sp),r2 / put parent process number in r2
 23835 00007E5F 66D1E3              <1> 	shl 	bx, 1
 23836                              <1> 		;asl r2 / multiply by 2 to get index into below tables
 23837                              <1> 	;movzx eax, word [ebx+p.pid-2]
 23838 00007E62 668B83[02AE0000]    <1> 	mov	ax, [ebx+p.pid-2]
 23839                              <1> 		; mov p.pid-2(r2),r2 / get process name of parent
 23840                              <1> 				   ; / process
 23841 00007E69 668986[22AE0000]    <1> 	mov	[esi+p.ppid-2], ax
 23842                              <1> 		; mov r2,p.ppid-2(r1) / put parent process name 
 23843                              <1> 			  ; / in parent process slot for child
 23844 00007E70 A3[10B10000]        <1> 	mov	[u.r0], eax	
 23845                              <1> 		; mov r2,*u.r0 / put parent process name on stack 
 23846                              <1> 			     ; / at location where r0 was saved
 23847 00007E75 8B2D[08B10000]      <1> 	mov 	ebp, [u.sp] ; points to return address (EIP for IRET)
 23848 00007E7B 895500              <1> 	mov	[ebp], edx ; *, CS:EIP -> EIP
 23849                              <1> 			   ; * return address for the child process
 23850                              <1> 		; mov $sysret1,-(sp) /
 23851                              <1> 		; mov sp,u.usp / contents of sp at the time when 
 23852                              <1> 			      ; / user is swapped out
 23853                              <1> 		; mov $sstack,sp / point sp to swapping stack space
 23854                              <1> 	; 04/09/2015 - 01/09/2015
 23855                              <1> 	; [u.usp] = esp
 23856 00007E7E 68[A57B0000]        <1> 	push	sysret ; ***
 23857 00007E83 8925[0CB10000]      <1> 	mov	[u.usp], esp ; points to 'sysret' address (***)
 23858                              <1> 			     ; (for child process)	
 23859 00007E89 31C0                <1> 	xor 	eax, eax
 23860 00007E8B 66A3[40B10000]      <1> 	mov 	[u.ttyp], ax ; 0
 23861                              <1> 	;
 23862 00007E91 E84F120000          <1> 	call	wswap ; Retro UNIX 8086 v1 modification !
 23863                              <1> 		;jsr r0,wswap / put child process out on drum
 23864                              <1> 		;jsr r0,unpack / unpack user stack
 23865                              <1> 		;mov u.usp,sp / restore user stack pointer
 23866                              <1> 		; tst (sp)+ / bump stack pointer
 23867                              <1> 	; Retro UNIX 386 v1 modification !
 23868 00007E96 58                  <1> 	pop	eax ; ***
 23869 00007E97 66D1E3              <1> 	shl	bx, 1
 23870 00007E9A 8B83[A0AE0000]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address ; 14/05/2015
 23871 00007EA0 E841120000          <1> 	call	rswap ; restore parent process 'u' structure, 
 23872                              <1> 		      ; registers and return address (for IRET)
 23873                              <1> 		;movb (sp)+,u.uno / put parent process number in u.uno
 23874 00007EA5 0FB705[FCB00000]    <1>         movzx   eax, word [mpid]
 23875 00007EAC A3[10B10000]        <1> 	mov	[u.r0], eax
 23876                              <1> 		; mov mpid,*u.r0 / put child process name on stack 
 23877                              <1> 			       ; / where r0 was saved
 23878                              <1> 		; add $2,18.(sp) / add 2 to pc on stack; gives parent
 23879                              <1> 			          ; / process return
 23880                              <1> 	;xor	ebx, ebx
 23881 00007EB1 31F6                <1> 	xor     esi, esi
 23882                              <1> 		;clr r1
 23883                              <1> sysfork_4: ; 1: / search u.fp list to find the files 
 23884                              <1> 	      ; / opened by the parent process
 23885                              <1> 	; 01/09/2015
 23886                              <1> 	;xor	bh, bh
 23887                              <1> 	;mov 	bl, [esi+u.fp]
 23888 00007EB3 8A86[16B10000]      <1> 	mov 	al, [esi+u.fp]
 23889                              <1> 		; movb u.fp(r1),r2 / get an open file for this process
 23890                              <1>         ;or      bl, bl
 23891 00007EB9 08C0                <1> 	or	al, al
 23892 00007EBB 740D                <1> 	jz	short sysfork_5	
 23893                              <1> 		; beq 2f / file has not been opened by parent, 
 23894                              <1> 		       ; / so branch
 23895 00007EBD B40A                <1> 	mov	ah, 10 ; Retro UNIX 386 v1 fsp structure size = 10 bytes
 23896 00007EBF F6E4                <1> 	mul	ah
 23897                              <1> 	;movzx	ebx, ax
 23898 00007EC1 6689C3              <1> 	mov	bx, ax
 23899                              <1> 	;shl     bx, 3
 23900                              <1> 		; asl r2 / multiply by 8
 23901                              <1>        		; asl r2 / to get index into fsp table
 23902                              <1>        		; asl r2
 23903 00007EC4 FE83[E2AE0000]      <1>   	inc     byte [ebx+fsp-2]
 23904                              <1> 		; incb fsp-2(r2) / increment number of processes
 23905                              <1> 			     ; / using file, because child will now be
 23906                              <1> 			     ; / using this file
 23907                              <1> sysfork_5: ; 2:
 23908 00007ECA 46                  <1>         inc     esi
 23909                              <1> 		; inc r1 / get next open file
 23910 00007ECB 6683FE0A            <1>         cmp     si, 10
 23911                              <1> 		; cmp r1,$10. / 10. files is the maximum number which
 23912                              <1> 			  ; / can be opened
 23913 00007ECF 72E2                <1> 	jb	short sysfork_4	
 23914                              <1> 		; blt 1b / check next entry
 23915 00007ED1 E9CFFCFFFF          <1> 	jmp	sysret
 23916                              <1> 		; br sysret1
 23917                              <1> 
 23918                              <1> sysread: ; < read from file >
 23919                              <1> 	; 13/05/2015
 23920                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 23921                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
 23922                              <1> 	;
 23923                              <1> 	; 'sysread' is given a buffer to read into and the number of
 23924                              <1> 	; characters to be read. If finds the file from the file
 23925                              <1> 	; descriptor located in *u.r0 (r0). This file descriptor
 23926                              <1> 	; is returned from a successful open call (sysopen).
 23927                              <1> 	; The i-number of file is obtained via 'rw1' and the data
 23928                              <1> 	; is read into core via 'readi'.
 23929                              <1> 	;
 23930                              <1> 	; Calling sequence:
 23931                              <1> 	;	sysread; buffer; nchars
 23932                              <1> 	; Arguments:
 23933                              <1> 	;	buffer - location of contiguous bytes where 
 23934                              <1> 	;		 input will be placed.
 23935                              <1> 	;	nchars - number of bytes or characters to be read.
 23936                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
 23937                              <1> 	; Outputs: *u.r0 - number of bytes read.	
 23938                              <1> 	; ...............................................................
 23939                              <1> 	;				
 23940                              <1> 	; Retro UNIX 8086 v1 modification: 
 23941                              <1> 	;       'sysread' system call has three arguments; so,
 23942                              <1> 	;	* 1st argument, file descriptor is in BX register
 23943                              <1> 	;	* 2nd argument, buffer address/offset in CX register
 23944                              <1> 	;	* 3rd argument, number of bytes is in DX register
 23945                              <1> 	;
 23946                              <1> 	;	AX register (will be restored via 'u.r0') will return
 23947                              <1> 	;	to the user with number of bytes read. 
 23948                              <1> 	;
 23949 00007ED6 E83D000000          <1> 	call	rw1
 23950 00007EDB 0F82A4FCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
 23951                              <1> 		; jsr r0,rw1 / get i-number of file to be read into r1
 23952 00007EE1 F6C480              <1> 	test	ah, 80h
 23953                              <1> 		; tst r1 / negative i-number?
 23954 00007EE4 0F859BFCFFFF        <1> 	jnz	error
 23955                              <1> 		; ble error1 / yes, error 1 to read
 23956                              <1> 			   ; / it should be positive
 23957 00007EEA E8F3110000          <1> 	call	readi
 23958                              <1> 		; jsr r0,readi / read data into core
 23959 00007EEF EB18                <1> 	jmp	short rw0
 23960                              <1> 		; br 1f
 23961                              <1> syswrite: ; < write to file >
 23962                              <1> 	; 13/05/2015
 23963                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 23964                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
 23965                              <1> 	;
 23966                              <1> 	; 'syswrite' is given a buffer to write onto an output file
 23967                              <1> 	; and the number of characters to write. If finds the file
 23968                              <1> 	; from the file descriptor located in *u.r0 (r0). This file 
 23969                              <1> 	; descriptor is returned from a successful open or create call
 23970                              <1> 	; (sysopen or syscreat). The i-number of file is obtained via
 23971                              <1> 	; 'rw1' and buffer is written on the output file via 'write'.
 23972                              <1> 	;
 23973                              <1> 	; Calling sequence:
 23974                              <1> 	;	syswrite; buffer; nchars
 23975                              <1> 	; Arguments:
 23976                              <1> 	;	buffer - location of contiguous bytes to be writtten.
 23977                              <1> 	;	nchars - number of characters to be written.
 23978                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
 23979                              <1> 	; Outputs: *u.r0 - number of bytes written.	
 23980                              <1> 	; ...............................................................
 23981                              <1> 	;				
 23982                              <1> 	; Retro UNIX 8086 v1 modification: 
 23983                              <1> 	;       'syswrite' system call has three arguments; so,
 23984                              <1> 	;	* 1st argument, file descriptor is in BX register
 23985                              <1> 	;	* 2nd argument, buffer address/offset in CX register
 23986                              <1> 	;	* 3rd argument, number of bytes is in DX register
 23987                              <1> 	;
 23988                              <1> 	;	AX register (will be restored via 'u.r0') will return
 23989                              <1> 	;	to the user with number of bytes written. 
 23990                              <1> 	;
 23991 00007EF1 E822000000          <1> 	call	rw1
 23992 00007EF6 0F8289FCFFFF        <1> 	jc	error ; 13/05/2015, ax < 1
 23993                              <1> 		; jsr r0,rw1 / get i-number in r1 of file to write
 23994 00007EFC F6C480              <1>         test	ah, 80h
 23995                              <1> 		; tst r1 / positive i-number ?
 23996 00007EFF 744E                <1>         jz	short rw3 ; 13/05/2015
 23997                              <1> 	;jz	error
 23998                              <1> 		; bge error1 / yes, error 1 
 23999                              <1> 			   ; / negative i-number means write
 24000 00007F01 66F7D8              <1>         neg	ax
 24001                              <1> 		; neg r1 / make it positive
 24002 00007F04 E8D8110000          <1> 	call	writei
 24003                              <1>         	; jsr r0,writei / write data
 24004                              <1> rw0: ; 1:
 24005 00007F09 A1[38B10000]        <1>         mov	eax, [u.nread]
 24006 00007F0E A3[10B10000]        <1> 	mov	[u.r0], eax
 24007                              <1> 		; mov u.nread,*u.r0 / put no. of bytes transferred
 24008                              <1> 				  ; / into (u.r0)
 24009 00007F13 E98DFCFFFF          <1> 	jmp	sysret
 24010                              <1>         	; br sysret1
 24011                              <1> rw1:	
 24012                              <1> 	; 14/05/2015
 24013                              <1> 	; 13/05/2015
 24014                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 24015                              <1> 	; 23/05/2013 - 24/05/2013 (Retro UNIX 8086 v1)
 24016                              <1> 	; System call registers: bx, cx, dx (through 'sysenter')
 24017                              <1> 	;
 24018                              <1> 	;mov	[u.base], ecx 	; buffer address/offset 
 24019                              <1> 				;(in the user's virtual memory space)
 24020                              <1> 	;mov	[u.count], edx 
 24021                              <1> 		; jsr r0,arg; u.base / get buffer pointer
 24022                              <1>         	; jsr r0,arg; u.count / get no. of characters
 24023                              <1> 	;;mov	eax, ebx ; file descriptor
 24024                              <1> 		; mov *u.r0,r1 / put file descriptor 
 24025                              <1> 		             ; / (index to u.fp table) in r1
 24026                              <1> 	; 13/05/2015
 24027 00007F18 C705[10B10000]0000- <1> 	mov	dword [u.r0], 0 ; r/w transfer count = 0 (reset)
 24028 00007F20 0000                <1>
 24029                              <1> 	;
 24030                              <1> 	;; call	getf
 24031                              <1>         ; eBX = File descriptor
 24032 00007F22 E8E30A0000          <1> 	call	getf1 ; calling point in 'getf' from 'rw1'
 24033                              <1> 		; jsr r0,getf / get i-number of the file in r1
 24034                              <1> 	; AX = I-number of the file ; negative i-number means write
 24035                              <1> 	; 13/05/2015
 24036 00007F27 6683F801            <1> 	cmp 	ax, 1
 24037 00007F2B 7217                <1> 	jb	short rw2
 24038                              <1> 	;
 24039 00007F2D 890D[30B10000]      <1> 	mov	[u.base], ecx 	; buffer address/offset 
 24040                              <1> 				;(in the user's virtual memory space)
 24041 00007F33 8915[34B10000]      <1> 	mov	[u.count], edx 
 24042                              <1> 	; 14/05/2015
 24043 00007F39 C705[65B10000]0000- <1>         mov     dword [u.error], 0 ; reset the last error code
 24044 00007F41 0000                <1>
 24045 00007F43 C3                  <1> 	retn
 24046                              <1>         	; rts r0
 24047                              <1> rw2:
 24048                              <1> 	; 13/05/2015
 24049 00007F44 C705[65B10000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
 24050 00007F4C 0000                <1>
 24051 00007F4E C3                  <1> 	retn
 24052                              <1> rw3: 
 24053                              <1> 	; 13/05/2015
 24054 00007F4F C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 24055 00007F57 0000                <1>
 24056 00007F59 F9                  <1> 	stc
 24057 00007F5A C3                  <1> 	retn
 24058                              <1> 
 24059                              <1> sysopen: ;<open file>
 24060                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 24061                              <1> 	; 22/05/2013 - 27/05/2013 (Retro UNIX 8086 v1)
 24062                              <1> 	;
 24063                              <1> 	; 'sysopen' opens a file in following manner:
 24064                              <1> 	;    1) The second argument in a sysopen says whether to
 24065                              <1> 	;	open the file ro read (0) or write (>0).
 24066                              <1> 	;    2) I-node of the particular file is obtained via 'namei'.
 24067                              <1> 	;    3) The file is opened by 'iopen'.
 24068                              <1> 	;    4) Next housekeeping is performed on the fsp table
 24069                              <1> 	;	and the user's open file list - u.fp.
 24070                              <1> 	;	a) u.fp and fsp are scanned for the next available slot.
 24071                              <1> 	;	b) An entry for the file is created in the fsp table.
 24072                              <1> 	;	c) The number of this entry is put on u.fp list.
 24073                              <1> 	;	d) The file descriptor index to u.fp list is pointed
 24074                              <1> 	;	   to by u.r0.
 24075                              <1> 	;
 24076                              <1> 	; Calling sequence:
 24077                              <1> 	;	sysopen; name; mode
 24078                              <1> 	; Arguments:
 24079                              <1> 	;	name - file name or path name
 24080                              <1> 	;	mode - 0 to open for reading
 24081                              <1> 	;	       1 to open for writing
 24082                              <1> 	; Inputs: (arguments)
 24083                              <1> 	; Outputs: *u.r0 - index to u.fp list (the file descriptor)
 24084                              <1> 	;		  is put into r0's location on the stack.	
 24085                              <1> 	; ...............................................................
 24086                              <1> 	;				
 24087                              <1> 	; Retro UNIX 8086 v1 modification: 
 24088                              <1> 	;       'sysopen' system call has two arguments; so,
 24089                              <1> 	;	* 1st argument, name is pointed to by BX register
 24090                              <1> 	;	* 2nd argument, mode is in CX register
 24091                              <1> 	;
 24092                              <1> 	;	AX register (will be restored via 'u.r0') will return
 24093                              <1> 	;	to the user with the file descriptor/number 
 24094                              <1> 	;	(index to u.fp list).
 24095                              <1> 	;
 24096                              <1> 	;call	arg2
 24097                              <1> 	; * name - 'u.namep' points to address of file/path name
 24098                              <1> 	;          in the user's program segment ('u.segmnt')
 24099                              <1> 	;          with offset in BX register (as sysopen argument 1).
 24100                              <1> 	; * mode - sysopen argument 2 is in CX register 
 24101                              <1> 	;          which is on top of stack.
 24102                              <1> 	;
 24103                              <1> 	; jsr r0,arg2 / get sys args into u.namep and on stack
 24104                              <1> 	;
 24105                              <1>        	; system call registers: ebx, ecx (through 'sysenter')
 24106                              <1> 
 24107 00007F5B 891D[28B10000]      <1> 	mov	[u.namep], ebx
 24108 00007F61 6651                <1> 	push	cx
 24109 00007F63 E8D90A0000          <1> 	call	namei
 24110                              <1> 		; jsr r0,namei / i-number of file in r1
 24111                              <1>      	;and	ax, ax
 24112                              <1> 	;jz	error ; File not found
 24113 00007F68 723B                <1> 	jc	short fnotfound ; 14/05/2015
 24114                              <1> 	;jc	error ; 27/05/2013
 24115                              <1> 		; br  error2 / file not found
 24116 00007F6A 665A                <1>    	pop	dx ; mode
 24117 00007F6C 6652                <1> 	push	dx
 24118                              <1> 	;or	dx, dx
 24119 00007F6E 08D2                <1> 	or	dl, dl
 24120                              <1> 		; tst (sp) / is mode = 0 (2nd arg of call; 
 24121                              <1> 		         ; / 0 means, open for read)
 24122 00007F70 7403                <1> 	jz	short sysopen_0
 24123                              <1> 		; beq 1f / yes, leave i-number positive
 24124                              <1> syscreat_0: ; 27/12/2015
 24125 00007F72 66F7D8              <1> 	neg	ax
 24126                              <1>         	; neg r1 / open for writing so make i-number negative
 24127                              <1> sysopen_0: ;1:
 24128 00007F75 E86D110000          <1> 	call	iopen
 24129                              <1> 		;jsr r0,iopen / open file whose i-number is in r1
 24130 00007F7A 665A                <1> 	pop	dx
 24131                              <1> 	;and	dx, dx
 24132 00007F7C 20D2                <1> 	and	dl, dl
 24133                              <1>         	; tst (sp)+ / pop the stack and test the mode
 24134 00007F7E 7403                <1> 	jz	short sysopen_2
 24135                              <1>         	; beq op1 / is open for read op1
 24136                              <1> sysopen_1: ;op0:
 24137 00007F80 66F7D8              <1> 	neg	ax
 24138                              <1>         	; neg r1 
 24139                              <1> 		     ;/ make i-number positive if open for writing [???]
 24140                              <1> 	;; NOTE: iopen always make i-number positive.
 24141                              <1> 	;; Here i-number becomes negative again. [22/05/2013]
 24142                              <1> sysopen_2: ;op1:
 24143 00007F83 31F6                <1>         xor     esi, esi
 24144                              <1>         	; clr r2 / clear registers
 24145 00007F85 31DB                <1>         xor     ebx, ebx
 24146                              <1> 		; clr r3
 24147                              <1> sysopen_3: ;1: / scan the list of entries in fsp table
 24148 00007F87 389E[16B10000]      <1>         cmp     [esi+u.fp], bl ; 0
 24149                              <1> 		; tstb u.fp(r2) / test the entry in the u.fp list
 24150 00007F8D 7625                <1>         jna      short sysopen_4
 24151                              <1> 		; beq 1f / if byte in list is 0 branch
 24152 00007F8F 46                  <1>         inc     esi
 24153                              <1> 		; inc r2 / bump r2 so next byte can be checked
 24154 00007F90 6683FE0A            <1>         cmp     si, 10
 24155                              <1> 		; cmp r2,$10. / reached end of list?
 24156 00007F94 72F1                <1> 	jb	short sysopen_3
 24157                              <1> 		; blt 1b / no, go back
 24158                              <1> toomanyf:
 24159                              <1> 	; 14/05/2015
 24160 00007F96 C705[65B10000]0D00- <1> 	mov	dword [u.error], ERR_TOO_MANY_FILES ; too many open files !
 24161 00007F9E 0000                <1>
 24162 00007FA0 E9E0FBFFFF          <1> 	jmp	error
 24163                              <1>         	; br error2 / yes, error (no files open)
 24164                              <1> fnotfound: 
 24165                              <1> 	; 14/05/2015
 24166 00007FA5 C705[65B10000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; file not found !
 24167 00007FAD 0000                <1>
 24168 00007FAF E9D1FBFFFF          <1> 	jmp	error
 24169                              <1> 
 24170                              <1> sysopen_4: ; 1:
 24171 00007FB4 6683BB[E4AE0000]00  <1>         cmp     word [ebx+fsp], 0
 24172                              <1> 		; tst fsp(r3) / scan fsp entries
 24173 00007FBC 7610                <1>         jna     short sysopen_5
 24174                              <1> 		; beq 1f / if 0 branch
 24175                              <1> 	; 14/05/2015 - Retro UNIX 386 v1 modification !
 24176 00007FBE 6683C30A            <1>         add     bx, 10 ; fsp structure size = 10 bytes/entry
 24177                              <1> 		; add $8.,r3 / add 8 to r3 
 24178                              <1> 			; / to bump it to next entry mfsp table
 24179 00007FC2 6681FBF401          <1>         cmp     bx, nfiles*10
 24180                              <1> 		; cmp r3,$[nfiles*8.] / done scanning
 24181 00007FC7 72EB                <1> 	jb	short sysopen_4
 24182                              <1>        		; blt 1b / no, back
 24183 00007FC9 E9B7FBFFFF          <1> 	jmp	error
 24184                              <1>         	; br error2 / yes, error
 24185                              <1> sysopen_5: ; 1: / r2 has index to u.fp list; r3, has index to fsp table
 24186 00007FCE 668983[E4AE0000]    <1>         mov     [ebx+fsp], ax
 24187                              <1> 		; mov r1,fsp(r3) / put i-number of open file 
 24188                              <1> 			; / into next available entry in fsp table,
 24189 00007FD5 668B3D[F4B00000]    <1> 	mov	di, [cdev] ; word ? byte ?
 24190 00007FDC 6689BB[E6AE0000]    <1>         mov     [ebx+fsp+2], di ; device number
 24191                              <1> 		; mov cdev,fsp+2(r3) / put # of device in next word
 24192 00007FE3 31FF                <1>         xor	edi, edi
 24193 00007FE5 89BB[E8AE0000]      <1>         mov     [ebx+fsp+4], edi ; offset pointer (0)
 24194                              <1> 		; clr fsp+4(r3)
 24195 00007FEB 6689BB[ECAE0000]    <1>         mov     [ebx+fsp+8], di ; open count (0), deleted flag (0)
 24196                              <1>        		; clr fsp+6(r3) / clear the next two words
 24197 00007FF2 89D8                <1>   	mov	eax, ebx
 24198 00007FF4 B30A                <1> 	mov	bl, 10
 24199 00007FF6 F6F3                <1> 	div	bl 
 24200                              <1> 		; asr r3
 24201                              <1> 		; asr r3 / divide by 8 
 24202                              <1> 		; asr r3 ; / to get number of the fsp entry-1
 24203 00007FF8 FEC0                <1> 	inc	al
 24204                              <1>         	; inc r3 / add 1 to get fsp entry number
 24205 00007FFA 8886[16B10000]      <1>         mov     [esi+u.fp], al
 24206                              <1> 		; movb r3,u.fp(r2) / move entry number into 
 24207                              <1> 			; / next available slot in u.fp list
 24208 00008000 8935[10B10000]      <1>         mov     [u.r0], esi
 24209                              <1> 		; mov r2,*u.r0 / move index to u.fp list 
 24210                              <1> 			     ; / into r0 loc on stack
 24211 00008006 E99AFBFFFF          <1>         jmp	sysret
 24212                              <1> 		; br sysret2
 24213                              <1> 
 24214                              <1> 	;
 24215                              <1> 	; 'fsp' table (10 bytes/entry)
 24216                              <1> 	; bit 15				   bit 0
 24217                              <1> 	; ---|-------------------------------------------
 24218                              <1> 	; r/w|		i-number of open file
 24219                              <1> 	; ---|-------------------------------------------
 24220                              <1> 	;		   device number
 24221                              <1> 	; -----------------------------------------------
 24222                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
 24223                              <1> 	; -----------------------------------------------
 24224                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
 24225                              <1> 	; ----------------------|------------------------
 24226                              <1> 	;  flag that says file 	| number of processes
 24227                              <1> 	;   has been deleted	| that have file open 
 24228                              <1> 	; ----------------------|------------------------
 24229                              <1> 	;
 24230                              <1> 
 24231                              <1> syscreat: ; < create file >
 24232                              <1> 	; 27/12/2015 (Retro UNIX 386 v1.1)
 24233                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 24234                              <1> 	; 27/05/2013 (Retro UNIX 8086 v1)
 24235                              <1> 	;
 24236                              <1> 	; 'syscreat' called with two arguments; name and mode.
 24237                              <1> 	; u.namep points to name of the file and mode is put
 24238                              <1> 	; on the stack. 'namei' is called to get i-number of the file.		
 24239                              <1> 	; If the file aready exists, it's mode and owner remain 
 24240                              <1> 	; unchanged, but it is truncated to zero length. If the file
 24241                              <1> 	; did not exist, an i-node is created with the new mode via
 24242                              <1> 	; 'maknod' whether or not the file already existed, it is
 24243                              <1> 	; open for writing. The fsp table is then searched for a free
 24244                              <1> 	; entry. When a free entry is found, proper data is placed
 24245                              <1> 	; in it and the number of this entry is put in the u.fp list.
 24246                              <1> 	; The index to the u.fp (also know as the file descriptor)
 24247                              <1> 	; is put in the user's r0. 			
 24248                              <1> 	;
 24249                              <1> 	; Calling sequence:
 24250                              <1> 	;	syscreate; name; mode
 24251                              <1> 	; Arguments:
 24252                              <1> 	;	name - name of the file to be created
 24253                              <1> 	;	mode - mode of the file to be created
 24254                              <1> 	; Inputs: (arguments)
 24255                              <1> 	; Outputs: *u.r0 - index to u.fp list 
 24256                              <1> 	;		   (the file descriptor of new file)
 24257                              <1> 	; ...............................................................
 24258                              <1> 	;				
 24259                              <1> 	; Retro UNIX 8086 v1 modification: 
 24260                              <1> 	;       'syscreate' system call has two arguments; so,
 24261                              <1> 	;	* 1st argument, name is pointed to by BX register
 24262                              <1> 	;	* 2nd argument, mode is in CX register
 24263                              <1> 	;
 24264                              <1> 	;	AX register (will be restored via 'u.r0') will return
 24265                              <1> 	;	to the user with the file descriptor/number 
 24266                              <1> 	;	(index to u.fp list).
 24267                              <1> 	;
 24268                              <1> 	;call	arg2
 24269                              <1> 	; * name - 'u.namep' points to address of file/path name
 24270                              <1> 	;          in the user's program segment ('u.segmnt')
 24271                              <1> 	;          with offset in BX register (as sysopen argument 1).
 24272                              <1> 	; * mode - sysopen argument 2 is in CX register 
 24273                              <1> 	;          which is on top of stack.
 24274                              <1> 	;
 24275                              <1>         	; jsr r0,arg2 / put file name in u.namep put mode 
 24276                              <1> 			    ; / on stack
 24277 0000800B 891D[28B10000]      <1> 	mov	[u.namep], ebx ; file name address
 24278 00008011 6651                <1> 	push	cx ; mode
 24279 00008013 E8290A0000          <1> 	call 	namei        	
 24280                              <1> 		; jsr r0,namei / get the i-number
 24281                              <1>         ;and	ax, ax
 24282                              <1> 	;jz	short syscreat_1	       	
 24283 00008018 721E                <1> 	jc	short syscreat_1
 24284                              <1> 		; br  2f / if file doesn't exist 2f
 24285                              <1> 	; 27/12/2015
 24286 0000801A 6683F829            <1> 	cmp	ax, 41 ; device inode ?
 24287 0000801E 0F824EFFFFFF        <1>         jb      syscreat_0 ; yes
 24288                              <1> 	;
 24289 00008024 66F7D8              <1> 	neg 	ax
 24290                              <1>         	; neg r1 / if file already exists make i-number 
 24291                              <1> 		       ; / negative (open for writing)
 24292 00008027 E8BB100000          <1> 	call	iopen
 24293                              <1>         	; jsr r0,iopen /
 24294 0000802C E8B8100000          <1> 	call	itrunc
 24295                              <1>         	; jsr r0,itrunc / truncate to 0 length
 24296 00008031 6659                <1> 	pop	cx ; pop mode (did not exist in original Unix v1 !?)
 24297 00008033 E948FFFFFF          <1>         jmp     sysopen_1
 24298                              <1>         	; br op0
 24299                              <1> syscreat_1: ; 2: / file doesn't exist
 24300 00008038 6658                <1> 	pop	ax
 24301                              <1>         	; mov (sp)+,r1 / put the mode in r1
 24302 0000803A 30E4                <1> 	xor	ah, ah	
 24303                              <1>         	; bic $!377,r1 / clear upper byte
 24304 0000803C E8D30C0000          <1> 	call 	maknod
 24305                              <1>         	; jsr r0,maknod / make an i-node for this file
 24306 00008041 66A1[42B10000]      <1> 	mov	ax, [u.dirbuf]
 24307                              <1>         	; mov u.dirbuf,r1 / put i-number 
 24308                              <1> 			        ; / for this new file in r1
 24309 00008047 E934FFFFFF          <1>         jmp     sysopen_1
 24310                              <1>         	; br op0 / open the file
 24311                              <1> 
 24312                              <1> sysmkdir: ; < make directory >
 24313                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 24314                              <1> 	; 27/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 24315                              <1> 	;
 24316                              <1> 	; 'sysmkdir' creates an empty directory whose name is
 24317                              <1> 	; pointed to by arg 1. The mode of the directory is arg 2.	
 24318                              <1> 	; The special entries '.' and '..' are not present.
 24319                              <1> 	; Errors are indicated if the directory already exists or		
 24320                              <1> 	; user is not the super user. 
 24321                              <1> 	;
 24322                              <1> 	; Calling sequence:
 24323                              <1> 	;	sysmkdir; name; mode
 24324                              <1> 	; Arguments:
 24325                              <1> 	;	name - points to the name of the directory
 24326                              <1> 	;	mode - mode of the directory
 24327                              <1> 	; Inputs: (arguments)
 24328                              <1> 	; Outputs: -
 24329                              <1> 	;    (sets 'directory' flag to 1; 
 24330                              <1> 	;    'set user id on execution' and 'executable' flags to 0)
 24331                              <1> 	; ...............................................................
 24332                              <1> 	;				
 24333                              <1> 	; Retro UNIX 8086 v1 modification: 
 24334                              <1> 	;       'sysmkdir' system call has two arguments; so,
 24335                              <1> 	;	* 1st argument, name is pointed to by BX register
 24336                              <1> 	;	* 2nd argument, mode is in CX register
 24337                              <1> 	;
 24338                              <1> 		
 24339                              <1> ; / make a directory
 24340                              <1> 
 24341                              <1> 	;call	arg2
 24342                              <1> 	; * name - 'u.namep' points to address of file/path name
 24343                              <1> 	;          in the user's program segment ('u.segmnt')
 24344                              <1> 	;          with offset in BX register (as sysopen argument 1).
 24345                              <1> 	; * mode - sysopen argument 2 is in CX register 
 24346                              <1> 	;          which is on top of stack.
 24347                              <1> 
 24348                              <1> 		; jsr r0,arg2 / put file name in u.namep put mode 
 24349                              <1> 			    ; / on stack
 24350 0000804C 891D[28B10000]      <1> 	mov	[u.namep], ebx
 24351 00008052 6651                <1> 	push	cx ; mode
 24352 00008054 E8E8090000          <1> 	call	namei
 24353                              <1>         	; jsr r0,namei / get the i-number
 24354                              <1>         	;     br .+4 / if file not found branch around error
 24355                              <1>         ;xor 	ax, ax
 24356                              <1> 	;jnz	error
 24357 00008059 731C                <1> 	jnc	short dir_exists ; 14/05/2015
 24358                              <1> 	;jnc	error	
 24359                              <1> 		; br  error2 / directory already exists (error)
 24360 0000805B 803D[5CB10000]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
 24361                              <1>         	;tstb u.uid / is user the super user
 24362 00008062 7622                <1> 	jna	short dir_access_err ; 14/05/2015
 24363                              <1> 	;jna	error
 24364                              <1>         	;bne error2 / no, not allowed
 24365 00008064 6658                <1> 	pop	ax
 24366                              <1>         	;mov (sp)+,r1 / put the mode in r1
 24367 00008066 6683E0CF            <1> 	and	ax, 0FFCFh ; 1111111111001111b
 24368                              <1>         	;bic $!317,r1 / all but su and ex
 24369                              <1> 	;or	ax , 4000h ; 1011111111111111b
 24370 0000806A 80CC40              <1> 	or	ah, 40h ; Set bit 14 to 1
 24371                              <1>         	;bis $40000,r1 / directory flag
 24372 0000806D E8A20C0000          <1> 	call	maknod
 24373                              <1>         	;jsr r0,maknod / make the i-node for the directory
 24374 00008072 E92EFBFFFF          <1> 	jmp	sysret
 24375                              <1>         	;br sysret2 /
 24376                              <1> dir_exists:
 24377                              <1> 	; 14/05/2015
 24378 00008077 C705[65B10000]0E00- <1> 	mov	dword [u.error], ERR_DIR_EXISTS ; dir. already exists !
 24379 0000807F 0000                <1>
 24380 00008081 E9FFFAFFFF          <1> 	jmp	error
 24381                              <1> dir_access_err:
 24382                              <1> 	; 14/05/2015
 24383 00008086 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_DIR_ACCESS ; permission denied !
 24384 0000808E 0000                <1>
 24385 00008090 E9F0FAFFFF          <1> 	jmp	error
 24386                              <1> 
 24387                              <1> sysclose: ;<close file>
 24388                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 24389                              <1> 	; 22/05/2013 - 26/05/2013 (Retro UNIX 8086 v1)
 24390                              <1> 	;
 24391                              <1> 	; 'sysclose', given a file descriptor in 'u.r0', closes the
 24392                              <1> 	; associated file. The file descriptor (index to 'u.fp' list)
 24393                              <1> 	; is put in r1 and 'fclose' is called.
 24394                              <1> 	;
 24395                              <1> 	; Calling sequence:
 24396                              <1> 	;	sysclose
 24397                              <1> 	; Arguments:
 24398                              <1> 	;	-  
 24399                              <1> 	; Inputs: *u.r0 - file descriptor
 24400                              <1> 	; Outputs: -
 24401                              <1> 	; ...............................................................
 24402                              <1> 	;				
 24403                              <1> 	; Retro UNIX 8086 v1 modification:
 24404                              <1> 	;	 The user/application program puts file descriptor
 24405                              <1> 	;        in BX register as 'sysclose' system call argument.
 24406                              <1> 	; 	 (argument transfer method 1)
 24407                              <1> 
 24408                              <1> 	; / close the file
 24409                              <1> 	
 24410 00008095 89D8                <1> 	mov 	eax, ebx
 24411 00008097 E823090000          <1> 	call 	fclose
 24412                              <1> 		; mov *u.r0,r1 / move index to u.fp list into r1
 24413                              <1> 		; jsr r0,fclose / close the file
 24414                              <1>                	; br error2 / unknown file descriptor
 24415                              <1> 		; br sysret2
 24416                              <1> 	; 14/05/2015
 24417 0000809C 0F8303FBFFFF        <1> 	jnc	sysret
 24418 000080A2 C705[65B10000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN ; file not open !
 24419 000080AA 0000                <1>
 24420 000080AC E9D4FAFFFF          <1> 	jmp	error
 24421                              <1> 
 24422                              <1> sysemt:
 24423                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 24424                              <1> 	; 10/12/2013 - 20/04/2014 (Retro UNIX 8086 v1)
 24425                              <1> 	;
 24426                              <1> 	; Retro UNIX 8086 v1 modification: 
 24427                              <1> 	;	'Enable Multi Tasking'  system call instead 
 24428                              <1> 	;	of 'Emulator Trap' in original UNIX v1 for PDP-11.
 24429                              <1> 	;
 24430                              <1> 	; Retro UNIX 8086 v1 feature only!
 24431                              <1> 	;	Using purpose: Kernel will start without time-out
 24432                              <1> 	;	(internal clock/timer) functionality.
 24433                              <1> 	;	Then etc/init will enable clock/timer for
 24434                              <1> 	;	multi tasking. (Then it will not be disabled again
 24435                              <1> 	;	except hardware reset/restart.)
 24436                              <1> 	;
 24437                              <1> 
 24438 000080B1 803D[5CB10000]00    <1> 	cmp	byte [u.uid], 0 ; root ?
 24439                              <1> 	;ja	error
 24440 000080B8 0F8770FBFFFF        <1> 	ja	badsys ; 14/05/2015
 24441                              <1> emt_0:
 24442 000080BE FA                  <1> 	cli
 24443 000080BF 21DB                <1> 	and	ebx, ebx
 24444 000080C1 7410                <1> 	jz	short emt_2
 24445                              <1> 	; Enable multi tasking -time sharing-
 24446 000080C3 B8[EA900000]        <1> 	mov	eax, clock
 24447                              <1> emt_1:
 24448 000080C8 A3[C2070000]        <1> 	mov	[x_timer], eax
 24449 000080CD FB                  <1> 	sti
 24450 000080CE E9D2FAFFFF          <1> 	jmp	sysret
 24451                              <1> emt_2:
 24452                              <1> 	; Disable multi tasking -time sharing-
 24453 000080D3 B8[CA070000]        <1> 	mov	eax, u_timer
 24454 000080D8 EBEE                <1> 	jmp	short emt_1
 24455                              <1> 
 24456                              <1> 	; Original UNIX v1 'sysemt' routine
 24457                              <1> ;sysemt:
 24458                              <1>         ;
 24459                              <1> 	;jsr    r0,arg; 30 / put the argument of the sysemt call 
 24460                              <1> 			 ; / in loc 30
 24461                              <1>         ;cmp    30,$core / was the argument a lower address 
 24462                              <1> 			; / than core
 24463                              <1>         ;blo    1f / yes, rtssym
 24464                              <1>         ;cmp    30,$ecore / no, was it higher than "core" 
 24465                              <1> 			; / and less than "ecore"
 24466                              <1>         ;blo    2f / yes, sysret2
 24467                              <1> ;1:
 24468                              <1>         ;mov    $rtssym,30
 24469                              <1> ;2:
 24470                              <1>         ;br     sysret2
 24471                              <1> 
 24472                              <1> sysilgins:
 24473                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
 24474                              <1> 	; 03/06/2013
 24475                              <1> 	; Retro UNIX 8086 v1 modification: 
 24476                              <1> 	;	not a valid system call ! (not in use)
 24477                              <1> 	;
 24478 000080DA E94FFBFFFF          <1> 	jmp	badsys
 24479                              <1> 	;jmp	error
 24480                              <1> 	;;jmp 	sysret
 24481                              <1> 
 24482                              <1> 	; Original UNIX v1 'sysemt' routine
 24483                              <1> ;sysilgins: / calculate proper illegal instruction trap address
 24484                              <1>         ;jsr    r0,arg; 10 / take address from sysilgins call
 24485                              <1> 			  ;/ put it in loc 8.,
 24486                              <1>         ;cmp    10,$core / making it the illegal instruction 
 24487                              <1> 		       ; / trap address
 24488                              <1>         ;blo    1f / is the address a user core address?  
 24489                              <1> 		; / yes, go to 2f
 24490                              <1>         ;cmp    10,$ecore
 24491                              <1>         ;blo    2f
 24492                              <1> ;1:
 24493                              <1>         ;mov    $fpsym,10 / no, make 'fpsum' the illegal 
 24494                              <1> 		    ; / instruction trap address for the system
 24495                              <1> ;2:
 24496                              <1>         ;br     sysret2 / return to the caller via 'sysret'
 24497                              <1> 
 24498                              <1> sysmdate: ; < change the modification time of a file >
 24499                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 24500                              <1> 	; 03/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 24501                              <1> 	;
 24502                              <1> 	; 'sysmdate' is given a file name. It gets inode of this 
 24503                              <1> 	; file into core. The user is checked if he is the owner 
 24504                              <1> 	; or super user. If he is neither an error occurs.
 24505                              <1> 	; 'setimod' is then called to set the i-node modification
 24506                              <1> 	; byte and the modification time, but the modification time
 24507                              <1> 	; is overwritten by whatever get put on the stack during
 24508                              <1> 	; a 'systime' system call. This calls are restricted to
 24509                              <1> 	; the super user.		
 24510                              <1> 	;
 24511                              <1> 	; Calling sequence:
 24512                              <1> 	;	sysmdate; name
 24513                              <1> 	; Arguments:
 24514                              <1> 	;	name - points to the name of file
 24515                              <1> 	; Inputs: (arguments)
 24516                              <1> 	; Outputs: -
 24517                              <1> 	; ...............................................................
 24518                              <1> 	;				
 24519                              <1> 	; Retro UNIX 8086 v1 modification: 
 24520                              <1> 	;	 The user/application program puts address 
 24521                              <1> 	;	 of the file name in BX register 
 24522                              <1> 	;	 as 'sysmdate' system call argument.
 24523                              <1> 	;
 24524                              <1> ; / change the modification time of a file
 24525                              <1> 		; jsr r0,arg; u.namep / point u.namep to the file name
 24526 000080DF 891D[28B10000]      <1>         mov	[u.namep], ebx
 24527 000080E5 E857090000          <1> 	call	namei
 24528                              <1> 		; jsr r0,namei / get its i-number
 24529 000080EA 0F82B5FEFFFF        <1>         jc	fnotfound ; file not found !
 24530                              <1> 	;jc	error       
 24531                              <1> 		; br error2 / no, such file
 24532 000080F0 E8E80F0000          <1> 	call	iget
 24533                              <1> 		; jsr r0,iget / get i-node into core
 24534 000080F5 A0[5CB10000]        <1> 	mov	al, [u.uid]
 24535 000080FA 3A05[E7AD0000]      <1> 	cmp	al, [i.uid]
 24536                              <1>         	; cmpb u.uid,i.uid / is user same as owner
 24537 00008100 7413                <1> 	je	short mdate_1
 24538                              <1>         	; beq 1f / yes
 24539 00008102 20C0                <1> 	and	al, al
 24540                              <1> 		; tstb u.uid / no, is user the super user
 24541                              <1> 	;jnz	error
 24542                              <1> 		; bne error2 / no, error
 24543 00008104 740F                <1> 	jz	short mdate_1
 24544 00008106 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 24545 0000810E 0000                <1>
 24546 00008110 E970FAFFFF          <1> 	jmp	error
 24547                              <1> mdate_1: ;1:
 24548 00008115 E8D10F0000          <1> 	call	setimod
 24549                              <1>         	; jsr r0,setimod / fill in modification data,
 24550                              <1> 		               ; / time etc.
 24551 0000811A BE[92A20000]        <1> 	mov	esi, p_time
 24552 0000811F BF[FEAD0000]        <1> 	mov	edi, i.mtim
 24553 00008124 A5                  <1> 	movsd
 24554                              <1> 		; mov 4(sp),i.mtim / move present time to
 24555                              <1>         	; mov 2(sp),i.mtim+2 / modification time
 24556 00008125 E97BFAFFFF          <1>         jmp	sysret
 24557                              <1> 		; br sysret2
 24558                              <1> 
 24559                              <1> sysstty: ; < set tty status and mode >
 24560                              <1> 	; 17/11/2015
 24561                              <1> 	; 12/11/2015
 24562                              <1> 	; 29/10/2015
 24563                              <1> 	; 17/10/2015
 24564                              <1> 	; 13/10/2015
 24565                              <1> 	; 29/06/2015
 24566                              <1> 	; 27/06/2015 (Retro UNIX 386 v1 - Beginning)
 24567                              <1> 	; 02/06/2013 - 12/07/2014 (Retro UNIX 8086 v1)
 24568                              <1> 	;
 24569                              <1> 	; 'sysstty' sets the status and mode of the typewriter 
 24570                              <1> 	; whose file descriptor is in (u.r0).
 24571                              <1> 	;
 24572                              <1> 	; Calling sequence:
 24573                              <1> 	;	sysstty; arg
 24574                              <1> 	; Arguments:
 24575                              <1> 	;	arg - address of 3 consequitive words that contain
 24576                              <1> 	;	      the source of status data	
 24577                              <1> 	; Inputs: ((*u.r0 - file descriptor & argument))
 24578                              <1> 	; Outputs: ((status in address which is pointed to by arg))
 24579                              <1> 	; ...............................................................
 24580                              <1> 	;	
 24581                              <1> 	; Retro UNIX 8086 v1 modification: 
 24582                              <1> 	;	'sysstty' system call will set the tty
 24583                              <1> 	;	(clear keyboard buffer and set cursor position)
 24584                              <1> 	;	 in following manner:
 24585                              <1> 	;   NOTE: All of tty setting functions are here (16/01/2014)
 24586                              <1> 	;
 24587                              <1> 	; Inputs:
 24588                              <1> 	;	BX = 0 --> means
 24589                              <1> 	;	   If CL = FFh
 24590                              <1> 	;	      set cursor position for console tty, only 
 24591                              <1> 	;	      CH will be ignored (char. will not be written)	
 24592                              <1> 	;	   If CH = 0 (CL < FFh)
 24593                              <1> 	;	      set console tty for (current) process
 24594                              <1> 	;	      CL = tty number (0 to 9)
 24595                              <1> 	;	      (If CH = 0, character will not be written)			
 24596                              <1> 	;          If CH > 0 (CL < FFh)	
 24597                              <1> 	;             CL = tty number (0 to 9)
 24598                              <1> 	;	      CH = character will be written
 24599                              <1> 	;	        at requested cursor position (in DX)	
 24600                              <1> 	;	   DX = cursor position for tty number 0 to 7.	
 24601                              <1>   	;		(only tty number 0 to 7) 
 24602                              <1> 	;          DL = communication parameters (for serial ports) 
 24603                              <1> 	;	        (only for COM1 and COM2 serial ports)
 24604                              <1> 	;	   DH < 0FFh -> DL is valid, initialize serial port
 24605                              <1> 	;			or set cursor position	
 24606                              <1> 	;	   DH = 0FFh -> DL is not valid
 24607                              <1> 	;		do not set serial port parameters 
 24608                              <1> 	;		or do not set cursor position
 24609                              <1> 	;
 24610                              <1> 	;	BX > 0 --> points to name of tty
 24611                              <1> 	;    	   CH > 0 -->
 24612                              <1> 	;		CH = character will be written in current 
 24613                              <1> 	;            	cursor position (for tty number from 0 to 7)
 24614                              <1> 	;	     	or character will be sent to serial port
 24615                              <1> 	;	     	(for tty number 8 or 9)
 24616                              <1> 	;		CL = color of the character if tty number < 8.
 24617                              <1> 	;    	   CH = 0 --> Do not write a character, 
 24618                              <1> 	;		set mode (tty 8 to 9) or 
 24619                              <1> 	;		set current cursor positions (tty 0 to 7) only. 
 24620                              <1> 	;   	   DX = cursor position for tty number 0 to 7.
 24621                              <1> 	;    	   DH = FFh --> Do not set cursor pos (or comm. params.)
 24622                              <1> 	;		(DL is not valid)
 24623                              <1> 	;	   DL = communication parameters 
 24624                              <1> 	;		for tty number 8 or 9 (COM1 or COM2).
 24625                              <1> 	; Outputs:
 24626                              <1> 	;	cf = 0 -> OK
 24627                              <1> 	;	     AL = tty number (0 to 9)
 24628                              <1> 	;	     AH = line status if tty number is 8 or 9
 24629                              <1> 	;	     AH = process number (of the caller) 	
 24630                              <1> 	;	cf = 1 means error (requested tty is not ready)
 24631                              <1> 	;	     AH = FFh if the tty is locked 
 24632                              <1> 	;		  (owned by another process)
 24633                              <1> 	;	        = process number (of the caller) 
 24634                              <1> 	;		  (if < FFh and tty number < 8)
 24635                              <1> 	;	     AL = tty number (0FFh if it does not exist)
 24636                              <1> 	;	     AH = line status if tty number is 8 or 9
 24637                              <1> 	;	NOTE: Video page will be cleared if cf = 0.
 24638                              <1> 	;
 24639                              <1> 	; 27/06/2015 (32 bit modifications)
 24640                              <1> 	; 14/01/2014
 24641 0000812A 31C0                <1> 	xor 	eax, eax
 24642 0000812C 6648                <1> 	dec	ax ; 17/10/2015
 24643 0000812E A3[10B10000]        <1> 	mov	[u.r0], eax ; 0FFFFh
 24644 00008133 21DB                <1> 	and	ebx, ebx
 24645 00008135 0F85CB000000        <1>         jnz     sysstty_6
 24646                              <1> ; set console tty
 24647                              <1> 	; 29/10/2015
 24648                              <1> 	; 17/01/2014 
 24649 0000813B 80F909              <1> 	cmp	cl, 9
 24650 0000813E 7613                <1> 	jna	short sysstty_0
 24651                              <1> 	; 17/11/2015
 24652 00008140 80F9FF              <1> 	cmp	cl, 0FFh
 24653 00008143 7202                <1> 	jb	short sysstty_13
 24654 00008145 88CD                <1> 	mov	ch, cl ; force CH value to FFh 
 24655                              <1> sysstty_13:
 24656 00008147 8A1D[5FB10000]      <1> 	mov	bl, [u.uno] ; process number
 24657 0000814D 8A8B[63AE0000]      <1> 	mov	cl, [ebx+p.ttyc-1] ; current/console tty
 24658                              <1> sysstty_0:
 24659                              <1> 	; 29/06/2015
 24660 00008153 6652                <1> 	push	dx
 24661 00008155 6651                <1> 	push	cx
 24662 00008157 30D2                <1> 	xor 	dl, dl	; sysstty call sign
 24663 00008159 88C8                <1> 	mov	al, cl
 24664 0000815B A2[10B10000]        <1> 	mov	[u.r0], al ; tyy number (0 to 9)
 24665 00008160 E8870F0000          <1> 	call	ottyp
 24666 00008165 6659                <1> 	pop	cx
 24667 00008167 665A                <1> 	pop	dx
 24668                              <1> 	;
 24669 00008169 7257                <1> 	jc	short sysstty_pd_err
 24670                              <1> 	;
 24671 0000816B 80F908              <1> 	cmp	cl, 8
 24672 0000816E 7222                <1> 	jb	short sysstty_2
 24673                              <1> 	;
 24674 00008170 80FEFF              <1> 	cmp	dh, 0FFh
 24675 00008173 741D                <1> 	je	short sysstty_2
 24676                              <1> 		; set communication parameters for serial ports
 24677                              <1> 	; 29/10/2015
 24678 00008175 88D4                <1> 	mov	ah, dl ; communication parameters
 24679                              <1> 		; ah = 0E3h = 11100011b = 115200 baud,
 24680                              <1> 		;			 THRE int + RDA int 
 24681                              <1> 		; ah = 23h = 00100011b = 9600 baud,
 24682                              <1> 		;			 THRE int + RDA int 
 24683 00008177 28C0                <1> 	sub	al, al ; 0
 24684                              <1> 	; 12/07/2014
 24685 00008179 80F909              <1> 	cmp	cl, 9
 24686 0000817C 7202                <1> 	jb	short sysstty_1
 24687 0000817E FEC0                <1> 	inc	al
 24688                              <1> sysstty_1:
 24689 00008180 6651                <1> 	push	cx
 24690                              <1> 	; 29/06/2015	
 24691 00008182 E821120000          <1> 	call 	sp_setp ; Set serial port communication parameters
 24692 00008187 66890D[11B10000]    <1> 	mov	[u.r0+1], cx ; Line status (ah)
 24693                              <1> 			     ; Modem status (EAX bits 16 to 23)
 24694 0000818E 6659                <1> 	pop	cx
 24695 00008190 7265                <1>         jc      short sysstty_tmout_err ; 29/10/2015
 24696                              <1> sysstty_2:
 24697                              <1> 	; 17/01/2014
 24698 00008192 20ED                <1> 	and	ch, ch 	; set cursor position 
 24699                              <1> 			; or comm. parameters ONLY
 24700 00008194 750D                <1> 	jnz	short sysstty_3
 24701 00008196 0FB61D[5FB10000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 24702 0000819D 888B[63AE0000]      <1> 	mov	[ebx+p.ttyc-1], cl ; console tty
 24703                              <1> sysstty_3:
 24704                              <1> 	; 16/01/2014
 24705 000081A3 88E8                <1> 	mov	al, ch ; character  ; 0 to FFh
 24706                              <1> 	; 17/11/2015
 24707 000081A5 B507                <1> 	mov 	ch, 7  ; Default color (light gray)
 24708 000081A7 38E9                <1> 	cmp	cl, ch ; 7 (tty number)
 24709 000081A9 0F86C5000000        <1>         jna     sysstty_9
 24710                              <1> sysstty_12:
 24711                              <1> 	;; BX = 0, CL = 8 or CL = 9
 24712                              <1> 	; (Set specified serial port as console tty port)
 24713                              <1> 	; CH = character to be written
 24714                              <1> 	; 15/04/2014
 24715                              <1> 	; CH = 0 --> initialization only
 24716                              <1> 	; AL = character
 24717                              <1> 	; 26/06/2014
 24718 000081AF 880D[64B10000]      <1> 	mov	[u.ttyn], cl
 24719                              <1> 	; 12/07/2014
 24720 000081B5 88CC                <1> 	mov	ah, cl ; tty number (8 or 9)
 24721 000081B7 20C0                <1> 	and	al, al
 24722 000081B9 7416                <1> 	jz	short sysstty_4 ; al = ch = 0
 24723                              <1>  	; 04/07/2014
 24724 000081BB E82E0F0000          <1> 	call 	sndc
 24725                              <1> 	; 12/07/2014
 24726 000081C0 EB1B                <1> 	jmp	short sysstty_5
 24727                              <1> sysstty_pd_err: ; 29/06/2015
 24728                              <1> 	; 'permission denied !' error
 24729 000081C2 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_NOT_OWNER
 24730 000081CA 0000                <1>
 24731 000081CC E9B4F9FFFF          <1> 	jmp	error
 24732                              <1> sysstty_4:
 24733                              <1> 	; 12/07/2014
 24734                              <1> 	;xchg 	ah, al	; al = 0 -> al = ah, ah = 0
 24735 000081D1 88E0                <1> 	mov	al, ah ; 29/06/2015
 24736 000081D3 2C08                <1> 	sub	al, 8
 24737                              <1> 	; 27/06/2015
 24738 000081D5 E8C6110000          <1> 	call	sp_status ; get serial port status
 24739                              <1> 	; AL = Line status, AH = Modem status
 24740                              <1> 	; 12/11/2015
 24741 000081DA 3C80                <1> 	cmp	al, 80h
 24742 000081DC F5                  <1> 	cmc
 24743                              <1> sysstty_5:
 24744 000081DD 66A3[11B10000]      <1> 	mov	[u.r0+1], ax ; ah = line status
 24745                              <1> 		     ; EAX bits 16-23 = modem status	
 24746 000081E3 9C                  <1> 	pushf
 24747 000081E4 30D2                <1> 	xor	dl, dl ; sysstty call sign
 24748 000081E6 A0[64B10000]        <1> 	mov	al, [u.ttyn] ; 26/06/2014
 24749 000081EB E8FD0E0000          <1> 	call	cttyp
 24750 000081F0 9D                  <1> 	popf
 24751 000081F1 0F83AEF9FFFF        <1> 	jnc	sysret	; time out error 
 24752                              <1> 
 24753                              <1> sysstty_tmout_err:
 24754 000081F7 C705[65B10000]1900- <1> 	mov	dword [u.error], ERR_TIME_OUT
 24755 000081FF 0000                <1>
 24756 00008201 E97FF9FFFF          <1> 	jmp	error
 24757                              <1> sysstty_6:
 24758 00008206 6652                <1> 	push	dx
 24759 00008208 6651                <1> 	push	cx
 24760 0000820A 891D[28B10000]      <1> 	mov	[u.namep], ebx
 24761 00008210 E82C080000          <1> 	call	namei
 24762 00008215 6659                <1> 	pop	cx
 24763 00008217 665A                <1> 	pop	dx
 24764 00008219 720E                <1> 	jc	short sysstty_inv_dn
 24765                              <1> 	;
 24766 0000821B 6683F813            <1> 	cmp	ax, 19  ; inode number of /dev/COM2
 24767 0000821F 7708                <1> 	ja	short sysstty_inv_dn ; 27/06/2015
 24768                              <1> 	;
 24769 00008221 3C0A                <1> 	cmp	al, 10 ; /dev/tty0 .. /dev/tty7
 24770                              <1> 		       ; /dev/COM1, /dev/COM2
 24771 00008223 7213                <1> 	jb	short sysstty_7
 24772 00008225 2C0A                <1> 	sub	al, 10
 24773 00008227 EB20                <1> 	jmp	short sysstty_8
 24774                              <1> sysstty_inv_dn: 
 24775                              <1> 	; 27/06/2015
 24776                              <1> 	; Invalid device name (not a tty) ! error
 24777                              <1> 	; (Device is not a tty or device name not found)
 24778 00008229 C705[65B10000]1800- <1> 	mov	dword [u.error], ERR_INV_DEV_NAME
 24779 00008231 0000                <1>
 24780 00008233 E94DF9FFFF          <1> 	jmp	error 
 24781                              <1> sysstty_7:
 24782 00008238 3C01                <1> 	cmp	al, 1 ; /dev/tty
 24783 0000823A 75ED                <1> 	jne	short sysstty_inv_dn ; 27/06/2015
 24784 0000823C 0FB61D[5FB10000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 24785 00008243 8A83[63AE0000]      <1> 	mov	al, [ebx+p.ttyc-1] ; console tty
 24786                              <1> sysstty_8:	
 24787 00008249 A2[10B10000]        <1> 	mov	[u.r0], al
 24788 0000824E 6652                <1> 	push	dx
 24789 00008250 6650                <1> 	push	ax
 24790 00008252 6651                <1> 	push	cx	
 24791 00008254 E8930E0000          <1> 	call	ottyp
 24792 00008259 6659                <1> 	pop	cx
 24793 0000825B 6658                <1> 	pop	ax
 24794 0000825D 665A                <1> 	pop	dx
 24795 0000825F 0F825DFFFFFF        <1>         jc      sysstty_pd_err ; 'permission denied !'
 24796                              <1> 	; 29/10/2015
 24797 00008265 86E9                <1> 	xchg 	ch, cl
 24798                              <1> 		; cl = character, ch = color code
 24799 00008267 86C1                <1> 	xchg	al, cl
 24800                              <1> 		; al = character, cl = tty number
 24801 00008269 80F907              <1> 	cmp	cl, 7
 24802 0000826C 0F873DFFFFFF        <1>         ja      sysstty_12
 24803                              <1> 	;
 24804                              <1> 	; 16/01/2014
 24805 00008272 30FF                <1> 	xor	bh, bh
 24806                              <1> 	;
 24807                              <1> sysstty_9: 	; tty 0 to tty 7
 24808                              <1> 	; al = character
 24809 00008274 80FEFF              <1> 	cmp	dh, 0FFh ; Do not set cursor position
 24810 00008277 740F                <1> 	je	short sysstty_10
 24811 00008279 6651                <1> 	push	cx
 24812 0000827B 6650                <1> 	push	ax	
 24813                              <1> 	; movzx, ebx, cl
 24814 0000827D 88CB                <1> 	mov	bl, cl ; (tty number = video page number)
 24815 0000827F E8C695FFFF          <1> 	call	_set_cpos
 24816 00008284 6658                <1> 	pop	ax
 24817 00008286 6659                <1> 	pop	cx
 24818                              <1> sysstty_10: 
 24819                              <1> 	; 29/10/2015
 24820 00008288 08C0                <1> 	or	al, al ; character
 24821 0000828A 740F                <1> 	jz      short sysstty_11 ; al = 0
 24822                              <1> 	; 17/11/2015
 24823 0000828C 3CFF                <1> 	cmp	al, 0FFh
 24824 0000828E 730B                <1> 	jnb	short sysstty_11
 24825                              <1> 		; ch > 0 and ch < FFh
 24826                              <1> 	; write a character at current cursor position
 24827 00008290 88EC                <1> 	mov	ah, ch ; color/attribute
 24828                              <1> 	; 12/07/2014
 24829 00008292 6651                <1> 	push	cx
 24830 00008294 E8EC94FFFF          <1> 	call	_write_c_current
 24831 00008299 6659                <1> 	pop	cx
 24832                              <1> sysstty_11:
 24833                              <1> 	; 14/01/2014
 24834 0000829B 30D2                <1> 	xor	dl, dl ; sysstty call sign
 24835                              <1> 	; 18/01/2014
 24836                              <1> 	;movzx	eax, cl ; 27/06/2015
 24837 0000829D 88C8                <1> 	mov	al, cl
 24838 0000829F E8490E0000          <1> 	call	cttyp
 24839 000082A4 E9FCF8FFFF          <1> 	jmp	sysret
 24840                              <1> 
 24841                              <1> ; Original UNIX v1 'sysstty' routine:
 24842                              <1> ; gtty:
 24843                              <1> ;sysstty: / set mode of typewriter; 3 consequtive word arguments
 24844                              <1>         ;jsr    r0,gtty / r1 will have offset to tty block, 
 24845                              <1> 	; 		/ r2 has source
 24846                              <1>         ;mov    r2,-(sp)
 24847                              <1>         ;mov    r1,-(sp) / put r1 and r2 on the stack
 24848                              <1> ;1: / flush the clist wait till typewriter is quiescent
 24849                              <1>         ;mov    (sp),r1 / restore r1 to tty block offset
 24850                              <1>         ;movb   tty+3(r1),0f / put cc offset into getc argument
 24851                              <1>         ;mov    $240,*$ps / set processor priority to 5
 24852                              <1>         ;jsr    r0,getc; 0:../ put character from clist in r1
 24853                              <1>         ;       br .+4 / list empty, skip branch
 24854                              <1>         ;br     1b / get another character until list is empty
 24855                              <1>         ;mov    0b,r1 / move cc offset to r1
 24856                              <1>         ;inc    r1 / bump it for output clist
 24857                              <1>         ;tstb   cc(r1) / is it 0
 24858                              <1>         ;beq    1f / yes, no characters to output
 24859                              <1>  	;mov    r1,0f / no, put offset in sleep arg
 24860                              <1>         ;jsr    r0,sleep; 0:.. / put tty output process to sleep
 24861                              <1>         ;br     1b / try to calm it down again
 24862                              <1> ;1:
 24863                              <1>         ;mov    (sp)+,r1
 24864                              <1>         ;mov    (sp)+,r2 / restore registers
 24865                              <1> 	;mov    (r2)+,r3 / put reader control status in r3
 24866                              <1>         ;beq    1f / if 0, 1f
 24867                              <1>         ;mov    r3,rcsr(r1) / move r.c. status to reader
 24868                              <1>         ;                   / control status register
 24869                              <1> ;1:
 24870                              <1>         ;mov    (r2)+,r3 / move pointer control status to r3
 24871                              <1>         ;beq    1f / if 0 1f
 24872                              <1>         ;mov    r3,tcsr(r1) / move p.c. status to printer 
 24873                              <1> 	;		    / control status reg
 24874                              <1> ;1:
 24875                              <1>         ;mov    (r2)+,tty+4(r1) / move to flag byte of tty block
 24876                              <1>         ;jmp     sysret2 / return to user
 24877                              <1> 
 24878                              <1> sysgtty: ; < get tty status >
 24879                              <1> 	; 23/11/2015
 24880                              <1> 	; 29/10/2015
 24881                              <1> 	; 17/10/2015
 24882                              <1> 	; 28/06/2015 (Retro UNIX 386 v1 - Beginning)
 24883                              <1> 	; 30/05/2013 - 12/07/2014 (Retro UNIX 8086 v1)
 24884                              <1> 	;
 24885                              <1> 	; 'sysgtty' gets the status of tty in question. 
 24886                              <1> 	; It stores in the three words addressed by it's argument
 24887                              <1> 	; the status of the typewriter whose file descriptor
 24888                              <1> 	; in (u.r0).
 24889                              <1> 	;
 24890                              <1> 	; Calling sequence:
 24891                              <1> 	;	sysgtty; arg
 24892                              <1> 	; Arguments:
 24893                              <1> 	;	arg - address of 3 words destination of the status
 24894                              <1> 	; Inputs: ((*u.r0 - file descriptor))
 24895                              <1> 	; Outputs: ((status in address which is pointed to by arg))
 24896                              <1> 	; ...............................................................
 24897                              <1> 	;	
 24898                              <1> 	; Retro UNIX 8086 v1 modification: 
 24899                              <1> 	;	'sysgtty' system call will return status of tty
 24900                              <1> 	;	(keyboard, serial port and video page status)
 24901                              <1> 	;	 in following manner:
 24902                              <1> 	;
 24903                              <1> 	; Inputs:
 24904                              <1> 	;	BX = 0 --> means 
 24905                              <1> 	;	     CH = 0 -->	'return status of the console tty' 
 24906                              <1> 	;	                 for (current) process
 24907                              <1> 	;	     CL = 0 --> return keyboard status (tty 0 to 9)
 24908                              <1> 	;	     CL = 1 --> return video page status (tty 0 to 7)
 24909                              <1> 	;	     CL = 1 --> return serial port status (tty 8 & 9)		
 24910                              <1> 	;	     CH > 0 -->	tty number + 1
 24911                              <1> 	;
 24912                              <1> 	;	BX > 0 --> points to name of tty
 24913                              <1> 	;	     CL = 0 --> return keyboard status
 24914                              <1> 	;	     CL = 1 --> return video page status
 24915                              <1> 	;	     CH = undefined		 
 24916                              <1> 	;
 24917                              <1> 	; Outputs:
 24918                              <1> 	;	cf = 0 ->
 24919                              <1> 	;
 24920                              <1> 	;	     AL = tty number from 0 to 9
 24921                              <1> 	;		  (0 to 7 is also the video page of the tty)	
 24922                              <1> 	;	     AH = 0 if the tty is free/unused
 24923                              <1> 	;	     AH = the process number of the caller 
 24924                              <1>  	;	     AH = FFh if the tty is locked by another process
 24925                              <1> 	;
 24926                              <1> 	;	  (if calling is for serial port status)
 24927                              <1> 	;	     BX = serial port status if tty number is 8 or 9
 24928                              <1> 	;		  (BH = modem status, BL = Line status)
 24929                              <1> 	;	     CX = 0FFFFh (if data is ready)
 24930                              <1> 	;	     CX = 0 (if data is not ready or undefined)		
 24931                              <1> 	;
 24932                              <1> 	;	  (if calling is for keyboard status)
 24933                              <1> 	;	     BX = current character in tty/keyboard buffer
 24934                              <1> 	;		  (BH = scan code, BL = ascii code)
 24935                              <1> 	;		  (BX=0 if there is not a waiting character)
 24936                              <1> 	;	     CX  is undefined
 24937                              <1> 	;
 24938                              <1> 	;	  (if calling is for video page status)	
 24939                              <1> 	;	     BX = cursor position on the video page
 24940                              <1> 	;		  if tty number < 8
 24941                              <1> 	;		  (BH = row, BL = column)
 24942                              <1> 	;	     CX = current character (in cursor position)
 24943                              <1> 	;		  on the video page of the tty 
 24944                              <1> 	;		  if tty number < 8
 24945                              <1> 	;		  (CH = color, CL = character)
 24946                              <1> 	;	
 24947                              <1> 	;	cf = 1 means error (requested tty is not ready)
 24948                              <1> 	;
 24949                              <1> 	;	     AH = FFh if the caller is not owner of
 24950                              <1> 	;		  specified tty or console tty
 24951                              <1> 	;	     AL = tty number (0FFh if it does not exist)
 24952                              <1> 	;	     BX, CX are undefined if cf = 1
 24953                              <1> 	;
 24954                              <1> 	;	  (If tty number is 8 or 9)
 24955                              <1> 	;	     AL = tty number 
 24956                              <1> 	;	     AH = the process number of the caller 
 24957                              <1> 	;	     BX = serial port status
 24958                              <1> 	;  		 (BH = modem status, BL = Line status)
 24959                              <1> 	;	     CX = 0
 24960                              <1> 	;
 24961                              <1> 		
 24962                              <1> gtty:   ; get (requested) tty number
 24963                              <1> 	; 17/10/2015
 24964                              <1> 	; 28/06/2015 (Retro UNIX 386 v1 - 32 bit modifications)
 24965                              <1> 	; 30/05/2013 - 12/07/2014
 24966                              <1> 	; Retro UNIX 8086 v1 modification ! 
 24967                              <1> 	;
 24968                              <1> 	; ((Modified regs: eAX, eBX, eCX, eDX, eSI, eDI, eBP))
 24969                              <1> 	;
 24970                              <1> 	; 28/06/2015 (32 bit modifications)
 24971                              <1> 	; 16/01/2014
 24972 000082A9 31C0                <1> 	xor 	eax, eax
 24973 000082AB 6648                <1> 	dec	ax ; 17/10/2015
 24974 000082AD A3[10B10000]        <1> 	mov 	[u.r0], eax ; 0FFFFh
 24975 000082B2 80F901              <1> 	cmp	cl, 1
 24976 000082B5 760F                <1> 	jna	short sysgtty_0
 24977                              <1> sysgtty_invp:
 24978                              <1> 	; 28/06/2015
 24979 000082B7 C705[65B10000]1700- <1>         mov     dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
 24980 000082BF 0000                <1>
 24981 000082C1 E9BFF8FFFF          <1> 	jmp	error
 24982                              <1> sysgtty_0:	
 24983 000082C6 21DB                <1> 	and	ebx, ebx
 24984 000082C8 7430                <1> 	jz	short sysgtty_1
 24985                              <1> 	;
 24986 000082CA 891D[28B10000]      <1> 	mov	[u.namep], ebx
 24987 000082D0 6651                <1> 	push	cx ; 23/11/2015
 24988 000082D2 E86A070000          <1> 	call	namei
 24989 000082D7 6659                <1> 	pop	cx ; 23/11/2015
 24990 000082D9 7210                <1> 	jc 	short sysgtty_inv_dn ; 28/06/2015
 24991                              <1> 	;
 24992 000082DB 6683F801            <1> 	cmp	ax, 1
 24993 000082DF 7622                <1> 	jna	short sysgtty_2
 24994 000082E1 6683E80A            <1> 	sub	ax, 10
 24995 000082E5 6683F809            <1> 	cmp	ax, 9
 24996                              <1> 	;ja	short sysgtty_inv_dn
 24997                              <1> 	;mov	ch, al
 24998                              <1> 	;jmp	short sysgtty_4
 24999                              <1> 	; 23/11/2015
 25000 000082E9 7629                <1> 	jna	short sysgtty_4
 25001                              <1> sysgtty_inv_dn: 
 25002                              <1> 	; 28/06/2015
 25003                              <1> 	; Invalid device name (not a tty) ! error
 25004                              <1> 	; (Device is not a tty or device name not found)
 25005 000082EB C705[65B10000]1800- <1> 	mov	dword [u.error], ERR_INV_DEV_NAME
 25006 000082F3 0000                <1>
 25007 000082F5 E98BF8FFFF          <1> 	jmp	error 
 25008                              <1> sysgtty_1:
 25009                              <1> 	; 16/01/2014
 25010 000082FA 80FD0A              <1> 	cmp	ch, 10
 25011 000082FD 77B8                <1> 	ja	short sysgtty_invp ; 28/06/2015
 25012 000082FF FECD                <1> 	dec	ch ; 0 -> FFh (negative)
 25013 00008301 790F                <1> 	jns	short sysgtty_3 ; not negative
 25014                              <1> 	;
 25015                              <1> sysgtty_2:
 25016                              <1> 	; get tty number of console tty
 25017 00008303 8A25[5FB10000]      <1> 	mov	ah, [u.uno]
 25018                              <1>  	; 28/06/2015
 25019 00008309 0FB6DC              <1> 	movzx 	ebx, ah
 25020 0000830C 8AAB[63AE0000]      <1> 	mov	ch, [ebx+p.ttyc-1]
 25021                              <1> sysgtty_3:
 25022 00008312 88E8                <1> 	mov	al, ch
 25023                              <1> sysgtty_4:
 25024 00008314 A2[10B10000]        <1> 	mov	[u.r0], al
 25025                              <1>  	; 28/06/2015
 25026                              <1> 	;cmp	al, 9
 25027                              <1> 	;ja	short sysgtty_invp
 25028 00008319 8B2D[0CB10000]      <1> 	mov	ebp, [u.usp]
 25029                              <1> 	; 23/11/2015
 25030 0000831F 20C9                <1> 	and	cl, cl
 25031 00008321 7436                <1> 	jz	short sysgtty_6 ; keyboard status
 25032 00008323 3C08                <1> 	cmp	al, 8 ; cmp ch, 8
 25033 00008325 7232                <1> 	jb	short sysgtty_6 ; video page status
 25034                              <1> 	; serial port status
 25035                              <1> 	; 12/07/2014
 25036                              <1> 	;mov	dx, 0
 25037                              <1> 	;je	short sysgtty_5
 25038                              <1> 	;inc	dl
 25039                              <1> ;sysgtty_5:
 25040                              <1> 	; 28/06/2015
 25041 00008327 2C08                <1> 	sub	al, 8
 25042 00008329 E872100000          <1> 	call	sp_status ; serial (COM) port (line) status
 25043                              <1> 	; AL = Line status, AH = Modem status
 25044 0000832E 66894510            <1> 	mov	[ebp+16], ax ; serial port status (in EBX)
 25045 00008332 8A25[5FB10000]      <1> 	mov	ah, [u.uno]
 25046 00008338 8825[11B10000]      <1>         mov     [u.r0+1], ah
 25047 0000833E 66C745180000        <1> 	mov	word [ebp+24], 0 ; data status (0 = not ready)	
 25048                              <1> 				; (in ECX)
 25049 00008344 A880                <1> 	test	al, 80h
 25050 00008346 7565                <1> 	jnz	short sysgtty_dnr_err ; 29/06/2015
 25051 00008348 A801                <1> 	test	al, 1
 25052 0000834A 0F8455F8FFFF        <1> 	jz	sysret
 25053 00008350 66FF4D18            <1> 	dec	word [ebp+24] ; data status (FFFFh = ready)	
 25054 00008354 E94CF8FFFF          <1> 	jmp	sysret
 25055                              <1> sysgtty_6:
 25056 00008359 A2[64B10000]        <1> 	mov	[u.ttyn], al ; tty number
 25057                              <1> 	;movzx	ebx, al
 25058 0000835E 88C3                <1> 	mov 	bl, al ; tty number (0 to 9)
 25059 00008360 D0E3                <1> 	shl 	bl, 1  ; aligned to word
 25060                              <1> 	; 22/04/2014 - 29/06/2015
 25061 00008362 81C3[96A20000]      <1>         add     ebx, ttyl
 25062 00008368 8A23                <1>  	mov	ah, [ebx]
 25063 0000836A 3A25[5FB10000]      <1> 	cmp	ah, [u.uno]
 25064 00008370 7404                <1> 	je	short sysgtty_7
 25065 00008372 20E4                <1> 	and	ah, ah
 25066                              <1> 	;jz	short sysgtty_7
 25067 00008374 7506                <1> 	jnz	short sysgtty_8
 25068                              <1> 	;mov	ah, 0FFh
 25069                              <1> sysgtty_7:
 25070 00008376 8825[11B10000]      <1>         mov     [u.r0+1], ah
 25071                              <1> sysgtty_8:
 25072 0000837C 08C9                <1> 	or	cl, cl
 25073 0000837E 7510                <1> 	jnz	short sysgtty_9
 25074 00008380 B401                <1> 	mov	ah, 1  ; test a key is available
 25075 00008382 E86088FFFF          <1> 	call	int16h ; 24/01/2016
 25076 00008387 66894510            <1> 	mov	[ebp+16], ax ; bx, character
 25077 0000838B E915F8FFFF          <1> 	jmp	sysret
 25078                              <1> sysgtty_9:
 25079 00008390 8A1D[64B10000]      <1> 	mov	bl, [u.ttyn]
 25080                              <1> 	; bl = video page number
 25081 00008396 E8E191FFFF          <1> 	call 	get_cpos
 25082                              <1> 	; dx = cursor position
 25083 0000839B 66895510            <1> 	mov	[ebp+16], dx ; bx
 25084                              <1> 	;mov	bl, [u.ttyn]
 25085                              <1> 	; bl = video page number
 25086 0000839F E89793FFFF          <1> 	call	_read_ac_current ; 24/01/2016
 25087                              <1> 	; ax = character and attribute/color
 25088 000083A4 66894518            <1> 	mov	[ebp+24], ax ; cx
 25089 000083A8 E9F8F7FFFF          <1> 	jmp	sysret
 25090                              <1> sysgtty_dnr_err:
 25091                              <1> 	; 'device not responding !' error	
 25092                              <1> 	;mov 	dword [u.error], ERR_TIME_OUT ; 25
 25093 000083AD C705[65B10000]1900- <1> 	mov 	dword [u.error], ERR_DEV_NOT_RESP ;  25				
 25094 000083B5 0000                <1>
 25095 000083B7 E9C9F7FFFF          <1> 	jmp	error	
 25096                              <1> 
 25097                              <1> ; Original UNIX v1 'sysgtty' routine:
 25098                              <1> ; sysgtty:
 25099                              <1>         ;jsr    r0,gtty / r1 will have offset to tty block,
 25100                              <1> 	;	       / r2 has destination
 25101                              <1>         ;mov    rcsr(r1),(r2)+ / put reader control status 
 25102                              <1> 	;                     / in 1st word of dest
 25103                              <1>         ;mov    tcsr(r1),(r2)+ / put printer control status
 25104                              <1> 	;                     / in 2nd word of dest
 25105                              <1>         ;mov    tty+4(r1),(r2)+ / put mode in 3rd word
 25106                              <1>         ;jmp    sysret2 / return to user
 25107                              <1> 	
 25108                              <1> ; Original UNIX v1 'gtty' routine:
 25109                              <1> ; gtty:
 25110                              <1>         ;jsr    r0,arg; u.off / put first arg in u.off
 25111                              <1>         ;mov    *u.r0,r1 / put file descriptor in r1
 25112                              <1>         ;jsr    r0,getf / get the i-number of the file
 25113                              <1>         ;tst    r1 / is it open for reading
 25114                              <1>         ;bgt    1f / yes
 25115                              <1>         ;neg    r1 / no, i-number is negative, 
 25116                              <1> 	;          / so make it positive
 25117                              <1> ;1:
 25118                              <1>         ;sub    $14.,r1 / get i-number of tty0
 25119                              <1>         ;cmp    r1,$ntty-1 / is there such a typewriter
 25120                              <1>         ;bhis   error9 / no, error
 25121                              <1>         ;asl    r1 / 0%2
 25122                              <1>         ;asl    r1 / 0%4 / yes
 25123                              <1>         ;asl    r1 / 0%8 / multiply by 8 so r1 points to 
 25124                              <1> 	;	       ; / tty block
 25125                              <1>         ;mov    u.off,r2 / put argument in r2
 25126                              <1>         ;rts    r0 / return
 25127                              <1> 
 25128                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u2.s
 25129                              <1> ; Last Modification: 03/01/2016
 25130                              <1> 
 25131                              <1> syslink:
 25132                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 25133                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 25134                              <1> 	;
 25135                              <1> 	; 'syslink' is given two arguments, name 1 and name 2.
 25136                              <1> 	; name 1 is a file that already exists. name 2 is the name
 25137                              <1> 	; given to the entry that will go in the current directory.
 25138                              <1> 	; name2 will then be a link to the name 1 file. The i-number
 25139                              <1> 	; in the name 2 entry of current directory is the same
 25140                              <1> 	; i-number for the name 1 file.
 25141                              <1> 	;
 25142                              <1> 	; Calling sequence:
 25143                              <1> 	;	syslink; name 1; name 2
 25144                              <1> 	; Arguments:
 25145                              <1> 	;	name 1 - file name to which link will be created.
 25146                              <1> 	;	name 2 - name of entry in current directory that
 25147                              <1> 	;		 links to name 1.
 25148                              <1> 	; Inputs: -
 25149                              <1> 	; Outputs: -
 25150                              <1> 	; ...............................................................
 25151                              <1> 	;	
 25152                              <1> 	; Retro UNIX 8086 v1 modification: 
 25153                              <1> 	;       'syslink' system call has two arguments; so,
 25154                              <1> 	;	* 1st argument, name 1 is pointed to by BX register
 25155                              <1> 	;	* 2nd argument, name 2 is pointed to by CX register
 25156                              <1> 	;
 25157                              <1> 		; / name1, name2
 25158                              <1> 		;jsr r0,arg2 / u.namep has 1st arg u.off has 2nd
 25159 000083BC 891D[28B10000]      <1> 	mov	[u.namep], ebx
 25160 000083C2 51                  <1> 	push	ecx
 25161 000083C3 E879060000          <1> 	call	namei
 25162                              <1> 		; jsr r0,namei / find the i-number associated with
 25163                              <1> 			     ; / the 1st path name
 25164                              <1>      	;;and	ax, ax
 25165                              <1> 	;;jz	error ; File not found
 25166                              <1> 	;jc	error 
 25167                              <1> 		; br error9 / cannot be found
 25168 000083C8 730F                <1> 	jnc	short syslink0
 25169                              <1> 	;pop 	ecx
 25170                              <1> 	; 'file not found !' error
 25171 000083CA C705[65B10000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 25172 000083D2 0000                <1>
 25173 000083D4 E9ACF7FFFF          <1> 	jmp	error
 25174                              <1> syslink0:
 25175 000083D9 E8FF0C0000          <1> 	call	iget
 25176                              <1> 		; jsr r0,iget / get the i-node into core
 25177 000083DE 8F05[28B10000]      <1> 	pop	dword [u.namep] ; ecx
 25178                              <1> 		; mov (sp)+,u.namep / u.namep points to 2nd name
 25179 000083E4 6650                <1> 	push	ax
 25180                              <1> 		; mov r1,-(sp) / put i-number of name1 on the stack
 25181                              <1> 			    ; / (a link to this file is to be created)
 25182 000083E6 66FF35[F4B00000]    <1> 	push	word [cdev]
 25183                              <1> 		; mov cdev,-(sp) / put i-nodes device on the stack
 25184 000083ED E855000000          <1> 	call	isdir
 25185                              <1> 		; jsr r0,isdir / is it a directory
 25186 000083F2 E84A060000          <1> 	call	namei
 25187                              <1> 		; jsr r0,namei / no, get i-number of name2
 25188                              <1> 	;jnc	error
 25189                              <1> 		; br .+4   / not found 
 25190                              <1> 			 ; / so r1 = i-number of current directory
 25191                              <1> 			 ; / ii = i-number of current directory
 25192                              <1> 		; br error9 / file already exists., error
 25193 000083F7 720F                <1> 	jc	short syslink1
 25194                              <1> 	; pop ax
 25195                              <1> 	; pop ax
 25196                              <1> 	; 'file exists !' error
 25197 000083F9 C705[65B10000]0E00- <1> 	mov	dword [u.error], ERR_FILE_EXISTS ; 14
 25198 00008401 0000                <1>
 25199 00008403 E97DF7FFFF          <1> 	jmp	error
 25200                              <1> syslink1:
 25201 00008408 6659                <1> 	pop	cx
 25202                              <1> 	;cmp	cx, [cdev]
 25203 0000840A 3A0D[F4B00000]      <1> 	cmp	cl, [cdev]
 25204                              <1> 	;jne	error
 25205                              <1> 		; cmp (sp)+,cdev / u.dirp now points to 
 25206                              <1> 			       ; / end of current directory
 25207                              <1> 	        ; bne error9
 25208 00008410 740F                <1> 	je	short syslink2
 25209                              <1> 	; 'not same drive !' error
 25210 00008412 C705[65B10000]1500- <1> 	mov	dword [u.error],  ERR_DRV_NOT_SAME ; 21
 25211 0000841A 0000                <1>
 25212 0000841C E964F7FFFF          <1> 	jmp	error
 25213                              <1> syslink2:
 25214 00008421 6658                <1> 	pop	ax
 25215 00008423 6650                <1> 	push	ax
 25216 00008425 66A3[42B10000]      <1> 	mov	[u.dirbuf], ax
 25217                              <1> 		; mov (sp),u.dirbuf / i-number of name1 into u.dirbuf
 25218 0000842B E8A8000000          <1> 	call	mkdir
 25219                              <1> 		; jsr r0,mkdir / make directory entry for name2 
 25220                              <1> 		 	     ; / in current directory
 25221 00008430 6658                <1> 	pop	ax
 25222                              <1> 		; mov (sp)+,r1 / r1 has i-number of name1
 25223 00008432 E8A60C0000          <1> 	call	iget
 25224                              <1> 		; jsr r0,iget / get i-node into core
 25225 00008437 FE05[E6AD0000]      <1> 	inc	byte [i.nlks]
 25226                              <1> 		; incb i.nlks / add 1 to its number of links
 25227 0000843D E8A90C0000          <1> 	call	setimod
 25228                              <1> 		; jsr r0,setimod / set the i-node modified flag
 25229 00008442 E95EF7FFFF          <1> 	jmp	sysret
 25230                              <1> 
 25231                              <1> isdir:
 25232                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 25233                              <1> 	; 04/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 25234                              <1> 	;
 25235                              <1> 	; 'isdir' check to see if the i-node whose i-number is in r1
 25236                              <1> 	;  is a directory. If it is, an error occurs, because 'isdir'
 25237                              <1> 	;  called by syslink and sysunlink to make sure directories
 25238                              <1> 	;  are not linked. If the user is the super user (u.uid=0),
 25239                              <1> 	; 'isdir' does not bother checking. The current i-node
 25240                              <1> 	;  is not disturbed.			
 25241                              <1> 	;		
 25242                              <1> 	; INPUTS ->
 25243                              <1> 	;    r1 - contains the i-number whose i-node is being checked.
 25244                              <1> 	;    u.uid - user id
 25245                              <1> 	; OUTPUTS ->
 25246                              <1> 	;    r1 - contains current i-number upon exit
 25247                              <1> 	;    	 (current i-node back in core) 
 25248                              <1> 	;	
 25249                              <1> 	; ((AX = R1))
 25250                              <1> 	;
 25251                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 25252                              <1> 	;
 25253                              <1> 
 25254                              <1> 	; / if the i-node whose i-number is in r1 is a directory 
 25255                              <1> 	; / there is an error unless super user made the call
 25256                              <1> 	
 25257 00008447 803D[5CB10000]00    <1> 	cmp	byte [u.uid], 0 
 25258                              <1> 		; tstb u.uid / super user
 25259 0000844E 762D                <1> 	jna	short isdir1
 25260                              <1> 		; beq 1f / yes, don't care
 25261 00008450 66FF35[F0B00000]    <1> 	push	word [ii]
 25262                              <1> 		; mov ii,-(sp) / put current i-number on stack
 25263 00008457 E8810C0000          <1> 	call	iget
 25264                              <1> 		; jsr r0,iget / get i-node into core (i-number in r1)
 25265 0000845C 66F705[E4AD0000]00- <1> 	test 	word [i.flgs], 4000h ; Bit 14 : Directory flag
 25266 00008464 40                  <1>
 25267                              <1> 		; bit $40000,i.flgs / is it a directory
 25268                              <1> 	;jnz	error
 25269                              <1> 		; bne error9 / yes, error
 25270 00008465 740F                <1> 	jz	short isdir0
 25271 00008467 C705[65B10000]0B00- <1> 	mov 	dword [u.error], ERR_NOT_FILE  ; 11 ; ERR_DIR_ACCESS 
 25272 0000846F 0000                <1>
 25273                              <1> 				; 'permission denied !' error
 25274                              <1> 	; pop	ax
 25275 00008471 E90FF7FFFF          <1> 	jmp	error	
 25276                              <1> isdir0:	
 25277 00008476 6658                <1> 	pop	ax
 25278                              <1> 		; mov (sp)+,r1 / no, put current i-number in r1 (ii)
 25279 00008478 E8600C0000          <1> 	call	iget
 25280                              <1> 		; jsr r0,iget / get it back in
 25281                              <1> isdir1: ; 1:
 25282 0000847D C3                  <1> 	retn
 25283                              <1> 		; rts r0
 25284                              <1> 
 25285                              <1> sysunlink:
 25286                              <1> 	; 04/12/2015 (14 byte file names)
 25287                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 25288                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 25289                              <1> 	;
 25290                              <1> 	; 'sysunlink' removes the entry for the file pointed to by
 25291                              <1> 	; name from its directory. If this entry was the last link
 25292                              <1> 	; to the file, the contents of the file are freed and the
 25293                              <1> 	; file is destroyed. If, however, the file was open in any
 25294                              <1> 	; process, the actual destruction is delayed until it is 
 25295                              <1> 	; closed, even though the directory entry has disappeared.
 25296                              <1> 	; 
 25297                              <1> 	; The error bit (e-bit) is set to indicate that the file	
 25298                              <1> 	; does not exist or that its directory can not be written.
 25299                              <1> 	; Write permission is not required on the file itself.
 25300                              <1> 	; It is also illegal to unlink a directory (except for
 25301                              <1> 	; the superuser).
 25302                              <1> 	;
 25303                              <1> 	; Calling sequence:
 25304                              <1> 	;	sysunlink; name
 25305                              <1> 	; Arguments:
 25306                              <1> 	;	name - name of directory entry to be removed 
 25307                              <1> 	; Inputs: -
 25308                              <1> 	; Outputs: -
 25309                              <1> 	; ...............................................................
 25310                              <1> 	;				
 25311                              <1> 	; Retro UNIX 8086 v1 modification:
 25312                              <1> 	;	 The user/application program puts address of the name
 25313                              <1> 	;        in BX register as 'sysunlink' system call argument.
 25314                              <1> 
 25315                              <1> 	; / name - remove link name
 25316 0000847E 891D[28B10000]      <1> 	mov	[u.namep], ebx
 25317                              <1> 		;jsr r0,arg; u.namep / u.namep points to name
 25318 00008484 E8B8050000          <1> 	call	namei
 25319                              <1> 		; jsr r0,namei / find the i-number associated 
 25320                              <1> 			     ; / with the path name
 25321                              <1> 	;jc	error
 25322                              <1> 		; br error9 / not found
 25323 00008489 730F                <1> 	jnc	short sysunlink1
 25324                              <1> 	; 'file not found !' error
 25325 0000848B C705[65B10000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 25326 00008493 0000                <1>
 25327 00008495 E9EBF6FFFF          <1> 	jmp	error
 25328                              <1> sysunlink1:
 25329 0000849A 6650                <1> 	push	ax
 25330                              <1> 		; mov r1,-(sp) / put its i-number on the stack
 25331 0000849C E8A6FFFFFF          <1> 	call	isdir
 25332                              <1> 		; jsr r0,isdir / is it a directory
 25333 000084A1 6631C0              <1> 	xor 	ax, ax
 25334 000084A4 66A3[42B10000]      <1> 	mov	[u.dirbuf], ax ; 0
 25335                              <1> 		; clr u.dirbuf / no, clear the location that will
 25336                              <1> 			   ; / get written into the i-number portion
 25337                              <1> 			 ; / of the entry
 25338 000084AA 832D[2CB10000]10    <1> 	sub	dword [u.off], 16 ; 04/12/2015 (10 -> 16) 
 25339                              <1> 		; sub $10.,u.off / move u.off back 1 directory entry
 25340 000084B1 E86E000000          <1> 	call	wdir
 25341                              <1> 		; jsr r0,wdir / free the directory entry
 25342 000084B6 6658                <1> 	pop	ax
 25343                              <1> 		; mov (sp)+,r1 / get i-number back
 25344 000084B8 E8200C0000          <1> 	call	iget
 25345                              <1> 		; jsr r0,iget / get i-node
 25346 000084BD E8290C0000          <1> 	call	setimod
 25347                              <1> 		; jsr r0,setimod / set modified flag
 25348 000084C2 FE0D[E6AD0000]      <1> 	dec	byte [i.nlks]
 25349                              <1> 		; decb i.nlks / decrement the number of links
 25350 000084C8 0F85D7F6FFFF        <1> 	jnz	sysret
 25351                              <1> 		; bgt sysret9 / if this was not the last link
 25352                              <1> 			    ; / to file return
 25353                              <1> 	; AX = r1 = i-number
 25354 000084CE E893090000          <1> 	call	anyi
 25355                              <1> 		; jsr r0,anyi / if it was, see if anyone has it open.
 25356                              <1> 			 ; / Then free contents of file and destroy it.
 25357 000084D3 E9CDF6FFFF          <1> 	jmp	sysret
 25358                              <1> 		; br sysret9
 25359                              <1> 
 25360                              <1> mkdir:
 25361                              <1> 	; 04/12/2015 (14 byte directory names)
 25362                              <1> 	; 12/10/2015
 25363                              <1> 	; 17/06/2015 (Retro UNIX 386 v1 - Beginning)
 25364                              <1> 	; 29/04/2013 - 01/08/2013 (Retro UNIX 8086 v1)
 25365                              <1> 	;
 25366                              <1> 	; 'mkdir' makes a directory entry from the name pointed to
 25367                              <1> 	; by u.namep into the current directory.
 25368                              <1> 	;
 25369                              <1> 	; INPUTS ->
 25370                              <1> 	;    u.namep - points to a file name 
 25371                              <1> 	;	           that is about to be a directory entry.
 25372                              <1> 	;    ii - current directory's i-number.	
 25373                              <1> 	; OUTPUTS ->
 25374                              <1> 	;    u.dirbuf+2 - u.dirbuf+10 - contains file name. 
 25375                              <1> 	;    u.off - points to entry to be filled 
 25376                              <1> 	;	     in the current directory		
 25377                              <1> 	;    u.base - points to start of u.dirbuf.
 25378                              <1> 	;    r1 - contains i-number of current directory 
 25379                              <1> 	;	
 25380                              <1> 	; ((AX = R1)) output
 25381                              <1> 	;
 25382                              <1> 	;    (Retro UNIX Prototype : 11/11/2012, UNIXCOPY.ASM)
 25383                              <1>         ;    ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 25384                              <1> 	;
 25385                              <1> 
 25386                              <1> 	; 17/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 25387 000084D8 31C0                <1> 	xor 	eax, eax
 25388 000084DA BF[44B10000]        <1> 	mov     edi, u.dirbuf+2
 25389 000084DF 89FE                <1> 	mov	esi, edi
 25390 000084E1 AB                  <1> 	stosd
 25391 000084E2 AB                  <1> 	stosd
 25392                              <1> 	; 04/12/2015 (14 byte directory names)
 25393 000084E3 AB                  <1> 	stosd
 25394 000084E4 66AB                <1> 	stosw
 25395                              <1> 		; jsr r0,copyz; u.dirbuf+2; u.dirbuf+10. / clear this
 25396 000084E6 89F7                <1> 	mov	edi, esi ; offset to u.dirbuf
 25397                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 25398                              <1> 	;mov 	ebp, [u.namep]
 25399 000084E8 E899060000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
 25400                              <1> 		; esi = physical address (page start + offset)
 25401                              <1> 		; ecx = byte count in the page (1 - 4096)
 25402                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 25403                              <1> 		; mov u.namep,r2 / r2 points to name of directory entry
 25404                              <1> 		; mov $u.dirbuf+2,r3 / r3 points to u.dirbuf+2
 25405                              <1> mkdir_1: ; 1: 
 25406 000084ED 45                  <1> 	inc	ebp ; 12/10/2015
 25407                              <1> 	;
 25408                              <1> 	; / put characters in the directory name in u.dirbuf+2 - u.dirbuf+10
 25409                              <1> 	 ; 01/08/2013
 25410 000084EE AC                  <1> 	lodsb
 25411                              <1> 		; movb (r2)+,r1 / move character in name to r1
 25412 000084EF 20C0                <1> 	and 	al, al
 25413 000084F1 7427                <1> 	jz 	short mkdir_3 	  
 25414                              <1> 		; beq 1f / if null, done
 25415 000084F3 3C2F                <1> 	cmp	al, '/'
 25416                              <1> 		; cmp r1,$'/ / is it a "/"?
 25417 000084F5 7414                <1> 	je	short mkdir_err
 25418                              <1> 	;je	error
 25419                              <1> 		; beq error9 / yes, error
 25420                              <1> 	; 12/10/2015
 25421 000084F7 6649                <1> 	dec	cx
 25422 000084F9 7505                <1> 	jnz	short mkdir_2
 25423                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 25424 000084FB E88C060000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 25425                              <1> 		; esi = physical address (page start + offset)
 25426                              <1> 		; ecx = byte count in the page
 25427                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 25428                              <1> mkdir_2:
 25429 00008500 81FF[52B10000]      <1> 	cmp     edi, u.dirbuf+16 ; ; 04/12/2015 (10 -> 16) 
 25430                              <1> 		; cmp r3,$u.dirbuf+10. / have we reached the last slot for
 25431                              <1> 				     ; / a char?
 25432 00008506 74E5                <1> 	je	short mkdir_1
 25433                              <1> 		; beq 1b / yes, go back
 25434 00008508 AA                  <1> 	stosb
 25435                              <1> 		; movb r1,(r3)+ / no, put the char in the u.dirbuf
 25436 00008509 EBE2                <1> 	jmp 	short mkdir_1
 25437                              <1> 		; br 1b / get next char
 25438                              <1> mkdir_err:
 25439                              <1> 	; 17/06/2015
 25440 0000850B C705[65B10000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
 25441 00008513 0000                <1>
 25442 00008515 E96BF6FFFF          <1> 	jmp	error
 25443                              <1> 
 25444                              <1> mkdir_3: ; 1:
 25445 0000851A A1[24B10000]        <1> 	mov	eax, [u.dirp]
 25446 0000851F A3[2CB10000]        <1> 	mov	[u.off], eax
 25447                              <1> 		; mov u.dirp,u.off / pointer to empty current directory
 25448                              <1> 				 ; / slot to u.off
 25449                              <1> wdir: ; 29/04/2013
 25450 00008524 C705[30B10000]-     <1>         mov     dword [u.base], u.dirbuf
 25451 0000852A [42B10000]          <1>
 25452                              <1> 		; mov $u.dirbuf,u.base / u.base points to created file name
 25453 0000852E C705[34B10000]1000- <1>         mov     dword [u.count], 16 ; 04/12/2015 (10 -> 16) 
 25454 00008536 0000                <1>
 25455                              <1> 		; mov $10.,u.count / u.count = 10
 25456 00008538 66A1[F0B00000]      <1> 	mov	ax, [ii] 
 25457                              <1> 		; mov ii,r1 / r1 has i-number of current directory
 25458 0000853E B201                <1> 	mov	dl, 1 ; owner flag mask ; RETRO UNIX 8086 v1 modification !
 25459 00008540 E8AA0B0000          <1> 	call 	access
 25460                              <1> 		; jsr r0,access; 1 / get i-node and set its file up 
 25461                              <1> 				 ; / for writing
 25462                              <1> 	; AX = i-number of current directory
 25463                              <1> 	; 01/08/2013
 25464 00008545 FE05[77B10000]      <1> 	inc     byte [u.kcall] ; the caller is 'mkdir' sign	
 25465 0000854B E8910B0000          <1> 	call	writei
 25466                              <1> 		; jsr r0,writei / write into directory
 25467 00008550 C3                  <1> 	retn	
 25468                              <1> 		; rts r0
 25469                              <1> 
 25470                              <1> sysexec:
 25471                              <1> 	; 23/10/2015
 25472                              <1> 	; 19/10/2015
 25473                              <1> 	; 18/10/2015
 25474                              <1> 	; 10/10/2015
 25475                              <1> 	; 26/08/2015
 25476                              <1> 	; 05/08/2015
 25477                              <1> 	; 29/07/2015
 25478                              <1> 	; 25/07/2015
 25479                              <1> 	; 24/07/2015
 25480                              <1> 	; 21/07/2015
 25481                              <1> 	; 20/07/2015
 25482                              <1> 	; 02/07/2015
 25483                              <1> 	; 01/07/2015
 25484                              <1> 	; 25/06/2015
 25485                              <1> 	; 24/06/2015
 25486                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 25487                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
 25488                              <1> 	;
 25489                              <1> 	; 'sysexec' initiates execution of a file whose path name if
 25490                              <1> 	; pointed to by 'name' in the sysexec call. 
 25491                              <1> 	; 'sysexec' performs the following operations:
 25492                              <1> 	;    1. obtains i-number of file to be executed via 'namei'.
 25493                              <1> 	;    2. obtains i-node of file to be exceuted via 'iget'.
 25494                              <1> 	;    3. sets trap vectors to system routines.
 25495                              <1> 	;    4. loads arguments to be passed to executing file into
 25496                              <1> 	;	highest locations of user's core
 25497                              <1> 	;    5. puts pointers to arguments in locations immediately
 25498                              <1> 	;	following arguments.
 25499                              <1> 	;    6.	saves number of arguments in next location.
 25500                              <1> 	;    7. intializes user's stack area so that all registers
 25501                              <1> 	;	will be zeroed and the PS is cleared and the PC set
 25502                              <1> 	;	to core when 'sysret' restores registers 
 25503                              <1> 	;	and does an rti.
 25504                              <1> 	;    8. inializes u.r0 and u.sp
 25505                              <1> 	;    9. zeros user's core down to u.r0
 25506                              <1> 	;   10.	reads executable file from storage device into core
 25507                              <1> 	;	starting at location 'core'.
 25508                              <1> 	;   11.	sets u.break to point to end of user's code with
 25509                              <1> 	;	data area appended.
 25510                              <1> 	;   12.	calls 'sysret' which returns control at location
 25511                              <1> 	;	'core' via 'rti' instruction. 		  		
 25512                              <1> 	;
 25513                              <1> 	; Calling sequence:
 25514                              <1> 	;	sysexec; namep; argp
 25515                              <1> 	; Arguments:
 25516                              <1> 	;	namep - points to pathname of file to be executed
 25517                              <1> 	;	argp  - address of table of argument pointers
 25518                              <1> 	;	argp1... argpn - table of argument pointers
 25519                              <1> 	;	argp1:<...0> ... argpn:<...0> - argument strings
 25520                              <1> 	; Inputs: (arguments)
 25521                              <1> 	; Outputs: -	
 25522                              <1> 	; ...............................................................
 25523                              <1> 	;
 25524                              <1> 	; Retro UNIX 386 v1 modification: 
 25525                              <1> 	;	User application runs in it's own virtual space 
 25526                              <1> 	;	which is izolated from kernel memory (and other
 25527                              <1> 	;	memory pages) via 80386	paging in ring 3 
 25528                              <1> 	;	privilige mode. Virtual start address is always 0.
 25529                              <1> 	;	User's core memory starts at linear address 400000h
 25530                              <1> 	;	(the end of the 1st 4MB).
 25531                              <1> 	;
 25532                              <1> 	; Retro UNIX 8086 v1 modification: 
 25533                              <1> 	;	user/application segment and system/kernel segment
 25534                              <1> 	;	are different and sysenter/sysret/sysrele routines
 25535                              <1> 	;	are different (user's registers are saved to 
 25536                              <1> 	;	and then restored from system's stack.)
 25537                              <1> 	;
 25538                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
 25539                              <1> 	;	      arguments which were in these registers;
 25540                              <1> 	;	      but, it returns by putting the 1st argument
 25541                              <1> 	;	      in 'u.namep' and the 2nd argument
 25542                              <1> 	;	      on top of stack. (1st argument is offset of the
 25543                              <1> 	;	      file/path name in the user's program segment.)		 	
 25544                              <1> 	
 25545                              <1> 	;call	arg2
 25546                              <1> 	; * name - 'u.namep' points to address of file/path name
 25547                              <1> 	;          in the user's program segment ('u.segmnt')
 25548                              <1> 	;          with offset in BX register (as sysopen argument 1).
 25549                              <1> 	; * argp - sysexec argument 2 is in CX register 
 25550                              <1> 	;          which is on top of stack.
 25551                              <1> 	;
 25552                              <1> 		; jsr r0,arg2 / arg0 in u.namep,arg1 on top of stack
 25553                              <1> 
 25554                              <1> 	; 23/06/2015 (32 bit modifications)
 25555                              <1> 
 25556 00008551 891D[28B10000]      <1> 	mov	[u.namep], ebx ; argument 1
 25557                              <1>         ; 18/10/2015
 25558 00008557 890D[90B10000]      <1> 	mov     [argv], ecx  ; * ; argument 2
 25559 0000855D E8DF040000          <1> 	call	namei
 25560                              <1> 		; jsr r0,namei / namei returns i-number of file 
 25561                              <1> 			     ; / named in sysexec call in r1
 25562                              <1> 	;jc	error
 25563                              <1> 		; br error9
 25564 00008562 731E                <1> 	jnc	short sysexec_0
 25565                              <1> 	;
 25566                              <1> 	; 'file not found !' error
 25567 00008564 C705[65B10000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND
 25568 0000856C 0000                <1>
 25569 0000856E E912F6FFFF          <1> 	jmp	error 
 25570                              <1> sysexec_not_exf:
 25571                              <1> 	; 'not executable file !' error
 25572 00008573 C705[65B10000]1600- <1> 	mov	dword [u.error], ERR_NOT_EXECUTABLE
 25573 0000857B 0000                <1>
 25574 0000857D E903F6FFFF          <1> 	jmp	error 
 25575                              <1> sysexec_0:
 25576 00008582 E8560B0000          <1> 	call	iget
 25577                              <1> 		; jsr r0,iget / get i-node for file to be executed
 25578 00008587 66F705[E4AD0000]10- <1>         test    word [i.flgs], 10h
 25579 0000858F 00                  <1>
 25580                              <1> 		; bit $20,i.flgs / is file executable
 25581 00008590 74E1                <1> 	jz	short sysexec_not_exf
 25582                              <1> 	;jz	error
 25583                              <1> 		; beq error9
 25584                              <1> 	;;
 25585 00008592 E8500B0000          <1> 	call	iopen
 25586                              <1> 		; jsr r0,iopen / gets i-node for file with i-number
 25587                              <1> 			     ; / given in r1 (opens file)
 25588                              <1> 	; AX = i-number of the file
 25589 00008597 66F705[E4AD0000]20- <1> 	test	word [i.flgs], 20h
 25590 0000859F 00                  <1>
 25591                              <1> 		; bit $40,i.flgs / test user id on execution bit
 25592 000085A0 7415                <1> 	jz	short sysexec_1
 25593                              <1> 		; beq 1f
 25594 000085A2 803D[5CB10000]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013
 25595                              <1> 		; tstb u.uid / test user id
 25596 000085A9 760C                <1> 	jna	short sysexec_1
 25597                              <1> 		; beq 1f / super user
 25598 000085AB 8A0D[E7AD0000]      <1> 	mov	cl, [i.uid]
 25599 000085B1 880D[5CB10000]      <1> 	mov	[u.uid], cl ; 02/08/2013
 25600                              <1> 		; movb i.uid,u.uid / put user id of owner of file
 25601                              <1> 				 ; / as process user id
 25602                              <1> sysexec_1:
 25603                              <1> 	; 18/10/2215
 25604                              <1> 	; 10/10/2015
 25605                              <1> 	; 24/07/2015
 25606                              <1> 	; 21/07/2015
 25607                              <1> 	; 25/06/2015
 25608                              <1> 	; 24/06/2015
 25609                              <1>         ; Moving arguments to the end of [u.upage]
 25610                              <1> 	; (by regarding page borders in user's memory space)
 25611                              <1> 	;
 25612                              <1> 	; 10/10/2015
 25613                              <1> 	; 21/07/2015
 25614 000085B7 89E5                <1> 	mov	ebp, esp ; (**)
 25615                              <1> 	; 18/10/2015
 25616 000085B9 89EF                <1> 	mov 	edi, ebp
 25617 000085BB B900010000          <1> 	mov 	ecx, MAX_ARG_LEN ; 256
 25618                              <1> 	;sub	edi, MAX_ARG_LEN ; 256
 25619 000085C0 29CF                <1> 	sub	edi, ecx
 25620 000085C2 89FC                <1> 	mov	esp, edi
 25621 000085C4 31C0                <1> 	xor	eax, eax
 25622 000085C6 A3[38B10000]        <1> 	mov 	[u.nread], eax ; 0
 25623 000085CB 49                  <1> 	dec	ecx ; 256 - 1
 25624 000085CC 890D[34B10000]      <1> 	mov 	[u.count], ecx ; MAX_ARG_LEN - 1 ; 255
 25625                              <1> 	;mov 	dword [u.count], MAX_ARG_LEN - 1 ; 255
 25626                              <1> sysexec_2:
 25627 000085D2 8B35[90B10000]      <1> 	mov	esi, [argv] ; 18/10/2015 
 25628 000085D8 E873020000          <1> 	call	get_argp
 25629 000085DD B904000000          <1> 	mov	ecx, 4 ; mov ecx, 4
 25630                              <1> sysexec_3:
 25631 000085E2 21C0                <1> 	and	eax, eax
 25632 000085E4 7456                <1> 	jz	short sysexec_6
 25633                              <1> 	; 18/10/2015
 25634 000085E6 010D[90B10000]      <1> 	add	[argv], ecx ; 4
 25635 000085EC 66FF05[8EB10000]    <1> 	inc	word [argc]
 25636                              <1> 	;
 25637 000085F3 A3[30B10000]        <1> 	mov	[u.base], eax
 25638                              <1>  	; 23/10/2015
 25639 000085F8 66C705[75B10000]00- <1> 	mov	word [u.pcount], 0
 25640 00008600 00                  <1>
 25641                              <1> sysexec_4:
 25642 00008601 E8EA0A0000          <1> 	call	cpass ; get a character from user's core memory
 25643 00008606 750B                <1>         jnz      short sysexec_5
 25644                              <1> 		; (max. 255 chars + null)
 25645                              <1> 	; 18/10/2015
 25646 00008608 28C0                <1> 	sub 	al, al
 25647 0000860A AA                  <1> 	stosb
 25648 0000860B FF05[38B10000]      <1> 	inc	dword [u.nread]
 25649 00008611 EB29                <1> 	jmp	short sysexec_6
 25650                              <1> sysexec_5:
 25651 00008613 AA                  <1> 	stosb
 25652 00008614 20C0                <1> 	and 	al, al
 25653 00008616 75E9                <1> 	jnz	short sysexec_4
 25654 00008618 B904000000          <1> 	mov	ecx, 4
 25655 0000861D 390D[8CB10000]      <1> 	cmp	[ncount], ecx ; 4
 25656 00008623 72AD                <1> 	jb	short sysexec_2
 25657 00008625 8B35[88B10000]      <1> 	mov	esi, [nbase]
 25658 0000862B 010D[88B10000]      <1> 	add	[nbase], ecx ; 4	
 25659 00008631 66290D[8CB10000]    <1> 	sub	[ncount], cx 
 25660 00008638 8B06                <1> 	mov	eax, [esi]
 25661 0000863A EBA6                <1> 	jmp	short sysexec_3
 25662                              <1> sysexec_6:
 25663                              <1> 	; 18/10/2015
 25664                              <1> 	; argument list transfer from user's core memory to
 25665                              <1> 	; kernel stack frame is OK here.
 25666                              <1> 	; [u.nread] = ; argument list length
 25667                              <1> 	;mov	[argv], esp ; start address of argument list 	
 25668                              <1> 	;
 25669                              <1> 	; 18/10/2015
 25670                              <1> 	; 24/07/2015
 25671                              <1>         ; 21/07/2015
 25672                              <1> 	; 02/07/2015
 25673                              <1> 	; 25/06/2015
 25674                              <1> 	; 24/06/2015
 25675                              <1> 	; 23/06/2015
 25676                              <1> 	;
 25677 0000863C 8B1D[6DB10000]      <1> 	mov	ebx, [u.ppgdir] ; parent's page directory
 25678 00008642 21DB                <1> 	and 	ebx, ebx  ; /etc/init ? (u.ppgdir = 0)	
 25679 00008644 740A                <1> 	jz	short sysexec_7
 25680 00008646 A1[69B10000]        <1> 	mov	eax, [u.pgdir] ; physical address of page directory
 25681 0000864B E8F0ABFFFF          <1> 	call	deallocate_page_dir
 25682                              <1> sysexec_7:
 25683 00008650 E820ABFFFF          <1> 	call	make_page_dir
 25684                              <1> 	;jc	short sysexec_14
 25685 00008655 0F8232B6FFFF        <1> 	jc	panic  ; allocation error 
 25686                              <1> 		       ; after a deallocation would be nonsence !?
 25687                              <1> 	; 24/07/2015
 25688                              <1> 	; map kernel pages (1st 4MB) to PDE 0
 25689                              <1> 	;     of the user's page directory
 25690                              <1> 	;     (It is needed for interrupts!)
 25691                              <1> 	; 18/10/2015
 25692 0000865B 8B15[48A20000]      <1> 	mov	edx, [k_page_dir] ; Kernel's page directory
 25693 00008661 8B02                <1> 	mov	eax, [edx] ; physical address of
 25694                              <1> 			   ; kernel's first page table (1st 4 MB)
 25695                              <1> 			   ; (PDE 0 of kernel's page directory)
 25696 00008663 8B15[69B10000]      <1> 	mov 	edx, [u.pgdir]
 25697 00008669 8902                <1> 	mov	[edx], eax ; PDE 0 (1st 4MB)
 25698                              <1> 	;
 25699                              <1> 	; 20/07/2015
 25700 0000866B BB00004000          <1> 	mov	ebx, CORE ; start address = 0 (virtual) + CORE
 25701                              <1> 	; 18/10/2015
 25702 00008670 BE[80B10000]        <1> 	mov	esi, pcore ; physical start address
 25703                              <1> sysexec_8:	
 25704 00008675 B907000000          <1> 	mov	ecx, PDE_A_USER + PDE_A_WRITE + PDE_A_PRESENT
 25705 0000867A E814ABFFFF          <1> 	call	make_page_table
 25706 0000867F 0F8208B6FFFF        <1> 	jc	panic
 25707                              <1> 	;mov	ecx, PTE_A_USER + PTE_A_WRITE + PTE_A_PRESENT
 25708 00008685 E817ABFFFF          <1> 	call	make_page ; make new page, clear and set the pte 
 25709 0000868A 0F82FDB5FFFF        <1> 	jc	panic
 25710                              <1> 	;
 25711 00008690 8906                <1> 	mov	[esi], eax ; 24/06/2015
 25712                              <1> 	; ebx = virtual address (24/07/2015)
 25713 00008692 E82DB0FFFF          <1> 	call 	add_to_swap_queue
 25714                              <1> 	; 18/10/2015
 25715 00008697 81FE[84B10000]      <1> 	cmp	esi, ecore ; user's stack (last) page ?
 25716 0000869D 740C                <1> 	je	short sysexec_9 ; yes
 25717 0000869F BE[84B10000]        <1> 	mov	esi, ecore  ; physical address of the last page 
 25718                              <1> 	; 20/07/2015
 25719 000086A4 BB00F0FFFF          <1> 	mov	ebx, (ECORE - PAGE_SIZE) + CORE
 25720                              <1> 	; ebx = virtual end address + segment base address - 4K
 25721 000086A9 EBCA                <1>         jmp     short sysexec_8
 25722                              <1> 
 25723                              <1> sysexec_9:
 25724                              <1> 	; 18/10/2015
 25725                              <1> 	; 26/08/2015
 25726                              <1> 	; 25/06/2015
 25727                              <1> 	; move arguments from kernel stack to [ecore]
 25728                              <1> 	; (argument list/line will be copied from kernel stack
 25729                              <1> 	; frame to the last (stack) page of user's core memory)
 25730                              <1> 	; 18/10/2015
 25731 000086AB 8B3D[84B10000]      <1> 	mov	edi, [ecore]
 25732 000086B1 81C700100000        <1> 	add	edi, PAGE_SIZE
 25733 000086B7 0FB705[8EB10000]    <1> 	movzx	eax, word [argc]
 25734 000086BE 09C0                <1> 	or	eax, eax
 25735 000086C0 7509                <1> 	jnz	short sysexec_10
 25736 000086C2 89FB                <1> 	mov 	ebx, edi
 25737 000086C4 83EB04              <1> 	sub	ebx, 4 
 25738 000086C7 8903                <1> 	mov	[ebx], eax ; 0
 25739 000086C9 EB40                <1> 	jmp 	short sysexec_13
 25740                              <1> sysexec_10:
 25741 000086CB 8B0D[38B10000]      <1> 	mov	ecx, [u.nread]
 25742                              <1> 	;mov 	esi, [argv}
 25743 000086D1 89E6                <1> 	mov	esi, esp ; start address of argument list
 25744 000086D3 29CF                <1> 	sub	edi, ecx ; page end address - argument list length
 25745 000086D5 89C2                <1> 	mov	edx, eax
 25746 000086D7 FEC2                <1> 	inc	dl ; argument count + 1 for argc value  
 25747 000086D9 C0E202              <1> 	shl 	dl, 2  ; 4 * (argument count + 1)
 25748 000086DC 89FB                <1> 	mov	ebx, edi
 25749 000086DE 80E3FC              <1> 	and	bl, 0FCh ; 32 bit (dword) alignment
 25750 000086E1 29D3                <1> 	sub 	ebx, edx
 25751 000086E3 89FA                <1> 	mov	edx, edi
 25752 000086E5 F3A4                <1> 	rep	movsb
 25753 000086E7 89D6                <1> 	mov 	esi, edx
 25754 000086E9 89DF                <1> 	mov 	edi, ebx
 25755 000086EB BA00F0BFFF          <1> 	mov	edx, ECORE - PAGE_SIZE ; virtual addr. of the last page
 25756 000086F0 2B15[84B10000]      <1> 	sub 	edx, [ecore] ; difference (virtual - physical) 
 25757 000086F6 AB                  <1> 	stosd	; eax = argument count	
 25758                              <1> sysexec_11:
 25759 000086F7 89F0                <1> 	mov	eax, esi
 25760 000086F9 01D0                <1> 	add	eax, edx
 25761 000086FB AB                  <1> 	stosd  ; eax = virtual address
 25762 000086FC FE0D[8EB10000]      <1> 	dec	byte [argc]
 25763 00008702 7407                <1> 	jz	short sysexec_13
 25764                              <1> sysexec_12:
 25765 00008704 AC                  <1> 	lodsb
 25766 00008705 20C0                <1> 	and	al, al
 25767 00008707 75FB                <1> 	jnz	short sysexec_12
 25768 00008709 EBEC                <1> 	jmp	short sysexec_11
 25769                              <1> 	;
 25770                              <1> 	; 1:
 25771                              <1> 		; mov (sp)+,r5 / r5 now contains address of list of 
 25772                              <1> 			     ; / pointers to arguments to be passed
 25773                              <1> 		; mov $1,u.quit / u.quit determines handling of quits;
 25774                              <1> 			      ; / u.quit = 1 take quit
 25775                              <1> 		; mov $1,u.intr / u.intr determines handling of 
 25776                              <1> 			     ; / interrupts; u.intr = 1 take interrupt
 25777                              <1> 		; mov $rtssym,30 / emt trap vector set to take 
 25778                              <1> 			       ; / system routine
 25779                              <1> 		; mov $fpsym,*10 / reserved instruction trap vector 
 25780                              <1> 			       ; / set to take system routine
 25781                              <1> 		; mov $sstack,sp / stack space used during swapping
 25782                              <1> 		; mov r5,-(sp) / save arguments pointer on stack
 25783                              <1> 		; mov $ecore,r5 / r5 has end of core
 25784                              <1> 		; mov $core,r4 / r4 has start of users core
 25785                              <1> 		; mov r4,u.base / u.base has start of users core
 25786                              <1> 		; mov (sp),r2 / move arguments list pointer into r2
 25787                              <1> 	; 1:
 25788                              <1> 		; tst (r2)+ / argument char = "nul"
 25789                              <1> 		; bne 1b
 25790                              <1> 		; tst -(r2) / decrement r2 by 2; r2 has addr of 
 25791                              <1> 			  ; / end of argument pointer list
 25792                              <1> 	; 1:
 25793                              <1> 	     ; / move arguments to bottom of users core
 25794                              <1> 		; mov -(r2),r3 / (r3) last non zero argument ptr
 25795                              <1> 		; cmp r2,(sp) / is r2 = beginning of argument
 25796                              <1> 			    ; / ptr list
 25797                              <1> 		; blo 1f / branch to 1f when all arguments
 25798                              <1> 		       ; / are moved
 25799                              <1> 		; mov -(r2),r3 / (r3) last non zero argument ptr
 25800                              <1> 	; 2:
 25801                              <1> 		; tstb (r3)+
 25802                              <1> 		; bne 2b / scan argument for \0 (nul)
 25803                              <1> 
 25804                              <1> 	; 2:
 25805                              <1> 		; movb -(r3),-(r5) / move argument char 
 25806                              <1> 				 ; / by char starting at "ecore"
 25807                              <1> 		; cmp r3,(r2) / moved all characters in 
 25808                              <1> 			    ; / this argument
 25809                              <1> 		; bhi 2b / branch 2b if not
 25810                              <1> 		; mov r5,(r4)+ / move r5 into top of users core;
 25811                              <1> 			     ; / r5 has pointer to nth arg
 25812                              <1> 		; br 1b / string
 25813                              <1> 	; 1:
 25814                              <1> 		; clrb -(r5)
 25815                              <1> 		; bic $1,r5 / make r5 even, r5 points to 
 25816                              <1> 			; / last word of argument strings
 25817                              <1> 		; mov $core,r2
 25818                              <1> 	
 25819                              <1> 	; 1: / move argument pointers into core following 
 25820                              <1> 	      ; / argument strings
 25821                              <1> 		; cmp r2,r4
 25822                              <1> 		; bhis 1f / branch to 1f when all pointers
 25823                              <1> 			; / are moved
 25824                              <1> 		; mov (r2)+,-(r5)
 25825                              <1> 		; br 1b
 25826                              <1> 	; 1:
 25827                              <1> 		; sub $core,r4 / gives number of arguments *2
 25828                              <1> 		; asr r4 / divide r4 by 2 to calculate 
 25829                              <1> 		       ; / the number of args stored
 25830                              <1> 		; mov r4,-(r5) / save number of arguments ahead
 25831                              <1> 			     ; / of the argument pointers
 25832                              <1> sysexec_13:
 25833                              <1> 	; 19/10/2015
 25834                              <1> 	; 18/10/2015
 25835                              <1> 	; 29/07/2015
 25836                              <1> 	; 25/07/2015
 25837                              <1> 	; 24/07/2015
 25838                              <1> 	; 20/07/2015
 25839                              <1> 	; 25/06/2015
 25840                              <1> 	; 24/06/2015
 25841                              <1> 	; 23/06/2015
 25842                              <1> 	;
 25843                              <1> 	; moving arguments to [ecore] is OK here..
 25844                              <1> 	; 18/10/2015
 25845 0000870B 89EC                <1> 	mov 	esp, ebp ; (**) restore kernel stack pointer
 25846                              <1> 	; ebx = beginning addres of argument list pointers
 25847                              <1> 	;	in user's stack
 25848                              <1> 	; 19/10/2015
 25849 0000870D 2B1D[84B10000]      <1> 	sub 	ebx, [ecore]
 25850 00008713 81C300F0BFFF        <1> 	add     ebx, (ECORE - PAGE_SIZE)
 25851                              <1> 			; end of core - 4096 (last page)
 25852                              <1> 			; (virtual address)
 25853 00008719 891D[90B10000]      <1> 	mov	[argv], ebx
 25854 0000871F 891D[3CB10000]      <1> 	mov	[u.break], ebx ; available user memory
 25855                              <1> 	;
 25856 00008725 29C0                <1> 	sub	eax, eax
 25857 00008727 C705[34B10000]2000- <1> 	mov	dword [u.count], 32 ; Executable file header size
 25858 0000872F 0000                <1>
 25859                              <1> 		; mov $14,u.count
 25860 00008731 C705[20B10000]-     <1> 	mov	dword [u.fofp], u.off
 25861 00008737 [2CB10000]          <1>
 25862                              <1> 		; mov $u.off,u.fofp
 25863 0000873B A3[2CB10000]        <1> 	mov	[u.off], eax ; 0
 25864                              <1> 		; clr u.off / set offset in file to be read to zero
 25865                              <1> 	; 25/07/2015
 25866 00008740 A3[30B10000]        <1> 	mov	[u.base], eax ; 0, start of user's core (virtual)
 25867                              <1> 	; 25/06/2015 
 25868 00008745 66A1[F0B00000]      <1> 	mov	ax, [ii]
 25869                              <1> 	; AX = i-number of the executable file
 25870 0000874B E892090000          <1> 	call	readi
 25871                              <1> 		; jsr r0,readi / read in first six words of 
 25872                              <1> 			; / user's file, starting at $core
 25873                              <1> 		; mov sp,r5 / put users stack address in r5
 25874                              <1> 		; sub $core+40.,r5 / subtract $core +40, 
 25875                              <1> 				; / from r5 (leaves number of words
 25876                              <1> 				; / less 26 available for
 25877                              <1> 			     	; / program in user core
 25878                              <1> 		; mov r5,u.count /
 25879                              <1> 	; 25/06/2015
 25880 00008750 8B0D[3CB10000]      <1> 	mov	ecx, [u.break] ; top of user's stack (physical addr.)
 25881 00008756 890D[34B10000]      <1> 	mov	[u.count], ecx ; save for overrun check
 25882                              <1> 	;
 25883 0000875C 8B0D[38B10000]      <1> 	mov	ecx, [u.nread]
 25884 00008762 890D[3CB10000]      <1> 	mov	[u.break], ecx ; virtual address (offset from start)
 25885 00008768 80F920              <1> 	cmp	cl, 32
 25886 0000876B 7540                <1>         jne     short sysexec_15
 25887                              <1> 	;:
 25888                              <1> 	; 25/06/2015
 25889                              <1> 	; Retro UNIX 386 v1 (32 bit) executable file header format
 25890                              <1> 	; 18/10/2015
 25891 0000876D 8B35[80B10000]      <1> 	mov	esi, [pcore] ; start address of user's core memory 
 25892                              <1> 		             ; (phys. start addr. of the exec. file)
 25893 00008773 AD                  <1> 	lodsd
 25894 00008774 663DEB1E            <1> 	cmp	ax, 1EEBh ; EBH, 1Eh -> jump to +32
 25895 00008778 7533                <1> 	jne	short sysexec_15
 25896                              <1> 		; cmp core,$405 / br .+14 is first instruction 
 25897                              <1> 			      ; / if file is standard a.out format
 25898                              <1> 		; bne 1f / branch, if not standard format
 25899 0000877A AD                  <1> 	lodsd
 25900 0000877B 89C1                <1> 	mov	ecx, eax ; text (code) section size
 25901 0000877D AD                  <1> 	lodsd
 25902 0000877E 01C1                <1> 	add	ecx, eax ; + data section size (initialized data)
 25903                              <1> 		; mov core+2,r5 / put 2nd word of users program in r5;
 25904                              <1> 		              ; / number of bytes in program text	
 25905                              <1> 		; sub $14,r5 / subtract 12
 25906 00008780 89CB                <1> 	mov	ebx, ecx
 25907                              <1> 	;
 25908                              <1> 	; 25/06/2015
 25909                              <1> 	; NOTE: These are for next versions of Retro UNIX 386
 25910                              <1> 	;	and SINGLIX operating systems (as code template).
 25911                              <1> 	;	Current Retro UNIX 386 v1 files can be max. 64KB
 25912                              <1> 	;	due to RUFS (floppy disk file system) restriction...
 25913                              <1> 	;	Overrun is not possible for current version. 	
 25914                              <1> 	;
 25915 00008782 AD                  <1> 	lodsd	
 25916 00008783 01C3                <1> 	add	ebx, eax ; + bss section size (for overrun checking)
 25917 00008785 3B1D[34B10000]      <1> 	cmp	ebx, [u.count]
 25918 0000878B 7711                <1> 	ja	short sysexec_14  ; program overruns stack !
 25919                              <1> 	;
 25920                              <1> 	; 24/07/2015
 25921                              <1> 	; add bss section size to [u.break]
 25922 0000878D 0105[3CB10000]      <1> 	add 	[u.break], eax
 25923                              <1> 	;
 25924 00008793 83E920              <1> 	sub	ecx, 32  ; header size (already loaded)
 25925                              <1> 	;cmp	ecx, [u.count]
 25926                              <1> 	;jnb	short sysexec_16
 25927                              <1> 		; cmp r5,u.count /
 25928                              <1> 		; bgt 1f / branch if r5 greater than u.count
 25929 00008796 890D[34B10000]      <1> 	mov	[u.count], ecx ; required read count
 25930                              <1> 		; mov r5,u.count
 25931                              <1> 	;
 25932 0000879C EB2A                <1> 	jmp	short sysexec_16
 25933                              <1> 	;
 25934                              <1> sysexec_14:
 25935                              <1> 	; 23/06/2015
 25936                              <1> 	; insufficient (out of) memory
 25937 0000879E C705[65B10000]0100- <1> 	mov	dword [u.error], ERR_MINOR_IM ; 1
 25938 000087A6 0000                <1>
 25939 000087A8 E9D8F3FFFF          <1> 	jmp	error
 25940                              <1> 	;
 25941                              <1> sysexec_15:
 25942                              <1> 	; 25/06/2015
 25943 000087AD 0FB715[E8AD0000]    <1>         movzx   edx, word [i.size] ; file size
 25944 000087B4 29CA                <1> 	sub	edx, ecx ; file size - loaded bytes
 25945 000087B6 7627                <1> 	jna	short sysexec_17 ; no need to next read
 25946 000087B8 01D1                <1> 	add	ecx, edx ; [i.size]
 25947 000087BA 3B0D[34B10000]      <1> 	cmp	ecx, [u.count] ; overrun check (!)
 25948 000087C0 77DC                <1> 	ja	short sysexec_14
 25949 000087C2 8915[34B10000]      <1> 	mov	[u.count], edx
 25950                              <1> sysexec_16:
 25951 000087C8 66A1[F0B00000]      <1> 	mov	ax, [ii] ; i-number
 25952 000087CE E80F090000          <1> 	call	readi
 25953                              <1> 		; add core+10,u.nread / add size of user data area 
 25954                              <1> 		                    ; / to u.nread
 25955                              <1> 		; br 2f
 25956                              <1> 	; 1:
 25957                              <1> 		; jsr r0,readi / read in rest of file
 25958                              <1> 	; 2:
 25959 000087D3 8B0D[38B10000]      <1> 	mov	ecx, [u.nread]
 25960 000087D9 010D[3CB10000]      <1> 	add	[u.break], ecx
 25961                              <1> 		; mov u.nread,u.break / set users program break to end of 
 25962                              <1> 				    ; / user code
 25963                              <1> 		; add $core+14,u.break / plus data area
 25964                              <1> sysexec_17: ; 20/07/2015
 25965                              <1> 	;mov	ax, [ii] ;rgc i-number
 25966 000087DF E804090000          <1> 	call	iclose
 25967                              <1> 		; jsr r0,iclose / does nothing
 25968 000087E4 31C0                <1>         xor     eax, eax
 25969 000087E6 FEC0                <1> 	inc	al
 25970 000087E8 66A3[54B10000]      <1> 	mov	[u.intr], ax ; 1 (interrupt/time-out is enabled)
 25971 000087EE 66A3[56B10000]      <1> 	mov	[u.quit], ax ; 1 ('crtl+brk' signal is enabled) 
 25972                              <1> 	; 02/07/2015
 25973 000087F4 833D[6DB10000]00    <1>         cmp	dword [u.ppgdir], 0  ; is the caller sys_init (kernel) ?
 25974 000087FB 770C                <1> 	ja	short sysexec_18 ; no, the caller is user process
 25975                              <1> 	; If the caller is kernel (sys_init), 'sysexec' will come here
 25976 000087FD 8B15[48A20000]      <1> 	mov	edx, [k_page_dir] ; kernel's page directory
 25977 00008803 8915[6DB10000]      <1> 	mov	[u.ppgdir], edx ; next time 'sysexec' must not come here 
 25978                              <1> sysexec_18:
 25979                              <1> 	; 18/10/2015
 25980                              <1> 	; 05/08/2015
 25981                              <1> 	; 29/07/2015
 25982 00008809 8B2D[90B10000]      <1> 	mov	ebp, [argv] ; user's stack pointer must point to argument
 25983                              <1> 			    ; list pointers (argument count)
 25984 0000880F FA                  <1> 	cli
 25985 00008810 8B25[E4A10000]      <1>         mov     esp, [tss.esp0]  ; ring 0 (kernel) stack pointer
 25986                              <1> 	;mov   	esp, [u.sp] ; Restore Kernel stack
 25987                              <1> 			    ; for this process	 
 25988                              <1> 	;add	esp, 20 ; --> EIP, CS, EFLAGS, ESP, SS
 25989                              <1> 	;xor	eax, eax ; 0
 25990 00008816 FEC8                <1> 	dec	al ; eax = 0
 25991 00008818 66BA2300            <1> 	mov	dx, UDATA
 25992 0000881C 6652                <1> 	push	dx  ; user's stack segment
 25993 0000881E 55                  <1> 	push	ebp ; user's stack pointer
 25994                              <1> 		    ; (points to number of arguments)
 25995 0000881F FB                  <1> 	sti
 25996 00008820 9C                  <1> 	pushfd	; EFLAGS
 25997                              <1> 		; Set IF for enabling interrupts in user mode	
 25998                              <1> 	;or	dword [esp], 200h 
 25999                              <1> 	;
 26000                              <1> 	;mov	bx, UCODE
 26001                              <1> 	;push	bx ; user's code segment
 26002 00008821 6A1B                <1> 	push	UCODE
 26003                              <1> 	;push	0
 26004 00008823 50                  <1> 	push	eax ; EIP (=0) - start address -	
 26005                              <1> 		; clr -(r5) / popped into ps when rti in 
 26006                              <1> 			  ; / sysrele is executed
 26007                              <1> 		; mov $core,-(r5) / popped into pc when rti 
 26008                              <1> 		                ; / in sysrele is executed
 26009                              <1> 		;mov r5,0f / load second copyz argument
 26010                              <1> 		;tst -(r5) / decrement r5
 26011 00008824 8925[08B10000]      <1> 	mov	[u.sp], esp ; 29/07/2015
 26012                              <1> 	; 05/08/2015
 26013                              <1> 	; Remedy of a General Protection Fault during 'iretd' is here !
 26014                              <1> 	; ('push dx' would cause to general protection fault, 
 26015                              <1> 	; after 'pop ds' etc.)
 26016                              <1> 	;
 26017                              <1> 	;; push dx ; ds (UDATA)
 26018                              <1> 	;; push dx ; es (UDATA)
 26019                              <1> 	;; push dx ; fs (UDATA)
 26020                              <1> 	;; push dx ; gs (UDATA)
 26021                              <1> 	;
 26022                              <1> 	; This is a trick to prevent general protection fault
 26023                              <1> 	; during 'iretd' intruction at the end of 'sysrele' (in u1.s):
 26024 0000882A 8EC2                <1> 	mov 	es, dx ; UDATA
 26025 0000882C 06                  <1> 	push 	es ; ds (UDATA)
 26026 0000882D 06                  <1> 	push 	es ; es (UDATA)
 26027 0000882E 06                  <1> 	push 	es ; fs (UDATA)
 26028 0000882F 06                  <1> 	push	es ; gs (UDATA)
 26029 00008830 66BA1000            <1> 	mov	dx, KDATA
 26030 00008834 8EC2                <1> 	mov	es, dx
 26031                              <1> 	;
 26032                              <1> 	;; pushad simulation
 26033 00008836 89E5                <1> 	mov	ebp, esp ; esp before pushad
 26034 00008838 50                  <1> 	push	eax ; eax (0)
 26035 00008839 50                  <1> 	push	eax ; ecx (0)
 26036 0000883A 50                  <1> 	push	eax ; edx (0)
 26037 0000883B 50                  <1> 	push	eax ; ebx (0)
 26038 0000883C 55                  <1> 	push	ebp ; esp before pushad
 26039 0000883D 50                  <1> 	push	eax ; ebp (0)
 26040 0000883E 50                  <1> 	push	eax ; esi (0)		
 26041 0000883F 50                  <1> 	push	eax ; edi (0)	
 26042                              <1> 	;
 26043 00008840 A3[10B10000]        <1> 	mov	[u.r0], eax ; eax = 0
 26044 00008845 8925[0CB10000]      <1> 	mov	[u.usp], esp
 26045                              <1> 		; mov r5,u.r0 /
 26046                              <1> 		; sub $16.,r5 / skip 8 words
 26047                              <1> 		; mov r5,u.sp / assign user stack pointer value, 
 26048                              <1> 		;             / effectively zeroes all regs
 26049                              <1> 			    ; / when sysrele is executed
 26050                              <1> 		; jsr r0,copyz; core; 0:0 / zero user's core
 26051                              <1> 		; clr u.break
 26052                              <1> 		; mov r5,sp / point sp to user's stack
 26053                              <1> 	;
 26054 0000884B E958F3FFFF          <1> 	jmp	sysret0
 26055                              <1> 	;jmp	sysret
 26056                              <1> 		; br sysret3 / return to core image at $core
 26057                              <1> 
 26058                              <1> get_argp:
 26059                              <1> 	; 18/10/2015 (nbase, ncount)
 26060                              <1> 	; 21/07/2015
 26061                              <1> 	; 24/06/2015 (Retro UNIX 386 v1)
 26062                              <1> 	; Get (virtual) address of argument from user's core memory
 26063                              <1> 	;
 26064                              <1> 	; INPUT:
 26065                              <1> 	;	esi = virtual address of argument pointer
 26066                              <1> 	; OUTPUT:
 26067                              <1> 	;	eax = virtual address of argument
 26068                              <1> 	;
 26069                              <1> 	; Modified registers: EAX, EBX, ECX, EDX, ESI 
 26070                              <1> 	;
 26071 00008850 833D[6DB10000]00    <1>  	cmp     dword [u.ppgdir], 0 ; /etc/init ?
 26072                              <1> 				    ; (the caller is kernel)
 26073 00008857 7667                <1>         jna     short get_argpk 
 26074                              <1> 	;
 26075 00008859 89F3                <1>      	mov	ebx, esi
 26076 0000885B E83AAFFFFF          <1> 	call	get_physical_addr ; get physical address
 26077 00008860 0F8289000000        <1>         jc      get_argp_err
 26078 00008866 A3[88B10000]        <1> 	mov 	[nbase], eax ; physical address	
 26079 0000886B 66890D[8CB10000]    <1> 	mov	[ncount], cx ; remain byte count in page (1-4096)
 26080 00008872 B804000000          <1> 	mov	eax, 4 ; 21/07/2015
 26081 00008877 6639C1              <1> 	cmp	cx, ax ; 4
 26082 0000887A 735D                <1> 	jnb	short get_argp2
 26083 0000887C 89F3                <1> 	mov	ebx, esi
 26084 0000887E 01CB                <1> 	add	ebx, ecx
 26085 00008880 E815AFFFFF          <1> 	call	get_physical_addr ; get physical address
 26086 00008885 7268                <1> 	jc	short get_argp_err
 26087                              <1> 	;push	esi
 26088 00008887 89C6                <1> 	mov	esi, eax
 26089 00008889 66870D[8CB10000]    <1> 	xchg	cx, [ncount]
 26090 00008890 8735[88B10000]      <1> 	xchg	esi, [nbase]
 26091 00008896 B504                <1> 	mov	ch, 4
 26092 00008898 28CD                <1> 	sub	ch, cl
 26093                              <1> get_argp0:
 26094 0000889A AC                  <1> 	lodsb
 26095 0000889B 6650                <1> 	push	ax
 26096 0000889D FEC9                <1> 	dec	cl
 26097 0000889F 75F9                <1>         jnz     short get_argp0
 26098 000088A1 8B35[88B10000]      <1> 	mov	esi, [nbase]
 26099                              <1> 	; 21/07/2015
 26100 000088A7 0FB6C5              <1> 	movzx	eax, ch
 26101 000088AA 0105[88B10000]      <1> 	add	[nbase], eax
 26102 000088B0 662905[8CB10000]    <1> 	sub	[ncount], ax
 26103                              <1> get_argp1:
 26104 000088B7 AC                  <1> 	lodsb
 26105 000088B8 FECD                <1> 	dec	ch
 26106 000088BA 743D                <1>         jz      short get_argp3
 26107 000088BC 6650                <1>         push	ax
 26108 000088BE EBF7                <1> 	jmp     short get_argp1
 26109                              <1> get_argpk:
 26110                              <1> 	; Argument is in kernel's memory space
 26111 000088C0 66C705[8CB10000]00- <1> 	mov	word [ncount], PAGE_SIZE ; 4096
 26112 000088C8 10                  <1>
 26113 000088C9 8935[88B10000]      <1> 	mov	[nbase], esi
 26114 000088CF 8305[88B10000]04    <1> 	add	dword [nbase], 4
 26115 000088D6 8B06                <1> 	mov	eax, [esi] ; virtual addr. = physcal addr.
 26116 000088D8 C3                  <1> 	retn
 26117                              <1> get_argp2:
 26118                              <1> 	; 21/07/2015
 26119                              <1> 	;mov	eax, 4
 26120 000088D9 8B15[88B10000]      <1> 	mov 	edx, [nbase] ; 18/10/2015
 26121 000088DF 0105[88B10000]      <1> 	add	[nbase], eax
 26122 000088E5 662905[8CB10000]    <1> 	sub	[ncount], ax
 26123                              <1> 	;
 26124 000088EC 8B02                <1> 	mov	eax, [edx]
 26125 000088EE C3                  <1> 	retn
 26126                              <1> get_argp_err:
 26127 000088EF A3[65B10000]        <1> 	mov	[u.error], eax
 26128 000088F4 E98CF2FFFF          <1> 	jmp	error
 26129                              <1> get_argp3:
 26130 000088F9 B103                <1> 	mov	cl, 3
 26131                              <1> get_argp4:
 26132 000088FB C1E008              <1> 	shl	eax, 8
 26133 000088FE 665A                <1> 	pop	dx
 26134 00008900 88D0                <1> 	mov 	al, dl
 26135 00008902 E2F7                <1>         loop    get_argp4
 26136                              <1> 	;pop	esi
 26137 00008904 C3                  <1> 	retn	
 26138                              <1> 
 26139                              <1> sysfstat: 
 26140                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 26141                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 26142                              <1> 	;
 26143                              <1> 	; 'sysfstat' is identical to 'sysstat' except that it operates
 26144                              <1> 	; on open files instead of files given by name. It puts the
 26145                              <1> 	; buffer address on the stack, gets the i-number and
 26146                              <1> 	; checks to see if the file is open for reading or writing.
 26147                              <1> 	; If the file is open for writing (i-number is negative)
 26148                              <1> 	; the i-number is set positive and a branch into 'sysstat'
 26149                              <1> 	; is made.	
 26150                              <1> 	;
 26151                              <1> 	; Calling sequence:
 26152                              <1> 	;	sysfstat; buf
 26153                              <1> 	; Arguments:
 26154                              <1> 	;	buf - buffer address
 26155                              <1> 	;
 26156                              <1> 	; Inputs: *u.r0 - file descriptor
 26157                              <1> 	; Outputs: buffer is loaded with file information
 26158                              <1> 	; ...............................................................
 26159                              <1> 	;				
 26160                              <1> 	; Retro UNIX 8086 v1 modification:
 26161                              <1> 	;       'sysfstat' system call has two arguments; so,
 26162                              <1> 	;	* 1st argument, file descriptor is in BX register
 26163                              <1> 	;	* 2nd argument, buf is pointed to by CX register
 26164                              <1> 
 26165                              <1> 	; / set status of open file
 26166                              <1> 		; jsr r0,arg; u.off / put buffer address in u.off
 26167 00008905 51                  <1> 	push	ecx
 26168                              <1> 		; mov u.off,-(sp) / put buffer address on the stack
 26169                              <1> 		; mov *u.r0,r1 / put file descriptor in r1
 26170                              <1> 		; jsr r0,getf / get the files i-number
 26171                              <1> 	; BX = file descriptor (file number)
 26172 00008906 E8FF000000          <1> 	call	getf1
 26173 0000890B 6621C0              <1> 	and	ax, ax ; i-number of the file
 26174                              <1> 		; tst	r1 / is it 0?
 26175                              <1> 	;jz	error
 26176                              <1> 		; beq error3 / yes, error
 26177 0000890E 750F                <1> 	jnz	short sysfstat1
 26178 00008910 C705[65B10000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
 26179 00008918 0000                <1>
 26180 0000891A E966F2FFFF          <1> 	jmp	error
 26181                              <1> sysfstat1:
 26182 0000891F 80FC80              <1> 	cmp	ah, 80h
 26183 00008922 7223                <1>         jb      short sysstat1
 26184                              <1> 		; bgt 1f / if i-number is negative (open for writing)
 26185 00008924 66F7D8              <1> 	neg	ax
 26186                              <1> 		; neg r1 / make it positive, then branch
 26187 00008927 EB1E                <1> 	jmp	short sysstat1
 26188                              <1> 		; br 1f / to 1f
 26189                              <1> sysstat:
 26190                              <1> 	; 18/10/2015
 26191                              <1> 	; 07/10/2015
 26192                              <1> 	; 02/09/2015
 26193                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 26194                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 26195                              <1> 	;
 26196                              <1> 	; 'sysstat' gets the status of a file. Its arguments are the
 26197                              <1> 	; name of the file and buffer address. The buffer is 34 bytes
 26198                              <1> 	; long and information about the file placed in it.	
 26199                              <1> 	; sysstat calls 'namei' to get the i-number of the file.
 26200                              <1> 	; Then 'iget' is called to get i-node in core. The buffer
 26201                              <1> 	; is then loaded and the results are given in the UNIX
 26202                              <1> 	; Programmers Manual sysstat (II).	
 26203                              <1> 	;
 26204                              <1> 	; Calling sequence:
 26205                              <1> 	;	sysstat; name; buf
 26206                              <1> 	; Arguments:
 26207                              <1> 	;	name - points to the name of the file
 26208                              <1> 	;	buf - address of a 34 bytes buffer
 26209                              <1> 	; Inputs: -
 26210                              <1> 	; Outputs: buffer is loaded with file information
 26211                              <1> 	; ...............................................................
 26212                              <1> 	;				
 26213                              <1> 	; Retro UNIX 8086 v1 modification: 
 26214                              <1> 	;       'sysstat' system call has two arguments; so,
 26215                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
 26216                              <1> 	;	to get sysstat system call arguments from the user;
 26217                              <1> 	;	* 1st argument, name is pointed to by BX register
 26218                              <1> 	;	* 2nd argument, buf is pointed to by CX register
 26219                              <1> 	;
 26220                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
 26221                              <1> 	;	      arguments which were in these registers;
 26222                              <1> 	;	      but, it returns by putting the 1st argument
 26223                              <1> 	;	      in 'u.namep' and the 2nd argument
 26224                              <1> 	;	      on top of stack. (1st argument is offset of the
 26225                              <1> 	;	      file/path name in the user's program segment.)		 	
 26226                              <1> 	
 26227                              <1> 	; / ; name of file; buffer - get files status
 26228                              <1> 		; jsr r0,arg2 / get the 2 arguments
 26229 00008929 891D[28B10000]      <1> 	mov	[u.namep], ebx
 26230 0000892F 51                  <1> 	push	ecx
 26231 00008930 E80C010000          <1> 	call	namei
 26232                              <1> 		; jsr r0,namei / get the i-number for the file
 26233                              <1> 	;jc	error
 26234                              <1> 		; br error3 / no such file, error
 26235 00008935 7310                <1> 	jnc	short sysstat1
 26236                              <1> 	; pop 	ecx
 26237                              <1> sysstat_err0:
 26238                              <1> 	; 'file not found !' error
 26239 00008937 C705[65B10000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 26240 0000893F 0000                <1>
 26241 00008941 E93FF2FFFF          <1> 	jmp	error
 26242                              <1> 
 26243 00008946 00                  <1> statx: db 0
 26244                              <1> 
 26245                              <1> sysstat1: ; 1:
 26246 00008947 E891070000          <1> 	call	iget
 26247                              <1> 		; jsr r0,iget / get the i-node into core
 26248                              <1> 	; 07/10/2015 (ax = [ii], inode number)
 26249                              <1> 	; 02/09/2015
 26250 0000894C 8F05[30B10000]      <1> 	pop	dword [u.base]
 26251                              <1> 		; mov (sp)+,r3 / move u.off to r3 (points to buffer)
 26252 00008952 E858000000          <1> 	call	sysstat_gpa ; get physical address
 26253 00008957 730A                <1> 	jnc 	short sysstat2
 26254                              <1> sysstat_err1:
 26255 00008959 A3[65B10000]        <1> 	mov	dword [u.error], eax ; error code
 26256 0000895E E922F2FFFF          <1> 	jmp	error
 26257                              <1> sysstat2:
 26258 00008963 A0[F0B00000]        <1> 	mov 	al, [ii] ; 07/10/2015 (result of 'iget' call, above)
 26259 00008968 AA                  <1> 	stosb
 26260 00008969 FF05[30B10000]      <1> 	inc 	dword [u.base]
 26261 0000896F 6649                <1> 	dec 	cx
 26262 00008971 7505                <1> 	jnz	short sysstat3
 26263 00008973 E837000000          <1> 	call	sysstat_gpa
 26264                              <1> 	;jc	short sysstat_err1
 26265                              <1> sysstat3:
 26266 00008978 A0[F1B00000]        <1> 	mov 	al, [ii+1] ; 07/10/2015 (result of 'iget' call, above)
 26267 0000897D AA                  <1> 	stosb
 26268                              <1> 		; mov r1,(r3)+ / put i-number in 1st word of buffer
 26269 0000897E FF05[30B10000]      <1> 	inc 	dword [u.base]
 26270                              <1> 	;dec 	word [u.pcount]
 26271 00008984 6649                <1> 	dec	cx
 26272 00008986 7505                <1> 	jnz	short sysstat4
 26273 00008988 E822000000          <1> 	call	sysstat_gpa
 26274                              <1> 	;jc	short sysstat_err1	
 26275                              <1> sysstat4:
 26276 0000898D BE[E4AD0000]        <1> 	mov	esi, inode
 26277                              <1> 		; mov $inode,r2 / r2 points to i-node
 26278                              <1> sysstat5: ; 1:
 26279 00008992 A4                  <1> 	movsb
 26280                              <1> 		; mov (r2)+,(r3)+ / move rest of i-node to buffer
 26281 00008993 FF05[30B10000]      <1> 	inc 	dword [u.base]
 26282                              <1> 	;dec 	word [u.pcount]
 26283 00008999 6649                <1> 	dec	cx
 26284 0000899B 7505                <1> 	jnz	short sysstat6
 26285 0000899D E80D000000          <1> 	call	sysstat_gpa
 26286                              <1> 	;jc	short sysstat_err1
 26287                              <1> sysstat6:		
 26288 000089A2 81FE[04AE0000]      <1> 	cmp	esi, inode + 32
 26289                              <1> 		; cmp r2,$inode+32 / done?
 26290 000089A8 75E8                <1> 	jne	short sysstat5
 26291                              <1> 		; bne 1b / no, go back
 26292 000089AA E9F6F1FFFF          <1> 	jmp	sysret
 26293                              <1> 		; br sysret3 / return through sysret
 26294                              <1> 	;
 26295                              <1> sysstat_gpa: ; get physical address of file status buffer
 26296                              <1> 	; 02/09/2015
 26297 000089AF 8B1D[30B10000]      <1> 	mov 	ebx, [u.base]
 26298                              <1> 	; 07/10/2015
 26299 000089B5 E8E0ADFFFF          <1> 	call	get_physical_addr ; get physical address
 26300                              <1> 	;jc	short sysstat_gpa1
 26301 000089BA 729D                <1> 	jc	short sysstat_err1
 26302                              <1> 	; 18/10/2015
 26303 000089BC 89C7                <1> 	mov	edi, eax ; physical address
 26304                              <1> 	;mov	[u.pcount], cx ; remain bytes in page
 26305                              <1> ;sysstat_gpa1:
 26306 000089BE C3                  <1> 	retn
 26307                              <1> 
 26308                              <1> fclose:
 26309                              <1> 	; 18/06/2015 (Retro UNIX 386 v1 - Beginning)
 26310                              <1> 	;            (32 bit offset pointer modification)
 26311                              <1> 	; 19/04/2013 - 12/01/2014 (Retro UNIX 8086 v1)
 26312                              <1> 	;
 26313                              <1> 	; Given the file descriptor (index to the u.fp list)
 26314                              <1> 	; 'fclose' first gets the i-number of the file via 'getf'.
 26315                              <1> 	; If i-node is active (i-number > 0) the entry in 
 26316                              <1> 	; u.fp list is cleared. If all the processes that opened
 26317                              <1> 	; that file close it, then fsp etry is freed and the file
 26318                              <1> 	; is closed. If not a return is taken. 
 26319                              <1> 	; If the file has been deleted while open, 'anyi' is called
 26320                              <1> 	; to see anyone else has it open, i.e., see if it is appears
 26321                              <1> 	; in another entry in the fsp table. Upon return from 'anyi'
 26322                              <1> 	; a check is made to see if the file is special.	
 26323                              <1> 	;
 26324                              <1> 	; INPUTS ->
 26325                              <1> 	;    r1 - contains the file descriptor (value=0,1,2...)
 26326                              <1> 	;    u.fp - list of entries in the fsp table
 26327                              <1> 	;    fsp - table of entries (4 words/entry) of open files.	 
 26328                              <1> 	; OUTPUTS ->
 26329                              <1> 	;    r1 - contains the same file descriptor
 26330                              <1> 	;    r2 - contains i-number
 26331                              <1> 	;
 26332                              <1> 	; ((AX = R1))
 26333                              <1> 	; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))
 26334                              <1> 	;
 26335                              <1> 	; Retro UNIX 8086 v1 modification : CF = 1
 26336                              <1> 	;              if i-number of the file is 0. (error)  	
 26337                              <1> 	;
 26338 000089BF 0FB7D0              <1> 	movzx	edx, ax ; **
 26339 000089C2 6650                <1> 	push	ax ; ***
 26340                              <1> 		; mov r1,-(sp) / put r1 on the stack (it contains 
 26341                              <1> 			     ; / the index to u.fp list)
 26342 000089C4 E83F000000          <1> 	call	getf
 26343                              <1> 		; jsr r0,getf / r1 contains i-number, 
 26344                              <1> 			    ; / cdev has device =, u.fofp 
 26345                              <1> 			    ; / points to 3rd word of fsp entry
 26346 000089C9 6683F801            <1> 	cmp	ax, 1 ; r1
 26347                              <1> 		; tst r1 / is i-number 0?
 26348 000089CD 7236                <1> 	jb	short fclose_2
 26349                              <1> 		; beq 1f / yes, i-node not active so return
 26350                              <1> 		; tst (r0)+ / no, jump over error return
 26351 000089CF 89D3                <1> 	mov	ebx, edx ; **
 26352 000089D1 6689C2              <1> 	mov 	dx, ax ; *
 26353                              <1> 		; mov r1,r2 / move i-number to r2 ;*
 26354                              <1> 		; mov (sp),r1 / restore value of r1 from the stack
 26355                              <1> 			    ; / which is index to u.fp ; **
 26356 000089D4 C683[16B10000]00    <1> 	mov	byte [ebx+u.fp], 0
 26357                              <1> 		; clrb u.fp(r1) / clear that entry in the u.fp list
 26358 000089DB 8B1D[20B10000]      <1> 	mov	ebx, [u.fofp]
 26359                              <1> 		; mov u.fofp,r1 / r1 points to 3rd word in fsp entry
 26360                              <1> fclose_0:
 26361 000089E1 FE4B04              <1> 	dec	byte [ebx+4] ; 18/06/2015
 26362                              <1> 		; decb 2(r1) / decrement the number of processes 
 26363                              <1> 			   ; / that have opened the file
 26364 000089E4 791F                <1> 	jns	short fclose_2 ; jump if not negative (jump if bit 7 is 0)	 
 26365                              <1> 		; bge 1f / if all processes haven't closed the file, return
 26366                              <1> 	;
 26367 000089E6 6652                <1> 	push	dx ;*
 26368                              <1> 		; mov r2,-(sp) / put r2 on the stack (i-number)
 26369 000089E8 6631C0              <1> 	xor	ax, ax ; 0
 26370 000089EB 668943FC            <1> 	mov	[ebx-4], ax ; 0
 26371                              <1> 		; clr -4(r1) / clear 1st word of fsp entry
 26372 000089EF 8A4305              <1> 	mov	al, [ebx+5] ; 18/06/2015
 26373                              <1> 		; tstb	3(r1) / has this file been deleted
 26374 000089F2 20C0                <1> 	and	al, al
 26375 000089F4 7408                <1> 	jz	short fclose_1
 26376                              <1> 		; beq 2f / no, branch
 26377 000089F6 6689D0              <1> 	mov	ax, dx ; *
 26378                              <1> 		; mov r2,r1 / yes, put i-number back into r1
 26379                              <1> 	; AX = inode number
 26380 000089F9 E868040000          <1> 	call	anyi
 26381                              <1> 		; jsr r0,anyi / free all blocks related to i-number
 26382                              <1> 			    ; / check if file appears in fsp again
 26383                              <1> fclose_1: ; 2:
 26384 000089FE 6658                <1> 	pop	ax ; *
 26385                              <1> 		; mov (sp)+,r1 / put i-number back into r1
 26386 00008A00 E8E3060000          <1> 	call	iclose ; close if it is special file 
 26387                              <1> 		; jsr r0,iclose / check to see if its a special file
 26388                              <1> fclose_2: ; 1:
 26389 00008A05 6658                <1> 	pop	ax ; ***
 26390                              <1> 		; mov (sp)+,r1 / put index to u.fp back into r1
 26391 00008A07 C3                  <1> 	retn
 26392                              <1> 		; rts r0
 26393                              <1> 
 26394                              <1> getf:	; / get the device number and the i-number of an open file
 26395                              <1> 	; 13/05/2015
 26396                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 26397                              <1> 	; 19/04/2013 - 18/11/2013 (Retro UNIX 8086 v1)
 26398                              <1> 	;
 26399 00008A08 89C3                <1> 	mov	ebx, eax
 26400                              <1> getf1: ;; Calling point from 'rw1' (23/05/2013)
 26401 00008A0A 83FB0A              <1> 	cmp	ebx, 10
 26402                              <1> 		; cmp r1,$10. / user limited to 10 open files
 26403 00008A0D 730A                <1>         jnb	short getf2 ; 13/05/2015
 26404                              <1> 	;jnb     error
 26405                              <1> 		; bhis error3 / u.fp is table of users open files, 
 26406                              <1> 			    ; / index in fsp table
 26407 00008A0F 8A9B[16B10000]      <1> 	mov	bl, [ebx+u.fp]
 26408                              <1> 		; movb	u.fp(r1),r1 / r1 contains number of entry 
 26409                              <1> 		                  ; / in fsp table
 26410 00008A15 08DB                <1> 	or	bl, bl
 26411 00008A17 7503                <1> 	jnz	short getf3
 26412                              <1> 	;jz	short getf4
 26413                              <1> 		; beq 1f / if its zero return
 26414                              <1> getf2:
 26415                              <1> 	; 'File not open !' error (ax=0)
 26416 00008A19 29C0                <1> 	sub	eax, eax
 26417 00008A1B C3                  <1> 	retn
 26418                              <1> getf3:	
 26419                              <1> 	; Retro UNIX 386 v1 modification ! (11/05/2015)
 26420                              <1> 	;
 26421                              <1> 	; 'fsp' table (10 bytes/entry)
 26422                              <1> 	; bit 15				   bit 0
 26423                              <1> 	; ---|-------------------------------------------
 26424                              <1> 	; r/w|		i-number of open file
 26425                              <1> 	; ---|-------------------------------------------
 26426                              <1> 	;		   device number
 26427                              <1> 	; -----------------------------------------------
 26428                              <1> 	; offset pointer, r/w pointer to file (bit 0-15)
 26429                              <1> 	; -----------------------------------------------
 26430                              <1> 	; offset pointer, r/w pointer to file (bit 16-31)
 26431                              <1> 	; ----------------------|------------------------
 26432                              <1> 	;  flag that says file 	| number of processes
 26433                              <1> 	;   has been deleted	| that have file open 
 26434                              <1> 	; ----------------------|------------------------
 26435                              <1> 	;
 26436 00008A1C B80A000000          <1> 	mov	eax, 10
 26437 00008A21 F6E3                <1> 	mul	bl
 26438 00008A23 BB[DEAE0000]        <1> 	mov	ebx, fsp - 6 ; the 3rd word in the fsp entry
 26439 00008A28 01C3                <1> 	add	ebx, eax
 26440                              <1> 		; asl r1
 26441                              <1> 		; asl r1 / multiply by 8 to get index into 
 26442                              <1> 		       ; / fsp table entry
 26443                              <1> 		; asl r1
 26444                              <1> 		; add $fsp-4,r1 / r1 is pointing at the 3rd word 
 26445                              <1> 			      ; / in the fsp entry
 26446 00008A2A 891D[20B10000]      <1> 	mov	[u.fofp], ebx
 26447                              <1> 		; mov r1,u.fofp / save address of 3rd word 
 26448                              <1> 			      ; / in fsp entry in u.fofp
 26449 00008A30 4B                  <1> 	dec	ebx
 26450 00008A31 4B                  <1> 	dec	ebx
 26451 00008A32 668B03              <1> 	mov	ax, [ebx]
 26452                              <1> 	;mov	[cdev], al ; ;;Retro UNIX 8086 v1 ! 
 26453 00008A35 66A3[F4B00000]      <1> 	mov	[cdev], ax ; ;;in fact (!) 
 26454                              <1> 			     ;;dev number is in 1 byte
 26455                              <1> 		; mov -(r1),cdev / remove the device number  cdev
 26456 00008A3B 4B                  <1> 	dec	ebx
 26457 00008A3C 4B                  <1> 	dec	ebx
 26458 00008A3D 668B03              <1> 	mov	ax, [ebx]
 26459                              <1> 		; mov -(r1),r1 / and the i-number  r1
 26460                              <1> getf4:	; 1:
 26461 00008A40 C3                  <1> 	retn
 26462                              <1> 		; rts r0
 26463                              <1> 
 26464                              <1> namei:
 26465                              <1> 	; 04/12/2015 (14 byte file names)
 26466                              <1> 	; 18/10/2015 (nbase, ncount)
 26467                              <1> 	; 12/10/2015
 26468                              <1> 	; 21/08/2015
 26469                              <1> 	; 18/07/2015
 26470                              <1> 	; 02/07/2015
 26471                              <1> 	; 17/06/2015
 26472                              <1> 	; 16/06/2015 (Retro UNIX 386 v1 - Beginning)
 26473                              <1> 	; 24/04/2013 - 31/07/2013 (Retro UNIX 8086 v1)
 26474                              <1> 	;
 26475                              <1> 	; 'namei' takes a file path name and returns i-number of
 26476                              <1> 	; the file in the current directory or the root directory
 26477                              <1> 	; (if the first character of the pathname is '/').	
 26478                              <1> 	;
 26479                              <1> 	; INPUTS ->
 26480                              <1> 	;    u.namep - points to a file path name
 26481                              <1> 	;    u.cdir - i-number of users directory
 26482                              <1> 	;    u.cdev - device number on which user directory resides	
 26483                              <1> 	; OUTPUTS ->
 26484                              <1> 	;    r1 - i-number of file
 26485                              <1> 	;    cdev
 26486                              <1> 	;    u.dirbuf - points to directory entry where a match 
 26487                              <1> 	;               occurs in the search for file path name.
 26488                              <1> 	;	        If no match u.dirb points to the end of 
 26489                              <1> 	;               the directory and r1 = i-number of the current
 26490                              <1> 	;	        directory.	
 26491                              <1> 	; ((AX = R1))
 26492                              <1> 	;
 26493                              <1> 	; (Retro UNIX Prototype : 07/10/2012 - 05/01/2013, UNIXCOPY.ASM)
 26494                              <1>         ; ((Modified registers: eDX, eBX, eCX, eSI, eDI, eBP))  
 26495                              <1> 	;
 26496                              <1> 
 26497 00008A41 66A1[14B10000]      <1> 	mov	ax, [u.cdir]
 26498                              <1> 		; mov u.cdir,r1 / put the i-number of current directory
 26499                              <1> 			      ; / in r1
 26500 00008A47 668B15[5AB10000]    <1> 	mov	dx, [u.cdrv]
 26501 00008A4E 668915[F4B00000]    <1> 	mov	[cdev], dx 	    ; NOTE: Retro UNIX 8086 v1 
 26502                              <1> 				    ; device/drive number is in 1 byte, 
 26503                              <1> 				    ; not in 1 word!
 26504                              <1> 		; mov u.cdev,cdev / device number for users directory 
 26505                              <1> 				; / into cdev
 26506                              <1> 	; 12/10/2015
 26507                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 26508                              <1>       	 ; convert virtual (pathname) addr to physical address
 26509 00008A55 E82C010000          <1> 	call    trans_addr_nmbp ; 12/10/2015
 26510                              <1> 		; esi = physical address of [u.namep]
 26511                              <1> 		; ecx = byte count in the page
 26512 00008A5A 803E2F              <1> 	cmp	byte [esi], '/'
 26513                              <1> 		; cmpb *u.namep,$'/ / is first char in file name a /
 26514 00008A5D 751E                <1> 	jne	short namei_1
 26515                              <1> 		; bne 1f
 26516 00008A5F FF05[28B10000]      <1> 	inc	dword [u.namep]
 26517                              <1> 		; inc u.namep / go to next char
 26518 00008A65 6649                <1> 	dec	cx ; remain byte count in the page
 26519 00008A67 7506                <1> 	jnz	short namei_0
 26520                              <1> 	; 12/10/2015
 26521 00008A69 E818010000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
 26522                              <1> 		; esi = physical address (page start + offset)
 26523                              <1> 		; ecx = byte count in the page
 26524 00008A6E 4E                  <1> 	dec	esi
 26525                              <1> namei_0:
 26526 00008A6F 46                  <1> 	inc 	esi  ; go to next char
 26527 00008A70 66A1[FEB00000]      <1> 	mov	ax, [rootdir] ; 09/07/2013
 26528                              <1> 		; mov rootdir,r1 / put i-number of rootdirectory in r1
 26529 00008A76 C605[F4B00000]00    <1> 	mov	byte [cdev], 0
 26530                              <1> 		; clr cdev / clear device number
 26531                              <1> namei_1: ; 1:
 26532 00008A7D F606FF              <1> 	test	byte [esi], 0FFh
 26533 00008A80 74BE                <1> 	jz	short getf4
 26534                              <1> 	;jz      nig
 26535                              <1> 		; tstb *u.namep / is the character in file name a nul
 26536                              <1> 		; beq nig / yes, end of file name reached; 
 26537                              <1> 			; / branch to "nig"
 26538                              <1> namei_2: ; 1:
 26539                              <1> 	; 18/10/2015
 26540 00008A82 8935[88B10000]      <1> 	mov 	[nbase], esi
 26541 00008A88 66890D[8CB10000]    <1> 	mov 	[ncount], cx
 26542                              <1> 	;
 26543                              <1> 	;mov	dx, 2
 26544 00008A8F B202                <1> 	mov	dl, 2 ; user flag (read, non-owner)
 26545 00008A91 E859060000          <1> 	call	access
 26546                              <1> 		; jsr r0,access; 2 / get i-node with i-number r1
 26547                              <1> 	; 'access' will not return here if user has not "r" permission !
 26548 00008A96 66F705[E4AD0000]00- <1> 	test 	word [i.flgs], 4000h
 26549 00008A9E 40                  <1>
 26550                              <1> 		; bit $40000,i.flgs / directory i-node?
 26551 00008A9F 746A                <1>         jz      short namei_err
 26552                              <1> 		; beq error3 / no, got an error
 26553                              <1> 	; 16/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 26554 00008AA1 31C0                <1> 	xor	eax, eax
 26555 00008AA3 A3[2CB10000]        <1> 	mov	[u.off], eax ; 0
 26556 00008AA8 66A1[E8AD0000]      <1> 	mov	ax, [i.size]
 26557 00008AAE A3[24B10000]        <1> 	mov	[u.dirp], eax
 26558                              <1> 		; mov i.size,u.dirp / put size of directory in u.dirp
 26559                              <1> 		; clr u.off / u.off is file offset used by user
 26560 00008AB3 C705[20B10000]-     <1> 	mov	dword [u.fofp], u.off
 26561 00008AB9 [2CB10000]          <1>
 26562                              <1> 		; mov $u.off,u.fofp / u.fofp is a pointer to 
 26563                              <1> 				  ; / the offset portion of fsp entry
 26564                              <1> namei_3: ; 2:
 26565 00008ABD C705[30B10000]-     <1> 	mov	dword [u.base], u.dirbuf
 26566 00008AC3 [42B10000]          <1>
 26567                              <1> 		; mov $u.dirbuf,u.base / u.dirbuf holds a file name 
 26568                              <1> 				    ; / copied from a directory
 26569 00008AC7 C705[34B10000]1000- <1> 	mov 	dword [u.count], 16 ; 04/12/2015 (10 -> 16) 	
 26570 00008ACF 0000                <1>
 26571                              <1>  		; mov $10.,u.count / u.count is byte count 
 26572                              <1> 				 ; / for reads and writes
 26573 00008AD1 66A1[F0B00000]      <1> 	mov 	ax, [ii]
 26574                              <1> 	; 31/07/2013 ('namei_r') - 16/06/2015 ('u.kcall')
 26575 00008AD7 FE05[77B10000]      <1>  	inc     byte [u.kcall] ; the caller is 'namei' sign	
 26576 00008ADD E800060000          <1>     	call	readi
 26577                              <1> 		; jsr r0,readi / read 10. bytes of file 
 26578                              <1> 		      ; with i-number (r1); i.e. read a directory entry
 26579 00008AE2 8B0D[38B10000]      <1> 	mov 	ecx, [u.nread]
 26580 00008AE8 09C9                <1> 	or 	ecx, ecx
 26581                              <1> 		; tst u.nread
 26582 00008AEA 741B                <1> 	jz	short nib
 26583                              <1> 		; ble nib / gives error return
 26584                              <1> 	;
 26585 00008AEC 668B1D[42B10000]    <1> 	mov 	bx, [u.dirbuf]
 26586 00008AF3 6621DB              <1> 	and 	bx, bx       
 26587                              <1> 		; tst u.dirbuf /
 26588 00008AF6 7522                <1> 	jnz	short namei_4
 26589                              <1> 		; bne 3f / branch when active directory entry 
 26590                              <1> 		       ; / (i-node word in entry non zero)
 26591 00008AF8 A1[2CB10000]        <1> 	mov	eax, [u.off]
 26592 00008AFD 83E810              <1> 	sub	eax, 16 ; 04/12/2015 (10 -> 16) 
 26593 00008B00 A3[24B10000]        <1> 	mov	[u.dirp], eax
 26594                              <1> 		; mov u.off,u.dirp
 26595                              <1> 		; sub $10.,u.dirp
 26596 00008B05 EBB6                <1> 	jmp	short namei_3
 26597                              <1> 		; br 2b
 26598                              <1> 
 26599                              <1> 	; 18/07/2013
 26600                              <1> nib: 
 26601 00008B07 31C0                <1> 	xor	eax, eax  ; xor ax, ax ; ax = 0 -> file not found 
 26602 00008B09 F9                  <1> 	stc
 26603                              <1> nig:
 26604 00008B0A C3                  <1> 	retn
 26605                              <1> 
 26606                              <1> namei_err:
 26607                              <1> 	; 16/06/2015
 26608 00008B0B C705[65B10000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a directory !' error
 26609 00008B13 0000                <1>
 26610 00008B15 E96BF0FFFF          <1> 	jmp	error
 26611                              <1> 
 26612                              <1> namei_4: ; 3:
 26613                              <1> 	; 18/10/2015
 26614                              <1> 	; 12/10/2015
 26615                              <1> 	; 21/08/2015
 26616                              <1> 	; 18/07/2015
 26617 00008B1A 8B2D[28B10000]      <1> 	mov	ebp, [u.namep]
 26618                              <1> 		; mov u.namep,r2 / u.namep points into a file name string
 26619 00008B20 BF[44B10000]        <1> 	mov 	edi, u.dirbuf + 2
 26620                              <1> 		; mov $u.dirbuf+2,r3 / points to file name of directory entry
 26621                              <1> 	; 18/10/2015
 26622 00008B25 8B35[88B10000]      <1> 	mov	esi, [nbase]	
 26623 00008B2B 668B0D[8CB10000]    <1> 	mov	cx, [ncount]
 26624                              <1> 	;
 26625 00008B32 6621C9              <1> 	and	cx, cx
 26626 00008B35 7505                <1> 	jnz	short namei_5	
 26627                              <1> 	;
 26628 00008B37 E850000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 26629                              <1> 		; esi = physical address (page start + offset)
 26630                              <1> 		; ecx = byte count in the page
 26631                              <1> namei_5: ; 3:
 26632 00008B3C 45                  <1> 	inc	ebp ; 18/07/2015
 26633 00008B3D AC                  <1> 	lodsb   ; mov al, [esi] ; inc esi (al = r4)
 26634                              <1> 		; movb (r2)+,r4 / move a character from u.namep string into r4
 26635 00008B3E 08C0                <1> 	or 	al, al
 26636 00008B40 741D                <1> 	jz 	short namei_7
 26637                              <1> 		; beq 3f / if char is nul, then the last char in string
 26638                              <1> 			; / has been moved
 26639 00008B42 3C2F                <1> 	cmp	al, '/'
 26640                              <1> 		; cmp r4,$'/ / is char a </>
 26641 00008B44 7419                <1> 	je 	short namei_7
 26642                              <1> 		; beq 3f	
 26643                              <1> 	; 12/10/2015
 26644 00008B46 6649                <1> 	dec	cx ; remain byte count in the page
 26645 00008B48 7505                <1> 	jnz	short namei_6
 26646 00008B4A E83D000000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 26647                              <1> 		; esi = physical address (page start + offset)
 26648                              <1> 		; ecx = byte count in the page
 26649                              <1> namei_6:
 26650 00008B4F 81FF[52B10000]      <1>         cmp     edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
 26651                              <1> 		; cmp r3,$u.dirbuf+10. / have I checked
 26652                              <1> 				     ; / all 8 bytes of file name
 26653 00008B55 74E5                <1> 	je	short namei_5
 26654                              <1> 		; beq 3b
 26655 00008B57 AE                  <1> 	scasb	
 26656                              <1> 		; cmpb (r3)+,r4 / compare char in u.namep string to file name 
 26657                              <1> 			      ; / char read from directory
 26658 00008B58 74E2                <1> 	je 	short namei_5
 26659                              <1> 		; beq 3b / branch if chars match
 26660                              <1> 
 26661 00008B5A E95EFFFFFF          <1>         jmp    namei_3 ; 2b
 26662                              <1> 		; br 2b / file names do not match go to next directory entry
 26663                              <1> namei_7: ; 3:
 26664 00008B5F 81FF[52B10000]      <1> 	cmp	edi, u.dirbuf + 16 ; 04/12/2015 (10 -> 16) 
 26665                              <1> 		; cmp r3,$u.dirbuf+10. / if equal all 8 bytes were matched
 26666 00008B65 740A                <1> 	je	short namei_8
 26667                              <1> 		; beq 3f
 26668 00008B67 8A27                <1> 	mov 	ah, [edi]
 26669                              <1> 	;inc 	edi 
 26670 00008B69 20E4                <1> 	and 	ah, ah
 26671                              <1> 		; tstb (r3)+ /
 26672 00008B6B 0F854CFFFFFF        <1>         jnz     namei_3
 26673                              <1> 		; bne 2b
 26674                              <1> namei_8: ; 3
 26675 00008B71 892D[28B10000]      <1> 	mov	[u.namep], ebp ; 18/07/2015
 26676                              <1> 		; mov r2,u.namep / u.namep points to char 
 26677                              <1> 			       ; / following a / or nul
 26678                              <1> 	;mov	bx, [u.dirbuf]
 26679                              <1> 		; mov u.dirbuf,r1 / move i-node number in directory 
 26680                              <1> 				; / entry to r1
 26681 00008B77 20C0                <1> 	and 	al, al
 26682                              <1> 		; tst r4 / if r4 = 0 the end of file name reached,
 26683                              <1> 		      ;  / if r4 = </> then go to next directory
 26684                              <1> 	; mov	ax, bx
 26685 00008B79 66A1[42B10000]      <1> 	mov 	ax, [u.dirbuf] ; 17/06/2015
 26686 00008B7F 0F85FDFEFFFF        <1>         jnz     namei_2 
 26687                              <1> 		; bne 1b
 26688                              <1> 	; AX = i-number of the file
 26689                              <1> ;;nig:
 26690 00008B85 C3                  <1> 	retn
 26691                              <1> 		; tst (r0)+ / gives non-error return
 26692                              <1> ;;nib:
 26693                              <1> ;;	xor	ax, ax ; Retro UNIX 8086 v1 modification !
 26694                              <1> 		       ; ax = 0 -> file not found 
 26695                              <1> ;;	stc	; 27/05/2013
 26696                              <1> ;;	retn
 26697                              <1> 		; rts r0
 26698                              <1> 
 26699                              <1> trans_addr_nmbp:
 26700                              <1> 	; 18/10/2015
 26701                              <1> 	; 12/10/2015
 26702 00008B86 8B2D[28B10000]      <1> 	mov 	ebp, [u.namep]
 26703                              <1> trans_addr_nm: 
 26704                              <1> 	; Convert virtual (pathname) address to physical address
 26705                              <1> 	; (Retro UNIX 386 v1 feature only !)
 26706                              <1> 	; 18/10/2015
 26707                              <1> 	; 12/10/2015 (u.pnbase & u.pncount has been removed from code)
 26708                              <1> 	; 02/07/2015
 26709                              <1> 	; 17/06/2015
 26710                              <1> 	; 16/06/2015
 26711                              <1> 	;
 26712                              <1> 	; INPUTS: 
 26713                              <1> 	;	ebp = pathname address (virtual) ; [u.namep]
 26714                              <1> 	;	[u.pgdir] = user's page directory
 26715                              <1> 	; OUTPUT:
 26716                              <1> 	;       esi = physical address of the pathname
 26717                              <1> 	;	ecx = remain byte count in the page
 26718                              <1> 	;
 26719                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI)
 26720                              <1> 	;
 26721 00008B8C 833D[6DB10000]00    <1>         cmp     dword [u.ppgdir], 0  ; /etc/init ? (sysexec)
 26722 00008B93 7618                <1> 	jna	short trans_addr_nmk ; the caller is os kernel;
 26723                              <1> 				     ; it is already physical address
 26724 00008B95 50                  <1>    	push	eax	
 26725 00008B96 89EB                <1> 	mov	ebx, ebp ; [u.namep] ; pathname address (virtual)
 26726 00008B98 E8FDABFFFF          <1>        	call	get_physical_addr ; get physical address
 26727 00008B9D 7204                <1> 	jc	short tr_addr_nm_err
 26728                              <1> 	; 18/10/2015
 26729                              <1> 	; eax = physical address 
 26730                              <1> 	; cx = remain byte count in page (1-4096) 
 26731                              <1> 		; 12/10/2015 (cx = [u.pncount])
 26732 00008B9F 89C6                <1> 	mov	esi, eax ; 12/10/2015 (esi=[u.pnbase])
 26733 00008BA1 58                  <1> 	pop	eax 
 26734 00008BA2 C3                  <1> 	retn
 26735                              <1> 
 26736                              <1> tr_addr_nm_err:
 26737 00008BA3 A3[65B10000]        <1> 	mov	[u.error], eax
 26738                              <1> 	;pop 	eax
 26739 00008BA8 E9D8EFFFFF          <1> 	jmp	error
 26740                              <1> 
 26741                              <1> trans_addr_nmk:
 26742                              <1> 	; 12/10/2015
 26743                              <1> 	; 02/07/2015
 26744 00008BAD 8B35[28B10000]      <1> 	mov	esi, [u.namep]  ; [u.pnbase]
 26745 00008BB3 66B90010            <1> 	mov	cx, PAGE_SIZE ; 4096 ; [u.pncount]
 26746 00008BB7 C3                  <1> 	retn
 26747                              <1> 
 26748                              <1> syschdir:
 26749                              <1> 	; / makes the directory specified in the argument
 26750                              <1> 	; / the current directory
 26751                              <1> 	;
 26752                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 26753                              <1> 	; 19/06/2013 (Retro UNIX 8086 v1)
 26754                              <1> 	;
 26755                              <1> 	; 'syschdir' makes the directory specified in its argument
 26756                              <1> 	; the current working directory.
 26757                              <1> 	;
 26758                              <1> 	; Calling sequence:
 26759                              <1> 	;	syschdir; name
 26760                              <1> 	; Arguments:
 26761                              <1> 	;	name - address of the path name of a directory
 26762                              <1> 	;	       terminated by nul byte.	
 26763                              <1> 	; Inputs: -
 26764                              <1> 	; Outputs: -
 26765                              <1> 	; ...............................................................
 26766                              <1> 	;				
 26767                              <1> 	; Retro UNIX 8086 v1 modification:
 26768                              <1> 	;	 The user/application program puts address of 
 26769                              <1> 	;	 the path name in BX register as 'syschdir' 
 26770                              <1> 	; 	 system call argument.
 26771                              <1> 
 26772 00008BB8 891D[28B10000]      <1> 	mov	[u.namep], ebx
 26773                              <1> 		;jsr r0,arg; u.namep / u.namep points to path name
 26774 00008BBE E87EFEFFFF          <1> 	call	namei
 26775                              <1> 		; jsr r0,namei / find its i-number
 26776                              <1> 	;jc	error
 26777                              <1> 		; br error3
 26778 00008BC3 730F                <1> 	jnc	short syschdir0
 26779                              <1> 	; 'directory not found !' error
 26780 00008BC5 C705[65B10000]0C00- <1> 	mov	dword [u.error], ERR_DIR_NOT_FOUND ; 12
 26781 00008BCD 0000                <1>
 26782 00008BCF E9B1EFFFFF          <1> 	jmp	error
 26783                              <1> syschdir0:
 26784 00008BD4 E816050000          <1> 	call	access
 26785                              <1> 		; jsr r0,access; 2 / get i-node into core
 26786 00008BD9 66F705[E4AD0000]00- <1> 	test	word [i.flgs], 4000h
 26787 00008BE1 40                  <1>
 26788                              <1> 		; bit $40000,i.flgs / is it a directory?
 26789                              <1> 	;jz	error 
 26790                              <1> 		; beq error3 / no error
 26791 00008BE2 750F                <1> 	jnz	short syschdir1
 26792 00008BE4 C705[65B10000]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
 26793 00008BEC 0000                <1>
 26794 00008BEE E992EFFFFF          <1> 	jmp	error
 26795                              <1> syschdir1:
 26796 00008BF3 66A3[14B10000]      <1> 	mov	[u.cdir], ax
 26797                              <1> 		; mov r1,u.cdir / move i-number to users 
 26798                              <1> 			      ; / current directory
 26799 00008BF9 66A1[F4B00000]      <1> 	mov	ax, [cdev]
 26800 00008BFF 66A3[5AB10000]      <1> 	mov	[u.cdrv], ax
 26801                              <1> 		; mov cdev,u.cdev / move its device to users 
 26802                              <1> 			        ; / current device
 26803 00008C05 E99BEFFFFF          <1> 	jmp	sysret
 26804                              <1> 		; br sysret3
 26805                              <1> 	
 26806                              <1> syschmod: ; < change mode of file >
 26807                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 26808                              <1> 	; 20/06/2013 - 07/07/2013 (Retro UNIX 8086 v1)
 26809                              <1> 	;
 26810                              <1> 	; 'syschmod' changes mode of the file whose name is given as
 26811                              <1> 	; null terminated string pointed to by 'name' has it's mode 
 26812                              <1> 	; changed to 'mode'.
 26813                              <1> 	;
 26814                              <1> 	; Calling sequence:
 26815                              <1> 	;	syschmod; name; mode
 26816                              <1> 	; Arguments:
 26817                              <1> 	;	name - address of the file name
 26818                              <1> 	;	       terminated by null byte.
 26819                              <1> 	;	mode - (new) mode/flags < attributes >
 26820                              <1> 	;	
 26821                              <1> 	; Inputs: -
 26822                              <1> 	; Outputs: -
 26823                              <1> 	; ...............................................................
 26824                              <1> 	;				
 26825                              <1> 	; Retro UNIX 8086 v1 modification: 
 26826                              <1> 	;       'syschmod' system call has two arguments; so,
 26827                              <1> 	;	* 1st argument, name is pointed to by BX register
 26828                              <1> 	;	* 2nd argument, mode is in CX register
 26829                              <1> 	;
 26830                              <1> 	; Mode bits (Flags):
 26831                              <1> 	;	bit 0 - write permission for non-owner (1)
 26832                              <1> 	;	bit 1 - read permission for non-owner (2)
 26833                              <1> 	;	bit 2 - write permission for owner (4)
 26834                              <1> 	;	bit 3 - read permission for owner (8)
 26835                              <1> 	;	bit 4 - executable flag (16) 	
 26836                              <1> 	;	bit 5 - set user ID on execution flag (32) 
 26837                              <1> 	;	bit 6,7,8,9,10,11 are not used (undefined)
 26838                              <1> 	;	bit 12 - large file flag (4096)
 26839                              <1> 	;	bit 13 - file has modified flag (always on) (8192)
 26840                              <1> 	;	bit 14 - directory flag (16384)
 26841                              <1> 	;	bit 15 - 'i-node is allocated' flag (32768)
 26842                              <1> 
 26843                              <1> 	; / name; mode
 26844 00008C0A E814000000          <1> 	call	isown
 26845                              <1> 		;jsr r0,isown / get the i-node and check user status
 26846 00008C0F 66F705[E4AD0000]00- <1> 	test	word [i.flgs], 4000h
 26847 00008C17 40                  <1>
 26848                              <1> 		; bit	$40000,i.flgs / directory?
 26849 00008C18 7402                <1> 	jz	short syschmod1
 26850                              <1> 		; beq 2f / no
 26851                              <1> 	; AL = (new) mode
 26852 00008C1A 24CF                <1> 	and	al, 0CFh ; 11001111b (clears bit 4 & 5)
 26853                              <1> 		; bic $60,r2 / su & ex / yes, clear set user id and 
 26854                              <1> 			   ; / executable modes
 26855                              <1> syschmod1: ; 2:
 26856 00008C1C A2[E4AD0000]        <1> 	mov	[i.flgs], al	
 26857                              <1> 		; movb r2,i.flgs / move remaining mode to i.flgs
 26858 00008C21 EB42                <1> 	jmp	short isown1
 26859                              <1> 		; br 1f
 26860                              <1> 
 26861                              <1> isown:
 26862                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 26863                              <1> 	; 04/05/2013 - 07/07/2013 (Retro UNIX 8086 v1)
 26864                              <1> 	;
 26865                              <1> 	; 'isown' is given a file name (the 1st argument).
 26866                              <1> 	;  It find the i-number of that file via 'namei' 
 26867                              <1> 	;  then gets the i-node into core via 'iget'.
 26868                              <1> 	;  It then tests to see if the user is super user. 
 26869                              <1> 	;  If not, it cheks to see if the user is owner of 
 26870                              <1> 	;  the file. If he is not an error occurs.
 26871                              <1> 	;  If user is the owner 'setimod' is called to indicate
 26872                              <1> 	;  the inode has been modificed and the 2nd argument of
 26873                              <1> 	;  the call is put in r2.
 26874                              <1> 	;
 26875                              <1> 	; INPUTS ->
 26876                              <1> 	;    arguments of syschmod and syschown calls
 26877                              <1> 	; OUTPUTS ->
 26878                              <1> 	;    u.uid - id of user
 26879                              <1> 	;    imod - set to a 1
 26880                              <1> 	;    r2 - contains second argument of the system call				 	
 26881                              <1> 	;
 26882                              <1> 	;   ((AX=R2) output as 2nd argument)
 26883                              <1> 	;
 26884                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 26885                              <1> 	;
 26886                              <1> 		; jsr r0,arg2 / u.namep points to file name
 26887                              <1> 	;; ! 2nd argument on top of stack !
 26888                              <1> 	;; 22/06/2015 - 32 bit modifications
 26889                              <1> 	;; 07/07/2013
 26890 00008C23 891D[28B10000]      <1> 	mov	[u.namep], ebx ;; 1st argument
 26891 00008C29 51                  <1> 	push 	ecx ;; 2nd argument
 26892                              <1> 	;;
 26893 00008C2A E812FEFFFF          <1> 	call	namei
 26894                              <1> 		; jsr r0,namei / get its i-number
 26895                              <1>        ; Retro UNIX 8086 v1 modification !
 26896                              <1>        ; ax = 0 -> file not found 
 26897                              <1> 	;and	ax, ax
 26898                              <1> 	;jz	error
 26899                              <1> 	;jc	error ; 27/05/2013
 26900                              <1> 		; br error3
 26901 00008C2F 730F                <1> 	jnc	short isown0
 26902                              <1> 	; 'file not found !' error
 26903 00008C31 C705[65B10000]0C00- <1> 	mov	dword [u.error], ERR_FILE_NOT_FOUND ; 12
 26904 00008C39 0000                <1>
 26905 00008C3B E945EFFFFF          <1> 	jmp	error
 26906                              <1> isown0:
 26907 00008C40 E898040000          <1> 	call	iget
 26908                              <1> 		; jsr r0,iget / get i-node into core
 26909 00008C45 A0[5CB10000]        <1> 	mov	al, [u.uid] ; 02/08/2013
 26910 00008C4A 08C0                <1> 	or	al, al
 26911                              <1> 		; tstb u.uid / super user?
 26912 00008C4C 7417                <1> 	jz	short isown1
 26913                              <1> 		; beq 1f / yes, branch
 26914 00008C4E 3A05[E7AD0000]      <1> 	cmp	al, [i.uid]
 26915                              <1> 		; cmpb i.uid,u.uid / no, is this the owner of
 26916                              <1> 				 ; / the file
 26917                              <1> 	;jne	error
 26918                              <1> 		; beq 1f / yes
 26919                              <1> 		; jmp error3 / no, error
 26920 00008C54 740F                <1> 	je	short isown1
 26921                              <1> 
 26922 00008C56 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_NOT_OWNER  ; 11
 26923 00008C5E 0000                <1>
 26924                              <1> 			;  'permission denied !' error
 26925 00008C60 E920EFFFFF          <1> 	jmp	error
 26926                              <1> isown1: ; 1:
 26927 00008C65 E881040000          <1> 	call	setimod
 26928                              <1> 		; jsr r0,setimod / indicates 
 26929                              <1> 		;	       ; / i-node has been modified
 26930 00008C6A 58                  <1> 	pop	eax ; 2nd argument
 26931                              <1> 		; mov (sp)+,r2 / mode is put in r2 
 26932                              <1> 		       ; / (u.off put on stack with 2nd arg)
 26933 00008C6B C3                  <1> 	retn
 26934                              <1> 		; rts r0
 26935                              <1> 
 26936                              <1> ;;arg:  ; < get system call arguments >
 26937                              <1> 	; 'arg' extracts an argument for a routine whose call is 
 26938                              <1> 	; of form:
 26939                              <1> 	;	sys 'routine' ; arg1
 26940                              <1> 	;		or
 26941                              <1> 	;	sys 'routine' ; arg1 ; arg2
 26942                              <1> 	;		or
 26943                              <1> 	;	sys 'routine' ; arg1;...;arg10 (sys exec) 
 26944                              <1> 	;	
 26945                              <1> 	; INPUTS ->
 26946                              <1> 	;    u.sp+18 - contains a pointer to one of arg1..argn
 26947                              <1> 	;	This pointers's value is actually the value of
 26948                              <1> 	;	update pc at the the trap to sysent (unkni) is
 26949                              <1> 	;	made to process the sys instruction
 26950                              <1> 	;    r0 - contains the return address for the routine
 26951                              <1> 	;	that called arg. The data in the word pointer 
 26952                              <1> 	;	to by the return address is used as address
 26953                              <1> 	;	in which the extracted argument is stored   		
 26954                              <1> 	;    	
 26955                              <1> 	; OUTPUTS ->
 26956                              <1> 	;    'address' - contains the extracted argument 
 26957                              <1> 	;    u.sp+18 - is incremented by 2 
 26958                              <1> 	;    r1 - contains the extracted argument
 26959                              <1> 	;    r0 - points to the next instruction to be
 26960                              <1> 	;	 executed in the calling routine.
 26961                              <1> 	;
 26962                              <1>   
 26963                              <1> 	; mov u.sp,r1
 26964                              <1> 	; mov *18.(r1),*(r0)+ / put argument of system call
 26965                              <1> 			; / into argument of arg2
 26966                              <1> 	; add $2,18.(r1) / point pc on stack 
 26967                              <1> 			      ; / to next system argument
 26968                              <1> 	; rts r0
 26969                              <1> 
 26970                              <1> ;;arg2: ; < get system calls arguments - with file name pointer>
 26971                              <1> 	; 'arg2' takes first argument in system call
 26972                              <1> 	;  (pointer to name of the file) and puts it in location
 26973                              <1> 	;  u.namep; takes second argument and puts it in u.off
 26974                              <1> 	;  and on top of the stack
 26975                              <1> 	;	
 26976                              <1> 	; INPUTS ->
 26977                              <1> 	;    u.sp, r0
 26978                              <1> 	;    	
 26979                              <1> 	; OUTPUTS ->
 26980                              <1> 	;    u.namep
 26981                              <1> 	;    u.off 
 26982                              <1> 	;    u.off pushed on stack
 26983                              <1> 	;    r1
 26984                              <1> 	;
 26985                              <1> 
 26986                              <1> 	; jsr	r0,arg; u.namep / u.namep contains value of
 26987                              <1> 				; / first arg in sys call
 26988                              <1> 	; jsr r0,arg; u.off / u.off contains value of 
 26989                              <1> 				; / second arg in sys call
 26990                              <1> 	; mov r0,r1 / r0 points to calling routine
 26991                              <1> 	; mov (sp),r0 / put operation code back in r0
 26992                              <1> 	; mov u.off,(sp) / put pointer to second argument 
 26993                              <1> 			; / on stack
 26994                              <1> 	; jmp (r1) / return to calling routine
 26995                              <1> 
 26996                              <1> syschown: ; < change owner of file >
 26997                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 26998                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 26999                              <1> 	;
 27000                              <1> 	; 'syschown' changes the owner of the file whose name is given
 27001                              <1> 	; as null terminated string pointed to by 'name' has it's owner
 27002                              <1> 	; changed to 'owner'
 27003                              <1> 	;
 27004                              <1> 	; Calling sequence:
 27005                              <1> 	;	syschown; name; owner
 27006                              <1> 	; Arguments:
 27007                              <1> 	;	name - address of the file name
 27008                              <1> 	;	       terminated by null byte.
 27009                              <1> 	;	owner - (new) owner (number/ID)
 27010                              <1> 	;	
 27011                              <1> 	; Inputs: -
 27012                              <1> 	; Outputs: -
 27013                              <1> 	; ...............................................................
 27014                              <1> 	;				
 27015                              <1> 	; Retro UNIX 8086 v1 modification: 
 27016                              <1> 	;       'syschown' system call has two arguments; so,
 27017                              <1> 	;	* 1st argument, name is pointed to by BX register
 27018                              <1> 	;	* 2nd argument, owner number is in CX register
 27019                              <1> 	;
 27020                              <1> 	; / name; owner
 27021 00008C6C E8B2FFFFFF          <1> 	call	isown
 27022                              <1> 		; jsr r0,isown / get the i-node and check user status
 27023 00008C71 803D[5CB10000]00    <1> 	cmp 	byte [u.uid], 0 ; 02/08/2013 
 27024                              <1> 		; tstb u.uid / super user
 27025 00008C78 7418                <1> 	jz	short syschown1
 27026                              <1> 		; beq 2f / yes, 2f
 27027 00008C7A F605[E4AD0000]20    <1>         test    byte [i.flgs], 20h ; 32
 27028                              <1> 		; bit $40,i.flgs / no, set userid on execution?
 27029                              <1> 	;jnz	error
 27030                              <1> 		; bne 3f / yes error, could create Trojan Horses
 27031 00008C81 740F                <1> 	jz	short syschown1
 27032                              <1> 	; 'permission denied !'
 27033 00008C83 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS  ; 11
 27034 00008C8B 0000                <1>
 27035 00008C8D E9F3EEFFFF          <1> 	jmp	error
 27036                              <1> syschown1: ; 2:
 27037                              <1> 	; AL = owner (number/ID)
 27038 00008C92 A2[E7AD0000]        <1> 	mov	[i.uid], al ; 23/06/2015
 27039                              <1> 		;  movb	r2,i.uid / no, put the new owners id 
 27040                              <1> 			       ; / in the i-node
 27041 00008C97 E909EFFFFF          <1> 	jmp	sysret
 27042                              <1> 	; 1: 
 27043                              <1> 		; jmp sysret4
 27044                              <1> 	; 3:
 27045                              <1> 		; jmp	error
 27046                              <1> 
 27047                              <1> systime: ; / get time of year
 27048                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 27049                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
 27050                              <1> 	;
 27051                              <1> 	; 20/06/2013
 27052                              <1> 	; 'systime' gets the time of the year.
 27053                              <1> 	; The present time is put on the stack.
 27054                              <1> 	;
 27055                              <1> 	; Calling sequence:
 27056                              <1> 	;	systime
 27057                              <1> 	; Arguments: -
 27058                              <1> 	;	
 27059                              <1> 	; Inputs: -
 27060                              <1> 	; Outputs: sp+2, sp+4 - present time
 27061                              <1> 	; ...............................................................
 27062                              <1> 	;	
 27063                              <1> 	; Retro UNIX 8086 v1 modification: 
 27064                              <1> 	;       'systime' system call will return to the user
 27065                              <1> 	;	with unix time (epoch) in DX:AX register pair
 27066                              <1> 	;
 27067                              <1> 	; 	!! Major modification on original Unix v1 'systime' 
 27068                              <1> 	;	system call for PC compatibility !!		 	
 27069                              <1> 
 27070 00008C9C E851040000          <1> 	call 	epoch
 27071 00008CA1 A3[10B10000]        <1> 	mov 	[u.r0], eax
 27072                              <1> 		; mov s.time,4(sp)
 27073                              <1> 		; mov s.time+2,2(sp) / put the present time 
 27074                              <1> 				   ; / on the stack
 27075                              <1> 		; br sysret4
 27076 00008CA6 E9FAEEFFFF          <1> 	jmp	sysret 
 27077                              <1> 
 27078                              <1> sysstime: ; / set time
 27079                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 27080                              <1> 	; 20/06/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 27081                              <1> 	;
 27082                              <1> 	; 'sysstime' sets the time. Only super user can use this call.
 27083                              <1> 	;
 27084                              <1> 	; Calling sequence:
 27085                              <1> 	;	sysstime
 27086                              <1> 	; Arguments: -
 27087                              <1> 	;	
 27088                              <1> 	; Inputs: sp+2, sp+4 - time system is to be set to.
 27089                              <1> 	; Outputs: -
 27090                              <1> 	; ...............................................................
 27091                              <1> 	;	
 27092                              <1> 	; Retro UNIX 8086 v1 modification: 
 27093                              <1> 	;	the user calls 'sysstime' with unix (epoch) time
 27094                              <1> 	;	(to be set) is in CX:BX register pair as two arguments.
 27095                              <1> 	; 
 27096                              <1> 	;	Retro UNIX 8086 v1 argument transfer method 2 is used
 27097                              <1> 	;	to get sysstime system call arguments from the user;
 27098                              <1> 	;	* 1st argument, lowword of unix time is in BX register
 27099                              <1> 	;	* 2nd argument, highword of unix time is in CX register		 	
 27100                              <1> 	;
 27101                              <1> 	; 	!! Major modification on original Unix v1 'sysstime' 
 27102                              <1> 	;	system call for PC compatibility !!	
 27103                              <1> 
 27104 00008CAB 803D[5CB10000]00    <1> 	cmp	byte [u.uid], 0
 27105                              <1> 		; tstb u.uid / is user the super user
 27106                              <1> 	;ja	error
 27107                              <1> 		; bne error4 / no, error
 27108 00008CB2 760F                <1> 	jna	short systime1
 27109                              <1> 	; 'permission denied !'
 27110 00008CB4 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11 
 27111 00008CBC 0000                <1>
 27112 00008CBE E9C2EEFFFF          <1> 	jmp	error
 27113                              <1> systime1:
 27114                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - 32 bit version)
 27115                              <1> 	; EBX = unix (epoch) time (from user)
 27116 00008CC3 89D8                <1> 	mov	eax, ebx
 27117 00008CC5 E829040000          <1> 	call 	set_date_time
 27118                              <1> 		; mov 4(sp),s.time
 27119                              <1> 		; mov 2(sp),s.time+2 / set the system time
 27120 00008CCA E9D6EEFFFF          <1> 	jmp	sysret
 27121                              <1> 		; br sysret4
 27122                              <1> 
 27123                              <1> sysbreak:
 27124                              <1> 	; 18/10/2015
 27125                              <1> 	; 07/10/2015
 27126                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 27127                              <1> 	; 20/06/2013 - 24/03/2014 (Retro UNIX 8086 v1)
 27128                              <1> 	;
 27129                              <1> 	; 'sysbreak' sets the programs break points. 
 27130                              <1> 	; It checks the current break point (u.break) to see if it is
 27131                              <1> 	; between "core" and the stack (sp). If it is, it is made an
 27132                              <1> 	; even address (if it was odd) and the area between u.break
 27133                              <1> 	; and the stack is cleared. The new breakpoint is then put
 27134                              <1> 	; in u.break and control is passed to 'sysret'.
 27135                              <1> 	;
 27136                              <1> 	; Calling sequence:
 27137                              <1> 	;	sysbreak; addr
 27138                              <1> 	; Arguments: -
 27139                              <1> 	;	
 27140                              <1> 	; Inputs: u.break - current breakpoint
 27141                              <1> 	; Outputs: u.break - new breakpoint 
 27142                              <1> 	;	area between old u.break and the stack (sp) is cleared.
 27143                              <1> 	; ...............................................................
 27144                              <1> 	;	
 27145                              <1> 	; Retro UNIX 8086 v1 modification:
 27146                              <1> 	;	The user/application program puts breakpoint address
 27147                              <1> 	;       in BX register as 'sysbreak' system call argument.
 27148                              <1> 	; 	(argument transfer method 1)
 27149                              <1> 	;
 27150                              <1> 	;  NOTE: Beginning of core is 0 in Retro UNIX 8086 v1 !
 27151                              <1> 	; 	((!'sysbreak' is not needed in Retro UNIX 8086 v1!))
 27152                              <1> 	;  NOTE:
 27153                              <1> 	; 	'sysbreak' clears extended part (beyond of previous
 27154                              <1> 	;	'u.break' address) of user's memory for original unix's
 27155                              <1> 	;	'bss' compatibility with Retro UNIX 8086 v1 (19/11/2013)
 27156                              <1> 
 27157                              <1> 		; mov u.break,r1 / move users break point to r1
 27158                              <1> 		; cmp r1,$core / is it the same or lower than core?
 27159                              <1> 		; blos 1f / yes, 1f
 27160                              <1> 	; 23/06/2015
 27161 00008CCF 8B2D[3CB10000]      <1> 	mov	ebp, [u.break] ; virtual address (offset)
 27162                              <1> 	;and	ebp, ebp
 27163                              <1> 	;jz	short sysbreak_3 
 27164                              <1> 	; Retro UNIX 386 v1 NOTE: u.break points to virtual address !!!
 27165                              <1> 	; (Even break point address is not needed for Retro UNIX 386 v1)
 27166 00008CD5 8B15[08B10000]      <1> 	mov	edx, [u.sp] ; kernel stack at the beginning of sys call
 27167 00008CDB 83C20C              <1> 	add	edx, 12 ; EIP -4-> CS -4-> EFLAGS -4-> ESP (user) 
 27168                              <1> 	; 07/10/2015
 27169 00008CDE 891D[3CB10000]      <1> 	mov	[u.break], ebx ; virtual address !!!
 27170                              <1> 	;
 27171 00008CE4 3B1A                <1> 	cmp	ebx, [edx] ; compare new break point with 
 27172                              <1> 			   ; with top of user's stack (virtual!)
 27173 00008CE6 7327                <1> 	jnb	short sysbreak_3
 27174                              <1> 		; cmp r1,sp / is it the same or higher 
 27175                              <1> 			  ; / than the stack?
 27176                              <1> 		; bhis 1f / yes, 1f
 27177 00008CE8 89DE                <1> 	mov	esi, ebx
 27178 00008CEA 29EE                <1> 	sub	esi, ebp ; new break point - old break point
 27179 00008CEC 7621                <1> 	jna	short sysbreak_3 
 27180                              <1> 	;push	ebx
 27181                              <1> sysbreak_1:
 27182 00008CEE 89EB                <1> 	mov	ebx, ebp  
 27183 00008CF0 E8A5AAFFFF          <1> 	call	get_physical_addr ; get physical address
 27184 00008CF5 0F82A8FEFFFF        <1> 	jc	tr_addr_nm_err
 27185                              <1> 	; 18/10/2015
 27186 00008CFB 89C7                <1> 	mov	edi, eax 
 27187 00008CFD 29C0                <1> 	sub	eax, eax ; 0
 27188                              <1> 		 ; ECX = remain byte count in page (1-4096)
 27189 00008CFF 39CE                <1> 	cmp	esi, ecx
 27190 00008D01 7302                <1> 	jnb	short sysbreak_2
 27191 00008D03 89F1                <1> 	mov	ecx, esi
 27192                              <1> sysbreak_2:
 27193 00008D05 29CE                <1> 	sub	esi, ecx
 27194 00008D07 01CD                <1> 	add	ebp, ecx
 27195 00008D09 F3AA                <1> 	rep 	stosb
 27196 00008D0B 09F6                <1> 	or	esi, esi
 27197 00008D0D 75DF                <1> 	jnz	short sysbreak_1
 27198                              <1> 	;
 27199                              <1> 		; bit $1,r1 / is it an odd address
 27200                              <1> 		; beq 2f / no, its even
 27201                              <1> 		; clrb (r1)+ / yes, make it even
 27202                              <1> 	; 2: / clear area between the break point and the stack
 27203                              <1> 		; cmp r1,sp / is it higher or same than the stack
 27204                              <1> 		; bhis 1f / yes, quit
 27205                              <1> 		; clr (r1)+ / clear word
 27206                              <1> 		; br 2b / go back
 27207                              <1> 	;pop	ebx
 27208                              <1> sysbreak_3: ; 1:
 27209                              <1> 	;mov	[u.break], ebx ; virtual address !!!
 27210                              <1> 		; jsr r0,arg; u.break / put the "address" 
 27211                              <1> 			; / in u.break (set new break point)
 27212                              <1> 		; br sysret4 / br sysret
 27213 00008D0F E991EEFFFF          <1> 	jmp	sysret
 27214                              <1> 
 27215                              <1> 
 27216                              <1> maknod: 
 27217                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27218                              <1> 	; 02/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 27219                              <1> 	;
 27220                              <1> 	; 'maknod' creates an i-node and makes a directory entry
 27221                              <1> 	; for this i-node in the current directory.
 27222                              <1> 	;
 27223                              <1> 	; INPUTS ->
 27224                              <1> 	;    r1 - contains mode
 27225                              <1> 	;    ii - current directory's i-number	
 27226                              <1> 	;    	
 27227                              <1> 	; OUTPUTS ->
 27228                              <1> 	;    u.dirbuf - contains i-number of free i-node 
 27229                              <1> 	;    i.flgs - flags in new i-node 
 27230                              <1> 	;    i.uid - filled with u.uid
 27231                              <1> 	;    i.nlks - 1 is put in the number of links
 27232                              <1> 	;    i.ctim - creation time				
 27233                              <1> 	;    i.ctim+2 - modification time
 27234                              <1> 	;    imod - set via call to setimod
 27235                              <1> 	;	
 27236                              <1> 	; ((AX = R1)) input
 27237                              <1> 	;
 27238                              <1> 	; (Retro UNIX Prototype : 
 27239                              <1> 	;	30/10/2012 - 01/03/2013, UNIXCOPY.ASM)
 27240                              <1>         ; ((Modified registers: eAX, eDX, eBX, eCX, eSI, eDI, eBP))  
 27241                              <1> 
 27242                              <1> 	; / r1 contains the mode
 27243 00008D14 80CC80              <1> 	or 	ah, 80h  ; 10000000b
 27244                              <1> 		; bis	$100000,r1 / allocate flag set
 27245 00008D17 6650                <1> 	push	ax
 27246                              <1> 		; mov r1,-(sp) / put mode on stack
 27247                              <1> 	; 31/07/2013
 27248 00008D19 66A1[F0B00000]      <1> 	mov	ax, [ii] ; move current i-number to AX/r1
 27249                              <1> 		; mov ii,r1 / move current i-number to r1
 27250 00008D1F B201                <1> 	mov	dl, 1 ; owner flag mask
 27251 00008D21 E8C9030000          <1> 	call	access	
 27252                              <1> 		; jsr r0,access; 1 / get its i-node into core
 27253 00008D26 6650                <1> 	push	ax
 27254                              <1> 		; mov r1,-(sp) / put i-number on stack
 27255 00008D28 66B82800            <1> 	mov	ax, 40
 27256                              <1> 		; mov $40.,r1 / r1 = 40
 27257                              <1> maknod1: ; 1: / scan for a free i-node (next 4 instructions)
 27258 00008D2C 6640                <1> 	inc	ax
 27259                              <1> 		; inc r1 / r1 = r1 + 1
 27260 00008D2E E8C1030000          <1> 	call	imap
 27261                              <1> 		; jsr r0,imap / get byte address and bit position in 
 27262                              <1> 			    ; /	inode map in r2 & m
 27263                              <1>           ; DX (MQ) has a 1 in the calculated bit position
 27264                              <1>           ; eBX (R2) has byte address of the byte with allocation bit
 27265                              <1> 	; 22/06/2015 - NOTE for next Retro UNIX version: 
 27266                              <1> 	;	       Inode count must be checked here
 27267                              <1> 	; (Original UNIX v1 did not check inode count here !?) 	
 27268 00008D33 8413                <1> 	test	[ebx], dl
 27269                              <1> 		; bitb mq,(r2) / is the i-node active
 27270 00008D35 75F5                <1> 	jnz	short maknod1
 27271                              <1> 		; bne 1b / yes, try the next one
 27272 00008D37 0813                <1> 	or	[ebx], dl
 27273                              <1> 		; bisb mq,(r2) / no, make it active 
 27274                              <1> 			     ; / (put a 1 in the bit map)
 27275 00008D39 E89F030000          <1> 	call	iget
 27276                              <1> 		; jsr r0,iget / get i-node into core
 27277 00008D3E 66F705[E4AD0000]00- <1> 	test	word [i.flgs], 8000h 
 27278 00008D46 80                  <1>
 27279                              <1> 		; tst i.flgs / is i-node already allocated
 27280 00008D47 75E3                <1> 	jnz	short maknod1	
 27281                              <1> 		; blt 1b / yes, look for another one
 27282 00008D49 66A3[42B10000]      <1> 	mov	[u.dirbuf], ax
 27283                              <1> 		; mov r1,u.dirbuf / no, put i-number in u.dirbuf
 27284 00008D4F 6658                <1> 	pop	ax
 27285                              <1> 		; mov (sp)+,r1 / get current i-number back
 27286 00008D51 E887030000          <1> 	call	iget
 27287                              <1> 		; jsr r0,iget / get i-node in core
 27288 00008D56 E87DF7FFFF          <1> 	call	mkdir
 27289                              <1> 		; jsr r0,mkdir / make a directory entry 
 27290                              <1> 			     ; / in current directory
 27291 00008D5B 66A1[42B10000]      <1> 	mov	ax, [u.dirbuf]
 27292                              <1> 		; mov u.dirbuf,r1 / r1 = new inode number
 27293 00008D61 E877030000          <1> 	call	iget
 27294                              <1> 		; jsr r0,iget / get it into core
 27295                              <1> 		; jsr r0,copyz; inode; inode+32. / 0 it out
 27296 00008D66 B908000000          <1> 	mov	ecx, 8 
 27297 00008D6B 31C0                <1> 	xor	eax, eax ; 0
 27298 00008D6D BF[E4AD0000]        <1> 	mov	edi, inode 
 27299 00008D72 F3AB                <1> 	rep	stosd
 27300                              <1> 	;
 27301 00008D74 668F05[E4AD0000]    <1> 	pop	word [i.flgs]
 27302                              <1> 		; mov (sp)+,i.flgs / fill flags
 27303 00008D7B 8A0D[5CB10000]      <1> 	mov 	cl, [u.uid] ; 02/08/2013
 27304 00008D81 880D[E7AD0000]      <1> 	mov 	[i.uid], cl
 27305                              <1> 		; movb u.uid,i.uid / user id	
 27306 00008D87 C605[E6AD0000]01    <1> 	mov     byte [i.nlks], 1
 27307                              <1> 		; movb $1,i.nlks / 1 link
 27308                              <1> 	;call	epoch ; Retro UNIX 8086 v1 modification !
 27309                              <1> 	;mov	eax, [s.time]
 27310                              <1> 	;mov 	[i.ctim], eax
 27311                              <1> 	 	; mov s.time,i.ctim / time created
 27312                              <1> 	 	; mov s.time+2,i.ctim+2 / time modified
 27313                              <1> 	; Retro UNIX 8086 v1 modification !
 27314                              <1> 	; i.ctime=0, i.ctime+2=0 and
 27315                              <1>         ; 'setimod' will set ctime of file via 'epoch'
 27316 00008D8E E858030000          <1> 	call setimod
 27317                              <1> 		; jsr r0,setimod / set modified flag
 27318 00008D93 C3                  <1> 	retn
 27319                              <1> 		; rts r0 / return
 27320                              <1> 
 27321                              <1> sysseek: ; / moves read write pointer in an fsp entry
 27322                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27323                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 27324                              <1> 	;
 27325                              <1> 	; 'sysseek' changes the r/w pointer of (3rd word of in an
 27326                              <1> 	; fsp entry) of an open file whose file descriptor is in u.r0.
 27327                              <1> 	; The file descriptor refers to a file open for reading or
 27328                              <1> 	; writing. The read (or write) pointer is set as follows:
 27329                              <1> 	;	* if 'ptrname' is 0, the pointer is set to offset.
 27330                              <1> 	;	* if 'ptrname' is 1, the pointer is set to its
 27331                              <1> 	;	  current location plus offset.
 27332                              <1> 	;	* if 'ptrname' is 2, the pointer is set to the
 27333                              <1> 	;	  size of file plus offset.
 27334                              <1> 	; The error bit (e-bit) is set for an undefined descriptor.
 27335                              <1> 	;
 27336                              <1> 	; Calling sequence:
 27337                              <1> 	;	sysseek; offset; ptrname
 27338                              <1> 	; Arguments:
 27339                              <1> 	;	offset - number of bytes desired to move 
 27340                              <1> 	;		 the r/w pointer
 27341                              <1> 	;	ptrname - a switch indicated above
 27342                              <1> 	;
 27343                              <1> 	; Inputs: r0 - file descriptor 
 27344                              <1> 	; Outputs: -
 27345                              <1> 	; ...............................................................
 27346                              <1> 	;	
 27347                              <1> 	; Retro UNIX 8086 v1 modification: 
 27348                              <1> 	;       'sysseek' system call has three arguments; so,
 27349                              <1> 	;	* 1st argument, file descriptor is in BX (BL) register
 27350                              <1> 	;	* 2nd argument, offset is in CX register
 27351                              <1> 	;	* 3rd argument, ptrname/switch is in DX (DL) register	
 27352                              <1> 	;	
 27353                              <1> 
 27354 00008D94 E823000000          <1> 	call	seektell
 27355                              <1> 	; AX = u.count
 27356                              <1> 	; BX = *u.fofp
 27357                              <1> 		; jsr r0,seektell / get proper value in u.count
 27358                              <1> 		; add u.base,u.count / add u.base to it
 27359 00008D99 0305[30B10000]      <1> 	add	eax, [u.base] ; add offset (u.base) to base
 27360 00008D9F 8903                <1> 	mov	[ebx], eax
 27361                              <1> 		; mov u.count,*u.fofp / put result into r/w pointer
 27362 00008DA1 E9FFEDFFFF          <1> 	jmp	sysret
 27363                              <1> 		; br sysret4
 27364                              <1> 
 27365                              <1> systell: ; / get the r/w pointer
 27366                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27367                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 27368                              <1> 	;
 27369                              <1> 	; Retro UNIX 8086 v1 modification:
 27370                              <1> 	; ! 'systell' does not work in original UNIX v1,
 27371                              <1> 	; 	    it returns with error !
 27372                              <1> 	; Inputs: r0 - file descriptor 
 27373                              <1> 	; Outputs: r0 - file r/w pointer
 27374                              <1> 
 27375                              <1> 	;xor	ecx, ecx ; 0
 27376 00008DA6 BA01000000          <1> 	mov	edx, 1 ; 05/08/2013
 27377                              <1> 	;call 	seektell
 27378 00008DAB E812000000          <1> 	call 	seektell0 ; 05/08/2013
 27379                              <1> 	;mov	ebx, [u.fofp]
 27380 00008DB0 8B03                <1> 	mov	eax, [ebx]
 27381 00008DB2 A3[10B10000]        <1> 	mov	[u.r0], eax
 27382 00008DB7 E9E9EDFFFF          <1> 	jmp	sysret
 27383                              <1> 
 27384                              <1> ; Original unix v1 'systell' system call:
 27385                              <1> 		; jsr r0,seektell
 27386                              <1> 		; br error4
 27387                              <1> 
 27388                              <1> seektell:
 27389                              <1> 	; 03/01/2016
 27390                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27391                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 27392                              <1> 	;
 27393                              <1> 	; 'seektell' puts the arguments from sysseek and systell
 27394                              <1> 	; call in u.base and u.count. It then gets the i-number of
 27395                              <1> 	; the file from the file descriptor in u.r0 and by calling
 27396                              <1> 	; getf. The i-node is brought into core and then u.count
 27397                              <1> 	; is checked to see it is a 0, 1, or 2.
 27398                              <1> 	; If it is 0 - u.count stays the same
 27399                              <1> 	;          1 - u.count = offset (u.fofp)
 27400                              <1> 	;	   2 - u.count = i.size (size of file)
 27401                              <1> 	; 	 		
 27402                              <1> 	; !! Retro UNIX 8086 v1 modification:
 27403                              <1> 	;	Argument 1, file descriptor is in BX;
 27404                              <1> 	;	Argument 2, offset is in CX;
 27405                              <1> 	;	Argument 3, ptrname/switch is in DX register.	
 27406                              <1> 	;
 27407                              <1> 	; mov 	ax, 3 ; Argument transfer method 3 (three arguments)	
 27408                              <1> 	; call 	arg
 27409                              <1> 	;
 27410                              <1> 	; ((Return -> ax = base for offset (position= base+offset))
 27411                              <1> 	;
 27412 00008DBC 890D[30B10000]      <1> 	mov 	[u.base], ecx ; offset
 27413                              <1> 		; jsr r0,arg; u.base / puts offset in u.base
 27414                              <1> seektell0:
 27415 00008DC2 8915[34B10000]      <1> 	mov 	[u.count], edx
 27416                              <1> 		; jsr r0,arg; u.count / put ptr name in u.count
 27417                              <1> 	; mov	ax, bx
 27418                              <1> 		; mov *u.r0,r1 / file descriptor in r1 
 27419                              <1> 			     ; / (index in u.fp list)
 27420                              <1> 	; call	getf
 27421                              <1> 		; jsr r0,getf / u.fofp points to 3rd word in fsp entry
 27422                              <1> 	; BX = file descriptor (file number)
 27423 00008DC8 E83DFCFFFF          <1> 	call	getf1
 27424 00008DCD 6609C0              <1> 	or	ax, ax ; i-number of the file
 27425                              <1> 		; mov r1,-(sp) / r1 has i-number of file, 
 27426                              <1> 		             ; / put it on the stack
 27427                              <1> 	;jz	error
 27428                              <1> 		; beq error4 / if i-number is 0, not active so error
 27429 00008DD0 750F                <1> 	jnz	short seektell1
 27430 00008DD2 C705[65B10000]0A00- <1> 	mov	dword [u.error], ERR_FILE_NOT_OPEN  ; 'file not open !'
 27431 00008DDA 0000                <1>
 27432 00008DDC E9A4EDFFFF          <1> 	jmp	error
 27433                              <1> seektell1:
 27434                              <1> 	;push	eax
 27435 00008DE1 80FC80              <1> 	cmp	ah, 80h
 27436 00008DE4 7203                <1> 	jb	short seektell2
 27437                              <1> 		; bgt .+4 / if its positive jump
 27438 00008DE6 66F7D8              <1> 	neg	ax
 27439                              <1> 		; neg r1 / if not make it positive
 27440                              <1> seektell2:
 27441 00008DE9 E8EF020000          <1> 	call	iget
 27442                              <1> 		; jsr r0,iget / get its i-node into core
 27443 00008DEE 8B1D[20B10000]      <1>         mov     ebx, [u.fofp] ; 05/08/2013
 27444 00008DF4 803D[34B10000]01    <1> 	cmp	byte [u.count], 1
 27445                              <1> 		; cmp u.count,$1 / is ptr name =1
 27446 00008DFB 7705                <1> 	ja	short seektell3
 27447                              <1> 		; blt 2f / no its zero
 27448 00008DFD 740A                <1> 	je	short seektell_4
 27449                              <1> 		; beq 1f / yes its 1
 27450 00008DFF 31C0                <1> 	xor	eax, eax
 27451                              <1> 	;jmp	short seektell_5
 27452 00008E01 C3                  <1> 	retn
 27453                              <1> seektell3:
 27454                              <1> 	; 03/01/2016
 27455                              <1> 	;movzx	eax, word [i.size]
 27456 00008E02 66A1[E8AD0000]      <1>         mov   	ax, [i.size]
 27457                              <1>                 ; mov i.size,u.count /  put number of bytes 
 27458                              <1>                                    ; / in file in u.count
 27459                              <1> 	;jmp	short seektell_5
 27460                              <1> 		; br 2f
 27461 00008E08 C3                  <1> 	retn
 27462                              <1> seektell_4: ; 1: / ptrname =1
 27463                              <1> 	;mov	ebx, [u.fofp]
 27464 00008E09 8B03                <1> 	mov	eax, [ebx]
 27465                              <1> 		; mov *u.fofp,u.count / put offset in u.count
 27466                              <1> ;seektell_5: ; 2: / ptrname =0
 27467                              <1> 	;mov	[u.count], eax
 27468                              <1> 	;pop	eax 
 27469                              <1> 		; mov (sp)+,r1 / i-number on stack  r1
 27470 00008E0B C3                  <1> 	retn
 27471                              <1> 		; rts r0
 27472                              <1> 
 27473                              <1> sysintr: ; / set interrupt handling
 27474                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27475                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 27476                              <1> 	;
 27477                              <1> 	; 'sysintr' sets the interrupt handling value. It puts
 27478                              <1> 	; argument of its call in u.intr then branches into 'sysquit'
 27479                              <1> 	; routine. u.tty is checked if to see if a control tty exists.
 27480                              <1> 	; If one does the interrupt character in the tty buffer is
 27481                              <1> 	; cleared and 'sysret'is called. If one does not exits
 27482                              <1> 	; 'sysret' is just called.	
 27483                              <1> 	;
 27484                              <1> 	; Calling sequence:
 27485                              <1> 	;	sysintr; arg
 27486                              <1> 	; Argument:
 27487                              <1> 	;	arg - if 0, interrupts (ASCII DELETE) are ignored.
 27488                              <1> 	;	    - if 1, intterupts cause their normal result
 27489                              <1> 	;		 i.e force an exit.
 27490                              <1> 	;	    - if arg is a location within the program,
 27491                              <1> 	;		control is passed to that location when
 27492                              <1> 	;		an interrupt occurs.	
 27493                              <1> 	; Inputs: -
 27494                              <1> 	; Outputs: -
 27495                              <1> 	; ...............................................................
 27496                              <1> 	;	
 27497                              <1> 	; Retro UNIX 8086 v1 modification: 
 27498                              <1> 	;       'sysintr' system call sets u.intr to value of BX
 27499                              <1> 	;	then branches into sysquit.
 27500                              <1> 	;
 27501 00008E0C 66891D[54B10000]    <1> 	mov	[u.intr], bx
 27502                              <1> 		; jsr r0,arg; u.intr / put the argument in u.intr
 27503                              <1> 		; br 1f / go into quit routine
 27504 00008E13 E98DEDFFFF          <1> 	jmp	sysret
 27505                              <1> 
 27506                              <1> sysquit:
 27507                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27508                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 27509                              <1> 	;
 27510                              <1> 	; 'sysquit' turns off the quit signal. it puts the argument of
 27511                              <1> 	; the call in u.quit. u.tty is checked if to see if a control 
 27512                              <1> 	; tty exists. If one does the interrupt character in the tty
 27513                              <1> 	; buffer is cleared and 'sysret'is called. If one does not exits
 27514                              <1> 	; 'sysret' is just called.	
 27515                              <1> 	;
 27516                              <1> 	; Calling sequence:
 27517                              <1> 	;	sysquit; arg
 27518                              <1> 	; Argument:
 27519                              <1> 	;	arg - if 0, this call diables quit signals from the
 27520                              <1> 	;		typewriter (ASCII FS)
 27521                              <1> 	;	    - if 1, quits are re-enabled and cause execution to
 27522                              <1> 	;		cease and a core image to be produced.
 27523                              <1> 	;		 i.e force an exit.
 27524                              <1> 	;	    - if arg is an addres in the program,
 27525                              <1> 	;		a quit causes control to sent to that
 27526                              <1> 	;		location.	
 27527                              <1> 	; Inputs: -
 27528                              <1> 	; Outputs: -
 27529                              <1> 	; ...............................................................
 27530                              <1> 	;	
 27531                              <1> 	; Retro UNIX 8086 v1 modification: 
 27532                              <1> 	;       'sysquit' system call sets u.quit to value of BX
 27533                              <1> 	;	then branches into 'sysret'.
 27534                              <1> 	;
 27535 00008E18 66891D[56B10000]    <1> 	mov	[u.quit], bx
 27536 00008E1F E981EDFFFF          <1> 	jmp	sysret
 27537                              <1> 		; jsr r0,arg; u.quit / put argument in u.quit
 27538                              <1> 	;1:
 27539                              <1> 		; mov u.ttyp,r1 / move pointer to control tty buffer
 27540                              <1> 			      ; / to r1
 27541                              <1> 		; beq sysret4 / return to user
 27542                              <1> 		; clrb 6(r1) / clear the interrupt character 
 27543                              <1> 			   ; / in the tty buffer
 27544                              <1> 		; br sysret4 / return to user
 27545                              <1> 
 27546                              <1> syssetuid: ; / set process id
 27547                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27548                              <1> 	; 07/07/2013 - 02/08/2013 (Retro UNIX 8086 v1)
 27549                              <1> 	;
 27550                              <1> 	; 'syssetuid' sets the user id (u.uid) of the current process
 27551                              <1> 	; to the process id in (u.r0). Both the effective user and 
 27552                              <1> 	; u.uid and the real user u.ruid are set to this. 
 27553                              <1> 	; Only the super user can make this call.	
 27554                              <1> 	;
 27555                              <1> 	; Calling sequence:
 27556                              <1> 	;	syssetuid
 27557                              <1> 	; Arguments: -
 27558                              <1> 	;
 27559                              <1> 	; Inputs: (u.r0) - contains the process id.
 27560                              <1> 	; Outputs: -
 27561                              <1> 	; ...............................................................
 27562                              <1> 	;	
 27563                              <1> 	; Retro UNIX 8086 v1 modification: 
 27564                              <1> 	;       BL contains the (new) user ID of the current process
 27565                              <1> 
 27566                              <1> 		; movb *u.r0,r1 / move process id (number) to r1
 27567 00008E24 3A1D[5DB10000]      <1> 	cmp	bl, [u.ruid] 
 27568                              <1> 		; cmpb r1,u.ruid / is it equal to the real user 
 27569                              <1> 			       ; / id number
 27570 00008E2A 741E                <1> 	je	short setuid1
 27571                              <1> 		; beq 1f / yes
 27572 00008E2C 803D[5CB10000]00    <1> 	cmp	byte [u.uid], 0 ; 02/08/2013
 27573                              <1> 		; tstb u.uid / no, is current user the super user?
 27574                              <1> 	;ja	error
 27575                              <1> 		; bne error4 / no, error
 27576 00008E33 760F                <1> 	jna	short setuid0
 27577 00008E35 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_NOT_SUPERUSER  ; 11
 27578 00008E3D 0000                <1>
 27579                              <1> 				;  'permission denied !' error
 27580 00008E3F E941EDFFFF          <1> 	jmp	error
 27581                              <1> setuid0:
 27582 00008E44 881D[5DB10000]      <1> 	mov	[u.ruid], bl
 27583                              <1> setuid1: ; 1:
 27584 00008E4A 881D[5CB10000]      <1> 	mov	[u.uid], bl ; 02/08/2013
 27585                              <1> 		; movb r1,u.uid / put process id in u.uid
 27586                              <1> 		; movb r1,u.ruid / put process id in u.ruid
 27587 00008E50 E950EDFFFF          <1> 	jmp	sysret
 27588                              <1> 		; br sysret4 / system return
 27589                              <1> 
 27590                              <1> sysgetuid: ; < get user id >
 27591                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27592                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 27593                              <1> 	;
 27594                              <1> 	; 'sysgetuid' returns the real user ID of the current process.
 27595                              <1> 	; The real user ID identifies the person who is logged in,
 27596                              <1> 	; in contradistinction to the effective user ID, which
 27597                              <1> 	; determines his access permission at each moment. It is thus
 27598                              <1> 	; useful to programs which operate using the 'set user ID'
 27599                              <1> 	; mode, to find out who invoked them.	
 27600                              <1> 	;
 27601                              <1> 	; Calling sequence:
 27602                              <1> 	;	syssetuid
 27603                              <1> 	; Arguments: -
 27604                              <1> 	;
 27605                              <1> 	; Inputs: -
 27606                              <1> 	; Outputs: (u.r0) - contains the real user's id.
 27607                              <1> 	; ...............................................................
 27608                              <1> 	;	
 27609                              <1> 	; Retro UNIX 8086 v1 modification: 
 27610                              <1> 	;       AL contains the real user ID at return.
 27611                              <1> 	;
 27612 00008E55 0FB605[5DB10000]    <1> 	movzx 	eax, byte [u.ruid]
 27613 00008E5C A3[10B10000]        <1> 	mov	[u.r0], eax
 27614                              <1> 		; movb	u.ruid,*u.r0 / move the real user id to (u.r0)
 27615 00008E61 E93FEDFFFF          <1> 	jmp	sysret
 27616                              <1> 		; br sysret4 / systerm return, sysret
 27617                              <1> 
 27618                              <1> anyi: 
 27619                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 27620                              <1> 	; 25/04/2013 (Retro UNIX 8086 v1)
 27621                              <1> 	;
 27622                              <1> 	; 'anyi' is called if a file deleted while open.
 27623                              <1> 	; "anyi" checks to see if someone else has opened this file.
 27624                              <1> 	;
 27625                              <1> 	; INPUTS ->
 27626                              <1> 	;    r1 - contains an i-number
 27627                              <1> 	;    fsp - start of table containing open files
 27628                              <1> 	;
 27629                              <1> 	; OUTPUTS ->
 27630                              <1> 	;    "deleted" flag set in fsp entry of another occurrence of
 27631                              <1> 	;	   this file and r2 points 1st word of this fsp entry.
 27632                              <1> 	;    if file not found - bit in i-node map is cleared
 27633                              <1> 	;    			 (i-node is freed)
 27634                              <1> 	;               all blocks related to i-node are freed
 27635                              <1> 	;	        all flags in i-node are cleared
 27636                              <1> 	; ((AX = R1)) input
 27637                              <1> 	;
 27638                              <1> 	;    (Retro UNIX Prototype : 02/12/2012, UNIXCOPY.ASM)
 27639                              <1>         ;    ((Modified registers: eDX, eCX, eBX, eSI, eDI, eBP))  
 27640                              <1> 	;
 27641                              <1> 		; / r1 contains an i-number
 27642 00008E66 BB[E4AE0000]        <1> 	mov	ebx, fsp
 27643                              <1> 		; mov $fsp,r2 / move start of fsp table to r2
 27644                              <1> anyi_1: ; 1:
 27645 00008E6B 663B03              <1> 	cmp	ax, [ebx]
 27646                              <1> 		; cmp r1,(r2) / do i-numbers match?
 27647 00008E6E 7433                <1> 	je	short anyi_3
 27648                              <1> 		; beq 1f / yes, 1f
 27649 00008E70 66F7D8              <1> 	neg	ax
 27650                              <1> 		; neg r1 / no complement r1
 27651 00008E73 663B03              <1> 	cmp	ax, [ebx]
 27652                              <1> 		; cmp r1,(r2) / do they match now?
 27653 00008E76 742B                <1> 	je	short anyi_3
 27654                              <1> 		; beq 1f / yes, transfer
 27655                              <1> 		; / i-numbers do not match
 27656 00008E78 83C30A              <1> 	add	ebx, 10 ; fsp table size is 10 bytes
 27657                              <1> 			; in Retro UNIX 386 v1 (22/06/2015)
 27658                              <1> 		; add $8,r2 / no, bump to next entry in fsp table
 27659 00008E7B 81FB[D8B00000]      <1> 	cmp	ebx, fsp + (nfiles*10) ; 22/06/2015 
 27660                              <1> 		; cmp r2,$fsp+[nfiles*8] 
 27661                              <1> 				; / are we at last entry in the table
 27662 00008E81 72E8                <1> 	jb	short anyi_1
 27663                              <1> 		; blt 1b / no, check next entries i-number
 27664                              <1> 	;cmp	ax, 32768
 27665 00008E83 80FC80              <1> 	cmp	ah, 80h ; negative number check
 27666                              <1> 		; tst r1 / yes, no match
 27667                              <1> 		; bge .+4
 27668 00008E86 7203                <1> 	jb	short anyi_2
 27669 00008E88 66F7D8              <1> 	neg	ax
 27670                              <1> 		; neg r1 / make i-number positive
 27671                              <1> anyi_2:	
 27672 00008E8B E864020000          <1> 	call	imap
 27673                              <1> 		; jsr r0,imap / get address of allocation bit 
 27674                              <1> 			    ; / in the i-map in r2
 27675                              <1> 	;; DL/DX (MQ) has a 1 in the calculated bit position
 27676                              <1>         ;; eBX (R2) has address of the byte with allocation bit
 27677                              <1>  	; not	dx
 27678 00008E90 F6D2                <1> 	not 	dl ;; 0 at calculated bit position, other bits are 1
 27679                              <1>         ;and	[ebx], dx
 27680 00008E92 2013                <1> 	and 	[ebx], dl 
 27681                              <1> 		; bicb mq,(r2) / clear bit for i-node in the imap
 27682 00008E94 E850020000          <1> 	call	itrunc
 27683                              <1> 		; jsr r0,itrunc / free all blocks related to i-node
 27684 00008E99 66C705[E4AD0000]00- <1>  	mov 	word [i.flgs], 0
 27685 00008EA1 00                  <1>
 27686                              <1> 		; clr i.flgs / clear all flags in the i-node
 27687 00008EA2 C3                  <1> 	retn
 27688                              <1> 		;rts	r0 / return
 27689                              <1> anyi_3: ; 1: / i-numbers match
 27690 00008EA3 FE4309              <1> 	inc 	byte [ebx+9] ; 22/06/2015
 27691                              <1> 		;incb 7(r2) / increment upper byte of the 4th word
 27692                              <1> 		   ; / in that fsp entry (deleted flag of fsp entry)
 27693 00008EA6 C3                  <1> 	retn
 27694                              <1> 		; rts r0
 27695                              <1> 
 27696                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - u7.s
 27697                              <1> ; Last Modification: 14/11/2015
 27698                              <1> 
 27699                              <1> sysmount: ; / mount file system; args special; name
 27700                              <1> 	; 14/11/2015
 27701                              <1> 	; 24/10/2015
 27702                              <1> 	; 13/10/2015
 27703                              <1> 	; 10/07/2015
 27704                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 27705                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
 27706                              <1> 	;
 27707                              <1> 	; 'sysmount' anounces to the system that a removable 
 27708                              <1> 	; file system has been mounted on a special file.
 27709                              <1> 	; The device number of the special file is obtained via
 27710                              <1> 	; a call to 'getspl'. It is put in the I/O queue entry for
 27711                              <1> 	; dismountable file system (sb1) and the I/O queue entry is
 27712                              <1> 	; set up to read (bit 10 is set). 'ppoke' is then called to
 27713                              <1> 	; to read file system into core, i.e. the first block on the
 27714                              <1> 	; mountable file system is read in. This block is super block
 27715                              <1> 	; for the file system. This call is super user restricted.	
 27716                              <1> 	;
 27717                              <1> 	; Calling sequence:
 27718                              <1> 	;	sysmount; special; name
 27719                              <1> 	; Arguments:
 27720                              <1> 	;	special - pointer to name of special file (device)
 27721                              <1> 	;	name -  pointer to name of the root directory of the
 27722                              <1> 	;		newly mounted file system. 'name' should 
 27723                              <1> 	;		always be a directory.
 27724                              <1> 	; Inputs: - 
 27725                              <1> 	; Outputs: -
 27726                              <1> 	; ...............................................................
 27727                              <1> 	;				
 27728                              <1> 	; Retro UNIX 8086 v1 modification: 
 27729                              <1> 	;       'sysmount' system call has two arguments; so,
 27730                              <1> 	;	* 1st argument, special is pointed to by BX register
 27731                              <1> 	;	* 2nd argument, name is in CX register
 27732                              <1> 	;
 27733                              <1> 	;	NOTE: Device numbers, names and related procedures are 
 27734                              <1> 	;	       already modified for IBM PC compatibility and 
 27735                              <1> 	;	       Retro UNIX 8086 v1 device configuration.	
 27736                              <1> 	
 27737                              <1> 	;call	arg2
 27738                              <1> 		; jsr r0,arg2 / get arguments special and name
 27739 00008EA7 891D[28B10000]      <1> 	mov	[u.namep], ebx
 27740 00008EAD 51                  <1> 	push	ecx ; directory name
 27741 00008EAE 66833D[FAB00000]00  <1> 	cmp	word [mnti], 0
 27742                              <1> 		; tst mnti / is the i-number of the cross device file
 27743                              <1> 			 ; / zero?
 27744                              <1> 	;ja	error
 27745                              <1>         	; bne errora / no, error
 27746 00008EB6 0F87E9000000        <1> 	ja	sysmnt_err0
 27747                              <1> 	;
 27748 00008EBC E8CC000000          <1> 	call	getspl
 27749                              <1> 		; jsr r0,getspl / get special files device number in r1
 27750                              <1> 	; 13/10/2015
 27751 00008EC1 0FB7D8              <1> 	movzx	ebx, ax ; ; Retro UNIX 8086 v1 device number (0 to 5)
 27752 00008EC4 F683[6A9D0000]80    <1>         test    byte [ebx+drv.status], 80h ; 24/10/2015 
 27753 00008ECB 750F                <1> 	jnz	short sysmnt_1
 27754                              <1> sysmnt_err1:
 27755 00008ECD C705[65B10000]0F00- <1>         mov     dword [u.error], ERR_DRV_NOT_RDY ; drive not ready !
 27756 00008ED5 0000                <1>
 27757 00008ED7 E9A9ECFFFF          <1> 	jmp	error
 27758                              <1> sysmnt_1:
 27759 00008EDC 8F05[28B10000]      <1> 	pop	dword [u.namep]
 27760                              <1>         	; mov (sp)+,u.namep / put the name of file to be placed
 27761                              <1> 				  ; / on the device
 27762                              <1> 	; 14/11/2015
 27763 00008EE2 53                  <1> 	push	ebx ; 13/10/2015
 27764                              <1> 		; mov r1,-(sp) / save the device number
 27765                              <1>         ;
 27766 00008EE3 E859FBFFFF          <1> 	call	namei
 27767                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
 27768                              <1> 		       ; ax = 0 -> file not found 	
 27769                              <1> 	;jz	error
 27770                              <1> 	;jc	error
 27771                              <1> 		; jsr r0,namei / get the i-number of the file
 27772                              <1>                	; br errora
 27773 00008EE8 730F                <1> 	jnc	short sysmnt_2
 27774                              <1> sysmnt_err2:
 27775 00008EEA C705[65B10000]0C00- <1>         mov     dword [u.error], ERR_FILE_NOT_FOUND ; drive not ready !
 27776 00008EF2 0000                <1>
 27777 00008EF4 E98CECFFFF          <1> 	jmp	error
 27778                              <1> sysmnt_2:	
 27779 00008EF9 66A3[FAB00000]      <1> 	mov	[mnti], ax
 27780                              <1>         	; mov r1,mnti / put it in mnti
 27781                              <1> ;	mov	ebx, sb1 ; super block buffer (of mounted disk)
 27782                              <1> sysmnt_3: ;1:
 27783                              <1>         ;cmp	byte [ebx+1], 0
 27784                              <1> 		; tstb sb1+1 / is 15th bit of I/O queue entry for
 27785                              <1> 			   ; / dismountable device set?
 27786                              <1>         ;jna	short sysmnt_4		
 27787                              <1> 		; bne 1b / (inhibit bit) yes, skip writing
 27788                              <1> 	;call	idle 	; (wait for hardware interrupt)
 27789                              <1> 	;jmp	short sysmnt_3
 27790                              <1> sysmnt_4:   
 27791 00008EFF 58                  <1> 	pop	eax ; Retro UNIX 8086 v1 device number/ID (0 to 5)     
 27792 00008F00 A2[F7B00000]        <1> 	mov	[mdev], al
 27793                              <1> 		; mov  (sp),mntd / no, put the device number in mntd
 27794 00008F05 8803                <1> 	mov	[ebx], al
 27795                              <1>         	; movb (sp),sb1 / put the device number in the lower byte
 27796                              <1> 			      ; / of the I/O queue entry
 27797                              <1> 	;mov	byte [cdev], 1 ; mounted device/drive
 27798                              <1>         	; mov (sp)+,cdev / put device number in cdev
 27799 00008F07 66810B0004          <1>         or	word [ebx], 400h ; Bit 10, 'read' flag/bit
 27800                              <1> 		; bis $2000,sb1 / set the read bit
 27801                              <1> 	; Retro UNIX 386 v1 modification : 
 27802                              <1> 	;	32 bit block number at buffer header offset 4
 27803 00008F0C C7430401000000      <1> 	mov	dword [ebx+4], 1 ; physical block number = 1
 27804 00008F13 E8DD010000          <1> 	call 	diskio
 27805 00008F18 731C                <1> 	jnc	short sysmnt_5
 27806 00008F1A 31C0                <1> 	xor 	eax, eax
 27807 00008F1C 66A3[FAB00000]      <1> 	mov	[mnti], ax ; 0
 27808 00008F22 A2[F7B00000]        <1> 	mov	[mdev], al ; 0
 27809                              <1> 	;mov	[cdev], al ; 0
 27810                              <1> sysmnt_invd:
 27811                              <1> 	; 14/11/2015
 27812 00008F27 FEC8                <1> 	dec 	al
 27813 00008F29 8903                <1> 	mov	[ebx], eax ; 000000FFh
 27814 00008F2B FEC0                <1> 	inc	al
 27815 00008F2D 48                  <1> 	dec	eax
 27816 00008F2E 894304              <1> 	mov	[ebx+4], eax ; 0FFFFFFFFh
 27817 00008F31 E94FECFFFF          <1> 	jmp	error
 27818                              <1> sysmnt_5:
 27819                              <1> 	; 14/11/2015 (Retro UNIX 386 v1 modification)
 27820                              <1> 	; (Following check is needed to prevent mounting an
 27821                              <1> 	; in valid valid file system (in valid super block).
 27822                              <1> 	; 
 27823 00008F36 0FB603              <1> 	movzx	eax, byte [ebx] ; device number
 27824 00008F39 C0E002              <1> 	shl	al, 2 ; 4*index
 27825 00008F3C 8B88[4E9D0000]      <1> 	mov	ecx, [eax+drv.size] ; volume (fs) size
 27826 00008F42 C1E103              <1> 	shl 	ecx, 3
 27827 00008F45 0FB715[C1BB0000]    <1> 	movzx	edx, word [sb1+4] ; the 1st data word
 27828 00008F4C 39D1                <1> 	cmp	ecx, edx ; compare free map bits and volume size
 27829                              <1> 			 ; (in sectors), if they are not equal
 27830                              <1> 			 ; the disk to be mounted is an...	
 27831 00008F4E 75D7                <1> 	jne	short sysmnt_invd ; invalid disk !
 27832                              <1> 			 ; (which has not got a valid super block)
 27833                              <1> 	;
 27834 00008F50 C6430100            <1> 	mov	byte [ebx+1], 0
 27835                              <1> 	       	; jsr r0,ppoke / read in entire file system
 27836                              <1> ;sysmnt_6: ;1:
 27837                              <1> 	;;cmp	byte [sb1+1], 0
 27838                              <1> 		; tstb   sb1+1 / done reading?
 27839                              <1>    	;;jna	sysret
 27840                              <1> 	;;call	idle ; (wait for hardware interrupt)
 27841                              <1> 	;;jmp	short sysmnt_6
 27842                              <1> 		;bne 1b / no, wait
 27843                              <1>         	;br sysreta / yes
 27844 00008F54 E94CECFFFF          <1> 	jmp	sysret
 27845                              <1> 
 27846                              <1> sysumount: ; / special dismount file system
 27847                              <1> 	; 16/05/2015 (Retro UNIX 386 v1 - Beginning)
 27848                              <1> 	; 09/07/2013 - 04/11/2013 (Retro UNIX 8086 v1)
 27849                              <1> 	;
 27850                              <1> 	; 04/11/2013
 27851                              <1> 	; 09/07/2013
 27852                              <1> 	; 'sysumount' anounces to the system that the special file, 
 27853                              <1> 	; indicated as an argument is no longer contain a removable
 27854                              <1> 	; file system. 'getspl' gets the device number of the special
 27855                              <1> 	; file. If no file system was mounted on that device an error
 27856                              <1> 	; occurs. 'mntd' and 'mnti' are cleared and control is passed
 27857                              <1> 	; to 'sysret'.
 27858                              <1> 	;
 27859                              <1> 	; Calling sequence:
 27860                              <1> 	;	sysmount; special
 27861                              <1> 	; Arguments:
 27862                              <1> 	;	special - special file to dismount (device)
 27863                              <1> 	;
 27864                              <1> 	; Inputs: - 
 27865                              <1> 	; Outputs: -
 27866                              <1> 	; ...............................................................
 27867                              <1> 	;				
 27868                              <1> 	; Retro UNIX 8086 v1 modification: 
 27869                              <1> 	;       'sysumount' system call has one argument; so,
 27870                              <1> 	;	* Single argument, special is pointed to by BX register
 27871                              <1> 	;
 27872                              <1> 	
 27873                              <1> 	;mov 	ax, 1 ; one/single argument, put argument in BX	
 27874                              <1> 	;call	arg
 27875                              <1> 		; jsr r0,arg; u.namep / point u.namep to special
 27876 00008F59 891D[28B10000]      <1>         mov	[u.namep], ebx
 27877 00008F5F E829000000          <1> 	call	getspl
 27878                              <1> 		; jsr r0,getspl / get the device number in r1
 27879 00008F64 3A05[F7B00000]      <1> 	cmp	al, [mdev]
 27880                              <1> 		; cmp r1,mntd / is it equal to the last device mounted?
 27881 00008F6A 7539                <1> 	jne	short sysmnt_err0 ; 'permission denied !' error
 27882                              <1> 	;jne	error
 27883                              <1>         	; bne errora / no error
 27884 00008F6C 30C0                <1> 	xor	al, al ; ah = 0
 27885                              <1> sysumnt_0: ;1:
 27886 00008F6E 3805[BEBB0000]      <1>      	cmp 	[sb1+1], al ; 0
 27887                              <1> 		; tstb sb1+1 / yes, is the device still doing I/O 
 27888                              <1> 			   ; / (inhibit bit set)?
 27889 00008F74 7607                <1> 	jna	short sysumnt_1		
 27890                              <1> 		; bne 1b / yes, wait
 27891 00008F76 E87B010000          <1> 	call	idle ; (wait for hardware interrupt)
 27892 00008F7B EBF1                <1> 	jmp	short sysumnt_0
 27893                              <1> sysumnt_1:        
 27894 00008F7D A2[F7B00000]        <1> 	mov	[mdev], al
 27895                              <1> 	     	; clr mntd / no, clear these
 27896 00008F82 66A3[FAB00000]      <1>    	mov	[mnti], ax
 27897                              <1>         	; clr mnti
 27898 00008F88 E918ECFFFF          <1>         jmp	sysret
 27899                              <1> 		; br sysreta / return
 27900                              <1> 
 27901                              <1> getspl: ; / get device number from a special file name
 27902 00008F8D E8AFFAFFFF          <1> 	call	namei
 27903                              <1> 	;or	ax, ax ; Retro UNIX 8086 v1 modification !
 27904                              <1> 		       ; ax = 0 -> file not found 	
 27905 00008F92 0F8252FFFFFF        <1>         jc      sysmnt_err2 ; 'file not found !' error
 27906                              <1> 	;jz	error
 27907                              <1> 	;jc	error
 27908                              <1> 		; jsr r0,namei / get the i-number of the special file
 27909                              <1>                 ; br errora / no such file
 27910 00008F98 6683E803            <1>         sub	ax, 3 ; Retro UNIX 8086 v1 modification !
 27911                              <1> 		      ;	i-number-3, 0 = fd0, 5 = hd3 
 27912                              <1> 		; sub $4,r1 / i-number-4 rk=1,tap=2+n
 27913 00008F9C 7207                <1>         jc	short sysmnt_err0 ; 'permission denied !' error
 27914                              <1> 	;jc	error
 27915                              <1> 		; ble errora / less than 0?  yes, error
 27916 00008F9E 6683F805            <1>         cmp	ax, 5 ;
 27917                              <1> 		; cmp  r1,$9. / greater than 9  tap 7
 27918 00008FA2 7701                <1> 	ja	short sysmnt_err0 ; 'permission denied !' error
 27919                              <1> 	;ja	error
 27920                              <1>         	; bgt errora / yes, error
 27921                              <1>         ; AX = Retro UNIX 8086 v1 Device Number (0 to 5)
 27922                              <1> iopen_retn:
 27923 00008FA4 C3                  <1> 	retn
 27924                              <1> 		; rts    r0 / return with device number in r1
 27925                              <1> sysmnt_err0:
 27926 00008FA5 C705[65B10000]0B00- <1> 	mov	dword [u.error], ERR_FILE_ACCESS ; permission denied !
 27927 00008FAD 0000                <1>
 27928 00008FAF E9D1EBFFFF          <1> 	jmp	error
 27929                              <1> 
 27930                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS9.INC
 27931                              <1> ; Last Modification: 09/12/2015
 27932                              <1> 
 27933                              <1> syssleep:
 27934                              <1> 	; 29/06/2015 - (Retro UNIX 386 v1)
 27935                              <1> 	; 11/06/2014 - (Retro UNIX 8086 v1)
 27936                              <1> 	;
 27937                              <1> 	; Retro UNIX 8086 v1 feature only
 27938                              <1> 	; (INPUT -> none)
 27939                              <1> 	;
 27940 00008FB4 0FB61D[5FB10000]    <1> 	movzx	ebx, byte [u.uno] ; process number
 27941 00008FBB 8AA3[63AE0000]      <1> 	mov	ah, [ebx+p.ttyc-1] ; current/console tty
 27942 00008FC1 E831010000          <1> 	call	sleep
 27943 00008FC6 E9DAEBFFFF          <1> 	jmp	sysret
 27944                              <1> 
 27945                              <1> vp_clr:
 27946                              <1> 	; Reset/Clear Video Page
 27947                              <1> 	;
 27948                              <1> 	; 30/06/2015 - (Retro UNIX 386 v1)
 27949                              <1> 	; 21/05/2013 - 30/10/2013(Retro UNIX 8086 v1) (U0.ASM)
 27950                              <1> 	;
 27951                              <1> 	; Retro UNIX 8086 v1 feature only !
 27952                              <1> 	;
 27953                              <1> 	; INPUTS -> 
 27954                              <1> 	;   BL = video page number	 
 27955                              <1> 	;
 27956                              <1> 	; OUTPUT ->
 27957                              <1> 	;   none
 27958                              <1> 	; ((Modified registers: eAX, BH, eCX, eDX, eSI, eDI))
 27959                              <1> 	;
 27960                              <1> 	; 04/12/2013
 27961 00008FCB 28C0                <1> 	sub	al, al
 27962                              <1> 	; al = 0 (clear video page)
 27963                              <1> 	; bl = video page
 27964 00008FCD B407                <1> 	mov	ah, 07h
 27965                              <1> 	; ah = 7 (attribute/color)
 27966 00008FCF 6631C9              <1> 	xor 	cx, cx ; 0, left upper column (cl) & row (cl)
 27967 00008FD2 66BA4F18            <1> 	mov	dx, 184Fh ; right lower column & row (dl=24, dh=79)
 27968 00008FD6 E83186FFFF          <1> 	call	_scroll_up
 27969                              <1> 	; bl = video page
 27970 00008FDB 6631D2              <1> 	xor	dx, dx ; 0 (cursor position) 
 27971 00008FDE E96788FFFF          <1> 	jmp 	_set_cpos
 27972                              <1> 
 27973                              <1> sysmsg:
 27974                              <1> 	; 11/11/2015
 27975                              <1> 	; 01/07/2015 - (Retro UNIX 386 v1 feature only!)
 27976                              <1> 	; Print user-application message on user's console tty
 27977                              <1> 	;
 27978                              <1> 	; Input -> EBX = Message address
 27979                              <1> 	;	   ECX = Message length (max. 255)
 27980                              <1> 	;	   DL = Color (IBM PC Rombios color attributes)
 27981                              <1> 	;
 27982 00008FE3 81F9FF000000        <1> 	cmp	ecx, MAX_MSG_LEN ; 255
 27983 00008FE9 0F87B6EBFFFF        <1> 	ja	sysret ; nothing to do with big message size
 27984 00008FEF 08C9                <1> 	or	cl, cl
 27985 00008FF1 0F84AEEBFFFF        <1> 	jz	sysret
 27986 00008FF7 20D2                <1> 	and	dl, dl
 27987 00008FF9 7502                <1> 	jnz	short sysmsg0
 27988 00008FFB B207                <1> 	mov	dl, 07h ; default color
 27989                              <1> 		; (black background, light gray character) 
 27990                              <1> sysmsg0:
 27991 00008FFD 891D[30B10000]      <1> 	mov	[u.base], ebx
 27992 00009003 8815[79A20000]      <1> 	mov	[ccolor], dl ; color attributes
 27993 00009009 89E5                <1> 	mov	ebp, esp
 27994 0000900B 31DB                <1> 	xor	ebx, ebx ; 0
 27995 0000900D 891D[38B10000]      <1> 	mov	[u.nread], ebx ; 0
 27996                              <1> 	;
 27997 00009013 381D[77B10000]      <1> 	cmp	[u.kcall], bl ; 0
 27998 00009019 7769                <1> 	ja	short sysmsgk ; Temporary (01/07/2015)
 27999                              <1> 	;
 28000 0000901B 890D[34B10000]      <1> 	mov	[u.count], ecx
 28001 00009021 41                  <1> 	inc	ecx ; + 00h ; ASCIZZ
 28002 00009022 29CC                <1> 	sub	esp, ecx
 28003 00009024 89E7                <1> 	mov	edi, esp
 28004 00009026 89E6                <1> 	mov	esi, esp
 28005 00009028 66891D[75B10000]    <1> 	mov	[u.pcount], bx ; reset page (phy. addr.) counter
 28006                              <1> 	; 11/11/2015
 28007 0000902F 8A25[40B10000]      <1> 	mov 	ah, [u.ttyp] ; recent open tty
 28008                              <1> 	; 0 = none
 28009 00009035 FECC                <1> 	dec	ah
 28010 00009037 790C                <1> 	jns	short sysmsg1 
 28011 00009039 8A1D[5FB10000]      <1> 	mov	bl, [u.uno] ; process number	
 28012 0000903F 8AA3[63AE0000]      <1> 	mov	ah, [ebx+p.ttyc-1] ; user's (process's) console tty
 28013                              <1> sysmsg1:
 28014 00009045 8825[64B10000]      <1> 	mov	[u.ttyn], ah
 28015                              <1> sysmsg2:
 28016 0000904B E8A0000000          <1> 	call	cpass
 28017 00009050 7416                <1> 	jz	short sysmsg5
 28018 00009052 AA                  <1> 	stosb
 28019 00009053 20C0                <1> 	and	al, al
 28020 00009055 75F4                <1> 	jnz	short sysmsg2
 28021                              <1> sysmsg3:
 28022 00009057 80FC07              <1> 	cmp	ah, 7 ; tty number
 28023 0000905A 7711                <1> 	ja	short sysmsg6 ; serial port
 28024 0000905C E83E000000          <1> 	call	print_cmsg
 28025                              <1> sysmsg4:
 28026 00009061 89EC                <1> 	mov	esp, ebp	
 28027 00009063 E93DEBFFFF          <1> 	jmp	sysret
 28028                              <1> sysmsg5:
 28029 00009068 C60700              <1> 	mov	byte [edi], 0
 28030 0000906B EBEA                <1> 	jmp	short sysmsg3
 28031                              <1> sysmsg6:
 28032 0000906D 8A06                <1> 	mov	al, [esi]
 28033 0000906F E87A000000          <1> 	call	sndc
 28034 00009074 72EB                <1> 	jc	short sysmsg4
 28035 00009076 803E00              <1> 	cmp	byte [esi], 0  ; 0 is stop character
 28036 00009079 76E6                <1> 	jna	short sysmsg4
 28037 0000907B 46                  <1> 	inc 	esi
 28038 0000907C 8A25[64B10000]      <1> 	mov	ah, [u.ttyn]
 28039 00009082 EBE9                <1> 	jmp	short sysmsg6
 28040                              <1> 
 28041                              <1> sysmsgk: ; Temporary (01/07/2015)
 28042                              <1> 	; The message has been sent by Kernel (ASCIIZ string)
 28043                              <1> 	; (ECX -character count- will not be considered)
 28044 00009084 8B35[30B10000]      <1> 	mov	esi, [u.base]
 28045 0000908A 8A25[78A20000]      <1> 	mov	ah, [ptty] ; present/current screen (video page)
 28046 00009090 8825[64B10000]      <1> 	mov	[u.ttyn], ah
 28047 00009096 C605[77B10000]00    <1> 	mov	byte [u.kcall], 0
 28048 0000909D EBB8                <1> 	jmp	short sysmsg3
 28049                              <1> 	
 28050                              <1> 
 28051                              <1> print_cmsg: 
 28052                              <1> 	; 01/07/2015 (retro UNIX 386 v1 feature only !)
 28053                              <1> 	;
 28054                              <1> 	; print message (on user's console tty) 
 28055                              <1> 	;	with requested color
 28056                              <1> 	;
 28057                              <1> 	; INPUTS:
 28058                              <1> 	;	esi = message address
 28059                              <1> 	;	[u.ttyn] = tty number (0 to 7)
 28060                              <1> 	;	[ccolor] = color attributes (IBM PC BIOS colors)
 28061                              <1> 	;
 28062 0000909F AC                  <1> 	lodsb
 28063                              <1> pcmsg1:
 28064 000090A0 56                  <1> 	push 	esi
 28065 000090A1 0FB61D[64B10000]    <1>         movzx   ebx, byte [u.ttyn]
 28066 000090A8 8A25[79A20000]      <1> 	mov	ah, [ccolor]
 28067 000090AE E80387FFFF          <1> 	call 	WRITE_TTY
 28068 000090B3 5E                  <1> 	pop	esi
 28069 000090B4 AC                  <1> 	lodsb
 28070 000090B5 20C0                <1> 	and 	al, al  ; 0
 28071 000090B7 75E7                <1> 	jnz 	short pcmsg1
 28072 000090B9 C3                  <1> 	retn
 28073                              <1> 
 28074                              <1> sysgeterr:
 28075                              <1> 	; 09/12/2015
 28076                              <1> 	; 21/09/2015 - (Retro UNIX 386 v1 feature only!)
 28077                              <1> 	; Get last error number or page fault count
 28078                              <1> 	; (for debugging)
 28079                              <1> 	;
 28080                              <1> 	; Input -> EBX = return type
 28081                              <1> 	;	   0 = last error code (which is in 'u.error')	
 28082                              <1> 	;	   FFFFFFFFh = page fault count for running process
 28083                              <1> 	;	   FFFFFFFEh = total page fault count
 28084                              <1> 	;	   1 .. FFFFFFFDh = undefined 
 28085                              <1> 	;
 28086                              <1> 	; Output -> EAX = last error number or page fault count
 28087                              <1> 	;	   (depending on EBX input)
 28088                              <1> 	; 	
 28089 000090BA 21DB                <1> 	and 	ebx, ebx
 28090 000090BC 750B                <1> 	jnz	short glerr_2
 28091                              <1> glerr_0:
 28092 000090BE A1[65B10000]        <1> 	mov	eax, [u.error]
 28093                              <1> glerr_1:
 28094 000090C3 A3[10B10000]        <1> 	mov	[u.r0], eax
 28095 000090C8 C3                  <1>  	retn
 28096                              <1> glerr_2:
 28097 000090C9 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0, FFFFFFFEh -> FFFFFFFFh
 28098 000090CA 74FD                <1> 	jz	short glerr_2 ; page fault count for process
 28099 000090CC 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0	
 28100 000090CD 75EF                <1> 	jnz	short glerr_0
 28101 000090CF A1[E4BD0000]        <1> 	mov	eax, [PF_Count] ; total page fault count
 28102 000090D4 EBED                <1>         jmp     short glerr_1
 28103                              <1> glerr_3:
 28104 000090D6 A1[79B10000]        <1> 	mov 	eax, [u.pfcount]
 28105 000090DB EBE6                <1> 	jmp	short glerr_1
 28106                              <1> 
 28107                              <1> ; temporary - 24/01/2016
 28108                              <1> 
 28109                              <1> iget:
 28110 000090DD C3                  <1> 	retn
 28111                              <1> poke:
 28112 000090DE C3                  <1> 	retn
 28113                              <1> tswap:
 28114 000090DF C3                  <1> 	retn
 28115                              <1> isintr:
 28116 000090E0 C3                  <1> 	retn
 28117                              <1> writei:
 28118 000090E1 C3                  <1> 	retn
 28119                              <1> readi:
 28120 000090E2 C3                  <1> 	retn
 28121                              <1> putlu:
 28122 000090E3 C3                  <1> 	retn
 28123                              <1> swap:
 28124 000090E4 C3                  <1> 	retn
 28125                              <1> wswap:
 28126 000090E5 C3                  <1> 	retn
 28127                              <1> rswap:
 28128 000090E6 C3                  <1> 	retn
 28129                              <1> iopen:
 28130 000090E7 C3                  <1> 	retn
 28131                              <1> iclose:
 28132 000090E8 C3                  <1> 	retn
 28133                              <1> itrunc:
 28134 000090E9 C3                  <1> 	retn
 28135                              <1> clock:
 28136 000090EA C3                  <1> 	retn
 28137                              <1> setimod:
 28138 000090EB C3                  <1> 	retn
 28139                              <1> ottyp:
 28140 000090EC C3                  <1> 	retn
 28141                              <1> cttyp:
 28142 000090ED C3                  <1> 	retn
 28143                              <1> sndc:
 28144 000090EE C3                  <1> 	retn
 28145                              <1> access:
 28146 000090EF C3                  <1> 	retn
 28147                              <1> cpass:
 28148 000090F0 C3                  <1> 	retn
 28149                              <1> passc:
 28150 000090F1 C3                  <1> 	retn
 28151                              <1> epoch:
 28152 000090F2 C3                  <1> 	retn
 28153                              <1> set_date_time:
 28154 000090F3 C3                  <1> 	retn
 28155                              <1> imap:
 28156 000090F4 C3                  <1> 	retn
 28157                              <1> diskio:
 28158 000090F5 C3                  <1> 	retn
 28159                              <1> idle:
 28160 000090F6 C3                  <1> 	retn
 28161                              <1> sleep:
 28162 000090F7 C3                  <1> 	retn
 28163                              <1> 
 28164                              <1> 
 28165                              <1> 
 28166                                  %include 'trdosk7.s' ; 24/01/2016
 28167                              <1> ; ****************************************************************************
 28168                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - DISK READ&WRITE : trdosk7.s
 28169                              <1> ; ----------------------------------------------------------------------------
 28170                              <1> ; Last Update: 25/02/2016
 28171                              <1> ; ----------------------------------------------------------------------------
 28172                              <1> ; Beginning: 24/01/2016
 28173                              <1> ; ----------------------------------------------------------------------------
 28174                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 28175                              <1> ; ----------------------------------------------------------------------------
 28176                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 28177                              <1> ; DISK_IO.ASM (20/07/2011)
 28178                              <1> ; ****************************************************************************
 28179                              <1> ; DISK_IO.ASM (c) 2009-2011 Erdogan TAN [ 04/07/2009 ] Last Update: 20/07/2011
 28180                              <1> 
 28181                              <1> 
 28182                              <1> disk_write:
 28183                              <1> 	; 25/02/2016
 28184                              <1> 	; 24/02/2016
 28185                              <1> 	; 23/02/2016
 28186 000090F8 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
 28187 000090FC 777B                <1>         ja      short lba_write
 28188                              <1> 
 28189                              <1> chs_write:
 28190                              <1> 	; 25/02/2016
 28191                              <1> 	; 23/02/2016
 28192 000090FE C605[01AC0000]03    <1> 	mov	byte [disk_rw_op], 3 ; CHS write
 28193 00009105 EB0D                <1> 	jmp	short chs_rw
 28194                              <1> 
 28195                              <1> disk_read:
 28196                              <1> 	; 25/02/2016
 28197                              <1> 	; 24/02/2016
 28198                              <1> 	; 23/02/2016
 28199                              <1> 	; 17/02/2016
 28200                              <1> 	; 14/02/2016
 28201                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 28202                              <1> 	; 17/10/2010
 28203                              <1> 	; 18/04/2010
 28204                              <1> 	;
 28205                              <1> 	; INPUT -> EAX = Logical Block Address
 28206                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
 28207                              <1> 	;	   ECX = Sector Count	
 28208                              <1> 	; 	   EBX = Destination Buffer
 28209                              <1> 	; OUTPUT -> 
 28210                              <1> 	;	   cf = 0 or cf = 1
 28211                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 28212                              <1> 
 28213 00009107 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
 28214 0000910B 7775                <1>         ja      short lba_read
 28215                              <1> 
 28216                              <1> chs_read:
 28217                              <1> 	; 25/02/2016
 28218                              <1> 	; 24/02/2016
 28219                              <1> 	; 23/02/2016
 28220                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 28221                              <1> 	; 20/07/2011
 28222                              <1> 	; 04/07/2009
 28223                              <1> 	;
 28224                              <1> 	; INPUT -> EAX = Logical Block Address
 28225                              <1> 	;	   ECX = Number of sectors to read
 28226                              <1> 	; 	   ESI = Logical Dos Disk Table Offset (DRV)
 28227                              <1> 	; 	   EBX = Destination Buffer
 28228                              <1> 	; OUTPUT -> 
 28229                              <1> 	;	   cf = 0 or cf = 1
 28230                              <1> 	; (Modified registers: EAX; EBX, ECX, EDX)
 28231                              <1> 
 28232                              <1> 	; 23/02/2016
 28233 0000910D C605[01AC0000]02    <1> 	mov	byte [disk_rw_op], 2 ; CHS read
 28234                              <1> 
 28235                              <1> chs_rw:
 28236                              <1> 	;;movzx	edx, word [esi+LD_BPB+SecPerTrack]
 28237                              <1> 	;movzx	edx, byte [esi+LD_BPB+SecPerTrack] ; <= 63
 28238                              <1> 	;mov	[disk_rw_spt], dl
 28239                              <1> 
 28240                              <1> chs_read_next_sector:
 28241 00009114 C605[02AC0000]04    <1> 	mov	byte [retry_count], 4
 28242                              <1>      
 28243                              <1> chs_read_retry:
 28244                              <1> 	;mov	[sector_count], ecx ; 23/02/2016
 28245                              <1> 
 28246 0000911B 50                  <1> 	push	eax			; Linear sector #
 28247 0000911C 51                  <1> 	push	ecx			; # of FAT/FILE/DIR sectors
 28248                              <1>                 
 28249 0000911D 0FB74E1E            <1> 	movzx	ecx, word [esi+LD_BPB+SecPerTrack]
 28250                              <1> 	;movzx	ecx, byte [disk_rw_spt] ; 23/02/2016
 28251 00009121 29D2                <1> 	sub	edx, edx
 28252 00009123 F7F1                <1> 	div	ecx
 28253                              <1> 	; eax = track, dx (dl ) = sector (on track)
 28254                              <1> 	;sub	cl, dl ; 24/02/2016 (spt - sec)
 28255                              <1> 	;push	ecx ; *
 28256 00009125 6689D1              <1> 	mov	cx, dx			; Sector (zero based)
 28257 00009128 6641                <1> 	inc	cx			; To make it 1 based
 28258 0000912A 6651                <1> 	push	cx
 28259 0000912C 668B4E20            <1> 	mov	cx, [esi+LD_BPB+Heads]
 28260 00009130 6629D2              <1> 	sub	dx, dx
 28261 00009133 F7F1                <1> 	div	ecx			; Convert track to head & cyl
 28262                              <1> 	; eax (ax) = cylinder, dx (dl) = head (max. FFh)
 28263 00009135 88D6                <1> 	mov	dh, dl
 28264 00009137 6659                <1> 	pop	cx			; AX=Cyl, DH=Head, CX=Sector
 28265 00009139 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
 28266                              <1> 
 28267 0000913C 88C5                <1> 	mov	ch, al			; NOTE: max. 1023 cylinders !                   
 28268 0000913E C0CC02              <1> 	ror	ah, 2			; Rotate 2 bits right
 28269 00009141 08E1                <1> 	or	cl, ah
 28270                              <1> 
 28271                              <1> 	; 24/02/2016
 28272                              <1> 	;pop	eax ; * (spt - sec) (example: 63 - 0 = 63)
 28273                              <1> 	;cmp	eax, [sector_count]
 28274                              <1> 	;jb	short chs_write_sectors
 28275                              <1> 	;je	short chs_read_sectors
 28276                              <1> 	;; (# of sectors to read is more than remaining sectors on the track)
 28277                              <1> 	;mov	al, [sector_count]
 28278                              <1> ;chs_read_sectors: ; read or write !
 28279 00009143 B001                <1> 	mov	al, 1 ; 25/02/2016
 28280 00009145 8A25[01AC0000]      <1> 	mov	ah, [disk_rw_op]  ; 02h = chs read, 03h = chs write 
 28281                              <1> 	;
 28282 0000914B E87B97FFFF          <1> 	call	int13h			; BIOS Service func ( ah ) = 2
 28283                              <1>                                         ; Read disk sectors
 28284                              <1>                                         ; AL-sec num CH-track CL-sec
 28285                              <1>                                         ; DH-head DL-drive ES:BX-buffer
 28286                              <1>                                         ; CF-flag AH-stat AL-sec read
 28287                              <1> 	                                ; If CF = 1 then (If AH > 0)
 28288 00009150 8825[03AC0000]      <1> 	mov	[disk_rw_err], ah
 28289                              <1> 	
 28290 00009156 59                  <1> 	pop	ecx
 28291 00009157 58                  <1> 	pop	eax
 28292 00009158 7314                <1> 	jnc	short chs_read_ok
 28293                              <1> 
 28294 0000915A 803D[03AC0000]09    <1> 	cmp	byte [disk_rw_err], 09h ; DMA crossed 64K segment boundary
 28295 00009161 7408                <1> 	je	short chs_read_error_retn
 28296                              <1>              
 28297 00009163 FE0D[02AC0000]      <1> 	dec	byte [retry_count]
 28298 00009169 75B0                <1> 	jnz	short chs_read_retry
 28299                              <1> 
 28300                              <1> chs_read_error_retn:
 28301 0000916B F9                  <1> 	stc
 28302                              <1> 	;retn
 28303 0000916C EB69                <1> 	jmp	short update_drv_error_byte
 28304                              <1> 
 28305                              <1> ;chs_write_sectors: ; read or write 
 28306                              <1> 	;; (# of sectors to read is less than remaining sectors on the track)
 28307                              <1> 	;mov	[sector_count], al
 28308                              <1> 	;jmp	short chs_read_sectors
 28309                              <1> 
 28310                              <1> chs_read_ok:
 28311                              <1> 	;; 23/02/2016
 28312                              <1> 	;movzx	edx, byte [sector_count] ; sector count (<= spt)	
 28313                              <1>         ;sub    ecx, edx  ; remaining sector count
 28314                              <1> 	;jna	short update_drv_error_byte	
 28315                              <1> 	;add	eax, edx ; next disk sector
 28316                              <1> 	;shl	edx, 9 ; 512 * sector count
 28317                              <1> 	;add	ebx, edx ; next buffer byte address 
 28318                              <1>         ;jmp     chs_read_next_sector        
 28319                              <1> 	; 25/02/2016
 28320 0000916E 40                  <1> 	inc	eax ; next sector
 28321 0000916F 81C300020000        <1> 	add	ebx, 512
 28322 00009175 E29D                <1> 	loop	chs_read_next_sector
 28323 00009177 EB5E                <1> 	jmp	short update_drv_error_byte
 28324                              <1> 
 28325                              <1> lba_write:
 28326                              <1> 	; 23/02/2016
 28327 00009179 C605[01AC0000]1C    <1> 	mov	byte [disk_rw_op], 1Ch ; LBA write
 28328 00009180 EB07                <1> 	jmp	short lba_rw
 28329                              <1> 
 28330                              <1> lba_read:
 28331                              <1> 	; 23/02/2016
 28332                              <1> 	; 17/02/2016
 28333                              <1> 	; 14/02/2016
 28334                              <1> 	; 13/02/2016
 28335                              <1> 	; 31/01/2016 (TRDOS 386 =  TRDOS v2.0)
 28336                              <1> 	; 10/07/2015 (Retro UNIX 386 v1)
 28337                              <1> 	;
 28338                              <1> 	; INPUT -> EAX = Logical Block Address
 28339                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)	
 28340                              <1> 	;	   ECX = Sector Count	
 28341                              <1> 	; 	   EBX = Destination Buffer
 28342                              <1> 	; OUTPUT -> 
 28343                              <1> 	;	   cf = 0 or cf = 1
 28344                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
 28345                              <1> 
 28346                              <1> 	; LBA read/write (with private LBA function) 
 28347                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
 28348                              <1> 
 28349                              <1> 
 28350                              <1> 	; 23/02/2016
 28351 00009182 C605[01AC0000]1B    <1> 	mov	byte [disk_rw_op], 1Bh ; LBA read
 28352                              <1> 
 28353                              <1> lba_rw:
 28354                              <1> 	; 17/02/2016
 28355 00009189 57                  <1> 	push	edi
 28356                              <1> 
 28357 0000918A 890D[04AC0000]      <1> 	mov	[sector_count], ecx ; total sector (read) count
 28358                              <1> 
 28359 00009190 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
 28360                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
 28361                              <1> 
 28362                              <1> lba_read_next:
 28363 00009193 81F900010000        <1> 	cmp	ecx, 256
 28364 00009199 7605                <1> 	jna	short lba_read_rsc
 28365 0000919B B900010000          <1> 	mov	ecx, 256 ; 17/02/2016
 28366                              <1> lba_read_rsc:
 28367 000091A0 290D[04AC0000]      <1> 	sub	[sector_count], ecx ; remain sectors
 28368                              <1> 
 28369 000091A6 89CF                <1> 	mov	edi, ecx 
 28370 000091A8 89C1                <1> 	mov	ecx, eax ; sector number/address
 28371                              <1> 
 28372 000091AA C605[02AC0000]04    <1> 	mov	byte [retry_count], 4
 28373                              <1> lba_read_retry:
 28374 000091B1 89F8                <1> 	mov	eax, edi
 28375                              <1> 	;
 28376                              <1> 	; ecx = sector number
 28377                              <1> 	; al = sector count (0 - 255) /// (0 = 256)
 28378                              <1> 	; dl = drive number
 28379                              <1> 	; ebx = buffer offset
 28380                              <1> 	;
 28381                              <1> 	; Function 1Bh = LBA read, 1Ch = LBA write
 28382                              <1> 	; 23/02/2016
 28383 000091B3 8A25[01AC0000]      <1> 	mov	ah, [disk_rw_op] ; 1Bh = LBA read, 1Ch = LBA write
 28384 000091B9 E80D97FFFF          <1> 	call	int13h
 28385                              <1> 	; al = ? (changed)
 28386                              <1> 	; ah = error code
 28387 000091BE 8825[03AC0000]      <1> 	mov	[disk_rw_err], ah
 28388 000091C4 7334                <1> 	jnc	short lba_read_ok
 28389 000091C6 80FC80              <1> 	cmp	ah, 80h ; time out?
 28390 000091C9 740A                <1>         je      short lba_read_stc_retn
 28391 000091CB FE0D[02AC0000]      <1> 	dec	byte [retry_count]
 28392 000091D1 7FDE                <1> 	jg	short lba_read_retry
 28393 000091D3 743A                <1> 	jz	short lba_read_reset
 28394                              <1> 	; sf =  1
 28395                              <1> 
 28396                              <1> lba_read_stc_retn:
 28397 000091D5 F9                  <1> 	stc
 28398                              <1> lba_read_retn:
 28399 000091D6 5F                  <1> 	pop	edi
 28400                              <1> 
 28401                              <1> update_drv_error_byte:
 28402 000091D7 9C                  <1> 	pushf
 28403 000091D8 53                  <1> 	push	ebx
 28404 000091D9 6651                <1> 	push	cx
 28405                              <1> 	;or	ecx, ecx
 28406                              <1> 	;jz	short udrv_errb0
 28407 000091DB 8A0D[03AC0000]      <1> 	mov	cl, [disk_rw_err]
 28408                              <1> udrv_errb0:
 28409 000091E1 0FB65E02            <1> 	movzx	ebx, byte [esi+LD_PhyDrvNo]
 28410 000091E5 80FB02              <1> 	cmp	bl, 2
 28411 000091E8 7203                <1>         jb      short udrv_errb1
 28412 000091EA 80EB7E              <1> 	sub	bl, 7Eh
 28413                              <1> 	;cmp	bl, 5
 28414                              <1> 	;ja	short udrv_errb2	
 28415                              <1> udrv_errb1:
 28416 000091ED 81C3[719D0000]      <1>         add     ebx, drv.error ; 13/02/2016
 28417 000091F3 880B                <1> 	mov	[ebx], cl ; error code
 28418                              <1> udrv_errb2:
 28419 000091F5 6659                <1> 	pop	cx
 28420 000091F7 5B                  <1> 	pop	ebx
 28421 000091F8 9D                  <1> 	popf
 28422 000091F9 C3                  <1> 	retn
 28423                              <1> 
 28424                              <1> lba_read_ok:
 28425 000091FA 89C8                <1> 	mov	eax, ecx ; sector number
 28426 000091FC 01F8                <1> 	add	eax, edi ; sector number (next)
 28427 000091FE C1E709              <1> 	shl	edi, 9 ; sector count * 512
 28428 00009201 01FB                <1> 	add	ebx, edi ; next buffer offset
 28429                              <1> 
 28430 00009203 8B0D[04AC0000]      <1> 	mov	ecx, [sector_count] ; remaining sectors
 28431 00009209 09C9                <1> 	or	ecx, ecx
 28432 0000920B 7586                <1> 	jnz	short lba_read_next
 28433 0000920D EBC7                <1> 	jmp	short lba_read_retn
 28434                              <1> 
 28435                              <1> lba_read_reset:
 28436 0000920F B40D                <1> 	mov	ah, 0Dh ; Alternate reset
 28437 00009211 E8B596FFFF          <1>         call	int13h
 28438                              <1> 	; al = ? (changed)
 28439                              <1> 	; ah = error code
 28440 00009216 7399                <1> 	jnc	short lba_read_retry
 28441 00009218 EBBC                <1> 	jmp	short lba_read_retn
 28442                                  %include 'trdosk8.s' ; 24/01/2016
 28443                              <1> ; ****************************************************************************
 28444                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - MAIN PROGRAM : trdosk8.s
 28445                              <1> ; ----------------------------------------------------------------------------
 28446                              <1> ; Last Update: 24/01/2016
 28447                              <1> ; ----------------------------------------------------------------------------
 28448                              <1> ; Beginning: 24/01/2016
 28449                              <1> ; ----------------------------------------------------------------------------
 28450                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 28451                              <1> ; ----------------------------------------------------------------------------
 28452                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 28453                              <1> ; XXXXXXXX.ASM (XX/XX/2011)
 28454                              <1> ;
 28455                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 28456                              <1> ; u0.s (20/11/2015)
 28457                              <1> ; ****************************************************************************
 28458                              <1> 
 28459                              <1> INT4Ah:
 28460                              <1> 	; 24/01/2016
 28461                              <1> 	; this procedure will be called by 'RTC_INT' (in 'timer.s')
 28462 0000921A C3                  <1> 	retn
 28463                              <1> 
 28464                              <1> ; u0.s
 28465                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS0.INC
 28466                              <1> ; Last Modification: 20/11/2015
 28467                              <1> 
 28468                              <1> com2_int:
 28469                              <1> 	; 07/11/2015 
 28470                              <1> 	; 24/10/2015
 28471                              <1> 	; 23/10/2015
 28472                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
 28473                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
 28474                              <1> 	; < serial port 2 interrupt handler >
 28475                              <1> 	;
 28476 0000921B 890424              <1> 	mov 	[esp], eax ; overwrite call return address
 28477                              <1> 	;push	eax
 28478 0000921E 66B80900            <1> 	mov	ax, 9
 28479 00009222 EB07                <1> 	jmp	short comm_int
 28480                              <1> com1_int:
 28481                              <1> 	; 07/11/2015
 28482                              <1> 	; 24/10/2015
 28483 00009224 890424              <1> 	mov 	[esp], eax ; overwrite call return address
 28484                              <1> 	; 23/10/2015
 28485                              <1> 	;push	eax
 28486 00009227 66B80800            <1> 	mov	ax, 8
 28487                              <1> comm_int:
 28488                              <1> 	; 20/11/2015
 28489                              <1> 	; 18/11/2015
 28490                              <1> 	; 17/11/2015
 28491                              <1> 	; 16/11/2015
 28492                              <1> 	; 09/11/2015
 28493                              <1> 	; 08/11/2015
 28494                              <1> 	; 07/11/2015
 28495                              <1> 	; 06/11/2015 (serial4.asm, 'serial')	
 28496                              <1> 	; 01/11/2015
 28497                              <1> 	; 26/10/2015
 28498                              <1> 	; 23/10/2015
 28499 0000922B 53                  <1> 	push	ebx
 28500 0000922C 56                  <1> 	push	esi
 28501 0000922D 57                  <1> 	push	edi
 28502 0000922E 1E                  <1> 	push 	ds
 28503 0000922F 06                  <1> 	push 	es
 28504                              <1> 	; 18/11/2015
 28505 00009230 0F20DB              <1> 	mov	ebx, cr3
 28506 00009233 53                  <1> 	push	ebx ; ****
 28507                              <1> 	;
 28508 00009234 51                  <1> 	push	ecx ; ***
 28509 00009235 52                  <1> 	push	edx ; **
 28510                              <1> 	;
 28511 00009236 BB10000000          <1> 	mov	ebx, KDATA
 28512 0000923B 8EDB                <1> 	mov	ds, bx
 28513 0000923D 8EC3                <1> 	mov	es, bx
 28514                              <1> 	;
 28515 0000923F 8B0D[48A20000]      <1> 	mov	ecx, [k_page_dir]
 28516 00009245 0F22D9              <1> 	mov	cr3, ecx
 28517                              <1> 	; 20/11/2015
 28518                              <1> 	; Interrupt identification register
 28519 00009248 66BAFA02            <1> 	mov	dx, 2FAh ; COM2
 28520                              <1> 	;
 28521 0000924C 3C08                <1> 	cmp 	al, 8 
 28522 0000924E 7702                <1> 	ja 	short com_i0
 28523                              <1> 	;
 28524                              <1> 	; 20/11/2015
 28525                              <1> 	; 17/11/2015
 28526                              <1> 	; 16/11/2015
 28527                              <1> 	; 15/11/2015
 28528                              <1> 	; 24/10/2015
 28529                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
 28530                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
 28531                              <1> 	; < serial port 1 interrupt handler >
 28532                              <1> 	;
 28533 00009250 FEC6                <1> 	inc	dh ; 3FAh ; COM1 Interrupt id. register
 28534                              <1> com_i0:
 28535                              <1> 	;push	eax ; *
 28536                              <1> 	; 07/11/2015
 28537 00009252 A2[B8A20000]        <1> 	mov 	byte [ccomport], al
 28538                              <1> 	; 09/11/2015
 28539 00009257 0FB7D8              <1> 	movzx	ebx, ax ; 8 or 9
 28540                              <1> 	; 17/11/2015
 28541                              <1>  	; reset request for response status
 28542 0000925A 88A3[AEA20000]      <1> 	mov	[ebx+req_resp-8], ah ; 0
 28543                              <1> 	;
 28544                              <1> 	; 20/11/2015
 28545 00009260 EC                  <1> 	in	al, dx		; read interrupt id. register
 28546 00009261 EB00                <1> 	JMP	$+2	   	; I/O DELAY
 28547 00009263 2404                <1> 	and	al, 4		; received data available?	
 28548 00009265 7470                <1> 	jz	short com_eoi	; (transmit. holding reg. empty)
 28549                              <1> 	;
 28550                              <1> 	; 20/11/2015
 28551 00009267 80EA02              <1> 	sub	dl, 3FAh-3F8h	; data register (3F8h, 2F8h)
 28552 0000926A EC                  <1> 	in	al, dx     	; read character
 28553                              <1> 	;JMP	$+2	   	; I/O DELAY
 28554                              <1> 	; 08/11/2015
 28555                              <1> 	; 07/11/2015
 28556 0000926B 89DE                <1> 	mov	esi, ebx 
 28557 0000926D 89DF                <1> 	mov	edi, ebx
 28558 0000926F 81C6[B2A20000]      <1> 	add 	esi, rchar - 8 ; points to last received char
 28559 00009275 81C7[B4A20000]      <1> 	add	edi, schar - 8 ; points to last sent char
 28560 0000927B 8806                <1> 	mov	[esi], al ; received char (current char)
 28561                              <1> 	; query
 28562 0000927D 20C0                <1> 	and	al, al
 28563 0000927F 7527                <1> 	jnz	short com_i2
 28564                              <1>    	; response
 28565                              <1> 	; 17/11/2015
 28566                              <1> 	; set request for response status
 28567 00009281 FE83[AEA20000]      <1>         inc     byte [ebx+req_resp-8] ; 1 
 28568                              <1> 	;
 28569 00009287 6683C205            <1> 	add	dx, 3FDh-3F8h	; (3FDh, 2FDh)
 28570 0000928B EC                  <1> 	in	al, dx	   	; read line status register 
 28571 0000928C EB00                <1> 	JMP	$+2	   	; I/O DELAY
 28572 0000928E 2420                <1> 	and	al, 20h	   	; transmitter holding reg. empty?
 28573 00009290 7445                <1> 	jz	short com_eoi 	; no
 28574 00009292 B0FF                <1> 	mov 	al, 0FFh   	; response			
 28575 00009294 6683EA05            <1> 	sub	dx, 3FDh-3F8h 	; data port (3F8h, 2F8h)
 28576 00009298 EE                  <1> 	out	dx, al	   	; send on serial port
 28577                              <1> 	; 17/11/2015
 28578 00009299 803F00              <1> 	cmp 	byte [edi], 0   ; query ? (schar)
 28579 0000929C 7502                <1> 	jne 	short com_i1    ; no
 28580 0000929E 8807                <1> 	mov	[edi], al 	; 0FFh (responded)
 28581                              <1> com_i1:
 28582                              <1> 	; 17/11/2015
 28583                              <1> 	; reset request for response status (again)
 28584 000092A0 FE8B[AEA20000]      <1>         dec     byte [ebx+req_resp-8] ; 0 
 28585 000092A6 EB2F                <1> 	jmp	short com_eoi
 28586                              <1> com_i2:	
 28587                              <1> 	; 08/11/2015
 28588 000092A8 3CFF                <1> 	cmp 	al, 0FFh	; (response ?)
 28589 000092AA 7417                <1> 	je	short com_i3	; (check for response signal)
 28590                              <1> 	; 07/11/2015
 28591 000092AC 3C04                <1> 	cmp	al, 04h	; EOT
 28592 000092AE 751C                <1> 	jne	short com_i4	
 28593                              <1> 	; EOT = 04h (End of Transmit) - 'CTRL + D'
 28594                              <1> 	;(an EOT char is supposed as a ctrl+brk from the terminal)
 28595                              <1> 	; 08/11/2015
 28596                              <1> 		; ptty -> tty 0 to 7 (pseudo screens)
 28597 000092B0 861D[78A20000]      <1> 	xchg	bl, [ptty]  ; tty number (8 or 9)
 28598 000092B6 E8F7A9FFFF          <1> 	call 	ctrlbrk
 28599 000092BB 861D[78A20000]      <1> 	xchg	[ptty], bl ; (restore ptty value and BL value)
 28600                              <1> 	;mov	al, 04h ; EOT
 28601                              <1> 	; 08/11/2015
 28602 000092C1 EB09                <1> 	jmp	short com_i4	
 28603                              <1> com_i3:
 28604                              <1> 	; 08/11/2015
 28605                              <1> 	; If 0FFh has been received just after a query
 28606                              <1> 	; (schar, ZERO), it is a response signal.
 28607                              <1> 	; 17/11/2015
 28608 000092C3 803F00              <1>         cmp     byte [edi], 0 ; query ? (schar)
 28609 000092C6 7704                <1> 	ja	short com_i4 ; no
 28610                              <1> 	; reset query status (schar)
 28611 000092C8 8807                <1> 	mov	[edi], al ; 0FFh
 28612 000092CA FEC0                <1> 	inc	al ; 0
 28613                              <1> com_i4:
 28614                              <1> 	; 27/07/2014
 28615                              <1> 	; 09/07/2014
 28616 000092CC D0E3                <1> 	shl	bl, 1	
 28617 000092CE 81C3[7AA20000]      <1> 	add	ebx, ttychr
 28618                              <1> 	; 23/07/2014 (always overwrite)
 28619                              <1> 	;;cmp	word [ebx], 0
 28620                              <1> 	;;ja	short com_eoi
 28621                              <1> 	;
 28622 000092D4 668903              <1> 	mov	[ebx], ax   ; Save ascii code
 28623                              <1> 			    ; scan code = 0
 28624                              <1> com_eoi:
 28625                              <1> 	;mov	al, 20h
 28626                              <1> 	;out	20h, al	   ; end of interrupt
 28627                              <1> 	;
 28628                              <1> 	; 07/11/2015
 28629                              <1>       	;pop	eax ; *
 28630 000092D7 A0[B8A20000]        <1> 	mov	al, byte [ccomport] ; current COM port
 28631                              <1> 	 ; al = tty number (8 or 9)
 28632 000092DC E85E010000          <1>         call	wakeup
 28633                              <1> com_iret:
 28634                              <1> 	; 23/10/2015
 28635 000092E1 5A                  <1> 	pop	edx ; **
 28636 000092E2 59                  <1> 	pop	ecx ; ***
 28637                              <1> 	; 18/11/2015
 28638                              <1> 	;pop	eax ; ****
 28639                              <1> 	;mov	cr3, eax
 28640                              <1> 	;jmp	iiret
 28641 000092E3 E97377FFFF          <1> 	jmp	iiretp
 28642                              <1> 
 28643                              <1> ;iiretp: ; 01/09/2015
 28644                              <1> ;	; 28/08/2015
 28645                              <1> ;	pop	eax ; (*) page directory
 28646                              <1> ;	mov	cr3, eax
 28647                              <1> ;iiret:
 28648                              <1> ;	; 22/08/2014
 28649                              <1> ;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
 28650                              <1> ;	out	20h, al	; 8259 PORT
 28651                              <1> ;	;
 28652                              <1> ;	pop	es
 28653                              <1> ;	pop	ds
 28654                              <1> ;	pop	edi
 28655                              <1> ;	pop	esi
 28656                              <1> ;	pop	ebx ; 29/08/2014
 28657                              <1> ;	pop 	eax
 28658                              <1> ;	iretd
 28659                              <1> 
 28660                              <1> sp_init:
 28661                              <1> 	; 07/11/2015
 28662                              <1> 	; 29/10/2015
 28663                              <1> 	; 26/10/2015
 28664                              <1> 	; 23/10/2015
 28665                              <1> 	; 29/06/2015
 28666                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - 115200 baud)
 28667                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1 - 9600 baud)
 28668                              <1> 	; Initialization of Serial Port Communication Parameters
 28669                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
 28670                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
 28671                              <1> 	;
 28672                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
 28673                              <1> 	;
 28674                              <1> 	; INPUT:  (29/06/2015)
 28675                              <1> 	;	AL = 0 for COM1
 28676                              <1> 	;	     1 for COM2
 28677                              <1> 	;	AH = Communication parameters	
 28678                              <1> 	;
 28679                              <1> 	;  (*) Communication parameters (except BAUD RATE):
 28680                              <1> 	;	Bit	4	3	2	1	0
 28681                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
 28682                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
 28683                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
 28684                              <1> 	;		11 = even
 28685                              <1> 	;  Baud rate setting bits: (29/06/2015)
 28686                              <1> 	;		Retro UNIX 386 v1 feature only !
 28687                              <1> 	;	Bit	7    6    5  | Baud rate
 28688                              <1> 	;		------------------------
 28689                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
 28690                              <1> 	;		0    0    1  | 9600 (12)
 28691                              <1> 	;		0    1    0  | 19200 (6) 
 28692                              <1> 	;		0    1	  1  | 38400 (3) 
 28693                              <1> 	;		1    0	  0  | 14400 (8)
 28694                              <1> 	;		1    0	  1  | 28800 (4)
 28695                              <1> 	;		1    1    0  | 57600 (2)
 28696                              <1> 	;		1    1    1  | 115200 (1) 	
 28697                              <1> 	
 28698                              <1> 	; References:	
 28699                              <1> 	; (1) IBM PC-XT Model 286 BIOS Source Code
 28700                              <1> 	;     RS232.ASM --- 10/06/1985 COMMUNICATIONS BIOS (RS232)
 28701                              <1> 	; (2) Award BIOS 1999 - ATORGS.ASM
 28702                              <1> 	; (3) http://wiki.osdev.org/Serial_Ports
 28703                              <1> 	;
 28704                              <1> 	; Set communication parameters for COM1 (= 03h)	
 28705                              <1> 	;
 28706 000092E8 BB[B4A20000]        <1> 	mov	ebx, com1p		; COM1 parameters  
 28707 000092ED 66BAF803            <1> 	mov	dx, 3F8h		; COM1
 28708                              <1> 	 ; 29/10/2015
 28709 000092F1 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
 28710 000092F5 E86F000000          <1> 	call	sp_i3	; call A4	
 28711 000092FA A880                <1> 	test	al, 80h
 28712 000092FC 7410                <1> 	jz	short sp_i0 ; OK..
 28713                              <1> 		; Error !
 28714                              <1> 	;mov	dx, 3F8h
 28715 000092FE 80EA05              <1> 	sub	dl, 5 ; 3FDh -> 3F8h
 28716 00009301 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
 28717 00009305 E85F000000          <1> 	call	sp_i3	; call A4	
 28718 0000930A A880                <1> 	test	al, 80h
 28719 0000930C 7508                <1> 	jnz	short sp_i1
 28720                              <1> sp_i0:
 28721                              <1>         ; (Note: Serial port interrupts will be disabled here...)	
 28722                              <1>         ; (INT 14h initialization code disables interrupts.)
 28723                              <1> 	;
 28724 0000930E C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
 28725 00009311 E8DC000000          <1> 	call	sp_i5 ; 29/06/2015
 28726                              <1> sp_i1:
 28727 00009316 43                  <1> 	inc	ebx
 28728 00009317 66BAF802            <1> 	mov	dx, 2F8h		; COM2
 28729                              <1> 	 ; 29/10/2015
 28730 0000931B 66B90103            <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
 28731 0000931F E845000000          <1> 	call	sp_i3	; call A4	
 28732 00009324 A880                <1> 	test	al, 80h
 28733 00009326 7410                <1> 	jz	short sp_i2 ; OK..
 28734                              <1> 		; Error !
 28735                              <1> 	;mov	dx, 2F8h
 28736 00009328 80EA05              <1> 	sub	dl, 5 ; 2FDh -> 2F8h
 28737 0000932B 66B90E03            <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
 28738 0000932F E835000000          <1> 	call	sp_i3	; call A4	
 28739 00009334 A880                <1> 	test	al, 80h
 28740 00009336 7530                <1> 	jnz	short sp_i7
 28741                              <1> sp_i2:
 28742 00009338 C603E3              <1> 	mov	byte [ebx], 0E3h ; 11100011b
 28743                              <1> sp_i6:
 28744                              <1> 	;; COM2 - enabling IRQ 3
 28745                              <1> 	; 07/11/2015
 28746                              <1> 	; 26/10/2015
 28747 0000933B 9C                  <1> 	pushf
 28748 0000933C FA                  <1> 	cli
 28749                              <1> 	;
 28750 0000933D 66BAFC02            <1> 	mov	dx, 2FCh   		; modem control register
 28751 00009341 EC                  <1> 	in	al, dx 	   		; read register
 28752 00009342 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 28753 00009344 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
 28754 00009346 EE                  <1> 	out	dx, al     		; write back to register
 28755 00009347 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 28756 00009349 66BAF902            <1> 	mov	dx, 2F9h   		; interrupt enable register
 28757 0000934D EC                  <1> 	in	al, dx     		; read register
 28758 0000934E EB00                <1> 	JMP	$+2	   		; I/O DELAY
 28759                              <1> 	;or	al, 1      		; receiver data interrupt enable and
 28760 00009350 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
 28761 00009352 EE                  <1> 	out	dx, al 	   		; write back to register
 28762 00009353 EB00                <1> 	JMP	$+2        		; I/O DELAY
 28763 00009355 E421                <1> 	in	al, 21h    		; read interrupt mask register
 28764 00009357 EB00                <1> 	JMP	$+2	   		; I/O DELAY
 28765 00009359 24F7                <1> 	and	al, 0F7h   		; enable IRQ 3 (COM2)
 28766 0000935B E621                <1> 	out	21h, al    		; write back to register
 28767                              <1> 	;
 28768                              <1> 	; 23/10/2015
 28769 0000935D B8[1B920000]        <1> 	mov 	eax, com2_int
 28770 00009362 A3[3A940000]        <1> 	mov	[com2_irq3], eax
 28771                              <1> 	; 26/10/2015
 28772 00009367 9D                  <1> 	popf	
 28773                              <1> sp_i7:
 28774 00009368 C3                  <1> 	retn
 28775                              <1> 
 28776                              <1> sp_i3:
 28777                              <1> ;A4:  	;-----	INITIALIZE THE COMMUNICATIONS PORT
 28778                              <1> 	; 28/10/2015
 28779 00009369 FEC2                <1> 	inc	dl	; 3F9h (2F9h)	; 3F9h, COM1 Interrupt enable register 
 28780 0000936B B000                <1> 	mov	al, 0
 28781 0000936D EE                  <1> 	out	dx, al			; disable serial port interrupt
 28782 0000936E EB00                <1> 	JMP	$+2			; I/O DELAY
 28783 00009370 80C202              <1> 	add	dl, 2 	; 3FBh (2FBh)	; COM1 Line control register (3FBh)
 28784 00009373 B080                <1> 	mov	al, 80h			
 28785 00009375 EE                  <1> 	out	dx, al			; SET DLAB=1 ; divisor latch access bit
 28786                              <1> 	;-----	SET BAUD RATE DIVISOR
 28787                              <1> 	; 26/10/2015
 28788 00009376 80EA03              <1> 	sub 	dl, 3   ; 3F8h (2F8h)	; register for least significant byte
 28789                              <1> 					; of the divisor value
 28790 00009379 88C8                <1> 	mov	al, cl	; 1
 28791 0000937B EE                  <1> 	out	dx, al			; 1 = 115200 baud (Retro UNIX 386 v1)
 28792                              <1> 					; 2 = 57600 baud
 28793                              <1> 					; 3 = 38400 baud
 28794                              <1> 					; 6 = 19200 baud
 28795                              <1> 					; 12 = 9600 baud (Retro UNIX 8086 v1)
 28796 0000937C EB00                <1> 	JMP	$+2			; I/O DELAY
 28797 0000937E 28C0                <1> 	sub	al, al
 28798 00009380 FEC2                <1> 	inc	dl      ; 3F9h (2F9h)	; register for most significant byte
 28799                              <1> 					; of the divisor value
 28800 00009382 EE                  <1> 	out	dx, al ; 0
 28801 00009383 EB00                <1> 	JMP	$+2			; I/O DELAY
 28802                              <1> 	;	
 28803 00009385 88E8                <1> 	mov	al, ch ; 3		; 8 data bits, 1 stop bit, no parity
 28804                              <1> 	;and	al, 1Fh ; Bits 0,1,2,3,4	
 28805 00009387 80C202              <1> 	add	dl, 2	; 3FBh (2FBh)	; Line control register
 28806 0000938A EE                  <1> 	out	dx, al			
 28807 0000938B EB00                <1> 	JMP	$+2			; I/O DELAY
 28808                              <1> 	; 29/10/2015
 28809 0000938D FECA                <1> 	dec 	dl 	; 3FAh (2FAh)	; FIFO Control register (16550/16750)
 28810 0000938F 30C0                <1> 	xor	al, al			; 0
 28811 00009391 EE                  <1> 	out	dx, al			; Disable FIFOs (reset to 8250 mode)
 28812 00009392 EB00                <1> 	JMP	$+2	
 28813                              <1> sp_i4:
 28814                              <1> ;A18:	;-----	COMM PORT STATUS ROUTINE
 28815                              <1> 	; 29/06/2015 (line status after modem status)
 28816 00009394 80C204              <1> 	add	dl, 4	; 3FEh (2FEh)	; Modem status register
 28817                              <1> sp_i4s:
 28818 00009397 EC                  <1> 	in	al, dx			; GET MODEM CONTROL STATUS
 28819 00009398 EB00                <1> 	JMP	$+2			; I/O DELAY
 28820 0000939A 88C4                <1> 	mov	ah, al			; PUT IN (AH) FOR RETURN
 28821 0000939C FECA                <1> 	dec	dl	; 3FDh (2FDh)	; POINT TO LINE STATUS REGISTER
 28822                              <1> 					; dx = 3FDh for COM1, 2FDh for COM2
 28823 0000939E EC                  <1> 	in	al, dx			; GET LINE CONTROL STATUS
 28824                              <1> 	; AL = Line status, AH = Modem status
 28825 0000939F C3                  <1> 	retn
 28826                              <1> 
 28827                              <1> sp_status:
 28828                              <1> 	; 29/06/2015
 28829                              <1> 	; 27/06/2015 (Retro UNIX 386 v1)
 28830                              <1> 	; Get serial port status
 28831 000093A0 66BAFE03            <1> 	mov	dx, 3FEh		; Modem status register (COM1)
 28832 000093A4 28C6                <1> 	sub	dh, al			; dh = 2 for COM2 (al = 1)
 28833                              <1> 					; dx = 2FEh for COM2
 28834 000093A6 EBEF                <1> 	jmp	short sp_i4s
 28835                              <1> 
 28836                              <1> sp_setp: ; Set serial port communication parameters
 28837                              <1> 	; 07/11/2015
 28838                              <1> 	; 29/10/2015
 28839                              <1> 	; 29/06/2015
 28840                              <1> 	; Retro UNIX 386 v1 feature only !	
 28841                              <1> 	;
 28842                              <1> 	; INPUT:
 28843                              <1> 	;	AL = 0 for COM1
 28844                              <1> 	;	     1 for COM2
 28845                              <1> 	;	AH = Communication parameters (*)
 28846                              <1> 	; OUTPUT:
 28847                              <1> 	;	CL = Line status
 28848                              <1> 	;	CH = Modem status
 28849                              <1> 	;   If cf = 1 -> Error code in [u.error]
 28850                              <1> 	;		 'invalid parameter !' 
 28851                              <1> 	;		 	 or
 28852                              <1> 	;		 'device not ready !' error
 28853                              <1> 	;	
 28854                              <1> 	;  (*) Communication parameters (except BAUD RATE):
 28855                              <1> 	;	Bit	4	3	2	1	0
 28856                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-	 		 
 28857                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
 28858                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
 28859                              <1> 	;		11 = even
 28860                              <1> 	;  Baud rate setting bits: (29/06/2015)
 28861                              <1> 	;		Retro UNIX 386 v1 feature only !
 28862                              <1> 	;	Bit	7    6    5  | Baud rate
 28863                              <1> 	;		------------------------
 28864                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
 28865                              <1> 	;		0    0    1  | 9600 (12)
 28866                              <1> 	;		0    1    0  | 19200 (6) 
 28867                              <1> 	;		0    1	  1  | 38400 (3) 
 28868                              <1> 	;		1    0	  0  | 14400 (8)
 28869                              <1> 	;		1    0	  1  | 28800 (4)
 28870                              <1> 	;		1    1    0  | 57600 (2)
 28871                              <1> 	;		1    1    1  | 115200 (1) 
 28872                              <1> 	;
 28873                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
 28874                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
 28875                              <1> 	;
 28876                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
 28877                              <1> 	;
 28878 000093A8 66BAF803            <1> 	mov	dx, 3F8h
 28879 000093AC BB[B4A20000]        <1> 	mov	ebx, com1p ; COM1 control byte offset
 28880 000093B1 3C01                <1> 	cmp	al, 1
 28881 000093B3 776B                <1> 	ja 	short sp_invp_err
 28882 000093B5 7203                <1> 	jb	short sp_setp1 ;  COM1 (AL = 0)
 28883 000093B7 FECE                <1> 	dec	dh ; 2F8h
 28884 000093B9 43                  <1> 	inc	ebx ; COM2 control byte offset
 28885                              <1> sp_setp1:
 28886                              <1> 	; 29/10/2015
 28887 000093BA 8823                <1> 	mov	[ebx], ah
 28888 000093BC 0FB6CC              <1> 	movzx 	ecx, ah
 28889 000093BF C0E905              <1> 	shr	cl, 5 ; -> baud rate index
 28890 000093C2 80E41F              <1> 	and	ah, 1Fh ; communication parameters except baud rate
 28891 000093C5 8A81[2F940000]      <1> 	mov	al, [ecx+b_div_tbl]
 28892 000093CB 6689C1              <1> 	mov	cx, ax
 28893 000093CE E896FFFFFF          <1> 	call	sp_i3
 28894 000093D3 6689C1              <1> 	mov	cx, ax ; CL = Line status, CH = Modem status
 28895 000093D6 A880                <1> 	test	al, 80h
 28896 000093D8 740F                <1> 	jz	short sp_setp2
 28897 000093DA C603E3              <1>         mov     byte [ebx], 0E3h ; Reset to initial value (11100011b)
 28898                              <1> stp_dnr_err:
 28899 000093DD C705[65B10000]0F00- <1> 	mov	dword [u.error], ERR_DEV_NOT_RDY ; 'device not ready !'
 28900 000093E5 0000                <1>
 28901                              <1> 	; CL = Line status, CH = Modem status
 28902 000093E7 F9                  <1> 	stc
 28903 000093E8 C3                  <1> 	retn
 28904                              <1> sp_setp2:
 28905 000093E9 80FE02              <1> 	cmp	dh, 2 ; COM2 (2F?h)
 28906 000093EC 0F8649FFFFFF        <1>         jna     sp_i6 
 28907                              <1> 		      ; COM1 (3F?h)
 28908                              <1> sp_i5: 
 28909                              <1> 	; 07/11/2015
 28910                              <1> 	; 26/10/2015
 28911                              <1> 	; 29/06/2015
 28912                              <1> 	;
 28913                              <1> 	;; COM1 - enabling IRQ 4
 28914 000093F2 9C                  <1> 	pushf
 28915 000093F3 FA                  <1> 	cli
 28916 000093F4 66BAFC03            <1> 	mov	dx, 3FCh   		; modem control register
 28917 000093F8 EC                  <1> 	in	al, dx 	   		; read register
 28918 000093F9 EB00                <1> 	JMP	$+2			; I/O DELAY
 28919 000093FB 0C08                <1> 	or	al, 8      		; enable bit 3 (OUT2)
 28920 000093FD EE                  <1> 	out	dx, al     		; write back to register
 28921 000093FE EB00                <1> 	JMP	$+2			; I/O DELAY
 28922 00009400 66BAF903            <1> 	mov	dx, 3F9h   		; interrupt enable register
 28923 00009404 EC                  <1> 	in	al, dx     		; read register
 28924 00009405 EB00                <1> 	JMP	$+2			; I/O DELAY
 28925                              <1> 	;or	al, 1      		; receiver data interrupt enable and
 28926 00009407 0C03                <1> 	or	al, 3	   		; transmitter empty interrupt enable
 28927 00009409 EE                  <1> 	out	dx, al 	   		; write back to register
 28928 0000940A EB00                <1> 	JMP	$+2        		; I/O DELAY
 28929 0000940C E421                <1> 	in	al, 21h    		; read interrupt mask register
 28930 0000940E EB00                <1> 	JMP	$+2			; I/O DELAY
 28931 00009410 24EF                <1> 	and	al, 0EFh   		; enable IRQ 4 (COM1)
 28932 00009412 E621                <1> 	out	21h, al    		; write back to register
 28933                              <1> 	;
 28934                              <1> 	; 23/10/2015
 28935 00009414 B8[24920000]        <1> 	mov 	eax, com1_int
 28936 00009419 A3[36940000]        <1> 	mov	[com1_irq4], eax
 28937                              <1> 	; 26/10/2015
 28938 0000941E 9D                  <1> 	popf
 28939 0000941F C3                  <1> 	retn
 28940                              <1> 
 28941                              <1> sp_invp_err:
 28942 00009420 C705[65B10000]1700- <1> 	mov	dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !' 
 28943 00009428 0000                <1>
 28944 0000942A 31C9                <1> 	xor	ecx, ecx
 28945 0000942C 49                  <1> 	dec	ecx ; 0FFFFh
 28946 0000942D F9                  <1> 	stc
 28947 0000942E C3                  <1> 	retn
 28948                              <1> 
 28949                              <1> ; 29/10/2015
 28950                              <1> b_div_tbl: ; Baud rate divisor table (115200/divisor)
 28951 0000942F 010C0603080401      <1> 	db 1, 12, 6, 3, 8, 4, 1
 28952                              <1> 
 28953                              <1> 
 28954                              <1> ; 23/10/2015
 28955                              <1> com1_irq4:
 28956 00009436 [3E940000]          <1> 	dd dummy_retn
 28957                              <1> com2_irq3:
 28958 0000943A [3E940000]          <1> 	dd dummy_retn
 28959                              <1> 
 28960                              <1> dummy_retn:
 28961 0000943E C3                  <1> 	retn
 28962                              <1> 
 28963                              <1> wakeup:
 28964                              <1> 	; 24/01/2016
 28965 0000943F C3                  <1> 	retn
 28966                                  %include 'trdosk9.s' ; 04/01/2016
 28967                              <1> ; ****************************************************************************
 28968                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - INITIALIZED DATA : trdosk9.s
 28969                              <1> ; ----------------------------------------------------------------------------
 28970                              <1> ; Last Update: 29/02/2016
 28971                              <1> ; ----------------------------------------------------------------------------
 28972                              <1> ; Beginning: 04/01/2016
 28973                              <1> ; ----------------------------------------------------------------------------
 28974                              <1> ; ----------------------------------------------------------------------------
 28975                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 28976                              <1> ; ----------------------------------------------------------------------------
 28977                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 28978                              <1> ; TRDOS2.ASM (09/11/2011)
 28979                              <1> ; ****************************************************************************
 28980                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
 28981                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
 28982                              <1> ; CMD_INTR.ASM [29/01/2005] Last Update: 09/11/2011
 28983                              <1> ; FILE.ASM [29/10/2009] Last Update: 09/10/2011
 28984                              <1> 
 28985                              <1> ; 12/02/2016
 28986                              <1> Last_DOS_DiskNo: 
 28987 00009440 01                  <1> 		db 1 ; A: = 0 & B: = 1
 28988                              <1> 
 28989                              <1> Restore_CDIR:	
 28990 00009441 FF                  <1> 		db 0FFh ; Initial value -> any number except 0
 28991                              <1> 
 28992                              <1> msg_CRLF_temp:  
 28993 00009442 070D0A00            <1> 		db  07h, 0Dh, 0Ah, 0
 28994                              <1> 
 28995                              <1> Magic_Bytes:
 28996 00009446 04                  <1> 		db 4
 28997 00009447 01                  <1> 		db 1
 28998                              <1> mainprog_Version:
 28999 00009448 07                  <1> 		db 7
 29000 00009449 5B5452444F535D204D- <1> 		db "[TRDOS] Main Program v2.0.290216"
 29001 00009452 61696E2050726F6772- <1>
 29002 0000945B 616D2076322E302E32- <1>
 29003 00009464 3930323136          <1>
 29004 00009469 0D0A                <1> 		db 0Dh, 0Ah
 29005 0000946B 286329204572646F67- <1> 		db "(c) Erdogan Tan 2005-2016"
 29006 00009474 616E2054616E203230- <1>
 29007 0000947D 30352D32303136      <1>
 29008 00009484 0D0A00              <1> 		db 0Dh, 0Ah, 0
 29009                              <1> 
 29010                              <1> MainProgCfgFile:
 29011 00009487 4D41494E50524F472E- <1> 		db "MAINPROG.CFG", 0
 29012 00009490 43464700            <1>
 29013                              <1> 
 29014                              <1> TRDOSPromptLabel:
 29015 00009494 5452444F53          <1> 		db "TRDOS"
 29016 00009499 00                  <1> 		db 0
 29017 0000949A 00<rept>            <1>                 times 5 db 0
 29018 0000949F 00                  <1> 		db 0
 29019                              <1> 
 29020                              <1> ; INTERNAL COMMANDS
 29021                              <1> Command_List:
 29022 000094A0 44495200            <1> Cmd_Dir:	db "DIR", 0
 29023 000094A4 434400              <1> Cmd_Cd:		db "CD", 0
 29024 000094A7 433A00              <1> Cmd_Drive:	db "C:", 0
 29025 000094AA 56455200            <1> Cmd_Ver:	db "VER", 0
 29026 000094AE 4558495400          <1> Cmd_Exit:	db "EXIT", 0
 29027 000094B3 50524F4D505400      <1> Cmd_Prompt:	db "PROMPT", 0
 29028 000094BA 564F4C554D4500      <1> Cmd_Volume:	db "VOLUME", 0
 29029 000094C1 4C4F4E474E414D4500  <1> Cmd_LongName:	db "LONGNAME", 0
 29030 000094CA 4441544500          <1> Cmd_Date:	db "DATE", 0
 29031 000094CF 54494D4500          <1> Cmd_Time:	db "TIME", 0
 29032 000094D4 52554E00            <1> Cmd_Run:	db "RUN", 0
 29033 000094D8 53455400            <1> Cmd_Set:	db "SET", 0 
 29034 000094DC 434C5300            <1> Cmd_Cls:	db "CLS", 0
 29035 000094E0 53484F5700          <1> Cmd_Show:	db "SHOW", 0
 29036 000094E5 44454C00            <1> Cmd_Del:	db "DEL", 0
 29037 000094E9 41545452494200      <1> Cmd_Attrib:	db "ATTRIB", 0
 29038 000094F0 52454E414D4500      <1> Cmd_Rename:	db "RENAME", 0
 29039 000094F7 524D44495200        <1> Cmd_Rmdir:	db "RMDIR", 0
 29040 000094FD 4D4B44495200        <1> Cmd_Mkdir:	db "MKDIR", 0
 29041 00009503 434F505900          <1> Cmd_Copy:	db "COPY", 0
 29042 00009508 4D4F564500          <1> Cmd_Move:	db "MOVE", 0
 29043 0000950D 5041544800          <1> Cmd_Path:	db "PATH", 0
 29044 00009512 4D454D00            <1> Cmd_Mem:	db "MEM", 0
 29045 00009516 00                  <1> 		db 0
 29046 00009517 46494E4400          <1> Cmd_Find:	db "FIND", 0
 29047 0000951C 5245414446494C4500  <1> Cmd_ReadFile:	db "READFILE", 0
 29048 00009525 4543484F00          <1> Cmd_Echo:	db "ECHO", 0
 29049 0000952A 2A00                <1> Cmd_Remark:	db "*", 0
 29050 0000952C 3F00                <1> Cmd_Help:	db "?", 0
 29051 0000952E 44455649434500      <1> Cmd_Device:	db "DEVICE", 0
 29052 00009535 4445564C49535400    <1> Cmd_DevList:	db "DEVLIST", 0
 29053 0000953D 434844495200        <1> Cmd_Chdir:	db "CHDIR", 0
 29054 00009543 4245455000          <1> Cmd_Beep:	db "BEEP", 0
 29055                              <1> 		
 29056 00009548 00                  <1> 		db 0
 29057                              <1> 
 29058                              <1> ; 15/02/2016 (FILE.ASM, 09/10/2011)
 29059                              <1> invalid_fname_chars:
 29060 00009549 222728292A2B2C2F    <1> 		db 22h, 27h, 28h, 29h, 2Ah, 2Bh, 2Ch, 2Fh
 29061 00009551 3A3B3C3D3E3F40      <1> 		db 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh, 40h
 29062 00009558 5B5C5D5E60          <1> 		db 5Bh, 5Ch, 5Dh, 5Eh, 60h
 29063                              <1> sizeInvFnChars  equ ($ - invalid_fname_chars)                
 29064                              <1> ;
 29065                              <1> 
 29066                              <1> Msg_Enter_Date:
 29067 0000955D 456E746572206E6577- <1>                 db 'Enter new date (dd-mm-yy): '
 29068 00009566 206461746520286464- <1>
 29069 0000956F 2D6D6D2D7979293A20  <1>
 29070 00009578 00                  <1>                 db 0
 29071                              <1> Msg_Show_Date:
 29072 00009579 43757272656E742064- <1>                 db   'Current date is '
 29073 00009582 61746520697320      <1>
 29074 00009589 30                  <1> Day:            db   '0'
 29075 0000958A 30                  <1> 		db   '0'
 29076 0000958B 2F                  <1>                 db   '/'
 29077 0000958C 30                  <1> Month:          db   '0'
 29078 0000958D 30                  <1> 		db   '0'
 29079 0000958E 2F                  <1>                 db   '/'
 29080 0000958F 30                  <1> Century:        db   '0'
 29081 00009590 30                  <1>                 db   '0'
 29082 00009591 30                  <1> Year:           db   '0'
 29083 00009592 30                  <1> 		db   '0'
 29084 00009593 0D0A00              <1>                 db   0Dh, 0Ah, 0
 29085                              <1> 
 29086                              <1> Msg_Enter_Time:
 29087 00009596 456E746572206E6577- <1> 		db 'Enter new time: '
 29088 0000959F 2074696D653A20      <1>
 29089 000095A6 00                  <1> 		db 0
 29090                              <1> Msg_Show_Time:
 29091 000095A7 43757272656E742074- <1> 		db   'Current time is '
 29092 000095B0 696D6520697320      <1>
 29093 000095B7 30                  <1> Hour:           db   '0'
 29094 000095B8 30                  <1> 		db   '0'
 29095 000095B9 3A                  <1> 		db   ':'
 29096 000095BA 30                  <1> Minute:         db   '0'
 29097 000095BB 30                  <1> 		db   '0'
 29098 000095BC 3A                  <1> 		db   ':'
 29099 000095BD 30                  <1> Second:         db   '0'
 29100 000095BE 30                  <1> 		db   '0'
 29101 000095BF 0D0A00              <1> 		db   0Dh, 0Ah, 0
 29102                              <1> 
 29103                              <1> ;VolSize_Unit1:   dd 0
 29104                              <1> ;VolSize_Unit2:   dd 0
 29105                              <1> 
 29106                              <1> VolSize_KiloBytes:
 29107 000095C2 206B696C6F62797465- <1> 		db " kilobytes", 0Dh, 0Ah, 0
 29108 000095CB 730D0A00            <1>
 29109                              <1> VolSize_Bytes:
 29110 000095CF 2062797465730D0A00  <1> 		db " bytes", 0Dh, 0Ah, 0
 29111                              <1> Volume_in_drive:
 29112 000095D8 0D0A                <1> 		db 0Dh, 0Ah
 29113                              <1> Vol_FS_Name:
 29114 000095DA 54522046533120      <1> 		db "TR FS1 "
 29115 000095E1 566F6C756D6520696E- <1> 		db "Volume in drive "
 29116 000095EA 20647269766520      <1>
 29117 000095F1 30                  <1> Vol_Drv_Name:   db 30h
 29118 000095F2 3A                  <1> 		db ":"
 29119 000095F3 20697320            <1> 		db " is "
 29120 000095F7 0D0A00              <1> 		db 0Dh, 0Ah, 0
 29121                              <1> Dir_Drive_Str:
 29122 000095FA 54522D444F53204472- <1>                 db "TR-DOS Drive "
 29123 00009603 69766520            <1>
 29124                              <1> Dir_Drive_Name:
 29125 00009607 303A                <1>                 db "0:"
 29126 00009609 0D0A                <1>                 db  0Dh, 0Ah
 29127                              <1> Vol_Str_Header:
 29128 0000960B 566F6C756D65204E61- <1>                 db "Volume Name: "
 29129 00009614 6D653A20            <1>
 29130                              <1> Vol_Name:
 29131 00009618 00<rept>            <1> 		times 64 db 0
 29132 00009658 00                  <1> 		db 0
 29133                              <1> Vol_Serial_Header:
 29134 00009659 0D0A                <1> 		db 0Dh, 0Ah
 29135 0000965B 566F6C756D65205365- <1> 		db "Volume Serial No: "
 29136 00009664 7269616C204E6F3A20  <1>
 29137                              <1> Vol_Serial1:
 29138 0000966D 30303030            <1> 		db "0000"
 29139 00009671 2D                  <1> 		db "-"
 29140                              <1> Vol_Serial2:
 29141 00009672 30303030            <1> 		db "0000"
 29142 00009676 0D0A00              <1> 		db 0Dh, 0Ah, 0
 29143                              <1> 
 29144                              <1> ;Vol_Tot_Sec_Str_Start:
 29145                              <1> ;		dd 0
 29146                              <1> Vol_Total_Sector_Header:
 29147 00009679 0D0A                <1> 		db 0Dh, 0Ah
 29148 0000967B 566F6C756D65205369- <1> 		db "Volume Size : ", 0
 29149 00009684 7A65203A2000        <1>
 29150                              <1> ;Vol_Tot_Sec_Str: 
 29151                              <1> ;		db "0000000000"
 29152                              <1> ;Vol_Tot_Sec_Str_End:
 29153                              <1> ;		db 0
 29154                              <1> ;Vol_Free_Sectors_Str_Start:
 29155                              <1> ;		dd 0
 29156                              <1> Vol_Free_Sectors_Header:
 29157 0000968A 467265652053706163- <1> 		db "Free Space  : ", 0
 29158 00009693 6520203A2000        <1>
 29159                              <1> ;Vol_Free_Sectors_Str:
 29160                              <1> ;		db "0000000000"
 29161                              <1> ;Vol_Free_Sectors_Str_End:
 29162                              <1> ;		db 0
 29163                              <1> 
 29164                              <1> Dir_Str_Header:
 29165 00009699 4469726563746F7279- <1>                 db "Directory: "
 29166 000096A2 3A20                <1>
 29167 000096A4 2F                  <1> Dir_Str_Root:   db "/"
 29168 000096A5 00<rept>            <1> Dir_Str:        times 64 db 0
 29169 000096E5 00000000            <1>                 dd 0
 29170 000096E9 00                  <1>                 db 0
 29171                              <1> 
 29172                              <1> Msg_Bad_Command:
 29173 000096EA 42616420636F6D6D61- <1>                 db "Bad command or file name!"
 29174 000096F3 6E64206F722066696C- <1>
 29175 000096FC 65206E616D6521      <1>
 29176 00009703 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29177                              <1> 
 29178                              <1> msgl_drv_not_ready: 
 29179 00009706 070D0A              <1> 		db 07h, 0Dh, 0Ah
 29180                              <1> 
 29181                              <1> ; CMD_INTR.ASM - 09/11/2011 - Messages
 29182                              <1> 
 29183                              <1> Msg_Not_Ready_Read_Err:
 29184 00009709 4472697665206E6F74- <1>                 db "Drive not ready or read error!"
 29185 00009712 207265616479206F72- <1>
 29186 0000971B 207265616420657272- <1>
 29187 00009724 6F7221              <1>
 29188 00009727 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29189                              <1> 
 29190                              <1> Msg_Not_Ready_Write_Err:
 29191 0000972A 4472697665206E6F74- <1>                 db "Drive not ready or write error!"
 29192 00009733 207265616479206F72- <1>
 29193 0000973C 207772697465206572- <1>
 29194 00009745 726F7221            <1>
 29195 00009749 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29196                              <1> 
 29197                              <1> Msg_Dir_Not_Found:
 29198 0000974C 4469726563746F7279- <1>                 db "Directory not found!"
 29199 00009755 206E6F7420666F756E- <1>
 29200 0000975E 6421                <1>
 29201 00009760 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29202                              <1> 
 29203                              <1> Msg_File_Not_Found:
 29204 00009763 46696C65206E6F7420- <1>                 db "File not found!"
 29205 0000976C 666F756E6421        <1>
 29206 00009772 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29207                              <1> 
 29208                              <1> Msg_File_Directory_Not_Found:
 29209 00009775 46696C65206F722064- <1>                 db "File or directory not found!"
 29210 0000977E 69726563746F727920- <1>
 29211 00009787 6E6F7420666F756E64- <1>
 29212 00009790 21                  <1>
 29213 00009791 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29214                              <1> 
 29215                              <1> Msg_LongName_Not_Found:
 29216 00009794 4C6F6E67206E616D65- <1>                 db "Long name not found!"
 29217 0000979D 206E6F7420666F756E- <1>
 29218 000097A6 6421                <1>
 29219 000097A8 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29220                              <1> 
 29221                              <1> Msg_Insufficient_Memory:
 29222 000097AB 496E73756666696369- <1>                 db "Insufficient memory!"
 29223 000097B4 656E74206D656D6F72- <1>
 29224 000097BD 7921                <1>
 29225 000097BF 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29226                              <1> 
 29227                              <1> Msg_Error_Code:
 29228 000097C2 436F6D6D616E642066- <1>                 db 'Command failed! Error code : '
 29229 000097CB 61696C656421204572- <1>
 29230 000097D4 726F7220636F646520- <1>
 29231 000097DD 3A20                <1>
 29232 000097DF 303068              <1> Error_Code:     db '00h'
 29233 000097E2 0A0A00              <1>                 db 0Ah, 0Ah, 0
 29234                              <1> 
 29235 000097E5 90                  <1> align 2
 29236                              <1> 
 29237                              <1> ; 10/02/2016
 29238                              <1> ; DIR.ASM - 09/10/2011
 29239                              <1> 
 29240 000097E6 3C4449523E20202020- <1> Type_Dir:       db '<DIR>     ' ; 10 bytes
 29241 000097EF 20                  <1>
 29242                              <1> 
 29243                              <1> File_Name:
 29244 000097F0 20<rept>            <1>                 times 12 db 20h
 29245 000097FC 20                  <1> 		db 20h
 29246                              <1> Dir_Or_FileSize:
 29247 000097FD 20<rept>            <1>                 times 10 db 20h
 29248 00009807 20                  <1> 		db 20h
 29249                              <1> File_Attribute:
 29250 00009808 20202020            <1> 		dd 20202020h
 29251 0000980C 20                  <1> 		db 20h
 29252                              <1> File_Day:
 29253 0000980D 3030                <1>                 db '0','0'
 29254 0000980F 2F                  <1> 		db '/'
 29255                              <1> File_Month:
 29256 00009810 3030                <1>                 db '0','0'
 29257 00009812 2F                  <1> 		db '/'
 29258                              <1> File_Year:
 29259 00009813 30303030            <1>                 db '0','0','0','0'
 29260 00009817 20                  <1> 		db 20h
 29261                              <1> File_Hour:
 29262 00009818 3030                <1>                 db '0','0'
 29263 0000981A 3A                  <1> 		db ':'
 29264                              <1> File_Minute:
 29265 0000981B 3030                <1>                 db '0','0'
 29266 0000981D 00                  <1> 		db 0
 29267                              <1> 
 29268                              <1> Decimal_File_Count_Header:
 29269 0000981E 0D0A                <1> 		db 0Dh, 0Ah
 29270                              <1> Decimal_File_Count:
 29271 00009820 00<rept>            <1> 		times 6 db 0
 29272                              <1> 
 29273 00009826 2066696C6528732920- <1> str_files:	db " file(s) & "
 29274 0000982F 2620                <1>
 29275                              <1> Decimal_Dir_Count: 
 29276 00009831 00<rept>            <1> 		times 6 db 0
 29277                              <1> str_dirs:       
 29278 00009837 206469726563746F72- <1> 		db " directory(s) "
 29279 00009840 7928732920          <1>
 29280 00009845 0D0A00              <1> 		db 0Dh, 0Ah, 0
 29281                              <1> 
 29282 00009848 206279746528732920- <1> str_bytes:	db " byte(s) in file(s)"
 29283 00009851 696E2066696C652873- <1>
 29284 0000985A 29                  <1>
 29285 0000985B 0D0A00              <1> 		db 0Dh, 0Ah, 0
 29286                              <1> 
 29287                              <1> ; CMD_INTR.ASM - 09/11/2011
 29288                              <1> ; 07/10/2010
 29289                              <1> Msg_invalid_name_chars:
 29290 0000985E 496E76616C69642066- <1>                 db "Invalid file or directory name characters!"
 29291 00009867 696C65206F72206469- <1>
 29292 00009870 726563746F7279206E- <1>
 29293 00009879 616D65206368617261- <1>
 29294 00009882 637465727321        <1>
 29295 00009888 0D0A00              <1>         	db 0Dh, 0Ah, 0
 29296                              <1> ; 21/02/2016
 29297 0000988B 46696C65206F722064- <1> Msg_Name_Exists: db "File or directory name exists!"
 29298 00009894 69726563746F727920- <1>
 29299 0000989D 6E616D652065786973- <1>
 29300 000098A6 747321              <1>
 29301 000098A9 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29302                              <1> Msg_DoYouWantMkdir:
 29303 000098AC 446F20796F75207761- <1>                 db "Do you want to make directory ", 0
 29304 000098B5 6E7420746F206D616B- <1>
 29305 000098BE 65206469726563746F- <1>
 29306 000098C7 72792000            <1>
 29307 000098CB 2028592F4E29203F20- <1> Msg_YesNo:      db " (Y/N) ? ", 0  
 29308 000098D4 00                  <1>
 29309 000098D5 000D0A00            <1> Y_N_nextline:	db 0, 0Dh, 0Ah, 0 
 29310 000098D9 4F4B2E0D0A00        <1> Msg_OK:		db "OK.", 0Dh, 0Ah, 0
 29311                              <1> 
 29312                              <1> ; 27/02/2016
 29313                              <1> Msg_DoYouWantRmDir:
 29314 000098DF 446F20796F75207761- <1>                 db "Do you want to delete directory ", 0
 29315 000098E8 6E7420746F2064656C- <1>
 29316 000098F1 657465206469726563- <1>
 29317 000098FA 746F72792000        <1>
 29318                              <1> Msg_Dir_Not_Empty:
 29319 00009900 4469726563746F7279- <1>                 db "Directory not empty!"
 29320 00009909 206E6F7420656D7074- <1>
 29321 00009912 7921                <1>
 29322 00009914 0D0A00              <1>                 db 0Dh, 0Ah, 0
 29323                              <1> 
 29324                              <1> Msg_DoYouWantDelete:
 29325 00009917 446F20796F75207761- <1>                 db "Do you want to delete file ",0
 29326 00009920 6E7420746F2064656C- <1>
 29327 00009929 6574652066696C6520- <1>
 29328 00009932 00                  <1>
 29329                              <1> 
 29330 00009933 44656C657465642E2E- <1> Msg_Deleted:    db "Deleted...", 0Dh, 0Ah, 0
 29331 0000993C 2E0D0A00            <1>
 29332                              <1> 
 29333                              <1> Msg_Permission_Denied:
 29334 00009940 07                  <1>                 db 7
 29335 00009941 5065726D697373696F- <1>                 db "Permission denied!", 0Dh, 0Ah, 0
 29336 0000994A 6E2064656E69656421- <1>
 29337 00009953 0D0A00              <1>
 29338                                  
 29339                                  ; 07/03/2015
 29340                                  ; Temporary Code
 29341                                  display_disks:
 29342 00009956 803D[1E9D0000]00        	cmp 	byte [fd0_type], 0
 29343 0000995D 7605                    	jna 	short ddsks1
 29344 0000995F E87D000000              	call	pdskm
 29345                                  ddsks1:
 29346 00009964 803D[1F9D0000]00        	cmp	byte [fd1_type], 0
 29347 0000996B 760C                    	jna	short ddsks2
 29348 0000996D C605[159F0000]31        	mov	byte [dskx], '1'
 29349 00009974 E868000000              	call	pdskm
 29350                                  ddsks2:
 29351 00009979 803D[209D0000]00        	cmp	byte [hd0_type], 0
 29352 00009980 7654                    	jna	short ddsk6
 29353 00009982 66C705[139F0000]68-     	mov	word [dsktype], 'hd'
 29354 0000998A 64                 
 29355 0000998B C605[159F0000]30        	mov	byte [dskx], '0'
 29356 00009992 E84A000000              	call	pdskm
 29357                                  ddsks3:
 29358 00009997 803D[219D0000]00        	cmp	byte [hd1_type], 0
 29359 0000999E 7636                    	jna	short ddsk6
 29360 000099A0 C605[159F0000]31        	mov	byte [dskx], '1'
 29361 000099A7 E835000000              	call	pdskm
 29362                                  ddsks4:
 29363 000099AC 803D[229D0000]00        	cmp	byte [hd2_type], 0
 29364 000099B3 7621                    	jna	short ddsk6
 29365 000099B5 C605[159F0000]32        	mov	byte [dskx], '2'
 29366 000099BC E820000000              	call	pdskm
 29367                                  ddsks5:
 29368 000099C1 803D[239D0000]00        	cmp	byte [hd3_type], 0
 29369 000099C8 760C                    	jna	short ddsk6
 29370 000099CA C605[159F0000]33        	mov	byte [dskx], '3'
 29371 000099D1 E80B000000              	call	pdskm
 29372                                  ddsk6:
 29373 000099D6 BE[269F0000]            	mov	esi, nextline
 29374 000099DB E806000000              	call	pdskml
 29375                                  pdskm_ok:
 29376 000099E0 C3                      	retn
 29377                                  pdskm:
 29378 000099E1 BE[119F0000]            	mov	esi, dsk_ready_msg
 29379                                  pdskml:	
 29380 000099E6 AC                      	lodsb
 29381 000099E7 08C0                    	or	al, al
 29382 000099E9 74F5                    	jz	short pdskm_ok
 29383 000099EB 56                      	push	esi
 29384 000099EC 31DB                    	xor	ebx, ebx ; 0
 29385                                  			; Video page 0 (bl=0)
 29386 000099EE B407                    	mov	ah, 07h ; Black background, 
 29387                                  			; light gray forecolor
 29388 000099F0 E8C17DFFFF              	call	WRITE_TTY
 29389 000099F5 5E                      	pop	esi
 29390 000099F6 EBEE                    	jmp	short pdskml
 29391                                  
 29392 000099F8 90<rept>                align 16
 29393                                  
 29394                                  gdt:	; Global Descriptor Table
 29395                                  	; (30/07/2015, conforming cs)
 29396                                  	; (26/03/2015)
 29397                                  	; (24/03/2015, tss)
 29398                                  	; (19/03/2015)
 29399                                  	; (29/12/2013)
 29400                                  	;
 29401 00009A00 0000000000000000        	dw 0, 0, 0, 0		; NULL descriptor
 29402                                  	; 18/08/2014
 29403                                  			; 8h kernel code segment, base = 00000000h		
 29404 00009A08 FFFF0000009ACF00        	dw 0FFFFh, 0, 9A00h, 00CFh	; KCODE
 29405                                  			; 10h kernel data segment, base = 00000000h	
 29406 00009A10 FFFF00000092CF00        	dw 0FFFFh, 0, 9200h, 00CFh	; KDATA
 29407                                  			; 1Bh user code segment, base address = 400000h ; CORE
 29408 00009A18 FFFB000040FACF00        	dw 0FBFFh, 0, 0FA40h, 00CFh	; UCODE 
 29409                                  			; 23h user data segment, base address = 400000h ; CORE
 29410 00009A20 FFFB000040F2CF00        	dw 0FBFFh, 0, 0F240h, 00CFh	; UDATA
 29411                                  			; Task State Segment
 29412 00009A28 6700                    	dw 0067h ; Limit = 103 ; (104-1, tss size = 104 byte, 
 29413                                  			       ;  no IO permission in ring 3)
 29414                                  gdt_tss0:
 29415 00009A2A 0000                    	dw 0  ; TSS base address, bits 0-15 
 29416                                  gdt_tss1:
 29417 00009A2C 00                      	db 0  ; TSS base address, bits 16-23 
 29418                                  	      		; 49h	
 29419 00009A2D E9                      	db 11101001b ; E9h => P=1/DPL=11/0/1/0/B/1 --> B = Task is busy (1)
 29420 00009A2E 00                      	db 0 ; G/0/0/AVL/LIMIT=0000 ; (Limit bits 16-19 = 0000) (G=0, 1 byte)
 29421                                  gdt_tss2:
 29422 00009A2F 00                      	db 0  ; TSS base address, bits 24-31 
 29423                                  
 29424                                  gdt_end:
 29425                                  	;; 9Ah = 1001 1010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
 29426                                  					;; Type= 1 (code)/C=0/R=1/A=0
 29427                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
 29428                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
 29429                                  
 29430                                  	;; 92h = 1001 0010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
 29431                                  					;; Type= 0 (data)/E=0/W=1/A=0
 29432                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
 29433                                  		; 0= Data E= Expansion direction (1= down, 0= up)
 29434                                  		; W= Writeable, A= Accessed
 29435                                  	
 29436                                  	;; FAh = 1111 1010b (GDT byte 5) P=1/DPL=11/1/TYPE=1010, 
 29437                                  					;; Type= 1 (code)/C=0/R=1/A=0
 29438                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
 29439                                  		; 1= Code C= non-Conforming, R= Readable, A = Accessed
 29440                                  
 29441                                  	;; F2h = 1111 0010b (GDT byte 5) P=1/DPL=11/1/TYPE=0010, 
 29442                                  					;; Type= 0 (data)/E=0/W=1/A=0
 29443                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
 29444                                  		; 0= Data E= Expansion direction (1= down, 0= up)
 29445                                  	
 29446                                  	;; CFh = 1100 1111b (GDT byte 6) G=1/B=1/0/AVL=0, Limit=1111b (3)
 29447                                  
 29448                                  		;; Limit = FFFFFh (=> FFFFFh+1= 100000h) // bits 0-15, 48-51 //
 29449                                  		;	 = 100000h * 1000h (G=1) = 4GB
 29450                                  		;; Limit = FFBFFh (=> FFBFFh+1= FFC00h) // bits 0-15, 48-51 //
 29451                                  		;	 = FFC00h * 1000h (G=1) = 4GB - 4MB
 29452                                  		; G= Granularity (1= 4KB), B= Big (32 bit), 
 29453                                  		; AVL= Available to programmers	
 29454                                  
 29455                                  gdtd:
 29456 00009A30 2F00                            dw gdt_end - gdt - 1    ; Limit (size)
 29457 00009A32 [009A0000]                      dd gdt			; Address of the GDT
 29458                                  
 29459                                  	; 20/08/2014
 29460                                  idtd:
 29461 00009A36 FF01                            dw idt_end - idt - 1    ; Limit (size)
 29462 00009A38 [E09F0000]                      dd idt			; Address of the IDT
 29463                                  
 29464                                  Align 4
 29465                                  
 29466                                  	; 21/08/2014
 29467                                  ilist:
 29468                                  	;times 	32 dd cpu_except ; INT 0 to INT 1Fh
 29469                                  	;
 29470                                  	; Exception list
 29471                                  	; 25/08/2014	
 29472 00009A3C [DB080000]              	dd	exc0	; 0h,  Divide-by-zero Error
 29473 00009A40 [E2080000]              	dd	exc1	
 29474 00009A44 [E9080000]              	dd 	exc2	
 29475 00009A48 [F0080000]              	dd	exc3	
 29476 00009A4C [F4080000]              	dd	exc4	
 29477 00009A50 [F8080000]              	dd	exc5	
 29478 00009A54 [FC080000]              	dd 	exc6	; 06h,  Invalid Opcode
 29479 00009A58 [00090000]              	dd	exc7	
 29480 00009A5C [04090000]              	dd	exc8	
 29481 00009A60 [08090000]              	dd	exc9	
 29482 00009A64 [0C090000]              	dd 	exc10	
 29483 00009A68 [10090000]              	dd	exc11
 29484 00009A6C [14090000]              	dd	exc12
 29485 00009A70 [18090000]              	dd	exc13	; 0Dh, General Protection Fault
 29486 00009A74 [1C090000]              	dd 	exc14	; 0Eh, Page Fault
 29487 00009A78 [20090000]              	dd	exc15
 29488 00009A7C [24090000]              	dd	exc16
 29489 00009A80 [28090000]              	dd	exc17
 29490 00009A84 [2C090000]              	dd 	exc18
 29491 00009A88 [30090000]              	dd	exc19
 29492 00009A8C [34090000]              	dd 	exc20
 29493 00009A90 [38090000]              	dd	exc21
 29494 00009A94 [3C090000]              	dd	exc22
 29495 00009A98 [40090000]              	dd	exc23
 29496 00009A9C [44090000]              	dd 	exc24
 29497 00009AA0 [48090000]              	dd	exc25
 29498 00009AA4 [4C090000]              	dd	exc26
 29499 00009AA8 [50090000]              	dd	exc27
 29500 00009AAC [54090000]              	dd 	exc28
 29501 00009AB0 [58090000]              	dd	exc29
 29502 00009AB4 [5C090000]              	dd 	exc30
 29503 00009AB8 [60090000]              	dd	exc31
 29504                                  	; Interrupt list
 29505 00009ABC [11070000]              	dd	timer_int	; INT 20h
 29506                                  		;dd	irq0	
 29507 00009AC0 [AD0D0000]              	dd	kb_int		; 24/01/2016
 29508                                  		;dd	irq1
 29509 00009AC4 [31080000]              	dd	irq2
 29510                                  		; COM2 int
 29511 00009AC8 [35080000]              	dd	irq3
 29512                                  		; COM1 int
 29513 00009ACC [40080000]              	dd	irq4
 29514 00009AD0 [4B080000]              	dd	irq5
 29515                                  ;DISKETTE_INT: ;06/02/2015
 29516 00009AD4 [76280000]              	dd	fdc_int		; 16/02/2015, IRQ 6 handler	
 29517                                  		;dd	irq6
 29518                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
 29519                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
 29520 00009AD8 [C70B0000]              	dd	default_irq7	; 25/02/2015
 29521                                  		;dd	irq7
 29522                                  ; Real Time Clock Interrupt
 29523 00009ADC [6A0A0000]              	dd	rtc_int		; 23/02/2015, IRQ 8 handler
 29524                                  		;dd	irq8	; INT 28h
 29525 00009AE0 [5B080000]              	dd	irq9
 29526 00009AE4 [5F080000]              	dd	irq10
 29527 00009AE8 [63080000]              	dd	irq11
 29528 00009AEC [67080000]              	dd	irq12
 29529 00009AF0 [6B080000]              	dd	irq13
 29530                                  ;HDISK_INT1:  ;06/02/2015 	
 29531 00009AF4 [BA300000]              	dd	hdc1_int 	; 21/02/2015, IRQ 14 handler		
 29532                                  		;dd	irq14
 29533                                  ;HDISK_INT2:  ;06/02/2015
 29534 00009AF8 [E1300000]              	dd	hdc2_int 	; 21/02/2015, IRQ 15 handler		
 29535                                  		;dd	irq15	; INT 2Fh
 29536                                  		; 14/08/2015
 29537 00009AFC [897A0000]              	dd	sysent		; INT 30h (system calls)
 29538                                  	
 29539                                  	;dd	ignore_int
 29540 00009B00 00000000                	dd	0
 29541                                  
 29542                                  ;;;
 29543                                  ;;; 11/03/2015
 29544                                  %include 'kybdata.s'	; KEYBOARD (BIOS) DATA
 29545                              <1> ; ****************************************************************************
 29546                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - kybdata.s
 29547                              <1> ; ----------------------------------------------------------------------------
 29548                              <1> ; Last Update: 17/01/2016
 29549                              <1> ; ----------------------------------------------------------------------------
 29550                              <1> ; Beginning: 17/01/2016
 29551                              <1> ; ----------------------------------------------------------------------------
 29552                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 29553                              <1> ; ----------------------------------------------------------------------------
 29554                              <1> ; Turkish Rational DOS
 29555                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 29556                              <1> ;
 29557                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 29558                              <1> ; kybdata.inc (11/03/2015)
 29559                              <1> ;
 29560                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 29561                              <1> ; ****************************************************************************
 29562                              <1> 
 29563                              <1> ; Retro UNIX 386 v1 Kernel - KYBDATA.INC
 29564                              <1> ; Last Modification: 11/03/2015
 29565                              <1> ;		 (Data Section for 'KEYBOARD.INC')	
 29566                              <1> ;
 29567                              <1> ; ///////// KEYBOARD DATA ///////////////
 29568                              <1> 
 29569                              <1> ; 05/12/2014
 29570                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-) 
 29571                              <1> ; 03/06/86  KEYBOARD BIOS
 29572                              <1> 
 29573                              <1> ;---------------------------------------------------------------------------------
 29574                              <1> ;	KEY IDENTIFICATION SCAN TABLES
 29575                              <1> ;---------------------------------------------------------------------------------
 29576                              <1> 
 29577                              <1> ;-----	TABLES FOR ALT CASE ------------
 29578                              <1> ;-----	ALT-INPUT-TABLE 
 29579 00009B04 524F50514B          <1> K30:	db	82,79,80,81,75
 29580 00009B09 4C4D474849          <1> 	db	76,77,71,72,73		; 10 NUMBER ON KEYPAD
 29581                              <1> ;-----	SUPER-SHIFT-TABLE 
 29582 00009B0E 101112131415        <1> 	db	16,17,18,19,20,21	; A-Z TYPEWRITER CHARS
 29583 00009B14 161718191E1F        <1> 	db	22,23,24,25,30,31
 29584 00009B1A 202122232425        <1> 	db	32,33,34,35,36,37
 29585 00009B20 262C2D2E2F30        <1> 	db	38,44,45,46,47,48
 29586 00009B26 3132                <1> 	db	49,50
 29587                              <1> 
 29588                              <1> ;-----	TABLE OF SHIFT KEYS AND MASK VALUES
 29589                              <1> ;-----	KEY_TABLE 
 29590 00009B28 52                  <1> _K6:    db      INS_KEY                 ; INSERT KEY
 29591 00009B29 3A4546381D          <1> 	db	CAPS_KEY,NUM_KEY,SCROLL_KEY,ALT_KEY,CTL_KEY
 29592 00009B2E 2A36                <1>         db      LEFT_KEY,RIGHT_KEY
 29593                              <1> _K6L    equ     $-_K6
 29594                              <1> 
 29595                              <1> ;-----	MASK_TABLE
 29596 00009B30 80                  <1> _K7:    db      INS_SHIFT               ; INSERT MODE SHIFT
 29597 00009B31 4020100804          <1> 	db	CAPS_SHIFT,NUM_SHIFT,SCROLL_SHIFT,ALT_SHIFT,CTL_SHIFT
 29598 00009B36 0201                <1> 	db	LEFT_SHIFT,RIGHT_SHIFT
 29599                              <1> 
 29600                              <1> ;-----	TABLES FOR CTRL CASE		;---- CHARACTERS ------
 29601 00009B38 1BFF00FFFFFF        <1> _K8:	db	27,-1,0,-1,-1,-1	; Esc, 1, 2, 3, 4, 5
 29602 00009B3E 1EFFFFFFFF1F        <1> 	db 	30,-1,-1,-1,-1,31	; 6, 7, 8, 9, 0, -
 29603 00009B44 FF7FFF111705        <1> 	db	-1,127,-1,17,23,5	; =, Bksp, Tab, Q, W, E
 29604 00009B4A 12141915090F        <1> 	db	18,20,25,21,9,15	; R, T, Y, U, I, O
 29605 00009B50 101B1D0AFF01        <1> 	db	16,27,29,10,-1,1	; P, [, ], Enter, Ctrl, A
 29606 00009B56 13040607080A        <1> 	db	19,4,6,7,8,10		; S, D, F, G, H, J
 29607 00009B5C 0B0CFFFFFFFF        <1> 	db	11,12,-1,-1,-1,-1	; K, L, :, ', `, LShift
 29608 00009B62 1C1A18031602        <1> 	db	28,26,24,3,22,2		; Bkslash, Z, X, C, V, B
 29609 00009B68 0E0DFFFFFFFF        <1> 	db	14,13,-1,-1,-1,-1	; N, M, ,, ., /, RShift
 29610 00009B6E 96FF20FF            <1> 	db	150,-1,' ',-1		; *, ALT, Spc, CL
 29611                              <1> 	;				;----- FUNCTIONS ------		
 29612 00009B72 5E5F60616263        <1> 	db 	94,95,96,97,98,99	; F1 - F6
 29613 00009B78 64656667FFFF        <1> 	db	100,101,102,103,-1,-1	; F7 - F10, NL, SL
 29614 00009B7E 778D848E738F        <1> 	db	119,141,132,142,115,143	; Home, Up, PgUp, -, Left, Pad5
 29615 00009B84 749075917692        <1> 	db 	116,144,117,145,118,146 ; Right, +, End, Down, PgDn, Ins
 29616 00009B8A 93FFFFFF898A        <1> 	db	147,-1,-1,-1,137,138	; Del, SysReq, Undef, WT, F11, F12
 29617                              <1> 
 29618                              <1> ;-----	TABLES FOR LOWER CASE ----------
 29619 00009B90 1B3132333435363738- <1> K10:	db 	27,'1234567890-=',8,9
 29620 00009B99 39302D3D0809        <1>
 29621 00009B9F 71776572747975696F- <1> 	db 	'qwertyuiop[]',13,-1,'asdfghjkl;',39
 29622 00009BA8 705B5D0DFF61736466- <1>
 29623 00009BB1 67686A6B6C3B27      <1>
 29624 00009BB8 60FF5C7A786376626E- <1> 	db	96,-1,92,'zxcvbnm,./',-1,'*',-1,' ',-1
 29625 00009BC1 6D2C2E2FFF2AFF20FF  <1>
 29626                              <1> ;-----	LC TABLE SCAN
 29627 00009BCA 3B3C3D3E3F          <1> 	db	59,60,61,62,63		; BASE STATE OF F1 - F10
 29628 00009BCF 4041424344          <1> 	db	64,65,66,67,68
 29629 00009BD4 FFFF                <1> 	db	-1,-1			; NL, SL
 29630                              <1> 
 29631                              <1> ;-----	KEYPAD TABLE
 29632 00009BD6 474849FF4BFF        <1> K15:	db	71,72,73,-1,75,-1	; BASE STATE OF KEYPAD KEYS
 29633 00009BDC 4DFF4F50515253      <1> 	db	77,-1,79,80,81,82,83
 29634 00009BE3 FFFF5C8586          <1> 	db	-1,-1,92,133,134	; SysRq, Undef, WT, F11, F12
 29635                              <1> 
 29636                              <1> ;-----	TABLES FOR UPPER CASE ----------
 29637 00009BE8 1B21402324255E262A- <1> K11:	db 	27,'!@#$%',94,'&*()_+',8,0
 29638 00009BF1 28295F2B0800        <1>
 29639 00009BF7 51574552545955494F- <1> 	db 	'QWERTYUIOP{}',13,-1,'ASDFGHJKL:"'
 29640 00009C00 507B7D0DFF41534446- <1>
 29641 00009C09 47484A4B4C3A22      <1>
 29642 00009C10 7EFF7C5A584356424E- <1> 	db	126,-1,'|ZXCVBNM<>?',-1,'*',-1,' ',-1
 29643 00009C19 4D3C3E3FFF2AFF20FF  <1>
 29644                              <1> ;-----	UC TABLE SCAN
 29645 00009C22 5455565758          <1> K12:	db	84,85,86,87,88		; SHIFTED STATE OF F1 - F10
 29646 00009C27 595A5B5C5D          <1> 	db	89,90,91,92,93
 29647 00009C2C FFFF                <1> 	db	-1,-1			; NL, SL
 29648                              <1> 
 29649                              <1> ;-----	NUM STATE TABLE
 29650 00009C2E 3738392D3435362B31- <1> K14:	db 	'789-456+1230.'		; NUMLOCK STATE OF KEYPAD KEYS
 29651 00009C37 3233302E            <1>
 29652                              <1> 	;
 29653 00009C3B FFFF7C8788          <1> 	db	-1,-1,124,135,136	; SysRq, Undef, WT, F11, F12
 29654                              <1> 
 29655                              <1> ; 26/08/2014
 29656                              <1> ; Retro UNIX 8086 v1 - UNIX.ASM (03/03/2014)
 29657                              <1> ; Derived from IBM "pc-at" 
 29658                              <1> ; rombios source code (06/10/1985)
 29659                              <1> ; 'dseg.inc'
 29660                              <1> 
 29661                              <1> ;---------------------------------------;
 29662                              <1> ;	SYSTEM DATA AREA		;
 29663                              <1> ;----------------------------------------
 29664 00009C40 00                  <1> BIOS_BREAK	db	0		; BIT 7=1 IF BREAK KEY HAS BEEN PRESSED
 29665                              <1> 
 29666                              <1> ;----------------------------------------
 29667                              <1> ;	KEYBOARD DATA AREAS		;
 29668                              <1> ;----------------------------------------
 29669                              <1> 
 29670 00009C41 00                  <1> KB_FLAG		db	0		; KEYBOARD SHIFT STATE AND STATUS FLAGS
 29671 00009C42 00                  <1> KB_FLAG_1	db	0		; SECOND BYTE OF KEYBOARD STATUS
 29672 00009C43 00                  <1> KB_FLAG_2	db	0		; KEYBOARD LED FLAGS
 29673 00009C44 00                  <1> KB_FLAG_3	db	0		; KEYBOARD MODE STATE AND TYPE FLAGS
 29674 00009C45 00                  <1> ALT_INPUT	db	0		; STORAGE FOR ALTERNATE KEY PAD ENTRY
 29675 00009C46 [569C0000]          <1> BUFFER_START	dd	KB_BUFFER 	; OFFSET OF KEYBOARD BUFFER START
 29676 00009C4A [769C0000]          <1> BUFFER_END	dd	KB_BUFFER + 32	; OFFSET OF END OF BUFFER
 29677 00009C4E [569C0000]          <1> BUFFER_HEAD	dd	KB_BUFFER 	; POINTER TO HEAD OF KEYBOARD BUFFER
 29678 00009C52 [569C0000]          <1> BUFFER_TAIL	dd	KB_BUFFER 	; POINTER TO TAIL OF KEYBOARD BUFFER
 29679                              <1> ; ------	HEAD = TAIL	INDICATES THAT THE BUFFER IS EMPTY
 29680 00009C56 0000<rept>          <1> KB_BUFFER	times	16 dw 0		; ROOM FOR 16 SCAN CODE ENTRIES
 29681                              <1> 
 29682                              <1> ; /// End Of KEYBOARD DATA ///
 29683                                  %include 'vidata.s'	; VIDEO (BIOS) DATA
 29684                              <1> ; ****************************************************************************
 29685                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - vidata.s
 29686                              <1> ; ----------------------------------------------------------------------------
 29687                              <1> ; Last Update: 30/01/2016
 29688                              <1> ; ----------------------------------------------------------------------------
 29689                              <1> ; Beginning: 16/01/2016
 29690                              <1> ; ----------------------------------------------------------------------------
 29691                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 29692                              <1> ; ----------------------------------------------------------------------------
 29693                              <1> ; Turkish Rational DOS
 29694                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 29695                              <1> ;
 29696                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 29697                              <1> ; vidata.inc (11/03/2015)
 29698                              <1> ;
 29699                              <1> ; Derived from 'IBM PC-AT' BIOS source code (1985) 
 29700                              <1> ; ****************************************************************************
 29701                              <1> 
 29702                              <1> ; Retro UNIX 386 v1 Kernel - VIDATA.S
 29703                              <1> ; Last Modification: 11/03/2015
 29704                              <1> ;		    (Data section for 'VIDEO.INC')	
 29705                              <1> ;
 29706                              <1> ; ///////// VIDEO DATA ///////////////
 29707                              <1> 
 29708                              <1> ;-----	COLUMNS
 29709                              <1> ;M6:
 29710                              <1> ;	db	40, 40, 80, 80, 40, 40, 80, 80
 29711                              <1> 
 29712                              <1> ;-----	C_REG_TAB
 29713                              <1> ;M7:
 29714                              <1> ;	db	2Ch, 28h, 2Dh, 29h, 2Ah, 2Eh, 1Eh, 29h	; TABLE OF MODE SETS
 29715                              <1> 
 29716                              <1> ;----------------------------------------
 29717                              <1> ;	VIDEO DISPLAY DATA AREA		;
 29718                              <1> ;----------------------------------------
 29719 00009C76 03                  <1> CRT_MODE	db	3	; CURRENT DISPLAY MODE (TYPE)
 29720 00009C77 29                  <1> CRT_MODE_SET	db	29h	; CURRENT SETTING OF THE 3X8 REGISTER
 29721                              <1> 				; (29h default setting for video mode 3)
 29722                              <1> 				; Mode Select register Bits
 29723                              <1> 				;   BIT 0 - 80x25 (1), 40x25 (0)
 29724                              <1> 				;   BIT 1 - ALPHA (0), 320x200 GRAPHICS (1)
 29725                              <1> 				;   BIT 2 - COLOR (0), BW (1)
 29726                              <1> 				;   BIT 3 - Video Sig. ENABLE (1), DISABLE (0)
 29727                              <1> 				;   BIT 4 - 640x200 B&W Graphics Mode (1)
 29728                              <1> 				;   BIT 5 - ALPHA mode BLINKING (1)
 29729                              <1> 				;   BIT 6, 7 - Not Used
 29730                              <1> 
 29731                              <1> ; Mode 0 - 2Ch = 101100b	; 40x25 text, 16 gray colors
 29732                              <1> ; Mode 1 - 28h = 101000b	; 40x25 text, 16 fore colors, 8 back colors
 29733                              <1> ; Mode 2 - 2Dh = 101101b	; 80x25 text, 16 gray colors	
 29734                              <1> ; MODE 3 - 29h = 101001b	; 80x25 text, 16 fore color, 8 back color
 29735                              <1> ; Mode 4 - 2Ah = 101010b	; 320x200 graphics, 4 colors
 29736                              <1> ; Mode 5 - 2Eh = 101110b	; 320x200 graphics, 4 gray colors
 29737                              <1> ; Mode 6 - 1Eh = 011110b	; 640x200 graphics, 2 colors
 29738                              <1> ; Mode 7 - 29h = 101001b	; 80x25 text, black & white colors
 29739                              <1> ; Mode & 37h = Video signal OFF
 29740                              <1> 			
 29741                              <1> video_params:
 29742                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
 29743                              <1> 	;ORGS.ASM ----- 06/10/85   COMPATIBILITY MODULE
 29744                              <1> 	; VIDEO MODE 3
 29745 00009C78 71505A0A1F0619      <1> 	db	71h,50h,5Ah,0Ah,1Fh,6,19h	; SET UP FOR 80X25
 29746 00009C7F 1C02070607          <1> 	db	1Ch,2,7,6,7	; cursor start = 6, cursor stop = 7
 29747 00009C84 00000000            <1> 	db	0,0,0,0
 29748                              <1> 
 29749                              <1> ; 16/01/2016
 29750                              <1> chr_attrib:  ; Character color/attributes for viode pages (0 to 7)
 29751 00009C88 0707070707070707    <1> 	db	07h, 07h, 07h, 07h, 07h, 07h, 07h, 07h
 29752                              <1> ; 30/01/2016
 29753                              <1> vmode:
 29754 00009C90 0303030303030303    <1> 	db	3,3,3,3,3,3,3,3 ; video modes for pseudo screens 
 29755                              <1> 
 29756                              <1> ; /// End Of VIDEO DATA ///
 29757                                  %include 'diskdata.s'	; DISK (BIOS) DATA (initialized)
 29758                              <1> ; ****************************************************************************
 29759                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskdata.s
 29760                              <1> ; ----------------------------------------------------------------------------
 29761                              <1> ; Last Update: 24/01/2016
 29762                              <1> ; ----------------------------------------------------------------------------
 29763                              <1> ; Beginning: 24/01/2016
 29764                              <1> ; ----------------------------------------------------------------------------
 29765                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 29766                              <1> ; ----------------------------------------------------------------------------
 29767                              <1> ; Turkish Rational DOS
 29768                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 29769                              <1> ;
 29770                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 29771                              <1> ; diskdata.inc (11/03/2015)
 29772                              <1> ;
 29773                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 29774                              <1> ; ****************************************************************************
 29775                              <1> 
 29776                              <1> ; Retro UNIX 386 v1 Kernel - DISKDATA.INC
 29777                              <1> ; Last Modification: 11/03/2015
 29778                              <1> ;	(Initialized Disk Parameters Data section for 'DISKIO.INC') 
 29779                              <1> ;
 29780                              <1> 
 29781                              <1> ;----------------------------------------
 29782                              <1> ;	80286 INTERRUPT LOCATIONS	:
 29783                              <1> ;	REFERENCED BY POST & BIOS	:
 29784                              <1> ;----------------------------------------
 29785                              <1> 
 29786 00009C98 [FB9C0000]          <1> DISK_POINTER:	dd	MD_TBL6		; Pointer to Diskette Parameter Table
 29787                              <1> 
 29788                              <1> ; IBM PC-XT Model 286 source code ORGS.ASM (06/10/85) - 14/12/2014
 29789                              <1> ;----------------------------------------------------------------
 29790                              <1> ; DISK_BASE							:
 29791                              <1> ;	THIS IS THE SET OF PARAMETERS REQUIRED FOR		:
 29792                              <1> ;	DISKETTE OPERATION. THEY ARE POINTED AT BY THE		:
 29793                              <1> ;	DATA VARIABLE @DISK_POINTER. TO MODIFY THE PARAMETERS,	:
 29794                              <1> ;	BUILD ANOTHER PARAMETER BLOCK AND POINT AT IT		:
 29795                              <1> ;----------------------------------------------------------------
 29796                              <1> 
 29797                              <1> ;DISK_BASE:	
 29798                              <1> ;	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 29799                              <1> ;	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 29800                              <1> ;	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 29801                              <1> ;	DB	2		; 512 BYTES/SECTOR
 29802                              <1> ;	;DB	15		; EOT (LAST SECTOR ON TRACK)
 29803                              <1> ;	db	18		; (EOT for 1.44MB diskette)
 29804                              <1> ;	DB	01BH		; GAP LENGTH
 29805                              <1> ;	DB	0FFH		; DTL
 29806                              <1> ;	;DB	054H		; GAP LENGTH FOR FORMAT
 29807                              <1> ;	db	06ch		; (for 1.44MB dsikette)
 29808                              <1> ;	DB	0F6H		; FILL BYTE FOR FORMAT
 29809                              <1> ;	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 29810                              <1> ;	DB	8		; MOTOR START TIME (1/8 SECONDS)
 29811                              <1> 
 29812                              <1> ;----------------------------------------
 29813                              <1> ;	ROM BIOS DATA AREAS		:
 29814                              <1> ;----------------------------------------
 29815                              <1> 
 29816                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
 29817                              <1> 
 29818                              <1> ;@EQUIP_FLAG	DW	?		; INSTALLED HARDWARE FLAGS
 29819                              <1> 
 29820                              <1> ;----------------------------------------
 29821                              <1> ;	DISKETTE DATA AREAS		:
 29822                              <1> ;----------------------------------------
 29823                              <1> 
 29824                              <1> ;@SEEK_STATUS	DB	?		; DRIVE RECALIBRATION STATUS
 29825                              <1> ;					; BIT 3-0 = DRIVE 3-0 RECALIBRATION
 29826                              <1> ;					; BEFORE NEXT SEEK IF BIT IS = 0
 29827                              <1> ;@MOTOR_STATUS	DB	?		; MOTOR STATUS
 29828                              <1> ;					; BIT 3-0 = DRIVE 3-0 CURRENTLY RUNNING
 29829                              <1> ;					; BIT 7 = CURRENT OPERATION IS A WRITE
 29830                              <1> ;@MOTOR_COUNT	DB	?		; TIME OUT COUNTER FOR MOTOR(S) TURN OFF
 29831                              <1> ;@DSKETTE_STATUS DB	?		; RETURN CODE STATUS BYTE
 29832                              <1> ;					; CMD_BLOCK  IN STACK FOR DISK OPERATION
 29833                              <1> ;@NEC_STATUS	DB	7 DUP(?)	; STATUS BYTES FROM DISKETTE OPERATION
 29834                              <1> 
 29835                              <1> ;----------------------------------------
 29836                              <1> ;	POST AND BIOS WORK DATA AREA	:
 29837                              <1> ;----------------------------------------
 29838                              <1> 
 29839                              <1> ;@INTR_FLAG	DB	?		; FLAG INDICATING AN INTERRUPT HAPPENED
 29840                              <1> 
 29841                              <1> ;----------------------------------------
 29842                              <1> ;	TIMER DATA AREA 		:
 29843                              <1> ;----------------------------------------
 29844                              <1> 
 29845                              <1> ; 17/12/2014  (IRQ 0 - INT 08H)
 29846                              <1> ;TIMER_LOW	equ	46Ch		; Timer ticks (counter)  @ 40h:006Ch
 29847                              <1> ;TIMER_HIGH	equ	46Eh		; (18.2 timer ticks per second)
 29848                              <1> ;TIMER_OFL	equ	470h		; Timer - 24 hours flag  @ 40h:0070h
 29849                              <1> 
 29850                              <1> ;----------------------------------------
 29851                              <1> ;	ADDITIONAL MEDIA DATA		:
 29852                              <1> ;----------------------------------------
 29853                              <1> 
 29854                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
 29855                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
 29856                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
 29857                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
 29858                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
 29859                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
 29860                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
 29861                              <1> 
 29862                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
 29863                              <1> 
 29864                              <1> ;--------------------------------------------------------
 29865                              <1> ;	DRIVE TYPE TABLE				:
 29866                              <1> ;--------------------------------------------------------
 29867                              <1> 		; 16/02/2015 (unix386.s, 32 bit modifications)
 29868                              <1> DR_TYPE:
 29869 00009C9C 01                  <1> 		DB	01		;DRIVE TYPE, MEDIA TABLE
 29870                              <1>                 ;DW      MD_TBL1
 29871 00009C9D [BA9C0000]          <1> 		dd	MD_TBL1
 29872 00009CA1 82                  <1> 		DB	02+BIT7ON
 29873                              <1> 		;DW      MD_TBL2
 29874 00009CA2 [C79C0000]          <1>                 dd      MD_TBL2
 29875 00009CA6 02                  <1> DR_DEFAULT:	DB	02
 29876                              <1>                 ;DW      MD_TBL3
 29877 00009CA7 [D49C0000]          <1> 		dd      MD_TBL3
 29878 00009CAB 03                  <1> 		DB	03
 29879                              <1>                 ;DW      MD_TBL4
 29880 00009CAC [E19C0000]          <1> 		dd      MD_TBL4
 29881 00009CB0 84                  <1> 		DB	04+BIT7ON
 29882                              <1>                 ;DW      MD_TBL5
 29883 00009CB1 [EE9C0000]          <1> 		dd      MD_TBL5
 29884 00009CB5 04                  <1> 		DB	04
 29885                              <1>                 ;DW      MD_TBL6
 29886 00009CB6 [FB9C0000]          <1> 		dd      MD_TBL6
 29887                              <1> DR_TYPE_E       equ $                   ; END OF TABLE
 29888                              <1> ;DR_CNT		EQU	(DR_TYPE_E-DR_TYPE)/3
 29889                              <1> DR_CNT		equ	(DR_TYPE_E-DR_TYPE)/5
 29890                              <1> ;--------------------------------------------------------
 29891                              <1> ;	MEDIA/DRIVE PARAMETER TABLES			:
 29892                              <1> ;--------------------------------------------------------
 29893                              <1> ;--------------------------------------------------------
 29894                              <1> ;	360 KB MEDIA IN 360 KB DRIVE			:
 29895                              <1> ;--------------------------------------------------------
 29896                              <1> MD_TBL1:        
 29897 00009CBA DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 29898 00009CBB 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 29899 00009CBC 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 29900 00009CBD 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 29901 00009CBE 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 29902 00009CBF 2A                  <1> 	DB	02AH		; GAP LENGTH
 29903 00009CC0 FF                  <1> 	DB	0FFH		; DTL
 29904 00009CC1 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 29905 00009CC2 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 29906 00009CC3 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 29907 00009CC4 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 29908 00009CC5 27                  <1> 	DB	39		; MAX. TRACK NUMBER
 29909 00009CC6 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 29910                              <1> ;--------------------------------------------------------
 29911                              <1> ;	360 KB MEDIA IN 1.2 MB DRIVE			:
 29912                              <1> ;--------------------------------------------------------
 29913                              <1> MD_TBL2:        
 29914 00009CC7 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 29915 00009CC8 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 29916 00009CC9 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 29917 00009CCA 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 29918 00009CCB 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 29919 00009CCC 2A                  <1> 	DB	02AH		; GAP LENGTH
 29920 00009CCD FF                  <1> 	DB	0FFH		; DTL
 29921 00009CCE 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 29922 00009CCF F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 29923 00009CD0 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 29924 00009CD1 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 29925 00009CD2 27                  <1> 	DB	39		; MAX. TRACK NUMBER
 29926 00009CD3 40                  <1> 	DB	RATE_300	; DATA TRANSFER RATE
 29927                              <1> ;--------------------------------------------------------
 29928                              <1> ;	1.2 MB MEDIA IN 1.2 MB DRIVE			:
 29929                              <1> ;--------------------------------------------------------
 29930                              <1> MD_TBL3:
 29931 00009CD4 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 29932 00009CD5 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 29933 00009CD6 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 29934 00009CD7 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 29935 00009CD8 0F                  <1> 	DB	15		; EOT (LAST SECTOR ON TRACK)
 29936 00009CD9 1B                  <1> 	DB	01BH		; GAP LENGTH
 29937 00009CDA FF                  <1> 	DB	0FFH		; DTL
 29938 00009CDB 54                  <1> 	DB	054H		; GAP LENGTH FOR FORMAT
 29939 00009CDC F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 29940 00009CDD 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 29941 00009CDE 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 29942 00009CDF 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 29943 00009CE0 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
 29944                              <1> ;--------------------------------------------------------
 29945                              <1> ;	720 KB MEDIA IN 720 KB DRIVE			:
 29946                              <1> ;--------------------------------------------------------
 29947                              <1> MD_TBL4:
 29948 00009CE1 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 29949 00009CE2 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 29950 00009CE3 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 29951 00009CE4 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 29952 00009CE5 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 29953 00009CE6 2A                  <1> 	DB	02AH		; GAP LENGTH
 29954 00009CE7 FF                  <1> 	DB	0FFH		; DTL
 29955 00009CE8 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 29956 00009CE9 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 29957 00009CEA 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 29958 00009CEB 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 29959 00009CEC 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 29960 00009CED 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 29961                              <1> ;--------------------------------------------------------
 29962                              <1> ;	720 KB MEDIA IN 1.44 MB DRIVE			:
 29963                              <1> ;--------------------------------------------------------
 29964                              <1> MD_TBL5:
 29965 00009CEE DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
 29966 00009CEF 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 29967 00009CF0 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 29968 00009CF1 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 29969 00009CF2 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
 29970 00009CF3 2A                  <1> 	DB	02AH		; GAP LENGTH
 29971 00009CF4 FF                  <1> 	DB	0FFH		; DTL
 29972 00009CF5 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
 29973 00009CF6 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 29974 00009CF7 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 29975 00009CF8 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 29976 00009CF9 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 29977 00009CFA 80                  <1> 	DB	RATE_250	; DATA TRANSFER RATE
 29978                              <1> ;--------------------------------------------------------
 29979                              <1> ;	1.44 MB MEDIA IN 1.44 MB DRIVE			:
 29980                              <1> ;--------------------------------------------------------
 29981                              <1> MD_TBL6:
 29982 00009CFB AF                  <1> 	DB	10101111B	; SRT=A, HD UNLOAD=0F - 1ST SPECIFY BYTE
 29983 00009CFC 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
 29984 00009CFD 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
 29985 00009CFE 02                  <1> 	DB	2		; 512 BYTES/SECTOR
 29986 00009CFF 12                  <1> 	DB	18		; EOT (LAST SECTOR ON TRACK)
 29987 00009D00 1B                  <1> 	DB	01BH		; GAP LENGTH
 29988 00009D01 FF                  <1> 	DB	0FFH		; DTL
 29989 00009D02 6C                  <1> 	DB	06CH		; GAP LENGTH FOR FORMAT
 29990 00009D03 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
 29991 00009D04 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
 29992 00009D05 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
 29993 00009D06 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
 29994 00009D07 00                  <1> 	DB	RATE_500	; DATA TRANSFER RATE
 29995                              <1> 
 29996                              <1> 
 29997                              <1> ; << diskette.inc >>
 29998                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 29999                              <1> ;
 30000                              <1> ;----------------------------------------
 30001                              <1> ;	ROM BIOS DATA AREAS		:
 30002                              <1> ;----------------------------------------
 30003                              <1> 
 30004                              <1> ;DATA		SEGMENT AT 40H		; ADDRESS= 0040:0000
 30005                              <1> 
 30006                              <1> ;----------------------------------------
 30007                              <1> ;	FIXED DISK DATA AREAS		:
 30008                              <1> ;----------------------------------------
 30009                              <1> 
 30010                              <1> ;DISK_STATUS1:	DB	0		; FIXED DISK STATUS
 30011                              <1> ;HF_NUM:		DB	0		; COUNT OF FIXED DISK DRIVES
 30012                              <1> ;CONTROL_BYTE:	DB	0		; HEAD CONTROL BYTE
 30013                              <1> ;@PORT_OFF	DB	?		;  RESERVED (PORT OFFSET)
 30014                              <1> 
 30015                              <1> ;----------------------------------------
 30016                              <1> ;	ADDITIONAL MEDIA DATA		:
 30017                              <1> ;----------------------------------------
 30018                              <1> 
 30019                              <1> ;@LASTRATE	DB	?		; LAST DISKETTE DATA RATE SELECTED
 30020                              <1> ;HF_STATUS	DB	0		; STATUS REGISTER
 30021                              <1> ;HF_ERROR	DB	0		; ERROR REGISTER
 30022                              <1> ;HF_INT_FLAG	DB	0		; FIXED DISK INTERRUPT FLAG
 30023                              <1> ;HF_CNTRL	DB	0		; COMBO FIXED DISK/DISKETTE CARD BIT 0=1
 30024                              <1> ;@DSK_STATE	DB	?		; DRIVE 0 MEDIA STATE
 30025                              <1> ;		DB	?		; DRIVE 1 MEDIA STATE
 30026                              <1> ;		DB	?		; DRIVE 0 OPERATION START STATE
 30027                              <1> ;		DB	?		; DRIVE 1 OPERATION START STATE
 30028                              <1> ;@DSK_TRK	DB	?		; DRIVE 0 PRESENT CYLINDER
 30029                              <1> ;		DB	?		; DRIVE 1 PRESENT CYLINDER
 30030                              <1> 
 30031                              <1> ;DATA		ENDS			; END OF BIOS DATA SEGMENT
 30032                              <1> ;
 30033                              <1> ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 30034                              <1> 
 30035                              <1> ERR_TBL:
 30036 00009D08 E0                  <1> 	db	NO_ERR
 30037 00009D09 024001BB            <1> 	db	BAD_ADDR_MARK,BAD_SEEK,BAD_CMD,UNDEF_ERR
 30038 00009D0D 04BB100A            <1> 	db	RECORD_NOT_FND,UNDEF_ERR,BAD_ECC,BAD_SECTOR
 30039                              <1> 
 30040                              <1> ; 17/12/2014 (mov ax, [cfd])
 30041                              <1> ; 11/12/2014
 30042 00009D11 00                  <1> cfd:		db 0			; current floppy drive (for GET_PARM)
 30043                              <1> ; 17/12/2014				; instead of 'DISK_POINTER'
 30044 00009D12 01                  <1> pfd:		db 1			; previous floppy drive (for GET_PARM)
 30045                              <1> 					; (initial value of 'pfd 
 30046                              <1> 					; must be different then 'cfd' value
 30047                              <1> 					; to force updating/initializing
 30048                              <1> 					; current drive parameters) 
 30049 00009D13 90                  <1> align 2
 30050                              <1> 
 30051 00009D14 F001                <1> HF_PORT:	dw 	1F0h  ; Default = 1F0h
 30052                              <1> 			      ; (170h)
 30053 00009D16 F603                <1> HF_REG_PORT:	dw	3F6h  ; HF_PORT + 206h
 30054                              <1> 
 30055                              <1> ; 05/01/2015 
 30056 00009D18 00                  <1> hf_m_s:         db      0     ; (0 = Master, 1 = Slave)
 30057                              <1> 
 30058                              <1> ; *****************************************************************************
 30059                                  ;;;
 30060                                  
 30061 00009D19 90                      Align 2
 30062                                  
 30063                                  ; 12/11/2014 (Retro UNIX 386 v1)
 30064 00009D1A 00                      boot_drv:    db 0 ; boot drive number (physical)
 30065                                  ; 24/11/2014
 30066 00009D1B 00                      drv:	     db 0 
 30067 00009D1C 00                      last_drv:    db 0 ; last hdd
 30068 00009D1D 00                      hdc:         db 0  ; number of hard disk drives
 30069                                  		     ; (present/detected)
 30070                                  ;
 30071                                  ; 24/11/2014 (Retro UNIX 386 v1)
 30072                                  ; Physical drive type & flags
 30073 00009D1E 00                      fd0_type:    db 0  ; floppy drive type
 30074 00009D1F 00                      fd1_type:    db 0  ; 4 = 1.44 Mb, 80 track, 3.5" (18 spt)
 30075                                  		     ; 6 = 2.88 Mb, 80 track, 3.5" (36 spt)
 30076                                  		     ; 3 = 720 Kb, 80 track, 3.5" (9 spt)
 30077                                  		     ; 2 = 1.2 Mb, 80 track, 5.25" (15 spt)
 30078                                  		     ; 1 = 360 Kb, 40 track, 5.25" (9 spt)		
 30079 00009D20 00                      hd0_type:    db 0  ; EDD status for hd0 (bit 7 = present flag)
 30080 00009D21 00                      hd1_type:    db 0  ; EDD status for hd1 (bit 7 = present flag)
 30081 00009D22 00                      hd2_type:    db 0  ; EDD status for hd2 (bit 7 = present flag)
 30082 00009D23 00                      hd3_type:    db 0  ; EDD status for hd3 (bit 7 = present flag)
 30083                                  		     ; bit 0 - Fixed disk access subset supported
 30084                                  		     ; bit 1 - Drive locking and ejecting
 30085                                  		     ; bit 2 - Enhanced disk drive support
 30086                                  		     ; bit 3 = Reserved (64 bit EDD support)
 30087                                  		     ; (If bit 0 is '1' Retro UNIX 386 v1
 30088                                  		     ; will interpret it as 'LBA ready'!)		
 30089                                  
 30090                                  ; 11/03/2015 - 10/07/2015
 30091 00009D24 000000000000000000-     drv.cylinders: dw 0,0,0,0,0,0,0
 30092 00009D2D 0000000000         
 30093 00009D32 000000000000000000-     drv.heads:     dw 0,0,0,0,0,0,0
 30094 00009D3B 0000000000         
 30095 00009D40 000000000000000000-     drv.spt:       dw 0,0,0,0,0,0,0
 30096 00009D49 0000000000         
 30097 00009D4E 000000000000000000-     drv.size:      dd 0,0,0,0,0,0,0
 30098 00009D57 000000000000000000-
 30099 00009D60 000000000000000000-
 30100 00009D69 00                 
 30101 00009D6A 00000000000000          drv.status:    db 0,0,0,0,0,0,0
 30102 00009D71 00000000000000          drv.error:     db 0,0,0,0,0,0,0		
 30103                                  ;
 30104                                  
 30105                                  ; 27/08/2014
 30106                                  scr_row:
 30107 00009D78 E0810B00                	dd 0B8000h + 0A0h + 0A0h + 0A0h ; Row 3
 30108                                  scr_col:
 30109 00009D7C 00000000                	dd 0
 30110                                  
 30111                                  ; 20/08/2014
 30112                                    ; /* This is the default interrupt "handler" :-) */ 
 30113                                    ; Linux v0.12 (head.s)
 30114                                  int_msg:
 30115 00009D80 556E6B6E6F776E2069-     	db "Unknown interrupt ! ", 0
 30116 00009D89 6E7465727275707420-
 30117 00009D92 212000             
 30118                                  
 30119                                  
 30120                                  ; 21/08/2014
 30121                                  timer_msg:
 30122 00009D95 49525120302028494E-     	db "IRQ 0 (INT 20h) ! Timer Interrupt : "
 30123 00009D9E 542032306829202120-
 30124 00009DA7 54696D657220496E74-
 30125 00009DB0 657272757074203A20 
 30126                                  tcountstr:
 30127 00009DB9 303030303020            	db "00000 "
 30128 00009DBF 00                      	db 0
 30129                                  
 30130                                  Align 2
 30131                                  	; 21/08/2014
 30132                                  exc_msg:
 30133 00009DC0 435055206578636570-     	db "CPU exception ! "
 30134 00009DC9 74696F6E202120     
 30135                                  excnstr: 		; 25/08/2014
 30136 00009DD0 3F3F68202045495020-     	db "??h", "  EIP : "
 30137 00009DD9 3A20               
 30138                                  EIPstr: ; 29/08/2014
 30139 00009DDB 00<rept>                	times 12 db 0
 30140                                  rtc_msg:
 30141 00009DE7 5265616C2054696D65-     	db "Real Time Clock - "
 30142 00009DF0 20436C6F636B202D20 
 30143                                  datestr:
 30144 00009DF9 30302F30302F303030-     	db "00/00/0000"
 30145 00009E02 30                 
 30146 00009E03 20                      	db " "
 30147                                  daystr:
 30148 00009E04 44415920                	db "DAY "
 30149                                  timestr:	
 30150 00009E08 30303A30303A3030                db "00:00:00"
 30151 00009E10 20                      	db " "
 30152 00009E11 00                      	db 0 
 30153                                  
 30154                                  daytmp:
 30155                                  	; 28/02/2015
 30156 00009E12 3F3F3F2053554E204D-     	db "??? SUN MON TUE WED THU FRI SAT "
 30157 00009E1B 4F4E20545545205745-
 30158 00009E24 442054485520465249-
 30159 00009E2D 2053415420         
 30160                                  
 30161 00009E32 FF                      ptime_seconds: db 0FFh
 30162                                  
 30163                                  	; 23/02/2015
 30164                                  	; 25/08/2014
 30165                                  ;scounter:
 30166                                  ;	db 5
 30167                                  ;	db 19
 30168                                  
 30169                                  ; 05/11/2014
 30170                                  msg_out_of_memory:
 30171 00009E33 070D0A                  	db 	07h, 0Dh, 0Ah
 30172 00009E36 496E73756666696369-             db      'Insufficient memory ! (Minimum 2 MB memory is needed.)'
 30173 00009E3F 656E74206D656D6F72-
 30174 00009E48 79202120284D696E69-
 30175 00009E51 6D756D2032204D4220-
 30176 00009E5A 6D656D6F7279206973-
 30177 00009E63 206E65656465642E29 
 30178 00009E6C 0D0A00                   	db	0Dh, 0Ah, 0
 30179                                  	;
 30180                                  setup_error_msg:
 30181 00009E6F 0D0A                    	db 0Dh, 0Ah
 30182 00009E71 4469736B2053657475-     	db 'Disk Setup Error!' 
 30183 00009E7A 70204572726F7221   
 30184 00009E82 0D0A00                  	db 0Dh, 0Ah,0
 30185                                  
 30186                                  ; 06/11/2014
 30187                                  ; Memory Information message
 30188                                  ; 14/08/2015
 30189                                  msg_memory_info:
 30190 00009E85 07                      	db	07h
 30191 00009E86 0D0A                    	db	0Dh, 0Ah
 30192                                  	;db 	"MEMORY ALLOCATION INFO", 0Dh, 0Ah, 0Dh, 0Ah
 30193 00009E88 546F74616C206D656D-     	db	"Total memory : "
 30194 00009E91 6F7279203A20       
 30195                                  mem_total_b_str: ; 10 digits
 30196 00009E97 303030303030303030-     	db	"0000000000 bytes", 0Dh, 0Ah
 30197 00009EA0 302062797465730D0A 
 30198 00009EA9 202020202020202020-     	db	"               ", 20h, 20h, 20h
 30199 00009EB2 202020202020202020 
 30200                                  mem_total_p_str: ; 7 digits
 30201 00009EBB 303030303030302070-     	db	"0000000 pages", 0Dh, 0Ah
 30202 00009EC4 616765730D0A       
 30203 00009ECA 0D0A                    	db 	0Dh, 0Ah
 30204 00009ECC 46726565206D656D6F-     	db	"Free memory  : "
 30205 00009ED5 727920203A20       
 30206                                  free_mem_b_str:  ; 10 digits
 30207 00009EDB 3F3F3F3F3F3F3F3F3F-     	db	"?????????? bytes", 0Dh, 0Ah
 30208 00009EE4 3F2062797465730D0A 
 30209 00009EED 202020202020202020-     	db	"               ", 20h, 20h, 20h
 30210 00009EF6 202020202020202020 
 30211                                  free_mem_p_str:  ; 7 digits
 30212 00009EFF 3F3F3F3F3F3F3F2070-     	db	"??????? pages", 0Dh, 0Ah
 30213 00009F08 616765730D0A       
 30214 00009F0E 0D0A00                  	db	0Dh, 0Ah, 0
 30215                                  
 30216                                  dsk_ready_msg:
 30217 00009F11 0D0A                    	db 	0Dh, 0Ah
 30218                                  dsktype:
 30219 00009F13 6664                    	db	'fd'
 30220                                  dskx:
 30221 00009F15 30                      	db	'0'
 30222 00009F16 20                      	db	20h
 30223 00009F17 697320524541445920-     	db 	'is READY ...'
 30224 00009F20 2E2E2E             
 30225 00009F23 00                      	db 	0
 30226                                  
 30227                                  next2line: ; 08/02/2016
 30228 00009F24 0D0A                    	db	0Dh, 0Ah
 30229                                  nextline:
 30230 00009F26 0D0A00                  	db 	0Dh, 0Ah, 0
 30231                                  
 30232                                  ; KERNEL - SYSINIT Messages
 30233                                  ; 24/08/2015
 30234                                  ; 13/04/2015 - (Retro UNIX 386 v1 Beginning)
 30235                                  ; 14/07/2013
 30236                                  ;kernel_init_err_msg:
 30237                                  ;	db 0Dh, 0Ah
 30238                                  ;	db 07h
 30239                                  ;	db 'Kernel initialization ERROR !'
 30240                                  ;	db 0Dh, 0Ah, 0 
 30241                                  
 30242                                  ;welcome_msg: 
 30243                                  ;	db 0Dh, 0Ah
 30244                                  ;	db 07h
 30245                                  ;	db 'Welcome to TRDOS 386 Operating System !'
 30246                                  ;	db 0Dh, 0Ah
 30247                                  ;	db 'by Erdogan Tan - 29/02/2016 (v2.0.0)'
 30248                                  ;	db 0Dh, 0Ah, 0
 30249                                  
 30250                                  panic_msg:
 30251 00009F29 0D0A07                  	db 0Dh, 0Ah, 07h
 30252 00009F2C 4552524F523A204B65-     	db 'ERROR: Kernel Panic !'
 30253 00009F35 726E656C2050616E69-
 30254 00009F3E 632021             
 30255 00009F41 0D0A00                  	db 0Dh, 0Ah, 0
 30256                                  
 30257                                  ; 10/05/2015
 30258                                  badsys_msg:
 30259 00009F44 0D0A                    	db 0Dh, 0Ah
 30260 00009F46 07                      	db 07h
 30261 00009F47 496E76616C69642053-     	db 'Invalid System Call !'
 30262 00009F50 797374656D2043616C-
 30263 00009F59 6C2021             
 30264 00009F5C 0D0A                    	db 0Dh, 0Ah
 30265 00009F5E 4541583A20              	db 'EAX: '
 30266                                  bsys_msg_eax:
 30267 00009F63 303030303030303068      	db '00000000h'
 30268 00009F6C 0D0A                    	db 0Dh, 0Ah
 30269 00009F6E 4549503A20              	db 'EIP: '
 30270                                  bsys_msg_eip:
 30271 00009F73 303030303030303068      	db '00000000h' 
 30272 00009F7C 0D0A00                  	db 0Dh, 0Ah, 0
 30273                                  
 30274                                  BSYS_M_SIZE equ $ - badsys_msg
 30275                                  
 30276                                  
 30277 00009F7F 90                      align 2
 30278                                  
 30279                                  ; EPOCH Variables
 30280                                  ; 13/04/2015 - Retro UNIX 386 v1 Beginning
 30281                                  ; 09/04/2013 epoch variables
 30282                                  ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013
 30283                                  ;
 30284 00009F80 B207                    year: 	dw 1970
 30285 00009F82 0100                    month: 	dw 1
 30286 00009F84 0100                    day: 	dw 1
 30287 00009F86 0000                    hour: 	dw 0
 30288 00009F88 0000                    minute: dw 0
 30289 00009F8A 0000                    second: dw 0
 30290                                  
 30291                                  DMonth:
 30292 00009F8C 0000                    	dw 0
 30293 00009F8E 1F00                    	dw 31
 30294 00009F90 3B00                    	dw 59
 30295 00009F92 5A00                    	dw 90
 30296 00009F94 7800                    	dw 120
 30297 00009F96 9700                    	dw 151
 30298 00009F98 B500                    	dw 181
 30299 00009F9A D400                    	dw 212
 30300 00009F9C F300                    	dw 243
 30301 00009F9E 1101                    	dw 273
 30302 00009FA0 3001                    	dw 304
 30303 00009FA2 4E01                    	dw 334
 30304                                  
 30305                                  ; 04/11/2014 (Retro UNIX 386 v1)
 30306 00009FA4 0000                    mem_1m_1k:   dw 0  ; Number of contiguous KB between
 30307                                                       ; 1 and 16 MB, max. 3C00h = 15 MB.
 30308 00009FA6 0000                    mem_16m_64k: dw 0  ; Number of contiguous 64 KB blocks
 30309                                  		   ;   between 16 MB and 4 GB.
 30310                                  
 30311                                  starting_msg:
 30312 00009FA8 5475726B6973682052-     	db "Turkish Rational DOS v2.0 [29/02/2016] ...", 0
 30313 00009FB1 6174696F6E616C2044-
 30314 00009FBA 4F532076322E30205B-
 30315 00009FC3 32392F30322F323031-
 30316 00009FCC 365D202E2E2E00     
 30317                                  NextLine:
 30318 00009FD3 0D0A00                  	db 0Dh, 0Ah, 0
 30319                                  
 30320                                  ;msgl_drv_not_ready: 
 30321                                  ;	db 07h, 0Dh, 0Ah
 30322                                  ;       db 'Drive not ready or read error !'
 30323                                  ;       db 0Dh, 0Ah, 0
 30324                                  
 30325 00009FD6 90<rept>                align 16
 30326                                  
 30327                                  bss_start:
 30328                                  
 30329                                  ABSOLUTE bss_start
 30330                                  
 30331                                  	; 11/03/2015
 30332                                  	; Interrupt Descriptor Table (20/08/2014)
 30333                                  idt:
 30334 00009FE0 <res 00000200>          	resb	64*8 ; INT 0 to INT 3Fh
 30335                                  idt_end:
 30336                                  
 30337                                  ;alignb 4
 30338                                  
 30339                                  task_state_segment:
 30340                                  	; 24/03/2015
 30341 0000A1E0 <res 00000002>          tss.link:   resw 1
 30342 0000A1E2 <res 00000002>          	    resw 1
 30343                                  ; tss offset 4	
 30344 0000A1E4 <res 00000004>          tss.esp0:   resd 1
 30345 0000A1E8 <res 00000002>          tss.ss0:    resw 1
 30346 0000A1EA <res 00000002>          	    resw 1	
 30347 0000A1EC <res 00000004>          tss.esp1:   resd 1
 30348 0000A1F0 <res 00000002>          tss.ss1:    resw 1
 30349 0000A1F2 <res 00000002>          	    resw 1 	
 30350 0000A1F4 <res 00000004>          tss.esp2:   resd 1
 30351 0000A1F8 <res 00000002>          tss.ss2:    resw 1
 30352 0000A1FA <res 00000002>          	    resw 1
 30353                                  ; tss offset 28
 30354 0000A1FC <res 00000004>          tss.CR3:    resd 1
 30355 0000A200 <res 00000004>          tss.eip:    resd 1
 30356 0000A204 <res 00000004>          tss.eflags: resd 1
 30357                                  ; tss offset 40
 30358 0000A208 <res 00000004>          tss.eax:    resd 1		 		
 30359 0000A20C <res 00000004>          tss.ecx:    resd 1
 30360 0000A210 <res 00000004>          tss.edx:    resd 1
 30361 0000A214 <res 00000004>          tss.ebx:    resd 1
 30362 0000A218 <res 00000004>          tss.esp:    resd 1
 30363 0000A21C <res 00000004>          tss.ebp:    resd 1
 30364 0000A220 <res 00000004>          tss.esi:    resd 1
 30365 0000A224 <res 00000004>          tss.edi:    resd 1
 30366                                  ; tss offset 72
 30367 0000A228 <res 00000002>          tss.ES:     resw 1
 30368 0000A22A <res 00000002>          	    resw 1	
 30369 0000A22C <res 00000002>          tss.CS:	    resw 1
 30370 0000A22E <res 00000002>          	    resw 1
 30371 0000A230 <res 00000002>          tss.SS:	    resw 1
 30372 0000A232 <res 00000002>          	    resw 1
 30373 0000A234 <res 00000002>          tss.DS:	    resw 1
 30374 0000A236 <res 00000002>          	    resw 1
 30375 0000A238 <res 00000002>          tss.FS:	    resw 1
 30376 0000A23A <res 00000002>          	    resw 1
 30377 0000A23C <res 00000002>          tss.GS:	    resw 1
 30378 0000A23E <res 00000002>          	    resw 1		
 30379 0000A240 <res 00000002>          tss.LDTR:   resw 1
 30380 0000A242 <res 00000002>          	    resw 1
 30381                                  ; tss offset 100		
 30382 0000A244 <res 00000002>          	    resw 1		
 30383 0000A246 <res 00000002>          tss.IOPB:   resw 1
 30384                                  ; tss offset 104 
 30385                                  tss_end:
 30386                                  
 30387 0000A248 <res 00000004>          k_page_dir:  resd 1 ; Kernel's (System) Page Directory address
 30388                                  		    ; (Physical address = Virtual address)	 	
 30389 0000A24C <res 00000004>          memory_size: resd 1 ; memory size in pages
 30390 0000A250 <res 00000004>          free_pages:  resd 1 ; number of free pages		
 30391 0000A254 <res 00000004>          next_page:   resd 1 ; offset value in M.A.T. for
 30392                                  		    ; first free page search
 30393 0000A258 <res 00000004>          last_page:   resd 1 ; offset value in M.A.T. which
 30394                                  		    ; next free page search will be
 30395                                  		    ; stopped after it. (end of M.A.T.)
 30396 0000A25C <res 00000004>          first_page:  resd 1 ; offset value in M.A.T. which
 30397                                  		    ; first free page search
 30398                                  		    ; will be started on it. (for user)
 30399 0000A260 <res 00000004>          mat_size:    resd 1 ; Memory Allocation Table size in pages		
 30400                                  
 30401                                  ; 02/09/2014 (Retro UNIX 386 v1)
 30402                                  ; 04/12/2013 (Retro UNIX 8086 v1)
 30403 0000A264 <res 00000002>          CRT_START:   resw 1 	  ; starting address in regen buffer
 30404                                  			  ; NOTE: active page only	
 30405 0000A266 <res 00000002>          CURSOR_MODE: resw 1 ; 24/01/2016
 30406 0000A268 <res 00000010>          CURSOR_POSN: resw 8 ; cursor positions for video pages
 30407                                  ACTIVE_PAGE: 
 30408 0000A278 <res 00000001>          ptty: 	     resb 1 ; current tty
 30409                                  ; 01/07/2015 - 29/01/2016
 30410 0000A279 <res 00000001>          ccolor:	     resb 1 ; current color attribute
 30411                                  ; 26/10/2015
 30412                                  ; 07/09/2014
 30413 0000A27A <res 00000014>          ttychr:      resw ntty+2 ; Character buffer (multiscreen)
 30414                                  
 30415                                  ; 21/08/2014
 30416 0000A28E <res 00000004>          tcount:	     resd 1
 30417                                  
 30418                                  ; 18/05/2015 (03/06/2013 - Retro UNIX 8086 v1 feature only!)
 30419 0000A292 <res 00000004>          p_time:      resd 1     ; present time (for systime & sysmdate)
 30420                                  
 30421                                  ; 18/05/2015 (16/08/2013 - Retro UNIX 8086 v1 feature only !)
 30422                                  ; (open mode locks for pseudo TTYs)
 30423                                  ; [ major tty locks (return error in any conflicts) ]
 30424 0000A296 <res 00000014>          ttyl:        resw ntty+2 ; opening locks for TTYs.
 30425                                  
 30426                                  ; 15/04/2015 (Retro UNIX 386 v1)
 30427                                  ; 22/09/2013 (Retro UNIX 8086 v1)
 30428 0000A2AA <res 0000000A>          wlist:       resb ntty+2 ; wait channel list (0 to 9 for TTYs)
 30429                                  ; 15/04/2015 (Retro UNIX 386 v1)
 30430                                  ;; 12/07/2014 -> sp_init set comm. parameters as 0E3h
 30431                                  ;; 0 means serial port is not available 
 30432                                  ;;comprm: ; 25/06/2014
 30433 0000A2B4 <res 00000001>          com1p:       resb 1  ;;0E3h
 30434 0000A2B5 <res 00000001>          com2p:       resb 1  ;;0E3h
 30435                                  
 30436                                  ; 17/11/2015
 30437                                  ; request for response (from the terminal)	
 30438 0000A2B6 <res 00000002>          req_resp:    resw 1 			
 30439                                  ; 07/11/2015
 30440 0000A2B8 <res 00000001>          ccomport:    resb 1 ; current COM (serial) port
 30441                                  		    ; (0= COM1, 1= COM2)
 30442                                  ; 09/11/2015
 30443 0000A2B9 <res 00000001>          comqr:	     resb 1 ; 'query or response' sign (u9.s, 'sndc')
 30444                                  ; 07/11/2015
 30445 0000A2BA <res 00000002>          rchar:	     resw 1 ; last received char for COM 1 and COM 2		
 30446 0000A2BC <res 00000002>          schar:	     resw 1 ; last sent char for COM 1 and COM 2
 30447                                  
 30448                                  ; 22/08/2014 (RTC)
 30449                                  ; (Packed BCD)
 30450 0000A2BE <res 00000001>          time_seconds: resb 1
 30451 0000A2BF <res 00000001>          time_minutes: resb 1
 30452 0000A2C0 <res 00000001>          time_hours:   resb 1
 30453 0000A2C1 <res 00000001>          date_wday:    resb 1
 30454 0000A2C2 <res 00000001>          date_day:     resb 1
 30455 0000A2C3 <res 00000001>          date_month:   resb 1			
 30456 0000A2C4 <res 00000001>          date_year:    resb 1
 30457 0000A2C5 <res 00000001>          date_century: resb 1
 30458                                  
 30459                                  ; 24/01/2016
 30460 0000A2C6 <res 00000004>          RTC_LH:	       resd 1
 30461 0000A2CA <res 00000001>          RTC_WAIT_FLAG: resb 1
 30462 0000A2CB <res 00000001>          USER_FLAG:     resb 1
 30463                                  
 30464                                  
 30465                                  %include 'diskbss.s'	; UNINITIALIZED DISK (BIOS) DATA
 30466                              <1> ; ****************************************************************************
 30467                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - diskbss.s
 30468                              <1> ; ----------------------------------------------------------------------------
 30469                              <1> ; Last Update: 24/01/2016
 30470                              <1> ; ----------------------------------------------------------------------------
 30471                              <1> ; Beginning: 24/01/2016
 30472                              <1> ; ----------------------------------------------------------------------------
 30473                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 30474                              <1> ; ----------------------------------------------------------------------------
 30475                              <1> ; Turkish Rational DOS
 30476                              <1> ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
 30477                              <1> ;
 30478                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 30479                              <1> ; diskbss.inc (10/07/2015)
 30480                              <1> ;
 30481                              <1> ; Derived from 'IBM PC-XT-286' BIOS source code (1986) 
 30482                              <1> ; ****************************************************************************
 30483                              <1> 
 30484                              <1> ; Retro UNIX 386 v1 Kernel - DISKBSS.INC
 30485                              <1> ; Last Modification: 10/07/2015
 30486                              <1> ;	(Unnitialized Disk Parameters Data section for 'DISKIO.INC') 
 30487                              <1> 
 30488                              <1> alignb 2
 30489                              <1> 
 30490                              <1> ;----------------------------------------
 30491                              <1> ;	TIMER DATA AREA 		:
 30492                              <1> ;----------------------------------------
 30493                              <1> 
 30494                              <1> TIMER_LH:	; 16/02/205
 30495 0000A2CC <res 00000002>      <1> TIMER_LOW:      resw	1               ; LOW WORD OF TIMER COUNT
 30496 0000A2CE <res 00000002>      <1> TIMER_HIGH:     resw	1               ; HIGH WORD OF TIMER COUNT
 30497 0000A2D0 <res 00000001>      <1> TIMER_OFL:      resb 	1               ; TIMER HAS ROLLED OVER SINCE LAST READ
 30498                              <1> 
 30499                              <1> ;----------------------------------------
 30500                              <1> ;	DISKETTE DATA AREAS		:
 30501                              <1> ;----------------------------------------
 30502                              <1> 
 30503 0000A2D1 <res 00000001>      <1> SEEK_STATUS:	resb	1
 30504 0000A2D2 <res 00000001>      <1> MOTOR_STATUS:	resb	1
 30505 0000A2D3 <res 00000001>      <1> MOTOR_COUNT:	resb	1
 30506 0000A2D4 <res 00000001>      <1> DSKETTE_STATUS:	resb	1
 30507 0000A2D5 <res 00000007>      <1> NEC_STATUS:	resb	7
 30508                              <1> 
 30509                              <1> ;----------------------------------------
 30510                              <1> ;	ADDITIONAL MEDIA DATA		:
 30511                              <1> ;----------------------------------------
 30512                              <1> 
 30513 0000A2DC <res 00000001>      <1> LASTRATE:	resb 	1
 30514 0000A2DD <res 00000001>      <1> HF_STATUS:	resb 	1
 30515 0000A2DE <res 00000001>      <1> HF_ERROR:	resb 	1
 30516 0000A2DF <res 00000001>      <1> HF_INT_FLAG:	resb 	1
 30517 0000A2E0 <res 00000001>      <1> HF_CNTRL:	resb 	1
 30518 0000A2E1 <res 00000004>      <1> DSK_STATE:	resb 	4
 30519 0000A2E5 <res 00000002>      <1> DSK_TRK:	resb 	2
 30520                              <1> 
 30521                              <1> ;----------------------------------------
 30522                              <1> ;	FIXED DISK DATA AREAS		:
 30523                              <1> ;----------------------------------------
 30524                              <1> 
 30525 0000A2E7 <res 00000001>      <1> DISK_STATUS1:	resb 	1		; FIXED DISK STATUS
 30526 0000A2E8 <res 00000001>      <1> HF_NUM:		resb 	1		; COUNT OF FIXED DISK DRIVES
 30527 0000A2E9 <res 00000001>      <1> CONTROL_BYTE:	resb 	1		; HEAD CONTROL BYTE
 30528                              <1> ;@PORT_OFF	resb	1		; RESERVED (PORT OFFSET)
 30529                              <1> ;port1_off	resb	1		; Hard disk controller 1 - port offset
 30530                              <1> ;port2_off	resb	1		; Hard idsk controller 2 - port offset
 30531                              <1> 
 30532 0000A2EA <res 00000002>      <1> alignb 4
 30533                              <1> 
 30534                              <1> ;HF_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
 30535                              <1> ;HF1_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
 30536                              <1> HF_TBL_VEC: ; 22/12/2014	
 30537 0000A2EC <res 00000004>      <1> HDPM_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
 30538 0000A2F0 <res 00000004>      <1> HDPS_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
 30539 0000A2F4 <res 00000004>      <1> HDSM_TBL_VEC:	resd	1 		; Secondary master disk param. tbl. pointer
 30540 0000A2F8 <res 00000004>      <1> HDSS_TBL_VEC:	resd	1		; Secondary slave disk param. tbl. pointer
 30541                              <1> 
 30542                              <1> ; 03/01/2015
 30543 0000A2FC <res 00000001>      <1> LBAMode:     	resb	1
 30544                              <1> 
 30545                              <1> ; *****************************************************************************
 30546                                  
 30547                                  ;;; Real Mode Data (10/07/2015 - BSS)
 30548                                  
 30549                                  ;alignb 2
 30550                                  
 30551                                  ; 10/01/2016
 30552                                  %include 'trdoskx.s'	; UNINITIALIZED KERNEL (Logical Drive & FS) DATA
 30553                              <1> ; ****************************************************************************
 30554                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED DATA : trdoskx.s
 30555                              <1> ; ----------------------------------------------------------------------------
 30556                              <1> ; Last Update: 28/02/2016
 30557                              <1> ; ----------------------------------------------------------------------------
 30558                              <1> ; Beginning: 04/01/2016
 30559                              <1> ; ----------------------------------------------------------------------------
 30560                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 30561                              <1> ; ----------------------------------------------------------------------------
 30562                              <1> ; Derived from TRDOS Operating System v1.0 (8086) source code by Erdogan Tan
 30563                              <1> ; TRDOS2.ASM (09/11/2011)
 30564                              <1> ; ****************************************************************************
 30565                              <1> ; DRV_INIT.ASM [26/09/2009] Last Update: 07/08/2011
 30566                              <1> ; MAINPROG.ASM [17/01/2004] Last Update: 09/11/2011
 30567                              <1> ; DIR.ASM      [17/01/2004] Last Update: 09/10/2011
 30568                              <1> ; CMD_INTR.ASM [29/01/2005] Last update: 09/11/2011
 30569                              <1> ; DRV_FAT.ASM  [07/07/2009] Last update: 21/08/2011
 30570                              <1> 
 30571 0000A2FD <res 00000003>      <1> alignb 4
 30572                              <1> 
 30573 0000A300 <res 00000002>      <1> MainProgCfg_FileSize:   resw 1
 30574 0000A302 <res 00000002>      <1> MainProgCfg_LineOffset: resw 1 
 30575                              <1> 
 30576 0000A304 <res 00000004>      <1> Current_VolSerial: resd 1
 30577                              <1> 
 30578 0000A308 <res 00000004>      <1> Current_Dir_FCluster: resd 1
 30579                              <1> 
 30580 0000A30C <res 00000001>      <1> Current_Dir_Level: resb 1
 30581 0000A30D <res 00000001>      <1> Current_FATType: resb 1
 30582 0000A30E <res 00000001>      <1> Current_Drv: resb 1
 30583 0000A30F <res 00000001>      <1> Current_Dir_Drv:   resb 1 ; '?'
 30584 0000A310 <res 00000001>      <1>                    resb 1 ; ':'
 30585 0000A311 <res 00000001>      <1> Current_Dir_Root:  resb 1 ; '/' 
 30586 0000A312 <res 0000005A>      <1> Current_Directory: resb 90
 30587 0000A36C <res 00000001>      <1> End_Of_Current_Dir_Str: resb 1
 30588 0000A36D <res 00000001>      <1> Current_Dir_StrLen: resb 1   
 30589                              <1> 
 30590 0000A36E <res 00000001>      <1> CursorColumn: 	resb 1
 30591 0000A36F <res 00000001>      <1> CmdArgStart:    resb 1
 30592                              <1> 
 30593                              <1> Remark: ; 03/02/2016
 30594 0000A370 <res 0000004E>      <1> 		resb 78
 30595                              <1> 
 30596 0000A3BE <res 00000050>      <1> CommandBuffer: 	resb 80
 30597                              <1> 
 30598 0000A40E <res 00000100>      <1> TextBuffer: resb 256
 30599                              <1> 
 30600                              <1> MasterBootBuff:
 30601 0000A50E <res 000001BE>      <1> MasterBootCode: resb 1BEh
 30602 0000A6CC <res 00000040>      <1> PartitionTable: resb 64
 30603 0000A70C <res 00000002>      <1> MBIDCode: resw 1
 30604                              <1> 
 30605                              <1> PTable_Buffer:
 30606 0000A70E <res 00000040>      <1> PTable_hd0: resb 64
 30607 0000A74E <res 00000040>      <1> PTable_hd1: resb 64
 30608 0000A78E <res 00000040>      <1> PTable_hd2: resb 64
 30609 0000A7CE <res 00000040>      <1> PTable_hd3: resb 64
 30610 0000A80E <res 00000040>      <1> PTable_ep0: resb 64
 30611 0000A84E <res 00000040>      <1> PTable_ep1: resb 64
 30612 0000A88E <res 00000040>      <1> PTable_ep2: resb 64
 30613 0000A8CE <res 00000040>      <1> PTable_ep3: resb 64
 30614                              <1> 
 30615 0000A90E <res 00000001>      <1> HD_LBA_yes: resb 1
 30616 0000A90F <res 00000001>      <1> PP_Counter: resb 1
 30617 0000A910 <res 00000001>      <1> EP_Counter: resb 1
 30618                              <1> 
 30619 0000A911 <res 00000004>      <1> EP_StartSector: resd 1
 30620 0000A915 <res 00000004>      <1>                 resd 1
 30621 0000A919 <res 00000004>      <1>                 resd 1
 30622 0000A91D <res 00000004>      <1>                 resd 1
 30623                              <1> 
 30624 0000A921 <res 00000200>      <1> DOSBootSectorBuff: resb 512
 30625                              <1> 
 30626                              <1> FAT_BuffDescriptor:
 30627 0000AB21 <res 00000004>      <1> FAT_CurrentCluster: resd 1
 30628 0000AB25 <res 00000001>      <1> FAT_BuffValidData: resb 1
 30629 0000AB26 <res 00000001>      <1> FAT_BuffDrvName: resb 1
 30630 0000AB27 <res 00000002>      <1> FAT_BuffOffset: resw 1
 30631 0000AB29 <res 00000004>      <1> FAT_BuffSector: resd 1
 30632                              <1> 
 30633 0000AB2D <res 00000004>      <1> FAT_ClusterCounter: resd 1
 30634 0000AB31 <res 00000004>      <1> LastCluster: resd 1
 30635                              <1> 
 30636 0000AB35 <res 00000001>      <1> resb 1
 30637                              <1> 
 30638                              <1> Dir_BuffDescriptor:
 30639 0000AB36 <res 00000001>      <1> DirBuff_DRV: resb 1
 30640 0000AB37 <res 00000001>      <1> DirBuff_FATType: resb 1
 30641 0000AB38 <res 00000001>      <1> DirBuff_ValidData: resb 1
 30642 0000AB39 <res 00000002>      <1> DirBuff_CurrentEntry: resw 1
 30643 0000AB3B <res 00000002>      <1> DirBuff_LastEntry: resw 1
 30644 0000AB3D <res 00000004>      <1> DirBuff_Cluster: resd 1 
 30645 0000AB41 <res 00000002>      <1> DirBuffer_Size: resw 1
 30646                              <1> ;DirBuff_EntryCounter: resw 1
 30647                              <1> 
 30648                              <1> ; 01/02/2016
 30649                              <1> ; these are on (real mode) segment 8000h and later
 30650                              <1> ; FAT_Buffer:	resb 1536 ; 3 sectors
 30651                              <1> ; Dir_Buffer:	resb 512*32
 30652                              <1> ; Logical_DOSDisks:  resb 6656 ; 26 * 256 bytes
 30653                              <1> 
 30654                              <1> ; 18/01/2016
 30655                              <1> 
 30656 0000AB43 <res 00000004>      <1> FreeClusterCount: resd 1
 30657                              <1> 
 30658 0000AB47 <res 00000004>      <1> VolSize_Unit1:   resd 1
 30659 0000AB4B <res 00000004>      <1> VolSize_Unit2:   resd 1
 30660                              <1> 
 30661 0000AB4F <res 00000004>      <1> Vol_Tot_Sec_Str_Start:	    resd 1
 30662 0000AB53 <res 0000000A>      <1> Vol_Tot_Sec_Str: 	    resb 10
 30663 0000AB5D <res 00000001>      <1> Vol_Tot_Sec_Str_End:	    resb 1
 30664 0000AB5E <res 00000001>      <1> resb 1
 30665 0000AB5F <res 00000004>      <1> Vol_Free_Sectors_Str_Start: resd 1
 30666 0000AB63 <res 0000000A>      <1> Vol_Free_Sectors_Str:	    resb 10				
 30667 0000AB6D <res 00000001>      <1> Vol_Free_Sectors_Str_End:   resb 1
 30668                              <1> 
 30669                              <1> ; 10/02/2016
 30670 0000AB6E <res 00000001>      <1> RUN_CDRV: resb 1 ; CMD_INTR.ASM  ; 09/11/2011
 30671                              <1> 
 30672                              <1> ; 24/01/2016
 30673 0000AB6F <res 00000080>      <1> PATH_Array:     resb 128 ; DIR.ASM ; 09/10/2011
 30674                              <1> ; 06/02/2016
 30675 0000ABEF <res 00000004>      <1> CCD_DriveDT:	resd 1 ; DIR.ASM ; (word)
 30676 0000ABF3 <res 00000001>      <1> CCD_Level:	resb 1 ; DIR.ASM
 30677 0000ABF4 <res 00000001>      <1> Last_Dir_Level:	resb 1 ; DIR.ASM
 30678                              <1> ;
 30679 0000ABF5 <res 00000002>      <1> CDLF_AttributesMask: resw 1 ; DIR.ASM
 30680 0000ABF7 <res 00000004>      <1> CDLF_FNAddress:	resd 1 ; DIR.ASM (word)
 30681 0000ABFB <res 00000002>      <1> CDLF_DEType:	resw 1 ; DIR.ASM
 30682                              <1> ;
 30683 0000ABFD <res 00000001>      <1> CD_COMMAND:	resb 1 ; DIR.ASM
 30684                              <1> 
 30685 0000ABFE <res 00000002>      <1> alignb 4
 30686                              <1> 
 30687                              <1> ; 29/01/2016
 30688 0000AC00 <res 00000001>      <1> Program_Exit:	resb 1 ; CMD_INTR.ASM  ; 09/11/2011
 30689                              <1> 
 30690                              <1> ;alignb 4
 30691                              <1> ; 23/02/2016
 30692 0000AC01 <res 00000001>      <1> disk_rw_op:	resb 1 ;  0 = disk read, 1 = disk write
 30693                              <1> ;disk_rw_spt:	resb 1 ; sectors per track (<= 63) /// (<256)
 30694                              <1> ; 31/01/2016
 30695 0000AC02 <res 00000001>      <1> retry_count: 	resb 1 ; DISK_IO.ASM ; 20/07/2011 (CHS_RetryCount)
 30696 0000AC03 <res 00000001>      <1> disk_rw_err: 	resb 1 ; DISK_IO.ASM ; (Disk_IO_err_code)
 30697 0000AC04 <res 00000004>      <1> sector_count:	resd 1 ; DISK_IO.ASM ; (Disk_RW_SectorCount)
 30698                              <1> 
 30699                              <1> ; 06/02/2016 (long name)
 30700 0000AC08 <res 00000002>      <1> FDE_AttrMask:	   resw 1 ; DIR.ASM
 30701 0000AC0A <res 00000002>      <1> AmbiguousFileName: resw 1 ; DIR.ASM
 30702 0000AC0C <res 00000001>      <1> PreviousAttr:	   resb 1 ; DIR.ASM
 30703                              <1> ;	
 30704 0000AC0D <res 00000001>      <1> LongNameFound:   resb 1	  ; DIR.ASM
 30705 0000AC0E <res 00000001>      <1> LFN_EntryLength: resb 1   ; DIR.ASM
 30706 0000AC0F <res 00000001>      <1> LFN_CheckSum:    resb 1   ; DIR.ASM
 30707 0000AC10 <res 00000084>      <1> LongFileName:    resb 132 ; DIR.ASM
 30708                              <1> 
 30709                              <1> ;PATH_Array_Ptr: resw 1 ; DIR.ASM
 30710 0000AC94 <res 00000001>      <1> PATH_CDLevel:	 resb 1 ; DIR.ASM
 30711 0000AC95 <res 00000001>      <1> PATH_Level:	 resb 1 ; DIR.ASM
 30712                              <1> 
 30713                              <1> ; 07/02/2016
 30714 0000AC96 <res 0000000D>      <1> Dir_File_Name:	resb 13 ; DIR.ASM ; 09/10/2011
 30715                              <1> 
 30716                              <1> ; 10/02/2016
 30717                              <1> Dir_Entry_Name:
 30718 0000ACA3 <res 0000000D>      <1> 		resb 13 ; DIR.ASM
 30719                              <1> 
 30720                              <1> alignb 2
 30721                              <1> 
 30722 0000ACB0 <res 00000002>      <1> AttributesMask: resw 1 ; CMD_INTR.ASM ; 09/11/2011
 30723                              <1> 
 30724                              <1> ; 10/02/2016 (128 bytes -> 126 bytes)
 30725                              <1> ; 08/02/2016
 30726                              <1> ;FFF Structure (128 bytes) ; DIR.ASM ; 09/10/2011
 30727 0000ACB2 <res 00000001>      <1> FindFile_Drv:		  resb 1
 30728 0000ACB3 <res 00000041>      <1> FindFile_Directory:	  resb 65
 30729 0000ACF4 <res 0000000D>      <1> FindFile_Name:		  resb 13
 30730                              <1> FindFile_LongNameEntryLength:
 30731 0000AD01 <res 00000001>      <1> FindFile_LongNameYes: 	  resb 1 ; Sign for longname procedures
 30732                              <1> ;Above 80 bytes form
 30733                              <1> ;TR-DOS Source/Destination File FullName Format/Structure
 30734 0000AD02 <res 00000002>      <1> FindFile_AttributesMask:  resw 1
 30735 0000AD04 <res 00000020>      <1> FindFile_DirEntry:	  resb 32
 30736 0000AD24 <res 00000004>      <1> FindFile_DirFirstCluster: resd 1
 30737 0000AD28 <res 00000004>      <1> FindFile_DirCluster:	  resd 1
 30738 0000AD2C <res 00000002>      <1> FindFile_DirEntryNumber:  resw 1
 30739 0000AD2E <res 00000002>      <1> FindFile_MatchCounter:	  resw 1
 30740                              <1> ;FindFile_Reserved:	  resw 1
 30741                              <1> 
 30742 0000AD30 <res 00000004>      <1> First_Path_Pos: resd 1	; DIR.ASM ; 09/10/2011
 30743 0000AD34 <res 00000004>      <1> Last_Slash_Pos: resd 1	; DIR.ASM 
 30744                              <1> 
 30745                              <1> ; 10/02/2016
 30746 0000AD38 <res 00000002>      <1> File_Count:     resw 1 	; DIR.ASM ; 09/10/2011
 30747 0000AD3A <res 00000002>      <1> Dir_Count:      resw 1
 30748 0000AD3C <res 00000004>      <1> Total_FSize:    resd 1
 30749 0000AD40 <res 00000004>      <1> TFS_Dec_Begin:  resd 1
 30750 0000AD44 <res 0000000A>      <1>                 resb 10
 30751 0000AD4E <res 00000001>      <1> TFS_Dec_End:    resb 1
 30752                              <1> 
 30753 0000AD4F <res 00000001>      <1> PrintDir_RowCounter: resb 1
 30754                              <1> 
 30755                              <1> alignb 4
 30756                              <1> ; 15/02/2015 ('show' command variables)
 30757 0000AD50 <res 00000004>      <1> Show_FDT:	resd 1
 30758 0000AD54 <res 00000004>      <1> Show_LDDDT:	resd 1
 30759 0000AD58 <res 00000004>      <1> Show_Cluster:	resd 1
 30760 0000AD5C <res 00000004>      <1> Show_FileSize:	resd 1
 30761 0000AD60 <res 00000004>      <1> Show_FilePointer: resd 1
 30762 0000AD64 <res 00000002>      <1> Show_ClusterPointer: resw 1
 30763 0000AD66 <res 00000002>      <1> Show_ClusterSize: resw 1
 30764 0000AD68 <res 00000001>      <1> Show_RowCount:	resb 1
 30765                              <1> 
 30766 0000AD69 <res 00000003>      <1> alignb 4
 30767                              <1> ; 21/02/2016
 30768 0000AD6C <res 00000004>      <1> DelFile_FNPointer:	resd 1 ; ; CMD_INTR.ASM (word) ; 09/11/2011
 30769                              <1> ; 27/02/2016
 30770                              <1> ; DIR.ASM (09/10/2011)
 30771 0000AD70 <res 00000004>      <1> DelFile_FCluster:	resd 1
 30772 0000AD74 <res 00000002>      <1> DelFile_EntryCounter:	resw 1
 30773 0000AD76 <res 00000001>      <1> DelFile_LNEL:		resb 1
 30774 0000AD77 <res 00000001>      <1> resb 1
 30775                              <1> 
 30776                              <1> ; DIR.ASM
 30777 0000AD78 <res 00000004>      <1> mkdir_DirName_Offset: 	resd 1
 30778 0000AD7C <res 00000004>      <1> mkdir_FFCluster:	resd 1
 30779 0000AD80 <res 00000004>      <1> mkdir_LastDirCluster:	resd 1
 30780 0000AD84 <res 00000004>      <1> mkdir_FreeSectors:	resd 1
 30781 0000AD88 <res 00000002>      <1> mkdir_attrib:		resw 1 
 30782 0000AD8A <res 00000001>      <1> mkdir_SecPerClust:	resb 1
 30783 0000AD8B <res 00000001>      <1> mkdir_add_new_cluster:	resb 1
 30784 0000AD8C <res 0000000D>      <1> mkdir_Name:		resb 13
 30785                              <1> ; 27/02/2016
 30786 0000AD99 <res 00000001>      <1> RmDir_MultiClusters:	resb 1  
 30787 0000AD9A <res 00000002>      <1> RmDir_DirEntryOffset:	resw 1
 30788 0000AD9C <res 00000004>      <1> RmDir_ParentDirCluster: resd 1
 30789 0000ADA0 <res 00000004>      <1> RmDir_DirLastCluster:   resd 1
 30790 0000ADA4 <res 00000004>      <1> RmDir_PreviousCluster:  resd 1
 30791                              <1> 
 30792                              <1> ; 22/02/2016
 30793 0000ADA8 <res 00000001>      <1> UPDLMDT_CDirLevel:	resb 1
 30794 0000ADA9 <res 00000004>      <1> UPDLMDT_CDirFCluster:	resd 1
 30795                              <1> 	
 30796 0000ADAD <res 00000003>      <1> alignb 4
 30797                              <1> ; DRV_FAT.ASM ; 21/08/2011
 30798 0000ADB0 <res 00000004>      <1> gffc_next_free_cluster:  resd 1
 30799 0000ADB4 <res 00000004>      <1> gffc_first_free_cluster: resd 1
 30800 0000ADB8 <res 00000004>      <1> gffc_last_free_cluster:  resd 1
 30801                              <1> 
 30802                              <1> ; 22/02/2016
 30803 0000ADBC <res 00000004>      <1> ClusterValue:	resd 1
 30804 0000ADC0 <res 00000001>      <1> resb 1
 30805 0000ADC1 <res 00000001>      <1> CFS_error:  resb 1
 30806 0000ADC2 <res 00000001>      <1> CFS_OPType: resb 1
 30807 0000ADC3 <res 00000001>      <1> CFS_Drv:    resb 1
 30808 0000ADC4 <res 00000004>      <1> CFS_CC:	    resd 1
 30809 0000ADC8 <res 00000004>      <1> CFS_FAT32FSINFOSEC: resd 1
 30810 0000ADCC <res 00000004>      <1> CFS_FAT32FC: resd 1
 30811                              <1> 
 30812                              <1> ; 27/02/2016
 30813                              <1> ;alignb 4
 30814 0000ADD0 <res 00000004>      <1> glc_prevcluster: resd 1 ; DRV_FAT.ASM (21/08/2011)
 30815                              <1> 
 30816                              <1> ; DIR.ASM
 30817 0000ADD4 <res 00000002>      <1> DLN_EntryNumber: resw 1
 30818 0000ADD6 <res 00000001>      <1> DLN_40h:	 resb 1
 30819                              <1> ; 28/02/2016
 30820 0000ADD7 <res 00000001>      <1> TCC_FATErr:	 resb 1 ; DRV_FAT.ASM
 30821                              <1> 
 30822                              <1> alignb 4
 30823                              <1> ; DIR.ASM (09/10/2011)
 30824 0000ADD8 <res 00000002>      <1> LCDE_EntryIndex: resw 1 ; LCDE_EntryOffset
 30825 0000ADDA <res 00000002>      <1> LCDE_ClusterSN:  resw 1
 30826 0000ADDC <res 00000004>      <1> LCDE_Cluster: 	 resd 1
 30827 0000ADE0 <res 00000004>      <1> LCDE_ByteOffset: resd 1
 30828                                  ; 24/01/2016
 30829                                  %include 'ubss.s'	; UNINITIALIZED KERNEL (USER) DATA
 30830                              <1> ; ****************************************************************************
 30831                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.0) - UNINITIALIZED USER DATA : ubss.s
 30832                              <1> ; ----------------------------------------------------------------------------
 30833                              <1> ; Last Update: 24/01/2016
 30834                              <1> ; ----------------------------------------------------------------------------
 30835                              <1> ; Beginning: 24/01/2016
 30836                              <1> ; ----------------------------------------------------------------------------
 30837                              <1> ; Assembler: NASM version 2.11 (trdos386.s)
 30838                              <1> ; ----------------------------------------------------------------------------
 30839                              <1> ; Derived from 'Retro UNIX 386 Kernel - v0.2.1.0' source code by Erdogan Tan
 30840                              <1> ; ux.s (04/12/2015)
 30841                              <1> ; ****************************************************************************
 30842                              <1> 
 30843                              <1> ; Retro UNIX 386 v1 Kernel - ux.s
 30844                              <1> ; Last Modification: 04/12/2015
 30845                              <1> ;
 30846                              <1> ; ///////// RETRO UNIX 386 V1 SYSTEM DEFINITIONS ///////////////
 30847                              <1> ; (Modified from 
 30848                              <1> ;	Retro UNIX 8086 v1 system definitions in 'UNIX.ASM', 01/09/2014)
 30849                              <1> ; ((UNIX.ASM (RETRO UNIX 8086 V1 Kernel), 11/03/2013 - 01/09/2014))
 30850                              <1> ; ----------------------------------------------------------------------------
 30851                              <1> ; Derived from UNIX Operating System (v1.0 for PDP-11) 
 30852                              <1> ; (Original) Source Code by Ken Thompson (1971-1972)
 30853                              <1> ; <Bell Laboratories (17/3/1972)>
 30854                              <1> ; <Preliminary Release of UNIX Implementation Document>
 30855                              <1> ; (Section E10 (17/3/1972) - ux.s)
 30856                              <1> ; ****************************************************************************
 30857                              <1> 
 30858                              <1> alignb 2
 30859                              <1> 
 30860                              <1> inode:
 30861                              <1> 	; 11/03/2013. 
 30862                              <1> 	;Derived from UNIX v1 source code 'inode' structure (ux).
 30863                              <1> 	;i.
 30864                              <1> 
 30865 0000ADE4 <res 00000002>      <1> 	i.flgs:	 resw 1
 30866 0000ADE6 <res 00000001>      <1> 	i.nlks:	 resb 1
 30867 0000ADE7 <res 00000001>      <1> 	i.uid:	 resb 1
 30868 0000ADE8 <res 00000002>      <1>         i.size:  resw 1 ; size
 30869 0000ADEA <res 00000010>      <1> 	i.dskp:	 resw 8 ; 16 bytes
 30870 0000ADFA <res 00000004>      <1> 	i.ctim:	 resd 1
 30871 0000ADFE <res 00000004>      <1> 	i.mtim:	 resd 1
 30872 0000AE02 <res 00000002>      <1> 	i.rsvd:  resw 1 ; Reserved (ZERO/Undefined word for UNIX v1.)
 30873                              <1> 
 30874                              <1> I_SIZE	equ $ - inode 
 30875                              <1> 
 30876                              <1> process:
 30877                              <1> 	; 06/05/2015
 30878                              <1> 	; 11/03/2013 - 05/02/2014
 30879                              <1> 	;Derived from UNIX v1 source code 'proc' structure (ux).
 30880                              <1> 	;p.
 30881                              <1> 	
 30882 0000AE04 <res 00000020>      <1>         p.pid:   resw nproc
 30883 0000AE24 <res 00000020>      <1>         p.ppid:  resw nproc
 30884 0000AE44 <res 00000020>      <1>         p.break: resw nproc
 30885 0000AE64 <res 00000010>      <1>         p.ttyc:  resb nproc ; console tty in Retro UNIX 8086 v1.
 30886 0000AE74 <res 00000010>      <1> 	p.waitc: resb nproc ; waiting channel in Retro UNIX 8086 v1.
 30887 0000AE84 <res 00000010>      <1> 	p.link:	 resb nproc
 30888 0000AE94 <res 00000010>      <1> 	p.stat:	 resb nproc
 30889                              <1> 
 30890                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 fetaure only !) 
 30891 0000AEA4 <res 00000040>      <1> 	p.upage: resd nproc ; Physical address of the process's
 30892                              <1> 			    ; 'user' structure	
 30893                              <1> 
 30894                              <1> 
 30895                              <1> P_SIZE	equ $ - process
 30896                              <1> 
 30897                              <1> 
 30898                              <1> ; fsp table (original UNIX v1)
 30899                              <1> ;
 30900                              <1> ;Entry
 30901                              <1> ;          15                                      0
 30902                              <1> ;  1     |---|---------------------------------------|
 30903                              <1> ;        |r/w|       i-number of open file           |
 30904                              <1> ;        |---|---------------------------------------| 
 30905                              <1> ;        |               device number               |
 30906                              <1> ;        |-------------------------------------------|
 30907                              <1> ;    (*) | offset pointer, i.e., r/w pointer to file |
 30908                              <1> ;        |-------------------------------------------| 
 30909                              <1> ;        |  flag that says    | number of processes  |
 30910                              <1> ;        |   file deleted     | that have file open  |
 30911                              <1> ;        |-------------------------------------------| 
 30912                              <1> ;  2     |                                           |
 30913                              <1> ;        |-------------------------------------------| 
 30914                              <1> ;        |                                           |
 30915                              <1> ;        |-------------------------------------------|
 30916                              <1> ;        |                                           |
 30917                              <1> ;        |-------------------------------------------|
 30918                              <1> ;        |                                           |
 30919                              <1> ;        |-------------------------------------------| 
 30920                              <1> ;  3     |                                           | 
 30921                              <1> ;        |                                           |  
 30922                              <1> ;
 30923                              <1> ; (*) Retro UNIX 386 v1 modification: 32 bit offset pointer 
 30924                              <1> 
 30925                              <1> 
 30926                              <1> ; 15/04/2015
 30927 0000AEE4 <res 000001F4>      <1> fsp:	 resb nfiles * 10 ; 11/05/2015 (8 -> 10)
 30928 0000B0D8 <res 00000018>      <1> bufp:	 resd (nbuf+2) ; will be initialized 
 30929 0000B0F0 <res 00000002>      <1> ii:	 resw 1
 30930 0000B0F2 <res 00000002>      <1> idev:	 resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
 30931 0000B0F4 <res 00000002>      <1> cdev:    resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
 30932                              <1> ; 18/05/2015
 30933                              <1> ; 26/04/2013 device/drive parameters (Retro UNIX 8086 v1 feature only!)
 30934                              <1> ; 'UNIX' device numbers (as in 'cdev' and 'u.cdrv')
 30935                              <1> ;	0 -> root device (which has Retro UNIX 8086 v1 file system)
 30936                              <1> ; 	1 -> mounted device (which has Retro UNIX 8086 v1 file system)
 30937                              <1> ; 'Retro UNIX 8086 v1' device numbers: (for disk I/O procedures)
 30938                              <1> ;	0 -> fd0 (physical drive, floppy disk 1), physical drive number = 0
 30939                              <1> ;	1 -> fd1 (physical drive, floppy disk 2), physical drive number = 1
 30940                              <1> ;	2 -> hd0 (physical drive, hard disk 1), physical drive number = 80h
 30941                              <1> ;	3 -> hd1 (physical drive, hard disk 2), physical drive number = 81h
 30942                              <1> ;	4 -> hd2 (physical drive, hard disk 3), physical drive number = 82h
 30943                              <1> ;	5 -> hd3 (physical drive, hard disk 4), physical drive number = 83h
 30944 0000B0F6 <res 00000001>      <1> rdev:	 resb 1 ; root device number ; Retro UNIX 8086 v1 feature only!
 30945                              <1> 	        ; as above, for physical drives numbers in following table
 30946 0000B0F7 <res 00000001>      <1> mdev:	 resb 1 ; mounted device number ; Retro UNIX 8086 v1 feature only!
 30947                              <1> ; 15/04/2015
 30948 0000B0F8 <res 00000001>      <1> active:	 resb 1 
 30949 0000B0F9 <res 00000001>      <1> 	 resb 1 ; 09/06/2015
 30950 0000B0FA <res 00000002>      <1> mnti:	 resw 1
 30951 0000B0FC <res 00000002>      <1> mpid:	 resw 1
 30952 0000B0FE <res 00000002>      <1> rootdir: resw 1
 30953                              <1> ; 14/02/2014
 30954                              <1> ; Major Modification: Retro UNIX 8086 v1 feature only!
 30955                              <1> ;		      Single level run queue
 30956                              <1> ;		      (in order to solve sleep/wakeup lock)
 30957 0000B100 <res 00000002>      <1> runq:	 resw 1
 30958 0000B102 <res 00000001>      <1> imod:	 resb 1
 30959 0000B103 <res 00000001>      <1> smod:	 resb 1
 30960 0000B104 <res 00000001>      <1> mmod:	 resb 1
 30961 0000B105 <res 00000001>      <1> sysflg:	 resb 1
 30962                              <1> 
 30963 0000B106 <res 00000002>      <1> alignb 4
 30964                              <1> 
 30965                              <1> user:
 30966                              <1> 	; 04/12/2015 
 30967                              <1> 	; 18/10/2015
 30968                              <1> 	; 12/10/2015
 30969                              <1> 	; 21/09/2015
 30970                              <1> 	; 24/07/2015
 30971                              <1> 	; 16/06/2015
 30972                              <1> 	; 09/06/2015
 30973                              <1> 	; 11/05/2015
 30974                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit modifications)
 30975                              <1> 	; 10/10/2013
 30976                              <1> 	; 11/03/2013. 
 30977                              <1> 	;Derived from UNIX v1 source code 'user' structure (ux).
 30978                              <1> 	;u.
 30979                              <1> 
 30980 0000B108 <res 00000004>      <1> 	u.sp:	  resd 1 ; esp (kernel stack at the beginning of 'sysent')
 30981 0000B10C <res 00000004>      <1> 	u.usp:	  resd 1 ; esp (kernel stack points to user's registers)
 30982 0000B110 <res 00000004>      <1> 	u.r0:	  resd 1 ; eax
 30983 0000B114 <res 00000002>      <1> 	u.cdir:	  resw 1
 30984 0000B116 <res 0000000A>      <1> 	u.fp:	  resb 10
 30985 0000B120 <res 00000004>      <1> 	u.fofp:	  resd 1
 30986 0000B124 <res 00000004>      <1> 	u.dirp:	  resd 1
 30987 0000B128 <res 00000004>      <1> 	u.namep:  resd 1
 30988 0000B12C <res 00000004>      <1> 	u.off:	  resd 1
 30989 0000B130 <res 00000004>      <1> 	u.base:	  resd 1
 30990 0000B134 <res 00000004>      <1> 	u.count:  resd 1
 30991 0000B138 <res 00000004>      <1> 	u.nread:  resd 1
 30992 0000B13C <res 00000004>      <1> 	u.break:  resd 1 ; break
 30993 0000B140 <res 00000002>      <1> 	u.ttyp:	  resw 1 
 30994 0000B142 <res 00000010>      <1> 	u.dirbuf: resb 16 ; 04/12/2015 (10 -> 16) 
 30995                              <1> 	;u.pri:	  resw 1 ; 14/02/2014
 30996 0000B152 <res 00000001>      <1> 	u.quant:  resb 1 ; Retro UNIX 8086 v1 Feature only ! (uquant)
 30997 0000B153 <res 00000001>      <1> 	u.pri:	  resb 1 ; 
 30998 0000B154 <res 00000002>      <1> 	u.intr:	  resw 1
 30999 0000B156 <res 00000002>      <1> 	u.quit:	  resw 1
 31000                              <1> 	;u.emt:	  resw 1 ; 10/10/2013
 31001 0000B158 <res 00000002>      <1> 	u.ilgins: resw 1
 31002 0000B15A <res 00000002>      <1> 	u.cdrv:	  resw 1 ; cdev
 31003 0000B15C <res 00000001>      <1> 	u.uid:	  resb 1 ; uid
 31004 0000B15D <res 00000001>      <1> 	u.ruid:	  resb 1
 31005 0000B15E <res 00000001>      <1> 	u.bsys:	  resb 1
 31006 0000B15F <res 00000001>      <1> 	u.uno:	  resb 1
 31007 0000B160 <res 00000004>      <1>         u.upage:  resd 1 ; 16/04/2015 - Retro Unix 386 v1 feature only !
 31008                              <1> 	; tty number (rtty, rcvt, wtty)
 31009 0000B164 <res 00000001>      <1> 	u.ttyn:	  resb 1 ; 28/07/2013 - Retro Unix 8086 v1 feature only !
 31010                              <1> 	; last error number
 31011 0000B165 <res 00000004>      <1> 	u.error:  resd 1 ; 28/07/2013 - 09/03/2015 
 31012                              <1> 		        ; Retro UNIX 8086/386 v1 feature only!
 31013 0000B169 <res 00000004>      <1> 	u.pgdir:  resd 1 ; 09/03/2015 (page dir addr of process)
 31014 0000B16D <res 00000004>      <1> 	u.ppgdir: resd 1 ; 06/05/2015 (page dir addr of the parent process)
 31015 0000B171 <res 00000004>      <1> 	u.pbase:  resd 1 ; 20/05/2015 (physical base/transfer address)
 31016 0000B175 <res 00000002>      <1> 	u.pcount: resw 1 ; 20/05/2015 (byte -transfer- count for page)
 31017                              <1> 	;u.pncount: resw 1 
 31018                              <1> 		; 16/06/2015 (byte -transfer- count for page, 'namei', 'mkdir')
 31019                              <1> 	;u.pnbase:  resd 1 
 31020                              <1> 		; 16/06/2015 (physical base/transfer address, 'namei', 'mkdir')
 31021                              <1> 			 ; 09/06/2015
 31022 0000B177 <res 00000001>      <1> 	u.kcall:  resb 1 ; The caller is 'namei' (dskr) or 'mkdir' (dskw) sign		
 31023 0000B178 <res 00000001>      <1> 	u.brwdev: resb 1 ; Block device number for direct I/O (bread & bwrite)
 31024                              <1> 			 ; 24/07/2015 - 24/06/2015
 31025                              <1> 	;u.args:  resd 1 ; arguments list (line) offset from start of [u.upage]
 31026                              <1> 			 ; (arg list/line is from offset [u.args] to 4096 in [u.upage])
 31027                              <1> 			 ; ([u.args] points to argument count -argc- address offset)
 31028                              <1>  			 ; 24/06/2015	  	
 31029                              <1> 	;u.core:  resd 1 ; physical start address of user's memory space (for sys exec)
 31030                              <1> 	;u.ecore: resd 1 ; physical end address of user's memory space (for sys exec)
 31031                              <1> 			 ; 21/09/2015 (debugging - page fault analyze)
 31032 0000B179 <res 00000004>      <1> 	u.pfcount: resd 1 ; page fault count for (this) process (for sys geterr)
 31033                              <1> 
 31034 0000B17D <res 00000003>      <1> alignb 4
 31035                              <1> 
 31036                              <1> U_SIZE	equ $ - user
 31037                              <1> 
 31038                              <1> ; 18/10/2015 - Retro UNIX 386 v1 (local variables for 'namei' and 'sysexec')
 31039 0000B180 <res 00000004>      <1> pcore:  resd 1 ; physical start address of user's memory space (for sys exec)
 31040 0000B184 <res 00000004>      <1> ecore:  resd 1 ; physical start address of user's memory space (for sys exec)
 31041 0000B188 <res 00000004>      <1> nbase:	resd 1	; physical base address for 'namei' & 'sysexec'
 31042 0000B18C <res 00000002>      <1> ncount: resw 1	; remain byte count in page for 'namei' & 'sysexec'
 31043 0000B18E <res 00000002>      <1> argc:	resw 1	; argument count for 'sysexec'
 31044 0000B190 <res 00000004>      <1> argv:	resd 1	; argument list (recent) address for 'sysexec'
 31045                              <1> 
 31046                              <1> ; 03/06/2015 - Retro UNIX 386 v1 Beginning
 31047                              <1> ; 07/04/2013 - 31/07/2013 - Retro UNIX 8086 v1
 31048 0000B194 <res 00000001>      <1> rw: 	 resb 1 ;; Read/Write sign (iget)
 31049                              <1> 
 31050                              <1> ;alignb 4
 31051                              <1> 
 31052                              <1> ; 22/08/2015
 31053 0000B195 <res 00000820>      <1> buffer: resb nbuf * 520
 31054                              <1> 
 31055 0000B9B5 <res 00000008>      <1> sb0:	resd 2
 31056                              <1> ;s:
 31057                              <1> ; (root disk) super block buffer
 31058                              <1> systm:
 31059                              <1> 	; 13/11/2015 (Retro UNIX 386 v1)	
 31060                              <1> 	; 11/03/2013. 
 31061                              <1> 	;Derived from UNIX v1 source code 'systm' structure (ux).
 31062                              <1> 	;s.
 31063                              <1> 
 31064 0000B9BD <res 00000002>      <1> 	resw 1
 31065 0000B9BF <res 00000168>      <1> 	resb 360 ; 2880 sectors ; original UNIX v1 value: 128
 31066 0000BB27 <res 00000002>      <1> 	resw 1
 31067 0000BB29 <res 00000020>      <1> 	resb 32	 ; 256+40 inodes ; original UNIX v1 value: 64
 31068 0000BB49 <res 00000004>      <1> 	s.time:	 resd 1
 31069 0000BB4D <res 00000004>      <1> 	s.syst:	 resd 1
 31070 0000BB51 <res 00000004>      <1>         s.wait_: resd 1 ; wait
 31071 0000BB55 <res 00000004>      <1> 	s.idlet: resd 1
 31072 0000BB59 <res 00000004>      <1> 	s.chrgt: resd 1
 31073 0000BB5D <res 00000002>      <1> 	s.drerr: resw 1
 31074                              <1> 
 31075                              <1> S_SIZE	equ $ - systm
 31076                              <1> 
 31077 0000BB5F <res 0000005E>      <1> 	resb 512-S_SIZE ; 03/06/2015	 
 31078                              <1> 
 31079 0000BBBD <res 00000008>      <1> sb1:	resd 2
 31080                              <1> ; (mounted disk) super block buffer
 31081                              <1> mount:	
 31082 0000BBC5 <res 00000200>      <1> 	resb 512  ; 03/06/2015
 31083                              <1> 
 31084                              <1> ;/ ux -- unix
 31085                              <1> ;
 31086                              <1> ;systm:
 31087                              <1> ;
 31088                              <1> ;	.=.+2
 31089                              <1> ;	.=.+128.
 31090                              <1> ;	.=.+2
 31091                              <1> ;	.=.+64.
 31092                              <1> ;	s.time: .=.+4
 31093                              <1> ;	s.syst: .=.+4
 31094                              <1> ;	s.wait: .=.+4
 31095                              <1> ;	s.idlet:.=.+4
 31096                              <1> ;	s.chrgt:.=.+4
 31097                              <1> ;	s.drerr:.=.+2
 31098                              <1> ;inode:
 31099                              <1> ;	i.flgs: .=.+2
 31100                              <1> ;	i.nlks: .=.+1
 31101                              <1> ;	i.uid:  .=.+1
 31102                              <1> ;	i.size: .=.+2
 31103                              <1> ;	i.dskp: .=.+16.
 31104                              <1> ;	i.ctim: .=.+4
 31105                              <1> ;	i.mtim: .=.+4
 31106                              <1> ;	. = inode+32.
 31107                              <1> ;mount:	.=.+1024.
 31108                              <1> ;proc:
 31109                              <1> ;	p.pid:  .=.+[2*nproc]
 31110                              <1> ;	p.dska: .=.+[2*nproc]
 31111                              <1> ;	p.ppid: .=.+[2*nproc]
 31112                              <1> ;	p.break:.=.+[2*nproc]
 31113                              <1> ;	p.link: .=.+nproc
 31114                              <1> ;	p.stat: .=.+nproc
 31115                              <1> ;tty:
 31116                              <1> ;	. = .+[ntty*8.]
 31117                              <1> ;fsp:	.=.+[nfiles*8.]
 31118                              <1> ;bufp:	.=.+[nbuf*2]+6
 31119                              <1> ;sb0:	.=.+8
 31120                              <1> ;sb1:	.=.+8
 31121                              <1> ;swp:	.=.+8
 31122                              <1> ;ii:	.=.+2
 31123                              <1> ;idev:	.=.+2
 31124                              <1> ;cdev:	.=.+2
 31125                              <1> ;deverr: .=.+12.
 31126                              <1> ;active: .=.+2
 31127                              <1> ;rfap:	.=.+2
 31128                              <1> ;rkap:	.=.+2
 31129                              <1> ;tcap:	.=.+2
 31130                              <1> ;tcstate:.=.+2
 31131                              <1> ;tcerrc: .=.+2
 31132                              <1> ;mnti:	.=.+2
 31133                              <1> ;mntd:	.=.+2
 31134                              <1> ;mpid:	.=.+2
 31135                              <1> ;clockp: .=.+2
 31136                              <1> ;rootdir:.=.+2
 31137                              <1> ;toutt:	.=.+16.
 31138                              <1> ;touts: .=.+32.
 31139                              <1> ;runq:	.=.+6
 31140                              <1> ;
 31141                              <1> ;wlist:	.=.+40.
 31142                              <1> ;cc:	.=.+30.
 31143                              <1> ;cf:	.=.+31.
 31144                              <1> ;cl:	.=.+31.
 31145                              <1> ;clist:	.=.+510.
 31146                              <1> ;imod:	.=.+1
 31147                              <1> ;smod:	.=.+1
 31148                              <1> ;mmod:	.=.+1
 31149                              <1> ;uquant: .=.+1
 31150                              <1> ;sysflg: .=.+1
 31151                              <1> ;pptiflg:.=.+1
 31152                              <1> ;ttyoch: .=.+1
 31153                              <1> ; .even
 31154                              <1> ; .=.+100.; sstack:
 31155                              <1> ;buffer: .=.+[ntty*140.]
 31156                              <1> ;	.=.+[nbuf*520.]
 31157                              <1> ;
 31158                              <1> ; . = core-64.
 31159                              <1> ;user:
 31160                              <1> ;	u.sp:    .=.+2
 31161                              <1> ;	u.usp:   .=.+2
 31162                              <1> ;	u.r0:    .=.+2
 31163                              <1> ;	u.cdir:  .=.+2
 31164                              <1> ;	u.fp:    .=.+10.
 31165                              <1> ;	u.fofp:  .=.+2
 31166                              <1> ;	u.dirp:  .=.+2
 31167                              <1> ;	u.namep: .=.+2
 31168                              <1> ;	u.off:   .=.+2
 31169                              <1> ;	u.base:  .=.+2
 31170                              <1> ;	u.count: .=.+2
 31171                              <1> ;	u.nread: .=.+2
 31172                              <1> ;	u.break: .=.+2
 31173                              <1> ;	u.ttyp:  .=.+2
 31174                              <1> ;	u.dirbuf:.=.+10.
 31175                              <1> ;	u.pri:   .=.+2
 31176                              <1> ;	u.intr:  .=.+2
 31177                              <1> ;	u.quit:  .=.+2
 31178                              <1> ;	u.emt:   .=.+2
 31179                              <1> ;	u.ilgins:.=.+2
 31180                              <1> ;	u.cdev:  .=.+2
 31181                              <1> ;	u.uid:   .=.+1
 31182                              <1> ;	u.ruid:  .=.+1
 31183                              <1> ;	u.bsys:  .=.+1
 31184                              <1> ;	u.uno:   .=.+1
 31185                              <1> ;. = core
 31186                                  
 31187                                  ;; Memory (swap) Data (11/03/2015)
 31188                                  ; 09/03/2015
 31189 0000BDC5 <res 00000002>          swpq_count: resw 1 ; count of pages on the swap queue
 31190 0000BDC7 <res 00000004>          swp_drv:    resd 1 ; logical drive description table address of the swap drive/disk
 31191 0000BDCB <res 00000004>          swpd_size:  resd 1 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
 31192 0000BDCF <res 00000004>          swpd_free:  resd 1 ; free page blocks (4096 bytes) on swap disk/drive (logical)
 31193 0000BDD3 <res 00000004>          swpd_next:  resd 1 ; next free page block
 31194 0000BDD7 <res 00000004>          swpd_last:  resd 1 ; last swap page block	
 31195                                  
 31196 0000BDDB <res 00000001>          alignb 4
 31197                                  
 31198                                  ; 10/07/2015
 31199                                  ; 28/08/2014
 31200 0000BDDC <res 00000004>          error_code:	resd 1
 31201                                  ; 29/08/2014
 31202 0000BDE0 <res 00000004>          FaultOffset: 	resd 1
 31203                                  ; 21/09/2015
 31204 0000BDE4 <res 00000004>          PF_Count:	resd 1	; total page fault count
 31205                                  		       	; (for debugging - page fault analyze)
 31206                                  		 	; 'page_fault_handler' (memory.inc)
 31207                                  			; 'sysgeterr' (u9.s)
 31208                                  ;; 21/08/2015
 31209                                  ;;buffer: resb (nbuf*520) ;; sysdefs.inc, ux.s
 31210                                  ;; ((NOTE: nbuf = 6, buffer r/w problem/bug here !? when nbuf > 4))
 31211                                  
 31212                                  bss_end:
 31213                                  
 31214                                  ; 27/12/2013
 31215                                  _end:  ; end of kernel code
